Skip to content

Commit

Permalink
Merge pull request #72 from matepek/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
matepek authored Mar 14, 2019
2 parents ca875f1 + 2494864 commit 31fe29e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 53 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ 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.

## [2.3.23] - 2019-03-14

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "resources/icon.png",
"author": "Mate Pek",
"publisher": "matepek",
"version": "2.3.23",
"version": "2.3.24-dev",
"license": "Unlicense",
"homepage": "https://github.com/matepek/vscode-catch2-test-adapter",
"repository": {
Expand Down
18 changes: 7 additions & 11 deletions src/RootTestSuiteInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SharedVariables } from './SharedVariables';

export class RootTestSuiteInfo extends AbstractTestSuiteInfoBase implements vscode.Disposable {
public readonly children: AbstractTestSuiteInfo[] = [];
private readonly _executables: TestExecutableInfo[] = [];
private _executables: TestExecutableInfo[] = [];
private readonly _taskPool: TaskPool;

public constructor(shared: SharedVariables, workerMaxNumber: number) {
Expand All @@ -33,16 +33,12 @@ export class RootTestSuiteInfo extends AbstractTestSuiteInfoBase implements vsco
this.children.forEach(c => c.cancel());
}

public async load(executables: TestExecutableInfo[]): Promise<void> {
for (let i = 0; i < executables.length; i++) {
const executable = executables[i];
try {
await executable.load();
this._executables.push(executable);
} catch (e) {
this._shared.log.error(e, i, executables);
}
}
public load(executables: TestExecutableInfo[]): Promise<void> {
this._executables.forEach(e => e.dispose());

this._executables = executables;

return Promise.all(executables.map(v => v.load().catch(e => this._shared.log.error(e, v)))).then(() => {});
}

public run(tests: string[]): Promise<void> {
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
52 changes: 29 additions & 23 deletions src/TestExecutableInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,36 +94,42 @@ export class TestExecutableInfo implements vscode.Disposable {
fileUris.push(absPatternAsUri);
}

const suiteCreationAndLoadingTasks: Promise<void>[] = [];

for (let i = 0; i < fileUris.length; i++) {
const file = fileUris[i];
this._shared.log.info('Checking file for tests:', file.fsPath);

await c2fs.isNativeExecutableAsync(file.fsPath).then(
() => {
return this._createSuiteByUri(file).then(
(suite: AbstractTestSuiteInfo) => {
return suite.reloadChildren().then(
() => {
if (this._rootSuite.insertChild(suite, false /* called later */)) {
this._executables.set(file.fsPath, suite);
}
},
(reason: Error) => {
this._shared.log.warn("Couldn't load executable:", reason, suite);
},
);
},
(reason: Error) => {
this._shared.log.warn('Not a test executable:', file.fsPath, 'reason:', reason);
},
);
},
(reason: Error) => {
this._shared.log.info('Not an executable:', file.fsPath, reason);
},
suiteCreationAndLoadingTasks.push(
c2fs.isNativeExecutableAsync(file.fsPath).then(
() => {
return this._createSuiteByUri(file).then(
(suite: AbstractTestSuiteInfo) => {
return suite.reloadChildren().then(
() => {
if (this._rootSuite.insertChild(suite, false /* called later */)) {
this._executables.set(file.fsPath, suite);
}
},
(reason: Error) => {
this._shared.log.warn("Couldn't load executable:", reason, suite);
},
);
},
(reason: Error) => {
this._shared.log.warn('Not a test executable:', file.fsPath, 'reason:', reason);
},
);
},
(reason: Error) => {
this._shared.log.info('Not an executable:', file.fsPath, reason);
},
),
);
}

await Promise.all(suiteCreationAndLoadingTasks);

this._rootSuite.uniquifySuiteLabels();
}

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 31fe29e

Please sign in to comment.