-
Notifications
You must be signed in to change notification settings - Fork 526
Build tests prior to executing them #4881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcodilla
wants to merge
19
commits into
main
Choose a base branch
from
building-tests2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−1
Open
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
89def45
Build the necessary targets prior to running tests.
3acf209
Merge branch 'microsoft:main' into building-tests
epistax 9e6cdcf
Cleaned up change log and ctest impl a bit.
d548f90
Fix build-before-test: correct target name resolution and error repor…
mcodilla 7fec8a3
Revert "Fix build-before-test: correct target name resolution and err…
mcodilla 8dc16aa
Merge branch 'main' of https://github.com/microsoft/vscode-cmake-tool…
mcodilla 66c3263
Closing brace
mcodilla 8195cc6
Readd these
mcodilla c5c3485
Compute the target name instead of the executable
mcodilla 6934a68
Merge branch 'main' into building-tests2
hanniavalera 2ecb65b
Merge branch 'main' into building-tests2
hanniavalera fb2f7c0
Merge branch 'main' into building-tests2
hanniavalera 3ae3c12
Fix typo in variable name
mcodilla 632b758
Update src/ctest.ts
mcodilla f818aaa
Merge branch 'building-tests2' of https://github.com/microsoft/vscode…
mcodilla ea4ee78
Use a precomputed map
mcodilla ddfb2a9
Merge branch 'main' into building-tests2
hanniavalera 1398c4e
Update src/ctest.ts
mcodilla 16a631c
Merge branch 'main' into building-tests2
hanniavalera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1832,6 +1832,10 @@ export class CTestDriver implements vscode.Disposable { | |
| return currentTestItem.id; | ||
| } | ||
|
|
||
| /** | ||
| * Determine and build all targets needed to rebuild the selected TestItems. Returns a false if anything goes | ||
| * wrong, and returns an early success if build-before-run is disabled. | ||
|
hanniavalera marked this conversation as resolved.
|
||
| */ | ||
| private async buildTests(tests: vscode.TestItem[], run: vscode.TestRun): Promise<boolean> { | ||
| // If buildBeforeRun is set to false, we skip the build step | ||
| if (!this.ws.config.buildBeforeRun) { | ||
|
|
@@ -1841,7 +1845,11 @@ export class CTestDriver implements vscode.Disposable { | |
| // Folder => status | ||
| const builtFolder = new Map<string, number>(); | ||
| let status: number = 0; | ||
| const foundTarget = new Map<CMakeProject, Map<string, vscode.TestItem[]>>(); | ||
| for (const test of tests) { | ||
| if (!await this.getTestTargets(test, foundTarget, run)) { | ||
| return false; | ||
| } | ||
| const folder = this.getTestRootFolder(test); | ||
| if (!builtFolder.has(folder)) { | ||
| const project = await this.projectController?.getProjectForFolder(folder); | ||
|
|
@@ -1869,7 +1877,80 @@ export class CTestDriver implements vscode.Disposable { | |
| } | ||
| } | ||
|
|
||
| return Array.from(builtFolder.values()).filter(v => v !== 0).length === 0; | ||
| return this.buildTestTargets(foundTarget, run); | ||
|
hanniavalera marked this conversation as resolved.
hanniavalera marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Given the TestItem, determine the owning CMakeProject and build targets to build the tests. If the given | ||
| * TestItem is a suite, then recurse. Information is passed back through the foundTarget parameter. A failure to | ||
| * identify the project of the test will result in a ctest error and a false value being returned. | ||
| */ | ||
| private async getTestTargets(test: vscode.TestItem, foundTarget: Map<CMakeProject, Map<string, vscode.TestItem[]>>, run: vscode.TestRun): Promise<boolean> { | ||
| if (test.children.size > 0) { | ||
| const children = this.testItemCollectionToArray(test.children); | ||
| for (const child of children) { | ||
| await this.getTestTargets(child, foundTarget, run); | ||
|
mcodilla marked this conversation as resolved.
Outdated
|
||
| } | ||
| } else { | ||
| const testProgram = this.testProgram(test.id); | ||
|
mcodilla marked this conversation as resolved.
|
||
| const folder = this.getTestRootFolder(test); | ||
| const project = await this.projectController?.getProjectForFolder(folder); | ||
| if (!project) { | ||
| this.ctestErrored(test, run, { message: localize('no.project.found', 'No project found for folder {0}', folder) }); | ||
| return false; | ||
| } | ||
| if (!foundTarget.has(project)) { | ||
| foundTarget.set(project, new Map<string, vscode.TestItem[]>([[testProgram, [test]]])); | ||
| } else { | ||
| const prj = foundTarget.get(project)!; | ||
| if (!prj.has(testProgram)) { | ||
| prj.set(testProgram, [test]); | ||
| } else { | ||
| prj.get(testProgram)!.push(test); | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Build the targets provided in foundTarget. CMake will be invoked once per CMakeProject for efficiency. On error, | ||
| * the associated tests will be flagged with a ctest error and a false value will be returned. | ||
| */ | ||
| private async buildTestTargets(foundTarget: Map<CMakeProject, Map<string, vscode.TestItem[]>>, run: vscode.TestRun): Promise<boolean> { | ||
| let overallSuccess = true; | ||
|
hanniavalera marked this conversation as resolved.
|
||
| for (const [project, targets] of foundTarget) { | ||
| const execTargets = await project.executableTargets; | ||
| const accmulatedTestList: vscode.TestItem[] = []; | ||
|
mcodilla marked this conversation as resolved.
Outdated
|
||
| const accumulatedTargets: string[] = []; | ||
| let success: boolean = true; | ||
| for (const [targetPath, testList] of targets) { | ||
| // Look up the CMake target name from executable targets by matching | ||
| // the executable path. Using path.relative() uses the executable instead of the target name | ||
| const normalizedTargetPath = util.platformNormalizePath(targetPath); | ||
| const execTarget = execTargets.find(t => util.platformNormalizePath(t.path) === normalizedTargetPath); | ||
|
mcodilla marked this conversation as resolved.
Outdated
|
||
| accumulatedTargets.push(execTarget ? execTarget.name : path.parse(targetPath).name); | ||
| accmulatedTestList.push(...testList); | ||
| } | ||
|
mcodilla marked this conversation as resolved.
Outdated
|
||
| try { | ||
| if (extensionManager !== undefined && extensionManager !== null) { | ||
| extensionManager.cleanOutputChannel(); | ||
| } | ||
| const buildResult = await project.build(accumulatedTargets, false, false); | ||
|
hanniavalera marked this conversation as resolved.
|
||
| if (buildResult.exitCode !== 0) { | ||
| success = false; | ||
| } | ||
| } catch (e) { | ||
| success = false; | ||
| } | ||
|
Comment on lines
+1947
to
+1953
|
||
| if (!success) { | ||
| overallSuccess = false; | ||
| accmulatedTestList.forEach(test => { | ||
| this.ctestErrored(test, run, { message: localize('build.failed', 'Build failed') }); | ||
| }); | ||
| } | ||
| }; | ||
|
hanniavalera marked this conversation as resolved.
|
||
| return overallSuccess; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.