Skip to content

Commit d2ebbd0

Browse files
authored
Automatic settings reload and test executable detection (#28)
* Update settings to homogeneously identify the extension as cpputestTestAdapter * Automatically reload settings * Update tests
1 parent 2a41e0b commit d2ebbd0

File tree

7 files changed

+75
-69
lines changed

7 files changed

+75
-69
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ This is the implementation for a [CppUTest](https://cpputest.github.io/) Test Ad
88

99
## Setup
1010

11-
To let this plugin know where your tests are set the ```cpputestExplorer.testExecutable``` to the executable of your tests. They are separated by semicolon and support wildcards, so you can add as many executables as you want:
11+
To let this plugin know where your tests are set the ```cpputestTestAdapter.testExecutable``` to the executable of your tests. They are separated by semicolon and support wildcards, so you can add as many executables as you want:
1212
```
1313
{
14-
"cpputestExplorer.testExecutable": "${workspaceFolder}/test/testrunner;${workspaceFolder}/test/subFolder/ut_*",
15-
"cpputestExplorer.testExecutablePath": "${workspaceFolder}/test"
14+
"cpputestTestAdapter.testExecutable": "${workspaceFolder}/test/testrunner;${workspaceFolder}/test/subFolder/ut_*",
15+
"cpputestTestAdapter.testExecutablePath": "${workspaceFolder}/test"
1616
}
1717
```
18-
They will be executed in the ```cpputestExplorer.testExecutablePath``` path.
18+
They will be executed in the ```cpputestTestAdapter.testExecutablePath``` path.
1919

2020
If you want to use the debugging functions you will also need to setup a launch.json file with your debugger path and arguments etc. The adapter will take care of the rest. Hopefully.
2121

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,27 @@
6868
"contributes": {
6969
"configuration": {
7070
"type": "object",
71-
"title": "CppUTest Explorer configuration",
71+
"title": "CppUTest Test Adapter",
7272
"properties": {
73-
"cpputestExplorer.testExecutable": {
74-
"description": "executable that contains all tests. Can be multiple executables separated by semicolon. Wildcard is supported (e.g. myExecutable;bin/test/ut_*)",
73+
"cpputestTestAdapter.testExecutable": {
74+
"description": "Executable that contains all tests. Can be multiple executables separated by semicolon. Wildcard is supported (e.g. myExecutable;bin/test/ut_*)",
7575
"default": "",
7676
"type": "string",
7777
"scope": "resource"
7878
},
79-
"cpputestExplorer.testExecutablePath": {
80-
"description": "path where the executable should be run in",
79+
"cpputestTestAdapter.testExecutablePath": {
80+
"description": "Path where the executable should be run in",
8181
"default": "",
8282
"type": "string",
8383
"scope": "resource"
8484
},
85-
"cpputestExplorer.logpanel": {
86-
"description": "write diagnotic logs to an output panel",
85+
"cpputestTestAdapter.logpanel": {
86+
"description": "Write diagnostic logs to an output panel",
8787
"type": "boolean",
8888
"scope": "resource"
8989
},
90-
"cpputestExplorer.logfile": {
91-
"description": "write diagnostic logs to the given file",
90+
"cpputestTestAdapter.logfile": {
91+
"description": "Write diagnostic logs to the given file",
9292
"type": "string",
9393
"scope": "resource"
9494
}

src/Domain/CppUTestContainer.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ export default class CppUTestContainer {
2525
this.onTestStartHandler = handler;
2626
}
2727

28-
constructor(runners: ExecutableRunner[], settingsProvider: SettingsProvider, vscodeAdapter: VscodeAdapter, resultParser: ResultParser) {
28+
constructor(settingsProvider: SettingsProvider, vscodeAdapter: VscodeAdapter, resultParser: ResultParser) {
2929
this.settingsProvider = settingsProvider;
30-
this.runners = runners;
30+
this.runners = [];
3131
this.vscodeAdapter = vscodeAdapter;
3232
this.resultParser = resultParser;
3333
this.suites = new Map<string, CppUTestSuite>();
3434
}
3535

36-
public LoadTests(): Promise<CppUTestSuite[]> {
36+
public LoadTests(runners: ExecutableRunner[]): Promise<CppUTestSuite[]> {
37+
this.runners = runners;
3738
return Promise.all(this.runners
3839
.map(runner => runner.GetTestList()
3940
.then(testString => this.UpdateTestSuite(runner, testString))

src/Infrastructure/VscodeSettingsProvider.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@ import { glob } from 'glob';
33
import { SettingsProvider } from './SettingsProvider';
44

55
export default class VscodeSettingsProvider implements SettingsProvider {
6-
private readonly Executables: string;
7-
private readonly ExecutablePath: string;
6+
private config: vscode.WorkspaceConfiguration;
87

9-
constructor(config: vscode.WorkspaceConfiguration) {
10-
this.Executables = config.testExecutable;
11-
this.ExecutablePath = config.testExecutablePath;
8+
constructor() {
9+
const configSection = "cpputestTestAdapter";
10+
this.config = vscode.workspace.getConfiguration(configSection);
11+
vscode.workspace.onDidChangeConfiguration(event => {
12+
if (event.affectsConfiguration(configSection)) {
13+
this.config = vscode.workspace.getConfiguration(configSection);
14+
}
15+
})
1216
}
1317

1418
GetWorkspaceFolders(): readonly vscode.WorkspaceFolder[] | undefined {
1519
return vscode.workspace.workspaceFolders;
1620
}
1721

1822
public GetTestRunners(): string[] {
19-
return this.SplitRunners(this.Executables);
23+
return this.SplitRunners(this.config.testExecutable);
2024
}
2125

2226
public GetTestPath(): string {
23-
return this.ResolveSettingsVariable(this.ExecutablePath);
27+
return this.ResolveSettingsVariable(this.config.testExecutablePath);
2428
}
2529

2630

src/adapter.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import VscodeSettingsProvider from "./Infrastructure/VscodeSettingsProvider";
1212
import ExecutableRunner from "./Infrastructure/ExecutableRunner";
1313
import { NodeProcessExecuter } from './Application/NodeProcessExecuter';
1414
import { VscodeAdapterImplementation } from "./Application/VscodeAdapterImplementation";
15+
import { SettingsProvider } from "./Infrastructure/SettingsProvider";
16+
import { ProcessExecuter } from "./Application/ProcessExecuter";
1517

1618
export class CppUTestAdapter implements TestAdapter {
1719

@@ -22,7 +24,8 @@ export class CppUTestAdapter implements TestAdapter {
2224
private readonly autorunEmitter = new vscode.EventEmitter<RetireEvent>();
2325
private readonly mainSuite: CppUTestGroup;
2426
private readonly root: CppUTestContainer;
25-
27+
private readonly settingsProvider: SettingsProvider;
28+
private readonly processExecuter: ProcessExecuter;
2629

2730
get tests(): vscode.Event<TestLoadStartedEvent | TestLoadFinishedEvent> { return this.testsEmitter.event; }
2831
get testStates(): vscode.Event<TestRunStartedEvent | TestRunFinishedEvent | TestSuiteEvent | TestEvent> { return this.testStatesEmitter.event; }
@@ -37,13 +40,12 @@ export class CppUTestAdapter implements TestAdapter {
3740

3841
this.disposables.push(this.testsEmitter, this.testStatesEmitter, this.autorunEmitter);
3942

40-
const settingsProvider = new VscodeSettingsProvider(vscode.workspace.getConfiguration("cpputestExplorer"));
41-
const processExecuter = new NodeProcessExecuter();
43+
this.settingsProvider = new VscodeSettingsProvider();
44+
this.processExecuter = new NodeProcessExecuter();
4245
const vscodeAdapter = new VscodeAdapterImplementation();
43-
const runners = settingsProvider.GetTestRunners().map(runner => new ExecutableRunner(processExecuter, runner));
4446
const resultParser = new RegexResultParser();
4547

46-
this.root = new CppUTestContainer(runners, settingsProvider, vscodeAdapter, resultParser);
48+
this.root = new CppUTestContainer(this.settingsProvider, vscodeAdapter, resultParser);
4749
this.root.OnTestFinish = this.handleTestFinished.bind(this);
4850
this.root.OnTestStart = this.handleTestStarted.bind(this);
4951

@@ -61,13 +63,9 @@ export class CppUTestAdapter implements TestAdapter {
6163
this.testsEmitter.fire(<TestLoadStartedEvent>{ type: 'started' });
6264
this.log.info('Loading tests');
6365

64-
this.root.ClearTests();
65-
const loadedTests = await this.root.LoadTests();
66+
await this.updateTests();
6667

6768
this.log.info('Tests loaded');
68-
69-
this.mainSuite.children = loadedTests;
70-
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type: 'finished', suite: this.mainSuite });
7169
}
7270

7371
public async run(tests: string[]): Promise<void> {
@@ -103,7 +101,8 @@ export class CppUTestAdapter implements TestAdapter {
103101

104102
private async updateTests(): Promise<void> {
105103
this.root.ClearTests();
106-
const loadedTests = await this.root.LoadTests();
104+
const runners = this.settingsProvider.GetTestRunners().map(runner => new ExecutableRunner(this.processExecuter, runner));
105+
const loadedTests = await this.root.LoadTests(runners);
107106
this.mainSuite.children = loadedTests;
108107
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type: 'finished', suite: this.mainSuite });
109108
}

src/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export async function activate(context: vscode.ExtensionContext) {
88
const workspaceFolder = (vscode.workspace.workspaceFolders || [])[0];
99

1010
// create a simple logger that can be configured with the configuration variables
11-
// `cpputestExplorer.logpanel"` and `cpputestExplorer.logfile`
12-
const log = new Log('cpputestExplorer', workspaceFolder, 'CppUTest Explorer Log');
11+
// `cpputestTestAdapter.logToOutputPanel"` and `cpputestTestAdapter.logToFile`
12+
const log = new Log('cpputestTestAdapter', workspaceFolder, 'CppUTest Test Adapter Log');
1313
context.subscriptions.push(log);
1414

1515
// get the Test Explorer extension

0 commit comments

Comments
 (0)