From 63be37d219ec33f5bb93207ffff121eeeacda191 Mon Sep 17 00:00:00 2001 From: Elie Richa Date: Wed, 28 Jun 2023 11:13:40 +0000 Subject: [PATCH] Improve test infrastructure * Add a launch configuration to run tests that match a given regexp --- .editorconfig | 3 + .vscode/launch.json | 106 +++++++++++------- .vscode/settings.json.tmpl | 2 +- .../vscode/ada/test/TestWorkspace/default.gpr | 4 +- .../ada/test/suite/highlighting.test.ts | 7 +- integration/vscode/ada/test/suite/index.ts | 4 + 6 files changed, 83 insertions(+), 43 deletions(-) diff --git a/.editorconfig b/.editorconfig index c40e18a1..bb71d33a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,9 @@ end_of_line = lf trim_trailing_whitespace = true insert_final_newline = true +[*.tokens] +insert_final_newline = false + [*.py] indent_size = 4 diff --git a/.vscode/launch.json b/.vscode/launch.json index ce87e773..02417059 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,9 +25,18 @@ // debug instance on the same workspace as the development instance. // So you can checkout a second copy of the ALS repository under // ../als-rt and use it with the following line. - "${workspaceFolder}/../als-rt" + // "${workspaceFolder}/../als-rt" + "${workspaceFolder}/integration/vscode/ada/test/TestWorkspace" ], - "preLaunchTask": "npm: compile" + "preLaunchTask": "npm: compile", + "env": { + // This is necessary to make the "child" vscode inherit the PATH + // variable set in the workspace settings. Without it in some setups + // (e.g. vscode remote) the child vscode does not get visibility + // over the Ada toolchain available in the parent vscode + // environment. + "PATH": "${env:PATH}" + } }, { "name": "Extension Tests", @@ -43,30 +52,21 @@ "--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index", "${workspaceFolder}/integration/vscode/ada/test/TestWorkspace" ], + // Below we make the executables of node modules visible to the tests. + // In particular, vscode-tmgrammar-snap is used for syntax highlighting + // tests. "env": { + // This is necessary to make the "child" vscode inherit the PATH + // variable set in the workspace settings. Without it in some setups + // (e.g. vscode remote) the child vscode does not get visibility + // over the Ada toolchain available in the parent vscode + // environment. + "PATH": "${env:PATH}", // This is custom env var that we use in // integration/vscode/ada/test/suite/index.ts to prevent timeouts in // tests when debugging "MOCHA_TIMEOUT": "0" }, - // Below we make the executables of node modules visible to the tests. - // In particular, vscode-tmgrammar-snap is used for syntax highlighting - // tests. - "windows": { - "env": { - "PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin;${env:PATH}" - } - }, - "osx": { - "env": { - "PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}" - } - }, - "linux": { - "env": { - "PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}" - } - }, "preLaunchTask": "npm: pretest" }, { @@ -83,7 +83,16 @@ "--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index", "${workspaceFolder}/integration/vscode/ada/test/TestWorkspace" ], + // Below we make the executables of node modules visible to the tests. + // In particular, vscode-tmgrammar-snap is used for syntax highlighting + // tests. "env": { + // This is necessary to make the "child" vscode inherit the PATH + // variable set in the workspace settings. Without it in some setups + // (e.g. vscode remote) the child vscode does not get visibility + // over the Ada toolchain available in the parent vscode + // environment. + "PATH": "${env:PATH}", // This is custom env var that we use in // integration/vscode/ada/test/suite/index.ts to prevent timeouts in // tests when debugging @@ -94,24 +103,6 @@ // integration/vscode/ada/test/suite/highlighting.test.ts "MOCHA_ALS_UPDATE": "1" }, - // Below we make the executables of node modules visible to the tests. - // In particular, vscode-tmgrammar-snap is used for syntax highlighting - // tests. - "windows": { - "env": { - "PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin;${env:PATH}" - } - }, - "osx": { - "env": { - "PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}" - } - }, - "linux": { - "env": { - "PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}" - } - }, "preLaunchTask": "npm: pretest" }, { @@ -121,6 +112,45 @@ "target": ".obj/server/ada_language_server", "cwd": "${workspaceRoot}", "valuesFormatting": "parseText" + }, + { + "name": "Extension Tests (Test Name Regexp)", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "outFiles": [ + "${workspaceFolder}/integration/vscode/ada/out/**/*.js", + "!**/node_modules/**" + ], + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada", + "--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index", + "${workspaceFolder}/integration/vscode/ada/test/TestWorkspace" + ], + // Below we make the executables of node modules visible to the tests. + // In particular, vscode-tmgrammar-snap is used for syntax highlighting + // tests. + "env": { + "MOCHA_GREP": "${input:testPattern}", + // This is necessary to make the "child" vscode inherit the PATH + // variable set in the workspace settings. Without it in some setups + // (e.g. vscode remote) the child vscode does not get visibility + // over the Ada toolchain available in the parent vscode + // environment. + "PATH": "${env:PATH}", + // This is custom env var that we use in + // integration/vscode/ada/test/suite/index.ts to prevent timeouts in + // tests when debugging + "MOCHA_TIMEOUT": "0" + }, + "preLaunchTask": "npm: pretest" + } + ], + "inputs": [ + { + "id": "testPattern", + "description": "A regexp of tests to run", + "type": "promptString" } ] } diff --git a/.vscode/settings.json.tmpl b/.vscode/settings.json.tmpl index c7c7025b..b9a13f09 100644 --- a/.vscode/settings.json.tmpl +++ b/.vscode/settings.json.tmpl @@ -2,7 +2,7 @@ "ada.projectFile": "gnat/lsp_server.gpr", "ada.scenarioVariables": { // Use static linking in local development to enable running the - // ada_language_server executable after relaction into the VS Code + // ada_language_server executable after relocation into the VS Code // extension. "LIBRARY_TYPE": "static" }, diff --git a/integration/vscode/ada/test/TestWorkspace/default.gpr b/integration/vscode/ada/test/TestWorkspace/default.gpr index 703af36a..ed758b49 100644 --- a/integration/vscode/ada/test/TestWorkspace/default.gpr +++ b/integration/vscode/ada/test/TestWorkspace/default.gpr @@ -4,10 +4,10 @@ project Default is ("gnatpp.adb", "test.adb"); - for Source_Dirs use ("src"); + for Source_Dirs use ("src", "highlighing"); for Object_Dir use "obj"; for Main use Tools_Mains; - + package Builder is for Executable ("gnatpp.adb") use "gnatpp"; for Executable ("test.adb") use "gnattest"; diff --git a/integration/vscode/ada/test/suite/highlighting.test.ts b/integration/vscode/ada/test/suite/highlighting.test.ts index e4e2a2c6..fe4fe06e 100644 --- a/integration/vscode/ada/test/suite/highlighting.test.ts +++ b/integration/vscode/ada/test/suite/highlighting.test.ts @@ -242,6 +242,7 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) { } const cmd = [ + // Use npx to avoid sensitivity to PATH env var 'npx', 'vscode-tmgrammar-snap', // We pass a non-existing language configuration, otherwise the tool @@ -263,7 +264,7 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) { cmd.push('--updateSnapshot'); } - const proc = spawnSync(cmd[0], cmd.slice(1)); + const proc = spawnSync(cmd[0], cmd.slice(1), { cwd: workDirPath }); if (proc.error) { // proc.error is set if we fail to spawn the child process @@ -278,7 +279,9 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) { assert.fail(msg); } else if (proc.status != 0) { const msg = - `Return code ${proc.status.toString()} for command: ${cmd.join(' ')}\n` + + `Return code ${proc.status.toString()} for command: cd ${workDirPath}; ${cmd.join( + ' ' + )}\n` + String(proc.stdout) + String(proc.stderr); assert.fail(msg); diff --git a/integration/vscode/ada/test/suite/index.ts b/integration/vscode/ada/test/suite/index.ts index 188b5ca1..4b57ddfb 100644 --- a/integration/vscode/ada/test/suite/index.ts +++ b/integration/vscode/ada/test/suite/index.ts @@ -35,6 +35,10 @@ export function run(): Promise { mocha.timeout(env['MOCHA_TIMEOUT']); } + if (env['MOCHA_GREP']) { + mocha.grep(env['MOCHA_GREP']); + } + // Run the mocha test mocha.run((failures) => { if (failures > 0) {