Skip to content

Commit

Permalink
Merge pull request #378 from matepek/continuous-tests
Browse files Browse the repository at this point in the history
Continuous tests
  • Loading branch information
matepek authored Mar 31, 2023
2 parents 1f1bb33 + f9251d6 commit ff591dc
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 58 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.4.0]

### Added

- support for vscode "continuous tests" [feature](https://github.com/microsoft/vscode/issues/134941), [release note](https://code.visualstudio.com/updates/v1_77#_finalized-support-for-continuous-test-runs)

## [4.3.12] - 2023-03-22

## [4.3.11] - 2023-03-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* https://github.com/catchorg/Catch2/blob/master/docs/own-main.md
*/
#define CATCH_CONFIG_RUNNER
#include "catch2/catch.hpp"
#include "catch2/catch_all.hpp"

#include "env_setter.hpp"

Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@types/sinon": "^10.0.13",
"@types/source-map-support": "^0.5.6",
"@vscode/vsce": "^2.18.0",
"@types/vscode": "1.65.0",
"@types/vscode": "1.77.0",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"@vscode/test-electron": "^2.3.0",
Expand All @@ -94,8 +94,9 @@
"webpack-bundle-analyzer": "^4.8.0",
"webpack-cli": "^5.0.1"
},
"enabledApiProposals": [],
"engines": {
"vscode": "^1.65.0"
"vscode": "^1.77.0"
},
"activationEvents": [
"onStartupFinished"
Expand Down
6 changes: 3 additions & 3 deletions src/ConfigOfExecGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
for (const exec of this._executables.values())
exec.reloadTests(this._shared.taskPool, this._shared.cancellationToken, modiTime);
});
//TODO:future this._shared.sendRetireEvent(this._executables.values());
this._shared.sendRetireEvent(this._executables.values());
});
} else {
absPatterns.push(p.absPath);
Expand All @@ -191,7 +191,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {

w.onAll((fsPath: string): void => {
this._shared.log.info('dependsOn watcher event:', fsPath);
//TODO:future this._shared.sendRetireEvent(this._executables.values());
this._shared.sendRetireEvent(this._executables.values());
});
}
} catch (e) {
Expand Down Expand Up @@ -471,7 +471,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
try {
await executable.reloadTests(this._shared.taskPool, this._shared.cancellationToken);
this._executables.set(filePath, executable); // it might be set already but we don't care
//TODO:release this._shared.sendRetireEvent([runnable]);
this._shared.sendRetireEvent([executable]);
} catch (reason: any /*eslint-disable-line*/) {
if (reason?.code === undefined)
this._shared.log.debug('problem under reloading', { reason, filePath, runnable: executable });
Expand Down
3 changes: 2 additions & 1 deletion src/WorkspaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { AbstractTest } from './framework/AbstractTest';
import { TestItemManager } from './TestItemManager';
import { ProgressReporter } from './util/ProgressReporter';

//TODO:release if workspace contains ".vscode/testMate.cpp.json" we have to start loading the tests
export class WorkspaceManager implements vscode.Disposable {
constructor(
private readonly workspaceFolder: vscode.WorkspaceFolder,
private readonly log: LoggerWrapper,
testItemManager: TestItemManager,
executableChanged: (e: Iterable<AbstractExecutable>) => void,
) {
const workspaceNameRes: ResolveRuleAsync = { resolve: '${workspaceName}', rule: this.workspaceFolder.name };

Expand Down Expand Up @@ -137,6 +137,7 @@ export class WorkspaceManager implements vscode.Disposable {
log,
testItemManager,
executeTask,
executableChanged,
variableToValue,
configuration.getRandomGeneratorSeed(),
configuration.getExecWatchTimeout(),
Expand Down
2 changes: 2 additions & 0 deletions src/WorkspaceShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BuildProcessChecker } from './util/BuildProcessChecker';
import { CancellationToken } from './Util';
import { TestItemManager } from './TestItemManager';
import { FrameworkSpecificConfig } from './AdvancedExecutableInterface';
import { AbstractExecutable } from './framework/AbstractExecutable';

export class WorkspaceShared {
constructor(
Expand All @@ -17,6 +18,7 @@ export class WorkspaceShared {
varsToResolve: readonly ResolveRuleAsync[],
cancellationToken: CancellationToken,
) => Promise<number | undefined>,
readonly sendRetireEvent: (executables: Iterable<AbstractExecutable>) => void,
readonly varToValue: readonly Readonly<ResolveRuleAsync>[],
public rngSeed: 'time' | number | null,
public execWatchTimeout: number,
Expand Down
12 changes: 12 additions & 0 deletions src/framework/AbstractExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export abstract class AbstractExecutable<TestT extends AbstractTest = AbstractTe
return this._tests.get(testId) as TestT;
}

public getTests(): Iterable<AbstractTest> {
return this._tests.values();
}

private async _getOrCreateChildGroup(
idIn: string | undefined,
label: string,
Expand Down Expand Up @@ -166,6 +170,10 @@ export abstract class AbstractExecutable<TestT extends AbstractTest = AbstractTe
*/
private readonly _execItem: ExecutableGroup;

public getExecTestItem(): vscode.TestItem | undefined {
return this._execItem.getItem();
}

protected async _createTreeAndAddTest(
testGrouping: TestGroupingConfig,
testId: string,
Expand Down Expand Up @@ -841,6 +849,10 @@ class ExecutableGroup {
// we need to be exclusive because we save prevTests
private _lock = Promise.resolve();

getItem(): vscode.TestItem | undefined {
return this._item ?? undefined;
}

setItem(item: vscode.TestItem) {
if (this._item !== undefined) {
if (this._item !== null && this._item !== item) {
Expand Down
82 changes: 55 additions & 27 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
const controller = vscode.tests.createTestController('testmatecpp', 'TestMate C++');
const workspace2manager = new Map<vscode.WorkspaceFolder, WorkspaceManager>();
const testItemManager = new TestItemManager(controller);
const executableChangedEmitter = new vscode.EventEmitter<Iterable<AbstractExecutable>>();
const executableChanged = (e: Iterable<AbstractExecutable>): void => executableChangedEmitter.fire(e);

///

const addWorkspaceManager = (wf: vscode.WorkspaceFolder): void => {
if (workspace2manager.get(wf)) log.errorS('Unexpected workspace manager', wf);
else workspace2manager.set(wf, new WorkspaceManager(wf, log, testItemManager));
else workspace2manager.set(wf, new WorkspaceManager(wf, log, testItemManager, executableChanged));
};

const removeWorkspaceManager = (wf: vscode.WorkspaceFolder): void => {
Expand Down Expand Up @@ -128,41 +130,67 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
let runCount = 0;
let debugCount = 0;

const runProfile = controller.createRunProfile(
'Run Test',
vscode.TestRunProfileKind.Run,
async (request: vscode.TestRunRequest, cancellation: vscode.CancellationToken): Promise<void> => {
if (debugCount) {
vscode.window.showWarningMessage('Cannot run new tests while debugging.');
return;
}
const startTestRun = async (request: vscode.TestRunRequest, cancellation: vscode.CancellationToken) => {
if (debugCount) {
vscode.window.showWarningMessage('Cannot run new tests while debugging.');
return;
}

const testRun = controller.createTestRun(request);
++runCount;
const testRun = controller.createTestRun(request);
++runCount;

try {
const managers = collectExecutablesForRun(request);
try {
const managers = collectExecutablesForRun(request);

const runQueue: Thenable<void>[] = [];
const runQueue: Thenable<void>[] = [];

for (const [manager, executables] of managers) {
runQueue.push(
manager.run(executables, cancellation, testRun).catch(e => {
vscode.window.showErrorMessage('Unexpected error from run: ' + e);
}),
);
}
for (const [manager, executables] of managers) {
runQueue.push(
manager.run(executables, cancellation, testRun).catch(e => {
vscode.window.showErrorMessage('Unexpected error from run: ' + e);
}),
);
}

await Promise.allSettled(runQueue);
} catch (e) {
log.errorS('runHandler errored. never should be here', e);
} finally {
testRun.end();
--runCount;
await Promise.allSettled(runQueue);
} catch (e) {
log.errorS('runHandler errored. never should be here', e);
} finally {
testRun.end();
--runCount;
}
};

const runProfile = controller.createRunProfile(
'Run Test',
vscode.TestRunProfileKind.Run,
async (request: vscode.TestRunRequest, cancellation: vscode.CancellationToken): Promise<void> => {
if (request.continuous) {
const l = executableChangedEmitter.event(executables => {
const include: vscode.TestItem[] = [];
if (request.include === undefined) {
for (const e of executables) {
const eit = e.getExecTestItem();
if (eit) include.push(eit);
else for (const t of e.getTests()) include.push(t.item);
}
} else {
for (const e of executables) {
for (const t of e.getTests()) {
if (request.include.indexOf(t.item) !== -1) include.push(t.item);
}
}
}
startTestRun(new vscode.TestRunRequest(include, request.exclude, request.profile, true), cancellation);
});
cancellation.onCancellationRequested(() => l.dispose());
} else {
return startTestRun(request, cancellation);
}
},
true,
SharedTestTags.runnable,
true,
);

// https://github.com/matepek/vscode-catch2-test-adapter/issues/375
Expand Down
15 changes: 6 additions & 9 deletions test/cpp/catch2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
include("Catch2Test.cmake")

add_catch2test_with_main(suite1 "suite1.cpp")
add_catch2test_with_main(suite2 "suite2.cpp")
add_catch2test_with_main(suite3 "suite3.cpp")
add_catch2test_with_main(suite4 "suite4.cpp")
add_catch2test_with_main(suite5 "suite5.cpp")

#
# include("Catch2Test.cmake")

include("Catch2v3Test.cmake")

add_catch2v3test_with_main(suite1 "suite1.cpp")
add_catch2v3test_with_main(suite2 "suite2.cpp")
add_catch2v3test_with_main(suite3 "suite3.cpp")
add_catch2v3test_with_main(suite4 "suite4.cpp")
add_catch2v3test_with_main(suite5 "suite5.cpp")
add_catch2v3test_with_main(catch2v3_test1 "catch2v3_test1.cpp")
3 changes: 2 additions & 1 deletion test/cpp/catch2/suite1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <iostream>

#include "catch2/catch.hpp"
#include "catch2/catch_all.hpp"
// c++ -x c++ -std=c++17 -I ../Catch2/single_include -O0 -g -o suite1
// ../vscode-catch2-test-adapter/src/test/suite1.cpp

Expand Down
2 changes: 1 addition & 1 deletion test/cpp/catch2/suite2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch2/catch.hpp"
#include "catch2/catch_all.hpp"

// c++ -x c++ -std=c++17 -I ../Catch2/single_include -O0 -g -o suite2
// ../vscode-catch2-test-adapter/src/test/suite2.cpp
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/catch2/suite3.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <chrono>
#include <thread>

#include "catch2/catch.hpp"
#include "catch2/catch_all.hpp"

// clang-format off
// c++ -x c++ -std=c++17 -I ../Catch2/single_include -O0 -g -o suite3 ../vscode-catch2-test-adapter/src/test/suite3.cpp
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/catch2/suite4.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch2/catch.hpp"
#include "catch2/catch_all.hpp"

#include <chrono>
#include <thread>
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/catch2/suite5.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch2/catch.hpp"
#include "catch2/catch_all.hpp"

TEST_CASE("suite with label 1", "descr [1][2]") {}
TEST_CASE("suite with label 2", "descr [2][3]") {}
Expand Down

0 comments on commit ff591dc

Please sign in to comment.