Skip to content

Commit 8d8423a

Browse files
committed
test: run all debugger tests in a single variables.test.ts invocation
Variables tests require to know which debugger to use, but running tests with single debugger is slow and uncomfortable. Now, variables.test.ts will run each tests for each of debugger in single run. That is run.sh invoked only once, thus increasing test speed. There is still an unpleasant situation - Extension Test Runner vscode extension shows variables tests as skipped while they are not and I do not know how to fix it. Anyway tests are run, but it will be more convenient to see each test in a separate tree item with it's status.
1 parent eb15a7d commit 8d8423a

File tree

8 files changed

+475
-505
lines changed

8 files changed

+475
-505
lines changed

.vscode-test.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineConfig } from '@vscode/test-cli';
44
// npx vscode-test --config .vscode-test.mjs
55
export default defineConfig([
66
{
7-
label: 'Unit tests',
7+
label: 'Tests',
88
files: 'out/test/**/*.test.js',
99
mocha: {
1010
ui: 'tdd',
@@ -14,7 +14,6 @@ export default defineConfig([
1414
version: 'stable',
1515
workspaceFolder: './pgsrc/18',
1616
env: {
17-
PGHH_DEBUGGER: 'cppdbg',
1817
PGHH_PG_VERSION: '18',
1918
PGHH_VSCODE_VERSION: 'stable',
2019
PGHH_TEST_MODE: 'vars,format,unit',

.vscode/tasks.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
"kind": "build",
1616
"isDefault": true
1717
}
18-
}
18+
},
19+
{
20+
"type": "npm",
21+
"script": "test",
22+
"group": {
23+
"kind": "test",
24+
"isDefault": true
25+
},
26+
"options": {
27+
"env": {
28+
"PGHH_TEST_MODES": "vars,format,unit"
29+
}
30+
}
31+
}
1932
]
2033
}

src/test/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ There are useful flags that allows to specify which value range to use:
5353

5454
```bash
5555
./src/test/test.sh --pg-versions="18 17 16" \
56-
--vscode-versions="stable 1.90" \
57-
--debuggers="lldb"
56+
--vscode-versions="stable 1.90"
5857
```
5958

6059
Use `--help` flag to get more info about.

src/test/runTests.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ import { downloadAndUnzipVSCode,
55
resolveCliArgsFromVSCodeExecutablePath,
66
runTests } from '@vscode/test-electron';
77
import { getTestEnv } from './suite/env';
8-
import { unnullify } from '../error';
9-
10-
function getDebuggerExtensionId(debuggerType: string) {
11-
if (debuggerType === 'cppdbg') {
12-
return 'ms-vscode.cpptools';
13-
} else {
14-
return 'vadimcn.vscode-lldb';
15-
}
16-
}
178

189
async function main() {
1910
/*
@@ -37,11 +28,13 @@ async function main() {
3728
/* Install required debugger extension */
3829
let extraArgs: string[] = [];
3930
if (testEnv.testDebugger()) {
40-
const dbgExtId = getDebuggerExtensionId(unnullify(testEnv.debugger, 'testEnv.debugger'));
41-
cp.spawnSync(cliPath, [...args, '--install-extension', dbgExtId],
42-
{ encoding: 'utf-8', stdio: 'inherit'});
43-
/* Disable warnings if any */
44-
extraArgs = ['--enable-proposed-api', dbgExtId];
31+
extraArgs = [];
32+
for (const dbgExt of ['ms-vscode.cpptools', 'vadimcn.vscode-lldb']) {
33+
cp.spawnSync(cliPath, [...args, '--install-extension', dbgExt],
34+
{ encoding: 'utf-8', stdio: 'inherit'});
35+
/* Disable warnings if any */
36+
extraArgs.push('--enable-proposed-api', dbgExt);
37+
}
4538
}
4639

4740
/*

src/test/suite/env.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from 'fs';
12
import * as path from 'path';
23

34
export enum DebuggerType {
@@ -23,24 +24,17 @@ export class TestEnv {
2324
pgVersion: string;
2425
/* Version of VS Code we are running on */
2526
vscodeVersion: string;
26-
/* Debugger extension is used */
27-
debugger: DebuggerType | undefined;
27+
/* Which tests are enabled */
2828
testMode: TestMode;
2929

3030
constructor(pgVersion: string,
3131
vscodeVersion: string,
32-
debuggerType: string | undefined,
3332
testMode: string) {
3433
if (Number.isNaN(Number(pgVersion))) {
3534
throw new Error(`Invalid PostgreSQL version "${pgVersion}".` +
3635
'Version must be in "major.minor" form.');
3736
}
3837

39-
if ( debuggerType !== undefined
40-
&& !(debuggerType === DebuggerType.CppDbg || debuggerType === DebuggerType.CodeLLDB)) {
41-
throw new Error(`Debugger ${debuggerType} is not supported`);
42-
}
43-
4438
let mode: TestMode = TestMode.None;
4539
if (testMode.indexOf('vars') !== -1) {
4640
mode |= TestMode.Debug;
@@ -55,26 +49,12 @@ export class TestEnv {
5549
if (mode === TestMode.None) {
5650
throw new Error(`No test modes specified: accept between "vars" and "format"`);
5751
}
58-
59-
if (mode & TestMode.Debug && !debuggerType) {
60-
throw new Error('Test mode is "vars", but debugger is not specified');
61-
}
6252

6353
this.pgVersion = pgVersion;
6454
this.vscodeVersion = vscodeVersion;
65-
this.debugger = debuggerType;
6655
this.testMode = mode;
6756
}
6857

69-
/* Which debugger is used to test variables */
70-
debuggerIsCodeLLDB() {
71-
return this.debugger === 'lldb';
72-
}
73-
74-
debuggerIsCppDbg() {
75-
return this.debugger === 'cppdbg';
76-
}
77-
7858
/* Determine which tests to run */
7959
testDebugger() {
8060
return this.testMode & TestMode.Debug;
@@ -115,8 +95,5 @@ export function getTestEnv(): TestEnv {
11595
const pgVersion = process.env.PGHH_PG_VERSION ?? defaultPostgresVersion;
11696
const vscodeVersion = process.env.PGHH_VSCODE_VERSION ?? defaultVsCodeVersion;
11797
const testMode = process.env.PGHH_TEST_MODE ?? defaultTestMode;
118-
119-
/* Flag for variables tests */
120-
const dbg = process.env.PGHH_DEBUGGER;
121-
return new TestEnv(pgVersion, vscodeVersion, dbg, testMode);
98+
return new TestEnv(pgVersion, vscodeVersion, testMode);
12299
}

src/test/suite/formatting.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ suite('Formatting', async function () {
5454
});
5555

5656
env = getTestEnv();
57-
unformattedFilePath = env.getWorkspaceFile('unformatted.c');
57+
unformattedFilePath = env.getWorkspaceFile('unformatted.c');
5858
expected = getFormattedFile(env);
5959
});
6060

0 commit comments

Comments
 (0)