Skip to content

Commit b278b5c

Browse files
committed
Output extension log contents
1 parent f1199d2 commit b278b5c

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

test/suite/extension.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as assert from 'assert';
33
import * as fs from 'fs';
44
import * as os from 'os';
55
import * as path from 'path';
6-
import { /* promisify ,*/ TextEncoder } from 'util';
6+
import { TextEncoder } from 'util';
77
import * as vscode from 'vscode';
88
import { CommandNames } from '../../src/commands/constants';
99

@@ -36,6 +36,17 @@ async function deleteWorkspaceFiles(pred?: (fileType: [string, vscode.FileType])
3636
await deleteFiles(getWorkspaceRoot().uri, pred);
3737
}
3838

39+
function getExtensionLogContent(): string | undefined {
40+
const extLog = getWorkspaceFile('hls.log').fsPath;
41+
if (fs.existsSync(extLog)) {
42+
const logContents = fs.readFileSync(extLog);
43+
return logContents.toString();
44+
} else {
45+
console.log(`${extLog} does not exist!`);
46+
return undefined;
47+
}
48+
}
49+
3950
async function deleteFiles(dir: vscode.Uri, pred?: (fileType: [string, vscode.FileType]) => boolean) {
4051
const dirContents = await vscode.workspace.fs.readDirectory(dir);
4152
console.log(`Deleting ${dir} contents: ${dirContents}`);
@@ -119,10 +130,9 @@ suite('Extension Test Suite', () => {
119130
test('Extension log should have server output', async () => {
120131
await vscode.workspace.openTextDocument(getWorkspaceFile('Main.hs'));
121132
await delay(10);
122-
const logContents = fs.readFileSync(getWorkspaceFile('hls.log').fsPath);
123-
console.log(`Log contents:\n${logContents.toString()}`);
133+
const logContents = getExtensionLogContent();
124134
assert.ok(logContents, 'Extension log file does not exist');
125-
assert.match(logContents.toString(), /INFO hls: Registering ide configuration/,
135+
assert.match(logContents, /INFO hls: Registering ide configuration/,
126136
'Extension log file has no hls output');
127137
});
128138

@@ -140,6 +150,11 @@ suite('Extension Test Suite', () => {
140150
console.log('Stopping the lsp server');
141151
await vscode.commands.executeCommand(CommandNames.StopServerCommandName);
142152
await delay(5);
153+
console.log('Contents of the extension log:');
154+
const logContent = getExtensionLogContent();
155+
if (logContent) {
156+
console.log(logContent);
157+
}
143158
console.log('Deleting test workspace contents');
144159
await deleteWorkspaceFiles(([name, type]) => !name.includes('.log'));
145160
});

0 commit comments

Comments
 (0)