Skip to content

Commit ec1fa54

Browse files
committed
Attachments Support
Work in progress patch to support swift-testing attachments. Currently prints the attachments out as a report at the end of a test run. In order to leverage them we need to set the --attachment-path, which is not available on the command line so we add a configuration json file. There is still more work to do to allow the user to specify their own attachment path on a per workspace basis. This will currently only work with swiftlang/swift-testing#770 as it isn't merged yet.
1 parent 182a0d7 commit ec1fa54

File tree

6 files changed

+347
-180
lines changed

6 files changed

+347
-180
lines changed

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@
4545
"request": "launch",
4646
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
4747
"runtimeArgs": ["${workspaceFolder}/scripts/update_swift_docc_render.ts"]
48+
},
49+
{
50+
"type": "lldb",
51+
"request": "launch",
52+
"args": [],
53+
"cwd": "${workspaceFolder:vscode-swift}/assets/test/defaultPackage",
54+
"name": "Debug PackageExe (assets/test/defaultPackage)",
55+
"program": "${workspaceFolder:vscode-swift}/assets/test/defaultPackage/.build/debug/PackageExe",
56+
"preLaunchTask": "swift: Build Debug PackageExe (assets/test/defaultPackage)"
57+
},
58+
{
59+
"type": "lldb",
60+
"request": "launch",
61+
"args": [],
62+
"cwd": "${workspaceFolder:vscode-swift}/assets/test/defaultPackage",
63+
"name": "Release PackageExe (assets/test/defaultPackage)",
64+
"program": "${workspaceFolder:vscode-swift}/assets/test/defaultPackage/.build/release/PackageExe",
65+
"preLaunchTask": "swift: Build Release PackageExe (assets/test/defaultPackage)"
4866
}
4967
]
5068
}

src/TestExplorer/TestParsers/SwiftTestingOutputParser.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export type EventRecordPayload =
5252
| TestCaseEnded
5353
| IssueRecorded
5454
| TestSkipped
55-
| RunEnded;
55+
| RunEnded
56+
| ValueAttached;
5657

5758
export interface EventRecord extends VersionedRecord {
5859
kind: "event";
@@ -95,6 +96,15 @@ interface RunEnded {
9596
messages: EventMessage[];
9697
}
9798

99+
interface ValueAttached {
100+
kind: "valueAttached";
101+
_attachment: {
102+
path?: string;
103+
};
104+
testID: string;
105+
messages: EventMessage[];
106+
}
107+
98108
interface Instant {
99109
absolute: number;
100110
since1970: number;
@@ -148,6 +158,7 @@ export enum TestSymbol {
148158
difference = "difference",
149159
warning = "warning",
150160
details = "details",
161+
attachment = "attachment",
151162
none = "none",
152163
}
153164

@@ -169,7 +180,8 @@ export class SwiftTestingOutputParser {
169180

170181
constructor(
171182
public testRunStarted: () => void,
172-
public addParameterizedTestCase: (testClass: TestClass, parentIndex: number) => void
183+
public addParameterizedTestCase: (testClass: TestClass, parentIndex: number) => void,
184+
public onAttachment: (testIndex: number, path: string) => void
173185
) {}
174186

175187
/**
@@ -457,6 +469,12 @@ export class SwiftTestingOutputParser {
457469
this.completionMap.set(testIndex, true);
458470
runState.completed(testIndex, { timestamp: item.payload.instant.absolute });
459471
return;
472+
} else if (item.payload.kind === "valueAttached" && item.payload._attachment.path) {
473+
const testID = this.idFromOptionalTestCase(item.payload.testID);
474+
const testIndex = this.getTestCaseIndex(runState, testID);
475+
476+
this.onAttachment(testIndex, item.payload._attachment.path);
477+
return;
460478
}
461479
}
462480
}
@@ -521,6 +539,8 @@ export class SymbolRenderer {
521539
return "\u{25B2}"; // Unicode: BLACK UP-POINTING TRIANGLE
522540
case TestSymbol.details:
523541
return "\u{2192}"; // Unicode: RIGHTWARDS ARROW
542+
case TestSymbol.attachment:
543+
return "\u{2399}"; // Unicode: PRINT SCREEN SYMBOL
524544
case TestSymbol.none:
525545
return "";
526546
}
@@ -540,6 +560,8 @@ export class SymbolRenderer {
540560
return "\u{26A0}\u{FE0E}"; // Unicode: WARNING SIGN + VARIATION SELECTOR-15 (disable emoji)
541561
case TestSymbol.details:
542562
return "\u{21B3}"; // Unicode: DOWNWARDS ARROW WITH TIP RIGHTWARDS
563+
case TestSymbol.attachment:
564+
return "\u{2399}"; // Unicode: PRINT SCREEN SYMBOL
543565
case TestSymbol.none:
544566
return " ";
545567
}
@@ -562,6 +584,8 @@ export class SymbolRenderer {
562584
return `${SymbolRenderer.ansiEscapeCodePrefix}91m${symbol}${SymbolRenderer.resetANSIEscapeCode}`;
563585
case TestSymbol.warning:
564586
return `${SymbolRenderer.ansiEscapeCodePrefix}93m${symbol}${SymbolRenderer.resetANSIEscapeCode}`;
587+
case TestSymbol.attachment:
588+
return `${SymbolRenderer.ansiEscapeCodePrefix}94m${symbol}${SymbolRenderer.resetANSIEscapeCode}`;
565589
case TestSymbol.none:
566590
default:
567591
return symbol;

0 commit comments

Comments
 (0)