Skip to content

Commit f7934a2

Browse files
committed
Don't mark swift-testing test case results as runnable
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 7924c60 commit f7934a2

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";
@@ -127,7 +127,12 @@ export class TestRunProxy {
127127
testClass.location = undefined;
128128

129129
// Results should inherit any tags from the parent.
130-
testClass.tags = parent.tags.map(t => new vscode.TestTag(t.id));
130+
// Until we can rerun a swift-testing test with an individual argument, mark
131+
// the argument test items as not runnable. This should be revisited when
132+
// https://github.com/swiftlang/swift-testing/issues/671 is resolved.
133+
testClass.tags = compactMap(parent.tags, t =>
134+
t.id === runnableTag.id ? null : new vscode.TestTag(t.id)
135+
);
131136

132137
const added = upsertTestItem(this.controller, testClass, parent);
133138

src/utilities/utilities.ts

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

208+
/**
209+
* Returns an array containing the non-null and non-undefined results of calling
210+
* the given transformation with each element of this sequence.
211+
*
212+
* @param arr An array to map
213+
* @param transform A transformation function to apply to each element
214+
* @returns An array containing the non-null and non-undefined results of calling transform on each element
215+
*/
216+
export function compactMap<T, U>(
217+
arr: readonly T[],
218+
transform: (value: T) => U | null | undefined
219+
): U[] {
220+
return arr.reduce<U[]>((acc, item) => {
221+
const result = transform(item);
222+
if (result !== null && result !== undefined) {
223+
acc.push(result);
224+
}
225+
return acc;
226+
}, []);
227+
}
208228
/**
209229
* Get path to swift executable, or executable in swift bin folder
210230
*

0 commit comments

Comments
 (0)