diff options
author | Rounak Shrestha <66557682+Rounak-stha@users.noreply.github.com> | 2023-10-22 16:00:44 +0545 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-22 12:15:44 +0200 |
commit | bd164adf149d3641145642ef29a17f099a691431 (patch) | |
tree | ed18144941dbb1e0bd360f054eb3a5a9b6b0aa1b | |
parent | 26ab4e6d4b71b10af1b1382976c247d854cb396f (diff) | |
download | compiler-explorer-bd164adf149d3641145642ef29a17f099a691431.tar.gz compiler-explorer-bd164adf149d3641145642ef29a17f099a691431.zip |
Test conversion ts (#5517)gh-9163
-rw-r--r-- | test/demangler-tests.ts (renamed from test/demangler-tests.js) | 82 | ||||
-rw-r--r-- | test/map-file-tests.ts (renamed from test/map-file-tests.js) | 70 | ||||
-rw-r--r-- | test/options-handler.ts (renamed from test/options-handler.js) | 222 | ||||
-rw-r--r-- | test/packager-tests.ts (renamed from test/packager-tests.js) | 2 |
4 files changed, 194 insertions, 182 deletions
diff --git a/test/demangler-tests.js b/test/demangler-tests.ts index be227e6bb..47c970f1e 100644 --- a/test/demangler-tests.js +++ b/test/demangler-tests.ts @@ -22,22 +22,45 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import {unwrap} from '../lib/assert.js'; +import {BaseCompiler} from '../lib/base-compiler.js'; +import {CompilationEnvironment} from '../lib/compilation-env.js'; import {CppDemangler, Win32Demangler} from '../lib/demangler/index.js'; import {PrefixTree} from '../lib/demangler/prefix-tree.js'; import * as exec from '../lib/exec.js'; +import * as properties from '../lib/properties.js'; import {SymbolStore} from '../lib/symbol-store.js'; import * as utils from '../lib/utils.js'; -import {chai, fs, path, resolvePathFromTestRoot} from './utils.js'; +import {chai, fs, makeFakeCompilerInfo, path, resolvePathFromTestRoot} from './utils.js'; const cppfiltpath = 'c++filt'; -class DummyCompiler { - exec(command, args, options) { +class DummyCompiler extends BaseCompiler { + constructor() { + const env = { + ceProps: properties.fakeProps({}), + compilerProps: () => {}, + } as unknown as CompilationEnvironment; + + // using c++ as the compiler needs at least one language + const compiler = makeFakeCompilerInfo({lang: 'c++'}); + + super(compiler, env); + } + override exec(command, args, options) { return exec.execute(command, args, options); } } +class DummyCppDemangler extends CppDemangler { + public override collectLabels = super.collectLabels; +} + +class DummyWin32Demangler extends Win32Demangler { + public override collectLabels = super.collectLabels; +} + const catchCppfiltNonexistence = err => { if (!err.message.startsWith('spawn c++filt')) { throw err; @@ -50,8 +73,7 @@ describe('Basic demangling', function () { asm: [{text: 'Hello, World!'}], }; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); return Promise.all([ demangler.process(result).then(output => { @@ -63,8 +85,7 @@ describe('Basic demangling', function () { it('One label and some asm', function () { const result = {asm: [{text: '_Z6squarei:'}, {text: ' ret'}]}; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); return Promise.all([ demangler @@ -80,8 +101,7 @@ describe('Basic demangling', function () { it('One label and use of a label', function () { const result = {asm: [{text: '_Z6squarei:'}, {text: ' mov eax, $_Z6squarei'}]}; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); return Promise.all([ demangler @@ -109,8 +129,7 @@ describe('Basic demangling', function () { ], }; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); return demangler .process(result) @@ -125,20 +144,20 @@ describe('Basic demangling', function () { it('Should ignore comments (CL)', function () { const result = {asm: [{text: ' call ??3@YAXPEAX_K@Z ; operator delete'}]}; - const demangler = new Win32Demangler(cppfiltpath, new DummyCompiler()); + const demangler = new DummyWin32Demangler(cppfiltpath, new DummyCompiler()); demangler.result = result; demangler.symbolstore = new SymbolStore(); demangler.collectLabels(); const output = demangler.win32RawSymbols; - output.should.deep.equal(['??3@YAXPEAX_K@Z']); + output?.should.deep.equal(['??3@YAXPEAX_K@Z']); }); it('Should ignore comments (CPP)', function () { const result = {asm: [{text: ' call hello ; operator delete'}]}; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); + demangler.result = result; demangler.symbolstore = new SymbolStore(); demangler.collectLabels(); @@ -150,8 +169,8 @@ describe('Basic demangling', function () { it('Should also support ARM branch instructions', () => { const result = {asm: [{text: ' bl _ZN3FooC1Ev'}]}; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); + demangler.result = result; demangler.symbolstore = new SymbolStore(); demangler.collectLabels(); @@ -163,20 +182,20 @@ describe('Basic demangling', function () { it('Should NOT handle undecorated labels', () => { const result = {asm: [{text: '$LN3@caller2:'}]}; - const demangler = new Win32Demangler(cppfiltpath, new DummyCompiler()); + const demangler = new DummyWin32Demangler(cppfiltpath, new DummyCompiler()); demangler.result = result; demangler.symbolstore = new SymbolStore(); demangler.collectLabels(); const output = demangler.win32RawSymbols; - output.should.deep.equal([]); + output?.should.deep.equal([]); }); it('Should ignore comments after jmps', function () { const result = {asm: [{text: ' jmp _Z1fP6mytype # TAILCALL'}]}; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); + demangler.result = result; demangler.symbolstore = new SymbolStore(); demangler.collectLabels(); @@ -188,8 +207,8 @@ describe('Basic demangling', function () { it('Should still work with normal jmps', function () { const result = {asm: [{text: ' jmp _Z1fP6mytype'}]}; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); + demangler.result = result; demangler.symbolstore = new SymbolStore(); demangler.collectLabels(); @@ -211,8 +230,7 @@ describe('Basic demangling', function () { ], }; - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); return Promise.all([ demangler @@ -244,8 +262,8 @@ async function DoDemangleTest(filename) { const resultIn = await readResultFile(filename); const resultOut = await readResultFile(filename + '.demangle'); - const demangler = new CppDemangler(cppfiltpath, new DummyCompiler()); - demangler.demanglerArguments = ['-n']; + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); + return demangler.process(resultIn).should.eventually.deep.equal(resultOut); } @@ -282,7 +300,7 @@ describe('File demangling', () => { }); describe('Demangler prefix tree', () => { - const replacements = new PrefixTree(); + const replacements = new PrefixTree([]); replacements.add('a', 'short_a'); replacements.add('aa', 'long_a'); replacements.add('aa_shouldnotmatch', 'ERROR'); @@ -299,7 +317,7 @@ describe('Demangler prefix tree', () => { replacements.replaceAll('a aa a aa').should.eq('short_a long_a short_a long_a'); }); it('should work with empty replacements', () => { - new PrefixTree().replaceAll('Testing 123').should.eq('Testing 123'); + new PrefixTree([]).replaceAll('Testing 123').should.eq('Testing 123'); }); it('should leave unmatching text alone', () => { replacements @@ -310,9 +328,9 @@ describe('Demangler prefix tree', () => { replacements.replaceAll('Everyone loves an aardvark').should.eq('Everyone loves short_an long_ardvshort_ark'); }); it('should find exact matches', () => { - replacements.findExact('a').should.eq('short_a'); - replacements.findExact('aa').should.eq('long_a'); - replacements.findExact('aa_shouldnotmatch').should.eq('ERROR'); + unwrap(replacements.findExact('a')).should.eq('short_a'); + unwrap(replacements.findExact('aa')).should.eq('long_a'); + unwrap(replacements.findExact('aa_shouldnotmatch')).should.eq('ERROR'); }); it('should find not find mismatches', () => { chai.expect(replacements.findExact('aaa')).to.be.null; diff --git a/test/map-file-tests.js b/test/map-file-tests.ts index 4305ae123..9be73d19a 100644 --- a/test/map-file-tests.js +++ b/test/map-file-tests.ts @@ -22,6 +22,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import {unwrap} from '../lib/assert.js'; import {MapFileReaderDelphi} from '../lib/mapfiles/map-file-delphi.js'; import {MapFileReaderVS} from '../lib/mapfiles/map-file-vs.js'; @@ -49,26 +50,26 @@ describe('Code Segments', function () { reader.segments.length.should.equal(1); let info = reader.getSegmentInfoByStartingAddress('0001', 0x2838); - info.unitName.should.equal('output.pas'); + expect(unwrap(info).unitName).to.equal('output.pas'); info = reader.getSegmentInfoByStartingAddress(undefined, reader.getSegmentOffset('0001') + 0x2838); - info.unitName.should.equal('output.pas'); + expect(unwrap(info).unitName).to.equal('output.pas'); info = reader.getSegmentInfoByStartingAddress('0001', 0x1234); expect(info, 'Address should not be a Start for any segment').to.be.undefined; info = reader.getSegmentInfoAddressIsIn('0001', 0x2838 + 0x10); - info.unitName.should.equal('output.pas'); + expect(unwrap(info).unitName).to.equal('output.pas'); info = reader.getSegmentInfoAddressIsIn(undefined, reader.getSegmentOffset('0001') + 0x2838 + 0x10); - info.unitName.should.equal('output.pas'); + expect(unwrap(info).unitName).to.equal('output.pas'); info = reader.getSegmentInfoAddressIsIn('0001', reader.getSegmentOffset('0001') + 0x2838 + 0x80 + 1); expect(info, 'Address should not be in any segment').to.be.undefined; info = reader.getSegmentInfoByUnitName('output.pas'); - info.unitName.should.equal('output.pas'); - info.addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); + expect(unwrap(info).unitName).to.equal('output.pas'); + unwrap(info).addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); }); it('Not include this segment', function () { @@ -89,13 +90,13 @@ describe('Code Segments', function () { reader.segments.length.should.equal(1); let info = reader.getSegmentInfoByStartingAddress('0001', 0x2838); - info.addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); + unwrap(info).addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); info = reader.getSegmentInfoByStartingAddress(undefined, 0x403838); - info.addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); + unwrap(info).addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); info = reader.getSegmentInfoAddressIsIn(undefined, reader.getSegmentOffset('0001') + 0x2838 + 0x10); - info.addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); + unwrap(info).addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2838); info = reader.getSegmentInfoAddressIsIn('0001', reader.getSegmentOffset('0001') + 0x2837); expect(info).to.be.undefined; @@ -109,12 +110,12 @@ describe('Code Segments', function () { ); let info = reader.getSegmentInfoByStartingAddress('0002', 0); - info.unitName.should.equal('ConsoleApplication1.obj'); + expect(unwrap(info).unitName).to.equal('ConsoleApplication1.obj'); reader.getSegmentOffset('0002').should.equal(0x411000); info = reader.getSegmentInfoByStartingAddress(undefined, 0x411000); - info.unitName.should.equal('ConsoleApplication1.obj'); + expect(unwrap(info).unitName).to.equal('ConsoleApplication1.obj'); }); }); @@ -125,12 +126,12 @@ describe('Symbol info', function () { reader.namedAddresses.length.should.equal(1); let info = reader.getSymbolAt('0001', 0x2838); - info.should.not.equal(undefined, 'Symbol Square should have been returned 1'); - info.displayName.should.equal('Square'); + expect(info).to.not.equal(undefined, 'Symbol Square should have been returned 1'); + expect(unwrap(info).displayName).to.equal('Square'); info = reader.getSymbolAt(undefined, reader.getSegmentOffset('0001') + 0x2838); - info.should.not.equal(undefined, 'Symbol Square should have been returned 2'); - info.displayName.should.equal('Square'); + expect(info).to.not.equal(undefined, 'Symbol Square should have been returned 2'); + expect(unwrap(info).displayName).to.equal('Square'); }); it('Delphi-Map D2009 symbol test', function () { @@ -139,12 +140,13 @@ describe('Symbol info', function () { reader.namedAddresses.length.should.equal(1); let info = reader.getSymbolAt('0001', 0x2c4c); - info.should.not.equal(undefined, 'Symbol MaxArray should have been returned'); - info.displayName.should.equal('output.MaxArray'); + expect(info).to.not.equal(undefined, 'Symbol MaxArray should have been returned'); + expect(unwrap(info).displayName).to.equal('output.MaxArray'); + //todo should not be undefined info = reader.getSymbolAt(undefined, reader.getSegmentOffset('0001') + 0x2c4c); - info.should.not.equal(undefined, 'Symbol MaxArray should have been returned'); - info.displayName.should.equal('output.MaxArray'); + expect(info).to.not.equal(undefined, 'Symbol MaxArray should have been returned'); + expect(unwrap(info).displayName).to.equal('output.MaxArray'); }); it('VS-Map symbol test', function () { @@ -155,12 +157,12 @@ describe('Symbol info', function () { reader.namedAddresses.length.should.equal(1); let info = reader.getSymbolAt('0002', 0x6b0); - info.should.not.equal(undefined, 'Symbol start_verify_argument should have been returned 1'); - info.displayName.should.equal('??$__vcrt_va_start_verify_argument_type@QBD@@YAXXZ'); + expect(info).to.not.equal(undefined, 'Symbol start_verify_argument should have been returned 1'); + expect(unwrap(info).displayName).to.equal('??$__vcrt_va_start_verify_argument_type@QBD@@YAXXZ'); info = reader.getSymbolAt(undefined, 0x4116b0); - info.should.not.equal(undefined, 'Symbol start_verify_argument should have been returned 2'); - info.displayName.should.equal('??$__vcrt_va_start_verify_argument_type@QBD@@YAXXZ'); + expect(info).to.not.equal(undefined, 'Symbol start_verify_argument should have been returned 2'); + expect(unwrap(info).displayName).to.equal('??$__vcrt_va_start_verify_argument_type@QBD@@YAXXZ'); }); it('Delphi-Map Duplication prevention', function () { @@ -184,10 +186,10 @@ describe('Delphi-Map Line number info', function () { reader.tryReadingLineNumbers(' 17 0001:000028A4').should.equal(true); let lineInfo = reader.getLineInfoByAddress('0001', 0x28a4); - lineInfo.lineNumber.should.equal(17); + expect(unwrap(lineInfo).lineNumber).to.equal(17); lineInfo = reader.getLineInfoByAddress(undefined, reader.getSegmentOffset('0001') + 0x28a4); - lineInfo.lineNumber.should.equal(17); + expect(unwrap(lineInfo).lineNumber).to.equal(17); }); it('Multiple lines', function () { @@ -197,16 +199,16 @@ describe('Delphi-Map Line number info', function () { .should.equal(true); let lineInfo = reader.getLineInfoByAddress('0001', 0x2838); - lineInfo.lineNumber.should.equal(12); + expect(unwrap(lineInfo).lineNumber).to.equal(12); lineInfo = reader.getLineInfoByAddress('0001', 0x2858); - lineInfo.lineNumber.should.equal(15); + expect(unwrap(lineInfo).lineNumber).to.equal(15); lineInfo = reader.getLineInfoByAddress('0001', 0x2854); - lineInfo.lineNumber.should.equal(14); + expect(unwrap(lineInfo).lineNumber).to.equal(14); lineInfo = reader.getLineInfoByAddress('0001', 0x283b); - lineInfo.lineNumber.should.equal(13); + expect(unwrap(lineInfo).lineNumber).to.equal(13); }); }); @@ -220,12 +222,12 @@ describe('Delphi-Map load test', function () { reader.namedAddresses.length.should.equal(11); let info = reader.getSegmentInfoByUnitName('output.pas'); - info.addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2c4c); + unwrap(info).addressInt.should.equal(reader.getSegmentOffset('0001') + 0x2c4c); info = reader.getICodeSegmentInfoByUnitName('output.pas'); - info.segment.should.equal('0002'); - info.addressWithoutOffset.should.equal(0xb0); - info.addressInt.should.equal(0x4040b0); + unwrap(info).segment.should.equal('0002'); + unwrap(info).addressWithoutOffset.should.equal(0xb0); + unwrap(info).addressInt.should.equal(0x4040b0); }); }); @@ -235,7 +237,7 @@ describe('VS-Map load test', function () { reader.run(); reader.segments.length.should.equal(1); - reader.getSegmentInfoByUnitName('ConsoleApplication1.obj').addressInt.should.equal(0x411000); + unwrap(reader.getSegmentInfoByUnitName('ConsoleApplication1.obj')).addressInt.should.equal(0x411000); reader.getSegmentOffset('0001').should.equal(0x401000, 'offset 1'); reader.getSegmentOffset('0002').should.equal(0x411000, 'offset 2'); diff --git a/test/options-handler.js b/test/options-handler.ts index e77a50639..96e21dfa0 100644 --- a/test/options-handler.js +++ b/test/options-handler.ts @@ -26,11 +26,16 @@ import {fileURLToPath} from 'url'; import _ from 'underscore'; +import {AppDefaultArguments} from '../app.js'; import {BaseCompiler} from '../lib/base-compiler.js'; -import {ClientOptionsHandler} from '../lib/options-handler.js'; +import {CompilationEnvironment} from '../lib/compilation-env.js'; +import {ClientOptionsHandler, ClientOptionsType} from '../lib/options-handler.js'; import * as properties from '../lib/properties.js'; +import {BaseTool} from '../lib/tooling/base-tool.js'; +import {CompilerInfo} from '../types/compiler.interfaces.js'; +import {LanguageKey} from '../types/languages.interfaces.js'; -import {should} from './utils.js'; +import {makeFakeCompilerInfo, should} from './utils.js'; const languages = { fake: { @@ -122,35 +127,57 @@ const moreLibProps = { 'libs.autolib.versions.autodetect.staticliblink': 'hello', }; -const makeFakeCompilerInfo = (id, lang, group, semver, isSemver) => { - return { +const fakeCompilerInfo = (id: string, lang: string, group: string, semver: string, isSemver: boolean) => { + return makeFakeCompilerInfo({ id: id, exe: '/dev/null', name: id, - lang: lang, + lang: lang as LanguageKey, group: group, isSemVer: isSemver, semver: semver, libsArr: [], - }; + }); }; +class TestBaseCompiler extends BaseCompiler { + public override supportedLibraries = super.supportedLibraries; +} + describe('Options handler', () => { - let fakeOptionProps; - let compilerProps; - let optionsHandler; - let fakeMoreCompilerProps; - let moreCompilerProps; - let moreOptionsHandler; + let fakeOptionProps: ReturnType<typeof properties.fakeProps>; + let compilerProps: properties.CompilerProps; + let optionsHandler: ClientOptionsHandler; + + let fakeMoreCompilerProps: ReturnType<typeof properties.fakeProps>; + let moreCompilerProps: properties.CompilerProps; + let moreOptionsHandler: ClientOptionsHandler; + + let env: CompilationEnvironment; + + function createClientOptions(libs: ReturnType<ClientOptionsHandler['parseLibraries']>) { + return { + libs: { + 'c++': libs.fake, + }, + } as unknown as ClientOptionsType; + } before(() => { fakeOptionProps = properties.fakeProps(optionsProps); compilerProps = new properties.CompilerProps(languages, fakeOptionProps); - optionsHandler = new ClientOptionsHandler([], compilerProps, {env: ['dev']}); + optionsHandler = new ClientOptionsHandler([], compilerProps, {env: ['dev']} as unknown as AppDefaultArguments); fakeMoreCompilerProps = properties.fakeProps(moreLibProps); moreCompilerProps = new properties.CompilerProps(languages, fakeMoreCompilerProps); - moreOptionsHandler = new ClientOptionsHandler([], moreCompilerProps, {env: ['dev']}); + moreOptionsHandler = new ClientOptionsHandler([], moreCompilerProps, { + env: ['dev'], + } as unknown as AppDefaultArguments); + + env = { + ceProps: properties.fakeProps({}), + compilerProps: () => {}, + } as unknown as CompilationEnvironment; }); it('should always return an array of paths', () => { @@ -270,32 +297,32 @@ describe('Options handler', () => { }); it('should order compilers as expected', () => { const compilers = [ - makeFakeCompilerInfo('a1', languages.fake.id, 'a', '0.0.1', true), - makeFakeCompilerInfo('a2', languages.fake.id, 'a', '0.2.0', true), - makeFakeCompilerInfo('a3', languages.fake.id, 'a', '0.2.1', true), + fakeCompilerInfo('a1', languages.fake.id, 'a', '0.0.1', true), + fakeCompilerInfo('a2', languages.fake.id, 'a', '0.2.0', true), + fakeCompilerInfo('a3', languages.fake.id, 'a', '0.2.1', true), - makeFakeCompilerInfo('b1', languages.fake.id, 'b', 'trunk', true), - makeFakeCompilerInfo('b2', languages.fake.id, 'b', '1.0.0', true), - makeFakeCompilerInfo('b3', languages.fake.id, 'b', '0.5.0', true), + fakeCompilerInfo('b1', languages.fake.id, 'b', 'trunk', true), + fakeCompilerInfo('b2', languages.fake.id, 'b', '1.0.0', true), + fakeCompilerInfo('b3', languages.fake.id, 'b', '0.5.0', true), - makeFakeCompilerInfo('c1', languages.fake.id, 'c', '3.0.0', true), - makeFakeCompilerInfo('c2', languages.fake.id, 'c', '3.0.0', true), - makeFakeCompilerInfo('c3', languages.fake.id, 'c', '3.0.0', true), + fakeCompilerInfo('c1', languages.fake.id, 'c', '3.0.0', true), + fakeCompilerInfo('c2', languages.fake.id, 'c', '3.0.0', true), + fakeCompilerInfo('c3', languages.fake.id, 'c', '3.0.0', true), - makeFakeCompilerInfo('d1', languages.fake.id, 'd', 1, true), - makeFakeCompilerInfo('d2', languages.fake.id, 'd', '2.0.0', true), - makeFakeCompilerInfo('d3', languages.fake.id, 'd', '0.0.5', true), + fakeCompilerInfo('d1', languages.fake.id, 'd', '1', true), + fakeCompilerInfo('d2', languages.fake.id, 'd', '2.0.0', true), + fakeCompilerInfo('d3', languages.fake.id, 'd', '0.0.5', true), - makeFakeCompilerInfo('e1', languages.fake.id, 'e', '0..0', false), - makeFakeCompilerInfo('e2', languages.fake.id, 'e', undefined, false), + fakeCompilerInfo('e1', languages.fake.id, 'e', '0..0', false), + fakeCompilerInfo('e2', languages.fake.id, 'e', '', false), - makeFakeCompilerInfo('f1', languages.fake.id, 'f', '5', true), - makeFakeCompilerInfo('f2', languages.fake.id, 'f', '5.1', true), - makeFakeCompilerInfo('f3', languages.fake.id, 'f', '5.2', true), + fakeCompilerInfo('f1', languages.fake.id, 'f', '5', true), + fakeCompilerInfo('f2', languages.fake.id, 'f', '5.1', true), + fakeCompilerInfo('f3', languages.fake.id, 'f', '5.2', true), - makeFakeCompilerInfo('g1', languages.fake.id, 'g', '5 a', true), - makeFakeCompilerInfo('g2', languages.fake.id, 'g', '5.1 b d', true), - makeFakeCompilerInfo('g3', languages.fake.id, 'g', '5.2 ce fg', true), + fakeCompilerInfo('g1', languages.fake.id, 'g', '5 a', true), + fakeCompilerInfo('g2', languages.fake.id, 'g', '5.1 b d', true), + fakeCompilerInfo('g3', languages.fake.id, 'g', '5.2 ce fg', true), ]; const expectedOrder = { a: { @@ -337,26 +364,20 @@ describe('Options handler', () => { _.each(optionsHandler.get().compilers, compiler => { should.equal( compiler['$order'], - expectedOrder[compiler.group][compiler.id], - `group: ${compiler.group} id: ${compiler.id}`, + expectedOrder[(compiler as CompilerInfo).group][(compiler as CompilerInfo).id], + `group: ${(compiler as CompilerInfo).group} id: ${(compiler as CompilerInfo).id}`, ); }); optionsHandler.setCompilers([]); }); it('should get static libraries', () => { const libs = optionsHandler.parseLibraries({fake: optionsProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); - const env = { - ceProps: properties.fakeProps({}), - compilerProps: () => {}, - }; + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); + + const clientOptions = createClientOptions(libs); const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + compiler.initialiseLibraries(clientOptions); const staticlinks = compiler.getStaticLibraryLinks([{id: 'fs', version: 'std'}]); staticlinks.should.deep.equal(['-lc++fs', '-lrt', '-lpthread']); @@ -366,18 +387,12 @@ describe('Options handler', () => { }); it('should sort static libraries', () => { const libs = optionsHandler.parseLibraries({fake: optionsProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); - const env = { - ceProps: properties.fakeProps({}), - compilerProps: () => {}, - }; + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); + + const clientOptions = createClientOptions(libs); const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + compiler.initialiseLibraries(clientOptions); let staticlinks = compiler.getSortedStaticLibraries([{id: 'someotherlib', version: 'trunk'}]); staticlinks.should.deep.equal(['someotherlib', 'c++fs']); @@ -390,36 +405,24 @@ describe('Options handler', () => { }); it('library sort special case 1', () => { const libs = moreOptionsHandler.parseLibraries({fake: moreLibProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); - const env = { - ceProps: properties.fakeProps({}), - compilerProps: () => {}, - }; + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + + const clientOptions = createClientOptions(libs); + compiler.initialiseLibraries(clientOptions); const staticlinks = compiler.getSortedStaticLibraries([{id: 'fs', version: 'std'}]); staticlinks.should.deep.equal(['fsextra', 'c++fs', 'rt', 'pthread']); }); it('library sort special case 2', () => { const libs = moreOptionsHandler.parseLibraries({fake: moreLibProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); - const env = { - ceProps: properties.fakeProps({}), - compilerProps: () => {}, - }; + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + + const clientOptions = createClientOptions(libs); + compiler.initialiseLibraries(clientOptions); const staticlinks = compiler.getSortedStaticLibraries([ {id: 'yalib', version: 'trunk'}, @@ -430,17 +433,12 @@ describe('Options handler', () => { }); it('library sort special case 3', () => { const libs = moreOptionsHandler.parseLibraries({fake: moreLibProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); - const env = { - ceProps: properties.fakeProps({}), - compilerProps: () => {}, - }; + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); + const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + + const clientOptions = createClientOptions(libs); + compiler.initialiseLibraries(clientOptions); const staticlinks = compiler.getSortedStaticLibraries([ {id: 'fourthlib', version: 'trunk'}, @@ -451,38 +449,26 @@ describe('Options handler', () => { }); it('filtered library list', () => { const libs = moreOptionsHandler.parseLibraries({fake: moreLibProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); - const env = { - ceProps: properties.fakeProps({}), - compilerProps: () => {}, - }; + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); compilerInfo.libsArr = ['fs.std', 'someotherlib']; - const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + const compiler = new TestBaseCompiler(compilerInfo, env); + + const clientOptions = createClientOptions(libs); + compiler.initialiseLibraries(clientOptions); const libNames = _.keys(compiler.supportedLibraries); libNames.should.deep.equal(['fs', 'someotherlib']); }); it('can detect libraries from options', () => { const libs = moreOptionsHandler.parseLibraries({fake: moreLibProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); - const env = { - ceProps: properties.fakeProps({}), - compilerProps: () => {}, - }; + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + + const clientOptions = createClientOptions(libs); + compiler.initialiseLibraries(clientOptions); const obj = { libraries: [{id: 'ctre', version: 'trunk'}], @@ -498,27 +484,33 @@ describe('Options handler', () => { }); it("server-side library alias support (just in case client doesn't support it)", () => { const libs = moreOptionsHandler.parseLibraries({fake: moreLibProps.libs}); - const compilerInfo = makeFakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); + const compilerInfo = fakeCompilerInfo('g82', 'c++', 'cpp', '8.2', true); const env = { ceProps: properties.fakeProps({}), compilerProps: () => {}, - }; + } as unknown as CompilationEnvironment; const compiler = new BaseCompiler(compilerInfo, env); - compiler.initialiseLibraries({ - libs: { - 'c++': libs.fake, - }, - }); + + const clientOptions = createClientOptions(libs); + compiler.initialiseLibraries(clientOptions); const staticlinks = compiler.getSortedStaticLibraries([{id: 'someotherlib', version: 'master'}]); staticlinks.should.deep.equal(['someotherlib', 'c++fs']); }); it('should be able to parse basic tools', () => { - const tools = optionsHandler.parseTools({fake: optionsProps.tools}); + class TestBaseTool extends BaseTool { + public override env = super.env; + } + const tools = optionsHandler.parseTools({fake: optionsProps.tools}) as unknown as Record< + string, + Record<string, Partial<TestBaseTool>> + >; + _.each(tools.fake, tool => { delete tool.env; }); + tools.should.deep.equal({ fake: { faketool: { diff --git a/test/packager-tests.js b/test/packager-tests.ts index 8544492b6..73fee2fe9 100644 --- a/test/packager-tests.js +++ b/test/packager-tests.ts @@ -28,7 +28,7 @@ import {Packager} from '../lib/packager.js'; import {fs, path} from './utils.js'; -function newTempDir() { +function newTempDir(): Promise<string> { return new Promise((resolve, reject) => { temp.mkdir({prefix: 'compiler-explorer-compiler', dir: process.env.tmpDir}, (err, dirPath) => { if (err) reject(`Unable to open temp file: ${err}`); |