Skip to content

Commit cc0f7d5

Browse files
committed
Revert "test: run all debugger tests in a single variables.test.ts invocation"
This reverts commit 8d8423a. After adding such thing strange exception started to show: ListError [Breakpoints] Invalid Index 2 I don't know how to fix it, because this is not my error and stack trace points to somewhere in VS Code source code. This fixes by just splitting test by debugger and running them in different sessions (I mean different VS Code windows).
1 parent 8267dd9 commit cc0f7d5

File tree

8 files changed

+518
-484
lines changed

8 files changed

+518
-484
lines changed

.vscode-test.mjs

Lines changed: 2 additions & 1 deletion
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: 'Tests',
7+
label: 'Unit tests',
88
files: 'out/test/**/*.test.js',
99
mocha: {
1010
ui: 'tdd',
@@ -14,6 +14,7 @@ export default defineConfig([
1414
version: 'stable',
1515
workspaceFolder: './pgsrc/18',
1616
env: {
17+
PGHH_DEBUGGER: 'cppdbg',
1718
PGHH_PG_VERSION: '18',
1819
PGHH_VSCODE_VERSION: 'stable',
1920
PGHH_TEST_MODE: 'vars,format,unit',

.vscode/tasks.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
"kind": "build",
1616
"isDefault": true
1717
}
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-
}
18+
}
3219
]
3320
}

src/test/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ 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"
56+
--vscode-versions="stable 1.90" \
57+
--debuggers="lldb"
5758
```
5859

5960
Use `--help` flag to get more info about.
@@ -96,3 +97,13 @@ You can use it when working with our custom members (i.e. number from `Bitmapset
9697
In other cases rely on *stable* parts - variable/member name or type.
9798

9899
Reason: each DAP provider uses it's own syntax, so we might get failed assertion, even though everything works correctly.
100+
101+
## Notes
102+
103+
### Split by debugger
104+
105+
There might be an idea to run variables tests with both cppdbg and codelldb in same window, but just have some sort of setup before changing debugger.
106+
Commit `8d8423a4ac36d1fa1ece8b6833e82564e9c4c99a` did exactly that, but after strange error emerged: `ListError [Breakpoints] Invalid Index 2`.
107+
This error comes from VS Code internals and is not my error, but because of it tests does not pass.
108+
109+
Why this error happened I still don't know, but such split does not cause much inconvenience.

src/test/runTests.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ 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+
}
817

918
async function main() {
1019
/*
@@ -28,13 +37,11 @@ async function main() {
2837
/* Install required debugger extension */
2938
let extraArgs: string[] = [];
3039
if (testEnv.testDebugger()) {
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-
}
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];
3845
}
3946

4047
/*

src/test/suite/env.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ export class TestEnv {
2323
pgVersion: string;
2424
/* Version of VS Code we are running on */
2525
vscodeVersion: string;
26-
/* Which tests are enabled */
26+
/* Debugger extension is used */
27+
debugger: DebuggerType | undefined;
2728
testMode: TestMode;
2829

2930
constructor(pgVersion: string,
3031
vscodeVersion: string,
32+
debuggerType: string | undefined,
3133
testMode: string) {
3234
if (Number.isNaN(Number(pgVersion))) {
3335
throw new Error(`Invalid PostgreSQL version "${pgVersion}".` +
3436
'Version must be in "major.minor" form.');
3537
}
3638

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

5263
this.pgVersion = pgVersion;
5364
this.vscodeVersion = vscodeVersion;
65+
this.debugger = debuggerType;
5466
this.testMode = mode;
5567
}
5668

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+
5778
/* Determine which tests to run */
5879
testDebugger() {
5980
return this.testMode & TestMode.Debug;
@@ -94,5 +115,8 @@ export function getTestEnv(): TestEnv {
94115
const pgVersion = process.env.PGHH_PG_VERSION ?? defaultPostgresVersion;
95116
const vscodeVersion = process.env.PGHH_VSCODE_VERSION ?? defaultVsCodeVersion;
96117
const testMode = process.env.PGHH_TEST_MODE ?? defaultTestMode;
97-
return new TestEnv(pgVersion, vscodeVersion, testMode);
118+
119+
/* Flag for variables tests */
120+
const dbg = process.env.PGHH_DEBUGGER;
121+
return new TestEnv(pgVersion, vscodeVersion, dbg, testMode);
98122
}

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)