Skip to content

Commit

Permalink
Build before running CTest
Browse files Browse the repository at this point in the history
I added functionality to run the `cmake.build` command before running
CTest. If the use has ms-vscode.cmake-tools extension, CTest Lab will
run the default `cmake.build` command. Then, if that command succeeds,
it will run the tests. I added a setting to disable this functionality.
I also updated the user documentation.

closes #23
  • Loading branch information
brobeson committed Nov 25, 2022
1 parent ca4b2cc commit bd1992d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 24 deletions.
41 changes: 24 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,42 @@

This file documents all notable changes to the CTest Lab extension.

## Next Release
## [0.4.0] — 2022-11-24

### Added

- [#12](https://github.com/brobeson/ctest-lab/issues/12) During test discovery,
exclude tests that are not built

### Fixed

- Activate the output channel before running the tests
[#25](https://github.com/brobeson/ctest-lab/issues/25)
- [#28](https://github.com/brobeson/ctest-lab/issues/28) Removed obsolete
information from the README file and user manual
- [#25](https://github.com/brobeson/ctest-lab/issues/25) Activate the output
channel before running the tests

## [0.3.1] — 2022-11-06

### Fixed

- The extension now activates properly
[#24](https://github.com/brobeson/ctest-lab/issues/24)
- [#24](https://github.com/brobeson/ctest-lab/issues/24) The extension now
activates properly

## [0.3.0] — 2022-10-08

### Added

- Run tests via the `ctest` command:
[#15](https://github.com/brobeson/ctest-lab/issues/15)
- Parse test results from `ctest` command output:
[#17](https://github.com/brobeson/ctest-lab/issues/15)
- Run individual tests from the test view:
[#21](https://github.com/brobeson/ctest-lab/issues/21)
- [#15](https://github.com/brobeson/ctest-lab/issues/15) Run tests via the
`ctest` command:
- [#17](https://github.com/brobeson/ctest-lab/issues/15) Parse test results from
`ctest` command output:
- [#21](https://github.com/brobeson/ctest-lab/issues/21) Run individual tests
from the test view:

### Removed

- `CTest: Discover Tests` command:
[#18](https://github.com/brobeson/ctest-lab/issues/18)
- [#18](https://github.com/brobeson/ctest-lab/issues/18) `CTest: Discover Tests`
command:
- Use VS Code's `Test: Refresh Tests` command, instead.
- Notice of which build directory CTest Lab will use when the extension
activates.
Expand All @@ -41,16 +48,16 @@ This file documents all notable changes to the CTest Lab extension.

### Added

- Ability to run discovered tests:
[#13](https://github.com/brobeson/ctest-lab/issues/13)
- [#13](https://github.com/brobeson/ctest-lab/issues/13) Ability to run
discovered tests:

## [0.1.0] — 2022-09-02

### Added

- Basic test discovery: [#2](https://github.com/brobeson/ctest-lab/issues/2)
- [#2](https://github.com/brobeson/ctest-lab/issues/2) Basic test discovery

[unreleased]: https://github.com/brobeson/ctest-lab/compare/v0.3.1...HEAD
[0.4.0]: https://github.com/brobeson/ctest-lab/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/brobeson/ctest-lab/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/brobeson/ctest-lab/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/brobeson/ctest-lab/compare/v0.1.0...v0.2.0
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CTest.

- Discover tests registered with CTest.
- Run tests from the Test view in VS Code.
- Automatically build before running tests.
- Visualize passed, failed, disabled, and skipped tests.
<!-- - Filter tests by CTest `LABELS` property. -->

Expand All @@ -23,14 +24,10 @@ CTest.
variables, please comment on
[#7](https://github.com/brobeson/ctest-lab/issues/7); I haven't found any
documentation for this.
- CTest Lab includes tests that are not built in the discovery results. See
[#12](https://github.com/brobeson/ctest-lab/issues/12) for details.

## Roadmap

[![GitHub milestones](https://img.shields.io/github/milestones/open/brobeson/ctest-lab?color=blue&label=Open%20Milestones)](https://github.com/brobeson/ctest-lab/milestones)
[![GitHub milestone](https://img.shields.io/github/milestones/progress/brobeson/ctest-lab/3)](https://github.com/brobeson/ctest-lab/milestone/3)
[![GitHub milestones](https://img.shields.io/github/milestones/closed/brobeson/ctest-lab?label=Completed%20Milestones)](https://github.com/brobeson/ctest-lab/milestones?state=closed)

## User Manual

Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ can run all your tests with one command, or run individual tests. Use the play
buttons in the Testing View to run tests. When you run tests, CTest Lab
activates the CTest output channel so you can see the test output.

If you have the
[cmake-tools extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)
installed, CTest Lab will run the default build command prior to running tests.
Note that this does not affect test discovery. If you have new tests to
discover, you need to manually build and run test discovery. You can disable
this functionality with the `ctest-lab.buildBeforeRun` setting.

## The Testing View

CTest Lab provides ways for you to interact with your tests in the Testing View.
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@
"configuration": {
"title": "ctest-lab",
"properties": {
"ctest-lab.buildBeforeRun": {
"type": "boolean",
"description": "Run cmake-tools' build command before running tests.",
"default": true
},
"ctest-lab.buildDirectory": {
"type": "string",
"description": ""
"description": "Path to the project build directory. CTest Lab uses this if `cmake.buildDirectory` is unavailable."
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(log_channel);
log_channel.appendLine("CTest Lab is available.");

const cmakeToolsAvailable =
vscode.extensions.getExtension("ms-vscode.cmake-tools") !== undefined;

const controller = vscode.tests.createTestController(
"ctest-lab-tests",
"CTest"
Expand All @@ -20,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
"Run",
vscode.TestRunProfileKind.Run,
(request, token) => {
run_tests(controller, log_channel, request, token);
run_tests(controller, log_channel, request, token, cmakeToolsAvailable);
}
);

Expand Down
26 changes: 25 additions & 1 deletion src/test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export async function run_tests(
test_controller: vscode.TestController,
log: vscode.OutputChannel,
run_request: vscode.TestRunRequest,
cancel_token: vscode.CancellationToken
cancel_token: vscode.CancellationToken,
cmakeToolsAvailable: boolean
) {
const abort_controller = new AbortController();
const { signal } = abort_controller;
Expand All @@ -28,6 +29,10 @@ export async function run_tests(
const test_queue = get_test_list(run_request, test_controller);
test_queue.forEach((test) => run.started(test));

if (!(await runBuild(cmakeToolsAvailable, test_queue, run))) {
return;
}

try {
log.show(true); // true -> output channel does not take focus
const command_result = await runCtestCommand(
Expand Down Expand Up @@ -142,3 +147,22 @@ function get_test_list(
}
return test_queue;
}

async function runBuild(
cmakeToolsAvailable: boolean,
testQueue: vscode.TestItem[],
run: vscode.TestRun
): Promise<boolean> {
if (cmakeToolsAvailable) {
if (
((await vscode.commands.executeCommand("cmake.build")) as number) !== 0
) {
testQueue.forEach((testItem) => {
run.failed(testItem, new vscode.TestMessage("Build failed."));
});
run.end();
return false;
}
}
return true;
}

0 comments on commit bd1992d

Please sign in to comment.