Skip to content

Commit ee88108

Browse files
authored
Don't mark swift-testing test case results as runnable (#1151)
When running a swift-testing test that takes arguments the results are added to the Test Explorer showing their pass/fail status. At this time these tests cannot be run with a specific argument so these tests should not be marked as runnable. This prevents the "Run", "Debug" and "Coverage" buttons from appearing on the test items in the explorer. Issue: #1147
1 parent 3e45bd1 commit ee88108

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/TestExplorer/TestDiscovery.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,13 @@ export function upsertTestItem(
231231
// parent tags down the tree as children are upserted.
232232
testItem = applyTagsToChildren(testItem);
233233

234-
// Manually add the test style as a tag so we can filter by test type.
235-
newItem.tags = [{ id: testItem.style }, ...testItem.tags];
234+
const hasTestStyleTag = testItem.tags.find(tag => tag.id === testItem.style);
235+
236+
// Manually add the test style as a tag if it isn't already in the tags list.
237+
// This lets the user filter by test type.
238+
newItem.tags = hasTestStyleTag
239+
? [...testItem.tags]
240+
: [{ id: testItem.style }, ...testItem.tags];
236241

237242
if (testItem.disabled === false) {
238243
newItem.tags = [...newItem.tags, runnableTag];

src/TestExplorer/TestRunner.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as stream from "stream";
1818
import * as os from "os";
1919
import * as asyncfs from "fs/promises";
2020
import { FolderContext } from "../FolderContext";
21-
import { execFile, getErrorDescription } from "../utilities/utilities";
21+
import { compactMap, execFile, getErrorDescription } from "../utilities/utilities";
2222
import { createSwiftTask } from "../tasks/SwiftTaskProvider";
2323
import configuration from "../configuration";
2424
import { WorkspaceContext } from "../WorkspaceContext";
@@ -135,7 +135,12 @@ export class TestRunProxy {
135135
testClass.location = undefined;
136136

137137
// Results should inherit any tags from the parent.
138-
testClass.tags = parent.tags.map(t => new vscode.TestTag(t.id));
138+
// Until we can rerun a swift-testing test with an individual argument, mark
139+
// the argument test items as not runnable. This should be revisited when
140+
// https://github.com/swiftlang/swift-testing/issues/671 is resolved.
141+
testClass.tags = compactMap(parent.tags, t =>
142+
t.id === runnableTag.id ? null : new vscode.TestTag(t.id)
143+
);
139144

140145
const added = upsertTestItem(this.controller, testClass, parent);
141146

src/utilities/utilities.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ export function wait(milliseconds: number): Promise<void> {
219219
return new Promise(resolve => setTimeout(resolve, milliseconds));
220220
}
221221

222+
/**
223+
* Returns an array containing the non-null and non-undefined results of calling
224+
* the given transformation with each element of this sequence.
225+
*
226+
* @param arr An array to map
227+
* @param transform A transformation function to apply to each element
228+
* @returns An array containing the non-null and non-undefined results of calling transform on each element
229+
*/
230+
export function compactMap<T, U>(
231+
arr: readonly T[],
232+
transform: (value: T) => U | null | undefined
233+
): U[] {
234+
return arr.reduce<U[]>((acc, item) => {
235+
const result = transform(item);
236+
if (result !== null && result !== undefined) {
237+
acc.push(result);
238+
}
239+
return acc;
240+
}, []);
241+
}
222242
/**
223243
* Get path to swift executable, or executable in swift bin folder
224244
*

0 commit comments

Comments
 (0)