@@ -3,7 +3,7 @@ import * as assert from 'assert';
3
3
import * as fs from 'fs' ;
4
4
import * as os from 'os' ;
5
5
import * as path from 'path' ;
6
- import { /* promisify ,*/ TextEncoder } from 'util' ;
6
+ import { TextEncoder } from 'util' ;
7
7
import * as vscode from 'vscode' ;
8
8
import { CommandNames } from '../../src/commands/constants' ;
9
9
@@ -36,6 +36,17 @@ async function deleteWorkspaceFiles(pred?: (fileType: [string, vscode.FileType])
36
36
await deleteFiles ( getWorkspaceRoot ( ) . uri , pred ) ;
37
37
}
38
38
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
+
39
50
async function deleteFiles ( dir : vscode . Uri , pred ?: ( fileType : [ string , vscode . FileType ] ) => boolean ) {
40
51
const dirContents = await vscode . workspace . fs . readDirectory ( dir ) ;
41
52
console . log ( `Deleting ${ dir } contents: ${ dirContents } ` ) ;
@@ -119,10 +130,9 @@ suite('Extension Test Suite', () => {
119
130
test ( 'Extension log should have server output' , async ( ) => {
120
131
await vscode . workspace . openTextDocument ( getWorkspaceFile ( 'Main.hs' ) ) ;
121
132
await delay ( 10 ) ;
122
- const logContents = fs . readFileSync ( getWorkspaceFile ( 'hls.log' ) . fsPath ) ;
123
- console . log ( `Log contents:\n${ logContents . toString ( ) } ` ) ;
133
+ const logContents = getExtensionLogContent ( ) ;
124
134
assert . ok ( logContents , 'Extension log file does not exist' ) ;
125
- assert . match ( logContents . toString ( ) , / I N F O h l s : R e g i s t e r i n g i d e c o n f i g u r a t i o n / ,
135
+ assert . match ( logContents , / I N F O h l s : R e g i s t e r i n g i d e c o n f i g u r a t i o n / ,
126
136
'Extension log file has no hls output' ) ;
127
137
} ) ;
128
138
@@ -140,6 +150,11 @@ suite('Extension Test Suite', () => {
140
150
console . log ( 'Stopping the lsp server' ) ;
141
151
await vscode . commands . executeCommand ( CommandNames . StopServerCommandName ) ;
142
152
await delay ( 5 ) ;
153
+ console . log ( 'Contents of the extension log:' ) ;
154
+ const logContent = getExtensionLogContent ( ) ;
155
+ if ( logContent ) {
156
+ console . log ( logContent ) ;
157
+ }
143
158
console . log ( 'Deleting test workspace contents' ) ;
144
159
await deleteWorkspaceFiles ( ( [ name , type ] ) => ! name . includes ( '.log' ) ) ;
145
160
} ) ;
0 commit comments