Skip to content

Commit 8b57d89

Browse files
fix output logs on integration test failure (#1400)
1 parent acf8084 commit 8b57d89

File tree

7 files changed

+24
-38
lines changed

7 files changed

+24
-38
lines changed

src/extension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface Api {
5656
*/
5757
export async function activate(context: vscode.ExtensionContext): Promise<Api> {
5858
try {
59-
const outputChannel = new SwiftOutputChannel("Swift", !process.env["VSCODE_TEST"]);
59+
const outputChannel = new SwiftOutputChannel("Swift");
6060
outputChannel.log("Activating Swift for Visual Studio Code...");
6161

6262
checkAndWarnAboutWindowsSymlinks(outputChannel);

src/sourcekit-lsp/LanguageClientManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ export class LanguageClientManager implements vscode.Disposable {
532532
documentSelector: LanguageClientManager.documentSelector,
533533
revealOutputChannelOn: RevealOutputChannelOn.Never,
534534
workspaceFolder: workspaceFolder,
535-
outputChannel: new SwiftOutputChannel("SourceKit Language Server", false),
535+
outputChannel: new SwiftOutputChannel("SourceKit Language Server"),
536536
middleware: {
537537
provideCodeLenses: async (document, token, next) => {
538538
const result = await next(document, token);

src/toolchain/toolchain.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ export class SwiftToolchain {
790790
const plistKey = type === "XCTest" ? "XCTEST_VERSION" : "SWIFT_TESTING_VERSION";
791791
const version = infoPlist.DefaultProperties[plistKey];
792792
if (!version) {
793-
new SwiftOutputChannel("swift", true).appendLine(
793+
new SwiftOutputChannel("swift").appendLine(
794794
`Warning: ${platformManifest} is missing the ${plistKey} key.`
795795
);
796796
return undefined;

src/ui/SwiftOutputChannel.ts

-12
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,21 @@ export class SwiftOutputChannel implements vscode.OutputChannel {
2525
*/
2626
constructor(
2727
public name: string,
28-
private logToConsole: boolean = true,
2928
logStoreLinesSize: number = 250_000 // default to capturing 250k log lines
3029
) {
3130
this.name = name;
32-
this.logToConsole = process.env["CI"] !== "1" && logToConsole;
3331
this.channel = vscode.window.createOutputChannel(name, "Swift");
3432
this.logStore = new RollingLog(logStoreLinesSize);
3533
}
3634

3735
append(value: string): void {
3836
this.channel.append(value);
3937
this.logStore.append(value);
40-
41-
if (this.logToConsole) {
42-
// eslint-disable-next-line no-console
43-
console.log(value);
44-
}
4538
}
4639

4740
appendLine(value: string): void {
4841
this.channel.appendLine(value);
4942
this.logStore.appendLine(value);
50-
51-
if (this.logToConsole) {
52-
// eslint-disable-next-line no-console
53-
console.log(value);
54-
}
5543
}
5644

5745
replace(value: string): void {

test/integration-tests/ui/SwiftOutputChannel.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suite("SwiftOutputChannel", function () {
2020
const channels: SwiftOutputChannel[] = [];
2121
setup(function () {
2222
const channelName = `SwiftOutputChannel Tests ${this.currentTest?.id ?? "<unknown test>"}`;
23-
channel = new SwiftOutputChannel(channelName, false, 3);
23+
channel = new SwiftOutputChannel(channelName, 3);
2424
channels.push(channel);
2525
});
2626

test/integration-tests/utilities/testutilities.ts

+19-21
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,8 @@ const extensionBootstrapper = (() => {
3535
let activator: (() => Promise<Api>) | undefined = undefined;
3636
let activatedAPI: Api | undefined = undefined;
3737
let lastTestName: string | undefined = undefined;
38-
let lastTestLogs: string[] = [];
3938
const testTitle = (currentTest: Mocha.Test) => currentTest.titlePath().join(" → ");
4039

41-
mocha.afterEach(function () {
42-
if (this.currentTest && this.currentTest.isFailed()) {
43-
console.log(`Captured logs during ${testTitle(this.currentTest)}:`);
44-
if (lastTestLogs.length === 0) {
45-
console.log("No logs captured.");
46-
}
47-
for (const log of lastTestLogs) {
48-
console.log(log);
49-
}
50-
}
51-
});
52-
53-
mocha.beforeEach(function () {
54-
if (this.currentTest && activatedAPI && process.env["VSCODE_TEST"]) {
55-
activatedAPI.outputChannel.clear();
56-
activatedAPI.outputChannel.appendLine(`Starting test: ${testTitle(this.currentTest)}`);
57-
}
58-
});
59-
6040
function testRunnerSetup(
6141
before: Mocha.HookFunction,
6242
setup:
@@ -119,6 +99,25 @@ const extensionBootstrapper = (() => {
11999
}
120100
});
121101

102+
mocha.beforeEach(function () {
103+
if (this.currentTest && activatedAPI) {
104+
activatedAPI.outputChannel.clear();
105+
activatedAPI.outputChannel.appendLine(
106+
`Starting test: ${testTitle(this.currentTest)}`
107+
);
108+
}
109+
});
110+
111+
mocha.afterEach(function () {
112+
if (this.currentTest && activatedAPI && this.currentTest.isFailed()) {
113+
console.log(`Captured logs during ${testTitle(this.currentTest)}:`);
114+
for (const log of activatedAPI.outputChannel.logs) {
115+
console.log(log);
116+
}
117+
console.log("======== END OF LOGS ========\n\n");
118+
}
119+
});
120+
122121
after(async function () {
123122
try {
124123
// First run the users supplied teardown, then await the autoTeardown if it exists.
@@ -196,7 +195,6 @@ const extensionBootstrapper = (() => {
196195
if (!activatedAPI) {
197196
throw new Error("Extension is not activated. Call activateExtension() first.");
198197
}
199-
lastTestLogs = activatedAPI.outputChannel.logs;
200198

201199
// Wait for up to 10 seconds for all tasks to complete before deactivating.
202200
// Long running tasks should be avoided in tests, but this is a safety net.

test/unit-tests/debugger/lldb.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ suite("debugger.lldb Tests", () => {
154154
});
155155
mockContext = mockObject<WorkspaceContext>({
156156
toolchain: instance(mockToolchain),
157-
outputChannel: new SwiftOutputChannel("mockChannel", false),
157+
outputChannel: new SwiftOutputChannel("mockChannel"),
158158
});
159159
});
160160

0 commit comments

Comments
 (0)