mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-02 02:09:27 -06:00
WIP
This commit is contained in:
+35
-29
@@ -22,6 +22,8 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import {beforeAll, describe, expect, it} from 'vitest';
|
||||
|
||||
import {CompilationEnvironment} from '../lib/compilation-env.js';
|
||||
import {JavaCompiler} from '../lib/compilers/index.js';
|
||||
import * as utils from '../lib/utils.js';
|
||||
@@ -56,51 +58,55 @@ describe('Basic compiler setup', () => {
|
||||
// it's not possible to determine the main class file before compilation/parsing
|
||||
const compiler = new JavaCompiler(info, env);
|
||||
if (process.platform === 'win32') {
|
||||
compiler.getOutputFilename('/tmp/').should.equal('\\tmp\\example.class');
|
||||
expect(compiler.getOutputFilename('/tmp/')).toEqual('\\tmp\\example.class');
|
||||
} else {
|
||||
compiler.getOutputFilename('/tmp/').should.equal('/tmp/example.class');
|
||||
expect(compiler.getOutputFilename('/tmp/')).toEqual('/tmp/example.class');
|
||||
}
|
||||
});
|
||||
|
||||
describe('Forbidden compiler arguments', () => {
|
||||
it('JavaCompiler should not allow -d parameter', () => {
|
||||
const compiler = new JavaCompiler(info, env);
|
||||
compiler
|
||||
.filterUserOptions(['hello', '-d', '--something', '--something-else'])
|
||||
.should.deep.equal(['hello', '--something-else']);
|
||||
compiler.filterUserOptions(['hello', '-d']).should.deep.equal(['hello']);
|
||||
compiler.filterUserOptions(['-d', 'something', 'something-else']).should.deep.equal(['something-else']);
|
||||
expect(compiler.filterUserOptions(['hello', '-d', '--something', '--something-else'])).toEqual([
|
||||
'hello',
|
||||
'--something-else',
|
||||
]);
|
||||
expect(compiler.filterUserOptions(['hello', '-d'])).toEqual(['hello']);
|
||||
expect(compiler.filterUserOptions(['-d', 'something', 'something-else'])).toEqual(['something-else']);
|
||||
});
|
||||
|
||||
it('JavaCompiler should not allow -s parameter', () => {
|
||||
const compiler = new JavaCompiler(info, env);
|
||||
compiler
|
||||
.filterUserOptions(['hello', '-s', '--something', '--something-else'])
|
||||
.should.deep.equal(['hello', '--something-else']);
|
||||
compiler.filterUserOptions(['hello', '-s']).should.deep.equal(['hello']);
|
||||
compiler.filterUserOptions(['-s', 'something', 'something-else']).should.deep.equal(['something-else']);
|
||||
expect(compiler.filterUserOptions(['hello', '-s', '--something', '--something-else'])).toEqual([
|
||||
'hello',
|
||||
'--something-else',
|
||||
]);
|
||||
expect(compiler.filterUserOptions(['hello', '-s'])).toEqual(['hello']);
|
||||
expect(compiler.filterUserOptions(['-s', 'something', 'something-else'])).toEqual(['something-else']);
|
||||
});
|
||||
|
||||
it('JavaCompiler should not allow --source-path parameter', () => {
|
||||
const compiler = new JavaCompiler(info, env);
|
||||
compiler
|
||||
.filterUserOptions(['hello', '--source-path', '--something', '--something-else'])
|
||||
.should.deep.equal(['hello', '--something-else']);
|
||||
compiler.filterUserOptions(['hello', '--source-path']).should.deep.equal(['hello']);
|
||||
compiler
|
||||
.filterUserOptions(['--source-path', 'something', 'something-else'])
|
||||
.should.deep.equal(['something-else']);
|
||||
expect(compiler.filterUserOptions(['hello', '--source-path', '--something', '--something-else'])).toEqual([
|
||||
'hello',
|
||||
'--something-else',
|
||||
]);
|
||||
expect(compiler.filterUserOptions(['hello', '--source-path'])).toEqual(['hello']);
|
||||
expect(compiler.filterUserOptions(['--source-path', 'something', 'something-else'])).toEqual([
|
||||
'something-else',
|
||||
]);
|
||||
});
|
||||
|
||||
it('JavaCompiler should not allow -sourcepath parameter', () => {
|
||||
const compiler = new JavaCompiler(info, env);
|
||||
compiler
|
||||
.filterUserOptions(['hello', '-sourcepath', '--something', '--something-else'])
|
||||
.should.deep.equal(['hello', '--something-else']);
|
||||
compiler.filterUserOptions(['hello', '-sourcepath']).should.deep.equal(['hello']);
|
||||
compiler
|
||||
.filterUserOptions(['-sourcepath', 'something', 'something-else'])
|
||||
.should.deep.equal(['something-else']);
|
||||
expect(compiler.filterUserOptions(['hello', '-sourcepath', '--something', '--something-else'])).toEqual([
|
||||
'hello',
|
||||
'--something-else',
|
||||
]);
|
||||
expect(compiler.filterUserOptions(['hello', '-sourcepath'])).toEqual(['hello']);
|
||||
expect(compiler.filterUserOptions(['-sourcepath', 'something', 'something-else'])).toEqual([
|
||||
'something-else',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -143,9 +149,9 @@ describe('javap parsing', () => {
|
||||
};
|
||||
|
||||
const processed = await compiler.processAsm(result);
|
||||
processed.should.have.property('asm');
|
||||
expect(processed).toHaveProperty('asm');
|
||||
const asmSegments = (processed as {asm: ParsedAsmResultLine[]}).asm;
|
||||
asmSegments.should.deep.equal(expectedSegments);
|
||||
expect(asmSegments).toEqual(expectedSegments);
|
||||
}
|
||||
|
||||
it('should handle errors', async () => {
|
||||
@@ -153,7 +159,7 @@ describe('javap parsing', () => {
|
||||
asm: '<Compilation failed>',
|
||||
};
|
||||
|
||||
(await compiler.processAsm(result)).should.deep.equal([{text: '<Compilation failed>', source: null}]);
|
||||
await expect(compiler.processAsm(result)).resolves.toEqual([{text: '<Compilation failed>', source: null}]);
|
||||
});
|
||||
|
||||
it('Parses simple class with one method', () => {
|
||||
|
||||
Reference in New Issue
Block a user