Skip to content

Commit

Permalink
fixed a bug related to debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Mar 14, 2019
1 parent 1ddd4de commit 2494864
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.3.24]

### Fixed

- a bug related to debugging (https://github.com/Microsoft/vscode/issues/70125).

### Changed

- test suite loading order from now is not deterministic. One can set `testExplorer.sort` for ordering.
Expand Down
39 changes: 24 additions & 15 deletions src/TestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as api from 'vscode-test-adapter-api';
import * as util from 'vscode-test-adapter-util';

import { RootTestSuiteInfo } from './RootTestSuiteInfo';
import { resolveVariables } from './Util';
import { resolveVariables, generateUniqueId } from './Util';
import { TaskQueue } from './TaskQueue';
import { TestExecutableInfo } from './TestExecutableInfo';
import { SharedVariables } from './SharedVariables';
Expand Down Expand Up @@ -387,32 +387,41 @@ export class TestAdapter implements api.TestAdapter, vscode.Disposable {
['${envObj}', Object.assign(Object.assign({}, process.env), testSuite.execOptions.env!)],
]);

// we dont know better :(
// https://github.com/Microsoft/vscode/issues/70125
const magicValueKey = 'magic variable 🤦🏼‍♂️';
const magicValue = generateUniqueId();
debugConfig[magicValueKey] = magicValue;

this._log.info('Debug: resolved catch2TestExplorer.debugConfigTemplate:', debugConfig);

const terminated = new Promise<vscode.DebugSession>(resolve => {
const conn = vscode.debug.onDidTerminateDebugSession((session: vscode.DebugSession) => {
const session2 = (session as unknown) as { configuration: { [prop: string]: string } };
if (session2.configuration && session2.configuration[magicValueKey] === magicValue) {
resolve(session);
conn.dispose();
}
});
});

return this._mainTaskQueue.then(() => {
return vscode.debug
.startDebugging(this.workspaceFolder, debugConfig)
.then((debugSessionStarted: boolean) => {
const currentSession = vscode.debug.activeDebugSession;

if (!debugSessionStarted || !currentSession) {
if (!debugSessionStarted) {
return Promise.reject(
'Failed starting the debug session - aborting. Maybe something wrong with "catch2TestExplorer.debugConfigTemplate"; ' +
+debugSessionStarted +
'; ' +
currentSession,
new Error(
'Failed starting the debug session. ' +
'Maybe something wrong with "catch2TestExplorer.debugConfigTemplate".',
),
);
}

this._log.info('debugSessionStarted');

return new Promise<void>(resolve => {
const subscription = vscode.debug.onDidTerminateDebugSession(session => {
if (currentSession != session) return;
this._log.info('Debug session ended.');
resolve();
subscription.dispose();
});
return terminated.finally(() => {
this._log.info('debugSessionTerminated');
});
})
.then(undefined, (reason: Error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/TestCatch2FrameworkLoad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ describe(path.basename(__filename), function() {

await adapter.load();

startDebuggingStub.onFirstCall().resolves(true);
startDebuggingStub.onFirstCall().resolves(false);

try {
await adapter.debug([adapter.suite1.children[0].id]);
Expand Down
4 changes: 3 additions & 1 deletion src/test/TestExecutablesVariable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ describe(path.basename(__filename), function() {
let adapter: TestAdapter;

before(async function() {
await settings.resetConfig();
this.timeout(4000);

imitation = new Imitation();
await settings.resetConfig();
});

beforeEach(function() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/TestLogOutputContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const expectedErrorLines = new Map<string /* test */, Set<string>>([
[
'TestCatch2FrameworkLoad.test.js -> vscode.debug -> should be debugged',
new Set([
'[ERROR] Failed starting the debug session - aborting. Maybe something wrong with "catch2TestExplorer.debugConfigTemplate"; 1; undefined',
'[ERROR] Error: Failed starting the debug session. Maybe something wrong with "catch2TestExplorer.debugConfigTemplate".',
]),
],
]);
Expand Down

0 comments on commit 2494864

Please sign in to comment.