diff --git a/test/exec-tests.ts b/test/exec-tests.ts index 8df79c2d6..1696dbe90 100644 --- a/test/exec-tests.ts +++ b/test/exec-tests.ts @@ -218,7 +218,6 @@ describe('Execution tests', async () => { '/not/custom/file', ]); expect(options).toEqual({}); - expect(filenameTransform).to.not.be.undefined; expect(filenameTransform).toBeTruthy(); expect(filenameTransform('moo')).toEqual('moo'); expect(filenameTransform('/some/custom/cwd/file')).toEqual('/app/file'); diff --git a/test/filter-tests.js b/test/filter-tests.ts similarity index 78% rename from test/filter-tests.js rename to test/filter-tests.ts index d581fde7e..e87b2d979 100644 --- a/test/filter-tests.js +++ b/test/filter-tests.ts @@ -24,25 +24,27 @@ import path from 'path'; -import approvals from 'approvals'; +import {configure, verifyAsJSON} from 'approvals'; +import type {ApprovalFailureReporter} from 'approvals/lib/Core/ApprovalFailureReporter'; +import {beforeAll, describe, expect, it} from 'vitest'; import {CC65AsmParser} from '../lib/parsers/asm-parser-cc65.js'; import {AsmEWAVRParser} from '../lib/parsers/asm-parser-ewavr.js'; import {SassAsmParser} from '../lib/parsers/asm-parser-sass.js'; import {VcAsmParser} from '../lib/parsers/asm-parser-vc.js'; import {AsmParser} from '../lib/parsers/asm-parser.js'; +import {fakeProps} from '../lib/properties.js'; +import {ParseFiltersAndOutputOptions} from '../types/features/filters.interfaces.js'; import {fs, resolvePathFromTestRoot} from './utils.js'; -approvals.mocha(resolvePathFromTestRoot('filters-cases')); - -function processAsm(filename, filters) { +function processAsm(filename: string, filters: ParseFiltersAndOutputOptions) { const file = fs.readFileSync(filename, 'utf8'); - let parser; + let parser: AsmParser; if (file.includes('Microsoft')) parser = new VcAsmParser(); else if (filename.includes('sass-')) parser = new SassAsmParser(); - else if (filename.includes('cc65-')) parser = new CC65AsmParser(); - else if (filename.includes('ewarm-')) parser = new AsmEWAVRParser(); + else if (filename.includes('cc65-')) parser = new CC65AsmParser(fakeProps({})); + else if (filename.includes('ewarm-')) parser = new AsmEWAVRParser(fakeProps({})); else { parser = new AsmParser(); parser.binaryHideFuncRe = @@ -65,14 +67,32 @@ const optionsOverride = { errorOnStaleApprovedFiles: process.platform !== 'win32', }; -function testFilter(filename, suffix, filters) { +function testFilter(filename: string, suffix: string, filters: ParseFiltersAndOutputOptions) { const testName = path.basename(filename + suffix); - it(testName, () => { - const result = processAsm(filename, filters); - delete result.parsingTime; - delete result.filteredCount; - approvals.verifyAsJSON(casesRoot, testName, result, optionsOverride); - }).timeout(10000); // Bump the timeout a bit so that we don't fail for slow cases + it( + testName, + () => { + const result = processAsm(filename, filters); + delete result.parsingTime; + delete result.filteredCount; + verifyAsJSON(casesRoot, testName, result, optionsOverride); + }, + {timeout: 10000}, + ); // Bump the timeout a bit so that we don't fail for slow cases +} + +class VitestReporter implements ApprovalFailureReporter { + name: string = 'VitestReporter'; + + canReportOn() { + return true; + } + + report(approvedFilePath: string, receivedFilePath: string) { + const approvedText = fs.readFileSync(approvedFilePath).toString(); + const receivedText = fs.readFileSync(receivedFilePath).toString(); + expect(receivedText).toBe(approvedText); + } } /* @@ -80,6 +100,7 @@ function testFilter(filename, suffix, filters) { That's sad because then we can't have cases be loaded in a before() for every describe child to see. */ describe('Filter test cases', () => { + beforeAll(() => configure({reporters: [new VitestReporter()]})); describe('No filters', () => { for (const x of cases) testFilter(x, '.none', {}); }); @@ -169,21 +190,21 @@ describe('Filter test cases', () => { describe('AsmParser tests', () => { const parser = new AsmParser(); it('should identify generic opcodes', () => { - parser.hasOpcode(' mov r0, #1').should.be.true; - parser.hasOpcode(' ROL A').should.be.true; + expect(parser.hasOpcode(' mov r0, #1')).toBe(true); + expect(parser.hasOpcode(' ROL A')).toBe(true); }); it('should not identify non-opcodes as opcodes', () => { - parser.hasOpcode(' ;mov r0, #1').should.be.false; - parser.hasOpcode('').should.be.false; - parser.hasOpcode('# moose').should.be.false; + expect(parser.hasOpcode(' ;mov r0, #1')).toBe(false); + expect(parser.hasOpcode('')).toBe(false); + expect(parser.hasOpcode('# moose')).toBe(false); }); it('should identify llvm opcodes', () => { - parser.hasOpcode(' %i1 = phi i32 [ %i2, %.preheader ], [ 0, %bb ]').should.be.true; + expect(parser.hasOpcode(' %i1 = phi i32 [ %i2, %.preheader ], [ 0, %bb ]')).toBe(true); }); }); describe('forceApproveAll should be false', () => { it('should have forceApproveAll false', () => { - optionsOverride.forceApproveAll.should.be.false; + expect(optionsOverride.forceApproveAll).toBe(false); }); }); diff --git a/test/filters-cases/vc-regex.asm.directives.approved.txt b/test/filters-cases/vc-regex.asm.directives.approved.txt index eb707c793..687ad9cad 100644 --- a/test/filters-cases/vc-regex.asm.directives.approved.txt +++ b/test/filters-cases/vc-regex.asm.directives.approved.txt @@ -1,4 +1,4 @@ -{ +moo{ "asm": [ { "source": null, diff --git a/test/golang-tests.ts b/test/golang-tests.ts index 53f872d26..dbae66a05 100644 --- a/test/golang-tests.ts +++ b/test/golang-tests.ts @@ -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 {GolangCompiler} from '../lib/compilers/golang.js'; import * as utils from '../lib/utils.js'; import {LanguageKey} from '../types/languages.interfaces.js'; @@ -43,10 +45,10 @@ const info = { lang: languages.go.id, }; -function testGoAsm(basefilename) { +async function testGoAsm(baseFilename: string) { const compiler = new GolangCompiler(makeFakeCompilerInfo(info), ce); - const asmLines = utils.splitLines(fs.readFileSync(basefilename + '.asm').toString()); + const asmLines = utils.splitLines(fs.readFileSync(baseFilename + '.asm').toString()); const result = { stderr: asmLines.map(line => { @@ -56,16 +58,13 @@ function testGoAsm(basefilename) { }), }; - return compiler.postProcess(result).then(([output]) => { - const expectedOutput = utils.splitLines(fs.readFileSync(basefilename + '.output.asm').toString()); - - utils.splitLines(output.asm).should.deep.equal(expectedOutput); - - return output.should.deep.equal({ - asm: expectedOutput.join('\n'), - stdout: [], - stderr: [], - }); + const [output] = await compiler.postProcess(result); + const expectedOutput = utils.splitLines(fs.readFileSync(baseFilename + '.output.asm').toString()); + expect(utils.splitLines(output.asm)).toEqual(expectedOutput); + expect(output).toEqual({ + asm: expectedOutput.join('\n'), + stdout: [], + stderr: [], }); } @@ -74,10 +73,10 @@ describe('GO asm tests', () => { ce = makeCompilationEnvironment({languages}); }); - it('Handles unknown line number correctly', () => { - return testGoAsm('test/golang/bug-901'); + it('Handles unknown line number correctly', async () => { + await testGoAsm('test/golang/bug-901'); }); - it('Rewrites PC jumps to labels', () => { - return testGoAsm('test/golang/labels'); + it('Rewrites PC jumps to labels', async () => { + await testGoAsm('test/golang/labels'); }); }); diff --git a/test/google-tests.ts b/test/google-tests.ts index bbee0a0fe..0d9b5402c 100644 --- a/test/google-tests.ts +++ b/test/google-tests.ts @@ -23,6 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. import nock from 'nock'; +import {afterAll, describe, expect, it} from 'vitest'; import * as google from '../lib/shortener/google.js'; @@ -39,25 +40,24 @@ describe('Google short URL resolver tests', () => { it('Resolves simple URLs', async () => { nock(googlDomain).head(shortUrl).reply(302, {}, {location: 'http://long.url/'}); - const resp = await resolver.resolve(googlDomain + shortUrl); - resp.should.deep.equal({longUrl: 'http://long.url/'}); + await expect(resolver.resolve(googlDomain + shortUrl)).resolves.toEqual({longUrl: 'http://long.url/'}); }); - it('Handles missing long urls', () => { + it('Handles missing long urls', async () => { nock(googlDomain).head(shortUrl).reply(404); - return resolver.resolve(googlDomain + shortUrl).should.be.rejectedWith('Got response 404'); + await expect(resolver.resolve(googlDomain + shortUrl)).rejects.toThrow('Got response 404'); }); - it('Handles missing location header', () => { + it('Handles missing location header', async () => { nock(googlDomain).head(shortUrl).reply(302); - return resolver.resolve(googlDomain + shortUrl).should.be.rejectedWith('Missing location url in undefined'); + await expect(resolver.resolve(googlDomain + shortUrl)).rejects.toThrow('Missing location url in undefined'); }); - it('Handles failed requests', () => { + it('Handles failed requests', async () => { nock(googlDomain).head(shortUrl).replyWithError('Something went wrong'); - return resolver.resolve(googlDomain + shortUrl).should.be.rejectedWith('Something went wrong'); + await expect(resolver.resolve(googlDomain + shortUrl)).rejects.toThrow('Something went wrong'); }); }); diff --git a/test/instructionsets-tests.ts b/test/instructionsets-tests.ts index 8c6c16c85..544cd10d9 100644 --- a/test/instructionsets-tests.ts +++ b/test/instructionsets-tests.ts @@ -22,33 +22,35 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import {describe, expect, it} from 'vitest'; + import {InstructionSets} from '../lib/instructionsets.js'; describe('InstructionSets', async () => { it('should recognize aarch64 for clang target', async () => { const isets = new InstructionSets(); - return isets - .getCompilerInstructionSetHint('aarch64-linux-gnu', '/opt/compiler-explorer/clang-11.0.1/bin/clang++') - .should.eventually.equal('aarch64'); + await expect( + isets.getCompilerInstructionSetHint('aarch64-linux-gnu', '/opt/compiler-explorer/clang-11.0.1/bin/clang++'), + ).resolves.toEqual('aarch64'); }); it('should recognize gcc aarch64 from filepath', async () => { const isets = new InstructionSets(); - return isets - .getCompilerInstructionSetHint( + await expect( + isets.getCompilerInstructionSetHint( false, '/opt/compiler-explorer/arm64/gcc-12.1.0/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-g++', - ) - .should.eventually.equal('aarch64'); + ), + ).resolves.toEqual('aarch64'); }); - it('should default to amd64 when not apparant', async () => { + it('should default to amd64 when not apparent', async () => { const isets = new InstructionSets(); - return isets - .getCompilerInstructionSetHint(false, '/opt/compiler-explorer/gcc-12.2.0/bin/g++') - .should.eventually.equal('amd64'); + await expect( + isets.getCompilerInstructionSetHint(false, '/opt/compiler-explorer/gcc-12.2.0/bin/g++'), + ).resolves.toEqual('amd64'); }); }); diff --git a/test/java-tests.ts b/test/java-tests.ts index be365a252..9eb85d574 100644 --- a/test/java-tests.ts +++ b/test/java-tests.ts @@ -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: '', }; - (await compiler.processAsm(result)).should.deep.equal([{text: '', source: null}]); + await expect(compiler.processAsm(result)).resolves.toEqual([{text: '', source: null}]); }); it('Parses simple class with one method', () => { diff --git a/test/lang-tests.ts b/test/lang-tests.ts index 5e66d02fd..5472960d1 100644 --- a/test/lang-tests.ts +++ b/test/lang-tests.ts @@ -22,22 +22,24 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import {describe, expect, it} from 'vitest'; + import {languages} from '../lib/languages.js'; -import {fs, path, should} from './utils.js'; +import {fs, path} from './utils.js'; describe('Language definitions tests', () => { it('Has id equal to object key', () => { - for (const languageKey of Object.keys(languages)) should.equal(languages[languageKey].id, languageKey); + for (const languageKey of Object.keys(languages)) expect(languages[languageKey].id).toEqual(languageKey); }); it('Has extensions with leading dots', () => { - for (const languageKey of Object.keys(languages)) should.equal(languages[languageKey].extensions[0][0], '.'); + for (const languageKey of Object.keys(languages)) expect(languages[languageKey].extensions[0][0]).toEqual('.'); }); it('Has examples & are initialized', () => { for (const languageKey of Object.keys(languages)) { const lang = languages[languageKey]; const example = fs.readFileSync(path.join('examples', lang.id, 'default' + lang.extensions[0]), 'utf8'); - should.equal(example, lang.example); + expect(example).toEqual(lang.example); } }); }); diff --git a/test/library-tests.ts b/test/library-tests.ts index 1d65f68ed..0141f0f3e 100644 --- a/test/library-tests.ts +++ b/test/library-tests.ts @@ -20,6 +20,7 @@ import path from 'path'; import fs from 'fs-extra'; +import {beforeAll, describe, expect, it} from 'vitest'; import {BaseCompiler} from '../lib/base-compiler.js'; import {BuildEnvSetupBase} from '../lib/buildenvsetup/base.js'; @@ -111,7 +112,7 @@ describe('Library directories (c++)', () => { it('should add libpaths and link to libraries', () => { const links = compiler.getSharedLibraryLinks([{id: 'fmt', version: '10'}]); - links.should.include('-lfmtd'); + expect(links).toContain('-lfmtd'); const fmtpaths = (compiler as any).getSharedLibraryPathsAsArguments( [{id: 'fmt', version: '10'}], @@ -119,7 +120,7 @@ describe('Library directories (c++)', () => { undefined, '/tmp/compiler-explorer-compiler-123', ); - fmtpaths.should.include('-L./lib'); + expect(fmtpaths).toContain('-L./lib'); const qtpaths = (compiler as any).getSharedLibraryPathsAsArguments( [{id: 'qt', version: '660'}], @@ -127,7 +128,7 @@ describe('Library directories (c++)', () => { undefined, '/tmp/compiler-explorer-compiler-123', ); - qtpaths.should.include('-L/tmp/compiler-explorer-compiler-123/qt/lib'); + expect(qtpaths).toContain('-L/tmp/compiler-explorer-compiler-123/qt/lib'); }); it('should add libpaths and link to libraries when using nsjail', () => { @@ -139,7 +140,7 @@ describe('Library directories (c++)', () => { undefined, '/tmp/compiler-explorer-compiler-123', ); - fmtpaths.should.include('-L/tmp/compiler-explorer-compiler-123/fmt/lib'); + expect(fmtpaths).toContain('-L/tmp/compiler-explorer-compiler-123/fmt/lib'); const qtpaths = (compiler as any).getSharedLibraryPathsAsArguments( [{id: 'qt', version: '660'}], @@ -147,7 +148,7 @@ describe('Library directories (c++)', () => { undefined, '/tmp/compiler-explorer-compiler-123', ); - qtpaths.should.include('-L/tmp/compiler-explorer-compiler-123/qt/lib'); + expect(qtpaths).toContain('-L/tmp/compiler-explorer-compiler-123/qt/lib'); }); it('should add extra include paths when using packagedheaders', () => { @@ -157,15 +158,15 @@ describe('Library directories (c++)', () => { [{id: 'fmt', version: '10'}], '/tmp/compiler-explorer-compiler-123', ); - fmtpaths.should.not.include('-I/tmp/compiler-explorer-compiler-123/fmt/include'); - fmtpaths.should.include('-I/opt/compiler-explorer/libs/fmt/1.0/include'); + expect(fmtpaths).not.toContain('-I/tmp/compiler-explorer-compiler-123/fmt/include'); + expect(fmtpaths).toContain('-I/opt/compiler-explorer/libs/fmt/1.0/include'); const qtpaths = (compiler as any).getIncludeArguments( [{id: 'qt', version: '660'}], '/tmp/compiler-explorer-compiler-123', ); - qtpaths.should.include('-I/opt/compiler-explorer/libs/qt/6.6.0/include'); - qtpaths.should.include('-I/tmp/compiler-explorer-compiler-123/qt/include'); + expect(qtpaths).toContain('-I/opt/compiler-explorer/libs/qt/6.6.0/include'); + expect(qtpaths).toContain('-I/tmp/compiler-explorer-compiler-123/qt/include'); }); it('should set LD_LIBRARY_PATH when executing', () => { @@ -175,17 +176,17 @@ describe('Library directories (c++)', () => { [{id: 'qt', version: '660'}], '/tmp/compiler-explorer-compiler-123', ); - qtpaths.should.include('/tmp/compiler-explorer-compiler-123/qt/lib'); + expect(qtpaths).toContain('/tmp/compiler-explorer-compiler-123/qt/lib'); }); it('should add libpaths and link when statically linking', () => { (compiler as any).executionType = 'nsjail'; const staticlinks = compiler.getStaticLibraryLinks([{id: 'cpptrace', version: '030'}], []); - staticlinks.should.include('-lcpptrace'); - staticlinks.should.include('-ldwarf'); - staticlinks.should.include('-ldl'); - staticlinks.should.include('-lz'); + expect(staticlinks).toContain('-lcpptrace'); + expect(staticlinks).toContain('-ldwarf'); + expect(staticlinks).toContain('-ldl'); + expect(staticlinks).toContain('-lz'); const libpaths = (compiler as any).getSharedLibraryPathsAsArguments( [{id: 'cpptrace', version: '030'}], @@ -193,7 +194,7 @@ describe('Library directories (c++)', () => { undefined, '/tmp/compiler-explorer-compiler-123', ); - libpaths.should.include('-L/tmp/compiler-explorer-compiler-123/cpptrace/lib'); + expect(libpaths).toContain('-L/tmp/compiler-explorer-compiler-123/cpptrace/lib'); }); }); @@ -262,12 +263,12 @@ describe('Library directories (fortran)', () => { await fs.mkdir(libPath, {recursive: true}); const libPaths = compiler.getSharedLibraryPaths([{id: 'json_fortran', version: '830'}], dirPath); - libPaths.should.include(libPath); + expect(libPaths).toContain(libPath); const libJsonFilepath = path.join(libPath, 'libjson-fortran.a'); const failedLinks = compiler.getStaticLibraryLinks([{id: 'json_fortran', version: '830'}], libPaths); - failedLinks.should.not.include(libJsonFilepath); + expect(failedLinks).not.toContain(libJsonFilepath); }); it('should add libpaths and link to libraries', async () => { @@ -279,13 +280,13 @@ describe('Library directories (fortran)', () => { const libJsonFilepath = path.join(libPath, 'libjson-fortran.a'); const libPaths = compiler.getSharedLibraryPaths([{id: 'json_fortran', version: '830'}], dirPath); - libPaths.should.include(libPath); + expect(libPaths).toContain(libPath); await fs.writeFile(libJsonFilepath, 'hello, world!'); // the file is now here and Should be linked to const links = compiler.getStaticLibraryLinks([{id: 'json_fortran', version: '830'}], libPaths); - links.should.include(libJsonFilepath); + expect(links).toContain(libJsonFilepath); const paths = (compiler as any).getSharedLibraryPathsAsArguments( [{id: 'json_fortran', version: '830'}], @@ -293,7 +294,7 @@ describe('Library directories (fortran)', () => { undefined, dirPath, ); - paths.should.include('-L' + libPath); + expect(paths).toContain('-L' + libPath); }); it('should add includes for packaged libraries', async () => { @@ -305,8 +306,8 @@ describe('Library directories (fortran)', () => { const cInclude = path.join(dirPath, 'json_fortran/include'); const paths = (compiler as any).getIncludeArguments([{id: 'json_fortran', version: '830'}], dirPath); - paths.should.include('-I' + fortranInclude); - paths.should.include('-isystem' + cInclude); + expect(paths).toContain('-I' + fortranInclude); + expect(paths).toContain('-isystem' + cInclude); }); it('should add includes for non-packaged C libraries', async () => { @@ -316,6 +317,6 @@ describe('Library directories (fortran)', () => { const dirPath = await compiler.newTempDir(); const paths = (compiler as any).getIncludeArguments([{id: 'curl', version: '7831'}], dirPath); - paths.should.include('-isystem/opt/compiler-explorer/libs/curl/7.83.1/include'); + expect(paths).toContain('-isystem/opt/compiler-explorer/libs/curl/7.83.1/include'); }); }); diff --git a/test/llvm-ast-parser-tests.ts b/test/llvm-ast-parser-tests.ts index 9a26172e4..e591e8cd4 100644 --- a/test/llvm-ast-parser-tests.ts +++ b/test/llvm-ast-parser-tests.ts @@ -23,12 +23,13 @@ // POSSIBILITY OF SUCH DAMAGE. import cloneDeep from 'lodash.clonedeep'; +import {beforeAll, describe, expect, it} from 'vitest'; import {LlvmAstParser} from '../lib/llvm-ast.js'; import * as properties from '../lib/properties.js'; import * as utils from '../lib/utils.js'; -import {fs, should} from './utils.js'; +import {fs} from './utils.js'; const languages = { 'c++': {id: 'c++'}, @@ -60,50 +61,51 @@ describe('llvm-ast', () => { it('keeps fewer lines than the original', () => { const origHeight = astDump.length; const processed = astParser.processAst(cloneDeep(compilerOutput)); - processed.length.should.be.below(origHeight); + expect(processed.length).toBeLessThan(origHeight); }); it('removes invalid slocs', () => { const processed = astParser.processAst(cloneDeep(compilerOutput)); - astDump.should.match(//); + expect(astDump).toMatch(//); const fullText = processed.map(l => l.text).join('\n'); - fullText.should.not.match(//); + expect(fullText).not.toMatch(//); }); it('keeps reasonable-sized output', () => { - astDumpWithCTime.length.should.be.above(200); + expect(astDumpWithCTime.length).toBeGreaterThan(200); const output = mockAstOutput(astDumpWithCTime); const processed = astParser.processAst(output); - processed.length.should.be.below(200); + expect(processed.length).toBeLessThan(200); }); it('links some source lines', () => { - should.exist(compilerOutput.stdout.find(l => l.text.match(/col:21, line:4:1/))); - should.exist(compilerOutput.stdout.find(l => l.text.match(/line:3:5, col:18/))); + expect(compilerOutput.stdout.find(l => l.text.match(/col:21, line:4:1/))).toBeTruthy(); + expect(compilerOutput.stdout.find(l => l.text.match(/line:3:5, col:18/))).toBeTruthy(); const processed = astParser.processAst(cloneDeep(compilerOutput)); - should.exist(processed.find(l => l.source && 0 < l.source.from.line)); - processed.find(l => l.text.match(/col:21, line:4:1/)).source.to.line.should.equal(4); - processed.find(l => l.text.match(/col:21, line:4:1/)).source.to.col.should.equal(1); - processed.find(l => l.text.match(/col:21, line:4:1/)).source.from.col.should.equal(21); - processed.find(l => l.text.match(/line:3:5, col:18/)).source.from.line.should.equal(3); - processed.find(l => l.text.match(/line:3:5, col:18/)).source.from.col.should.equal(5); - processed.find(l => l.text.match(/line:3:5, col:18/)).source.to.line.should.equal(3); - processed.find(l => l.text.match(/line:3:5, col:18/)).source.to.col.should.equal(18); + expect(processed.find(l => l.source && 0 < l.source.from.line)).toBeTruthy(); + expect(processed.find(l => l.text.match(/col:21, line:4:1/))).toMatchObject({ + source: {to: {line: 4, col: 1}, from: {line: 2, col: 21}}, + }); + expect(processed.find(l => l.text.match(/line:3:5, col:18/))).toMatchObject({ + source: {to: {line: 3, col: 18}, from: {line: 3, col: 5}}, + }); // Here "from.line" is inherited from the parent "FunctionDecl <:2:1, line:4:1>" - processed.find(l => l.text.match(/CompoundStmt.*/)).source.from.line.should.equal(2); + expect(processed.find(l => l.text.match(/CompoundStmt.*/))).toMatchObject({ + source: {from: {line: 2}}, + }); }); it('does not truncate nested declarations', () => { // See https://github.com/compiler-explorer/compiler-explorer/issues/1346 const output = mockAstOutput(astDumpNestedDecl1346); const processed = astParser.processAst(output); - processed.length.should.be.above(2); - should.exist(processed.find(l => l.text.match(/CXXRecordDecl.*struct x/))); - should.exist(processed.find(l => l.text.match(/TypedefDecl.*struct x/))); - should.exist(processed.find(l => l.text.match(/ElaboratedType/))); - should.exist(processed.find(l => l.text.match(/RecordType/))); - should.exist(processed.find(l => l.text.match(/CXXRecord/))); + expect(processed.length).toBeGreaterThan(2); + expect(processed.find(l => l.text.match(/CXXRecordDecl.*struct x/))).toBeTruthy(); + expect(processed.find(l => l.text.match(/TypedefDecl.*struct x/))).toBeTruthy(); + expect(processed.find(l => l.text.match(/ElaboratedType/))).toBeTruthy(); + expect(processed.find(l => l.text.match(/RecordType/))).toBeTruthy(); + expect(processed.find(l => l.text.match(/CXXRecord/))).toBeTruthy(); }); }); @@ -124,7 +126,7 @@ describe('llvm-ast bug-3849a', () => { it('should have more than 2 lines', () => { const processed = astParser.processAst(compilerOutput); - processed.length.should.be.above(2); + expect(processed.length).toBeGreaterThan(2); }); }); @@ -145,8 +147,8 @@ describe('llvm-ast bug-3849b', () => { it('should have not too many lines', () => { const processed = astParser.processAst(compilerOutput); - processed.length.should.be.above(200); - processed.length.should.be.below(300); + expect(processed.length).toBeGreaterThan(200); + expect(processed.length).toBeLessThan(300); }); }); @@ -167,6 +169,6 @@ describe('llvm-ast bug-5889', () => { it('should have not too many lines', () => { const processed = astParser.processAst(compilerOutput); - processed.length.should.be.below(50); + expect(processed.length).toBeLessThan(50); }); }); diff --git a/test/llvm-ir-parser-tests.ts b/test/llvm-ir-parser-tests.ts index a57d45085..f310ef7fe 100644 --- a/test/llvm-ir-parser-tests.ts +++ b/test/llvm-ir-parser-tests.ts @@ -22,14 +22,12 @@ // 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 {LLVMIRDemangler} from '../lib/demangler/llvm.js'; import {LlvmIrParser} from '../lib/llvm-ir.js'; import * as properties from '../lib/properties.js'; -import {chai} from './utils.js'; - -const expect = chai.expect; - const languages = { 'c++': {id: 'c++'}, }; @@ -46,7 +44,7 @@ describe('llvm-ir parseMetaNode', () => { }); it('should parse DILocation node', () => { - llvmIrParser.parseMetaNode('!60 = !DILocation(line: 9, column: 15, scope: !58)').should.deep.equal({ + expect(llvmIrParser.parseMetaNode('!60 = !DILocation(line: 9, column: 15, scope: !58)')).toEqual({ metaType: 'Location', metaId: '!60', line: '9', @@ -56,48 +54,50 @@ describe('llvm-ir parseMetaNode', () => { }); it('should parse distinct DILexicalBlock', () => { - llvmIrParser - .parseMetaNode('!50 = distinct !DILexicalBlock(scope: !44, file: !1, line: 8, column: 5)') - .should.deep.equal({ - metaType: 'LexicalBlock', - metaId: '!50', - scope: '!44', - file: '!1', - line: '8', - column: '5', - }); + expect( + llvmIrParser.parseMetaNode('!50 = distinct !DILexicalBlock(scope: !44, file: !1, line: 8, column: 5)'), + ).toEqual({ + metaType: 'LexicalBlock', + metaId: '!50', + scope: '!44', + file: '!1', + line: '8', + column: '5', + }); }); it('should parse all value types', () => { - llvmIrParser - .parseMetaNode( + expect( + llvmIrParser.parseMetaNode( '!44 = distinct !DISubprogram(name: "func", ' + 'scope: !1, line: 7, isLocal: false, isDefinition: true, flags: ' + 'DIFlagPrototyped, ceEmpty: "", ceTest: "a:b\\"c,d")', - ) - .should.deep.equal({ - metaType: 'Subprogram', - metaId: '!44', - name: 'func', - line: '7', - scope: '!1', - isLocal: 'false', - isDefinition: 'true', - flags: 'DIFlagPrototyped', - ceTest: 'a:b\\"c,d', - ceEmpty: '', - }); + ), + ).toEqual({ + metaType: 'Subprogram', + metaId: '!44', + name: 'func', + line: '7', + scope: '!1', + isLocal: 'false', + isDefinition: 'true', + flags: 'DIFlagPrototyped', + ceTest: 'a:b\\"c,d', + ceEmpty: '', + }); }); it('should parse distinct DILexicalBlock', () => { - llvmIrParser - .parseMetaNode('!1 = !DIFile(filename: "/tmp/example.cpp", directory: "/home/compiler-explorer")') - .should.deep.equal({ - metaType: 'File', - metaId: '!1', - filename: '/tmp/example.cpp', - directory: '/home/compiler-explorer', - }); + expect( + llvmIrParser.parseMetaNode( + '!1 = !DIFile(filename: "/tmp/example.cpp", directory: "/home/compiler-explorer")', + ), + ).toEqual({ + metaType: 'File', + metaId: '!1', + filename: '/tmp/example.cpp', + directory: '/home/compiler-explorer', + }); }); }); diff --git a/test/llvm-ir-tests.ts b/test/llvm-ir-tests.ts index f17405e48..7dc37e590 100644 --- a/test/llvm-ir-tests.ts +++ b/test/llvm-ir-tests.ts @@ -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 {LLCCompiler} from '../lib/compilers/llc.js'; import {OptCompiler} from '../lib/compilers/opt.js'; @@ -55,64 +57,64 @@ describe('LLVM IR Compiler', () => { }); it('llc options for at&t assembly', () => { - compiler - .optionsForFilter( + expect( + compiler.optionsForFilter( { intel: false, binary: false, }, 'output.s', - ) - .should.eql(['-o', 'output.s']); + ), + ).toEqual(['-o', 'output.s']); }); it('llc options for intel assembly', () => { - compiler - .optionsForFilter( + expect( + compiler.optionsForFilter( { intel: true, binary: false, }, 'output.s', - ) - .should.eql(['-o', 'output.s', '-x86-asm-syntax=intel']); + ), + ).toEqual(['-o', 'output.s', '-x86-asm-syntax=intel']); }); it('llc options for at&t binary', () => { - compiler - .optionsForFilter( + expect( + compiler.optionsForFilter( { intel: false, binary: true, }, 'output.s', - ) - .should.eql(['-o', 'output.s', '-filetype=obj']); + ), + ).toEqual(['-o', 'output.s', '-filetype=obj']); }); it('llc options for intel binary', () => { - compiler - .optionsForFilter( + expect( + compiler.optionsForFilter( { intel: true, binary: true, }, 'output.s', - ) - .should.eql(['-o', 'output.s', '-filetype=obj']); + ), + ).toEqual(['-o', 'output.s', '-filetype=obj']); }); it('opt options', () => { const compiler = createCompiler(OptCompiler); - compiler - .optionsForFilter( + expect( + compiler.optionsForFilter( { intel: false, binary: false, }, 'output.s', - ) - .should.eql(['-o', 'output.s', '-S']); + ), + ).toEqual(['-o', 'output.s', '-S']); }); }); diff --git a/vitest.config.ts b/vitest.config.ts index 5b3dc1a4d..38ee92bbc 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,5 +1,7 @@ +// eslint-disable-next-line node/no-unpublished-import import {defineConfig} from 'vitest/config'; +// eslint-disable-next-line import/no-default-export export default defineConfig({ test: { include: ['test/**/*.ts'],