Skip to content

Commit 389bb4d

Browse files
authored
test: make tests more stable (#601)
This PR adjusts tests that check the contents of 'All Messages' to check the content of 'Messages' instead, which (when initializing the InfoView for the first time) is sometimes subject to a race condition that makes it not display any messages. This is a known, albeit minor, issue.
1 parent a56f7ea commit 389bb4d

File tree

7 files changed

+82
-53
lines changed

7 files changed

+82
-53
lines changed

vscode-lean4/test/suite/bootstrap/bootstrap.test.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
initLean4Untitled,
1111
waitForActiveClient,
1212
waitForActiveClientRunning,
13-
waitForInfoviewHtml,
13+
waitForInfoviewHtmlAt,
1414
} from '../utils/helpers'
1515

1616
suite('Lean4 Bootstrap Test Suite', () => {
@@ -32,20 +32,7 @@ suite('Lean4 Bootstrap Test Suite', () => {
3232
await waitForActiveClient(features.clientProvider, 120)
3333
await waitForActiveClientRunning(features.clientProvider, 300)
3434

35-
const hackNeeded = false
36-
if (hackNeeded) {
37-
// this is a hack we can do if it turns out this bootstrap test is unreliable.
38-
// The hack would be covering a product bug, which is why we'd prefer not to use it.
39-
// if it times out at 600 seconds then waitForInfoviewHtml prints the contents of the InfoView so we can see what happened.
40-
// await waitForInfoviewHtml(info, expected, 10, 60000, true, async () => {
41-
// // 60 seconds elapsed, and infoview is not updating, try and re-edit
42-
// // the file to force the LSP to update.
43-
// await deleteAllText();
44-
// await insertText('#eval Lean.versionString');
45-
// });
46-
} else {
47-
await waitForInfoviewHtml(info, expected, 600)
48-
}
35+
await waitForInfoviewHtmlAt('#eval', info, expected, 600)
4936

5037
logger.log('Lean installation is complete.')
5138

@@ -74,7 +61,7 @@ suite('Lean4 Bootstrap Test Suite', () => {
7461
assert(info, 'No InfoProvider export')
7562

7663
logger.log('Wait for Lean nightly build server to start...')
77-
await waitForInfoviewHtml(info, '4.0.0-nightly-', 120)
64+
await waitForInfoviewHtmlAt('#eval', info, '4.0.0-nightly-', 120)
7865
logger.log('Lean nightly build server is running.')
7966

8067
// make sure test is always run in predictable state, which is no file or folder open

vscode-lean4/test/suite/info/info.test.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as vscode from 'vscode'
44
import { logger } from '../../../src/utils/logger'
55
import {
66
assertStringInInfoview,
7+
assertStringInInfoviewAt,
78
clickInfoViewButton,
89
closeActiveEditor,
910
closeAllEditors,
@@ -12,8 +13,10 @@ import {
1213
gotoPosition,
1314
initLean4Untitled,
1415
insertText,
16+
insertTextAfter,
1517
waitForActiveEditor,
1618
waitForInfoviewHtml,
19+
waitForInfoviewHtmlAt,
1720
waitForInfoviewNotHtml,
1821
} from '../utils/helpers'
1922

@@ -29,7 +32,7 @@ suite('InfoView Test Suite', () => {
2932
const info = features.infoProvider
3033
assert(info, 'No InfoProvider export')
3134

32-
await assertStringInInfoview(info, expectedEval1)
35+
await assertStringInInfoviewAt('#eval', info, expectedEval1)
3336

3437
logger.log('Clicking copyToComment button in InfoView')
3538
await clickInfoViewButton(info, 'copy-to-comment')
@@ -50,7 +53,8 @@ suite('InfoView Test Suite', () => {
5053
const c = 77
5154
const d = 7
5255

53-
const features = await initLean4Untitled(`#eval ${a}*${b}`)
56+
const evalLine1 = `#eval ${a}*${b}`
57+
const features = await initLean4Untitled(evalLine1)
5458
const info = features.infoProvider
5559
assert(info, 'No InfoProvider export')
5660

@@ -61,11 +65,12 @@ suite('InfoView Test Suite', () => {
6165
await clickInfoViewButton(info, 'toggle-pinned')
6266

6367
logger.log('Insert another couple lines and another eval')
64-
await insertText(`\n\n/- add another unpinned eval -/\n#eval ${c}*${d}`)
68+
const evalLine2 = `#eval ${c}*${d}`
69+
await insertTextAfter(evalLine1, `\n\n/- add another unpinned eval -/\n${evalLine2}`)
6570

6671
logger.log('wait for the new expression to appear')
6772
const expectedEval2 = (c * d).toString()
68-
await assertStringInInfoview(info, expectedEval2)
73+
await assertStringInInfoviewAt(evalLine2, info, expectedEval2)
6974

7075
logger.log('make sure pinned expression is still there')
7176
await assertStringInInfoview(info, expectedEval1)
@@ -75,7 +80,7 @@ suite('InfoView Test Suite', () => {
7580

7681
logger.log('Make sure pinned eval is gone, but unpinned eval remains')
7782
await waitForInfoviewNotHtml(info, expectedEval1)
78-
await assertStringInInfoview(info, expectedEval2)
83+
await assertStringInInfoviewAt(evalLine2, info, expectedEval2)
7984

8085
await closeAllEditors()
8186
}).timeout(60000)
@@ -92,7 +97,7 @@ suite('InfoView Test Suite', () => {
9297

9398
const info = features.infoProvider
9499
assert(info, 'No InfoProvider export')
95-
await waitForInfoviewHtml(info, expectedEval, 30, 1000, false)
100+
await waitForInfoviewHtmlAt('#eval', info, expectedEval, 30, 1000, false)
96101

97102
logger.log('Pin this info')
98103
await clickInfoViewButton(info, 'toggle-pinned')
@@ -106,7 +111,7 @@ suite('InfoView Test Suite', () => {
106111

107112
logger.log('wait for the new expression to appear')
108113
const expectedEval2 = '[4, 1, 2, 3]'
109-
await waitForInfoviewHtml(info, expectedEval2, 30, 1000, false)
114+
await waitForInfoviewHtmlAt('#eval', info, expectedEval2, 30, 1000, false)
110115

111116
logger.log('make sure pinned expression is not showing an error')
112117
await waitForInfoviewNotHtml(info, 'Incorrect position')
@@ -116,7 +121,7 @@ suite('InfoView Test Suite', () => {
116121
editor.selection = new vscode.Selection(newLastLine.start, newLastLine.start)
117122

118123
logger.log('make sure pinned value reverts after an undo')
119-
await waitForInfoviewHtml(info, expectedEval, 30, 1000, false)
124+
await waitForInfoviewHtmlAt('#eval', info, expectedEval, 30, 1000, false)
120125

121126
await closeAllEditors()
122127
}).timeout(60000)
@@ -128,21 +133,22 @@ suite('InfoView Test Suite', () => {
128133
const b = 95
129134
const prefix = 'Lean version is:'
130135

131-
const features = await initLean4Untitled(`#eval ${a}*${b}`)
136+
const evalLine = `#eval ${a}*${b}`
137+
const features = await initLean4Untitled(evalLine)
132138
const info = features.infoProvider
133139
assert(info, 'No InfoProvider export')
134140

135141
const expectedEval = (a * b).toString()
136-
await assertStringInInfoview(info, expectedEval)
142+
await assertStringInInfoviewAt('#eval', info, expectedEval)
137143

138144
logger.log('Pin this info')
139145
await clickInfoViewButton(info, 'toggle-pinned')
140146

141147
logger.log('Insert another eval')
142-
await insertText('\n\n#eval s!"' + prefix + ': {Lean.versionString}"')
148+
await insertTextAfter(evalLine, '\n\n#eval s!"' + prefix + ': {Lean.versionString}"')
143149

144150
logger.log('make sure output of versionString is also there')
145-
await assertStringInInfoview(info, prefix)
151+
await assertStringInInfoviewAt('#eval s!', info, prefix)
146152

147153
logger.log('make sure pinned expression is not showing an error')
148154
await waitForInfoviewNotHtml(info, 'Incorrect position')
@@ -177,7 +183,7 @@ suite('InfoView Test Suite', () => {
177183
const info = features.infoProvider
178184
assert(info, 'No InfoProvider export')
179185

180-
gotoPosition(0, text.indexOf('by'))
186+
gotoPosition('by')
181187
await assertStringInInfoview(info, 'issue461')
182188

183189
logger.log('Opening tooltip for goal type')

vscode-lean4/test/suite/multi/multi.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path'
44
import * as vscode from 'vscode'
55
import { logger } from '../../../src/utils/logger'
66
import { displayNotification } from '../../../src/utils/notifs'
7-
import { assertStringInInfoview, closeAllEditors, getAltBuildVersion, initLean4 } from '../utils/helpers'
7+
import { assertStringInInfoviewAt, closeAllEditors, getAltBuildVersion, initLean4 } from '../utils/helpers'
88

99
suite('Multi-Folder Test Suite', () => {
1010
test('Load a multi-project workspace', async () => {
@@ -19,7 +19,7 @@ suite('Multi-Folder Test Suite', () => {
1919
// verify we have a nightly build running in this folder.
2020
const info = features.infoProvider
2121
assert(info, 'No InfoProvider export')
22-
await assertStringInInfoview(info, '4.0.0-nightly-')
22+
await assertStringInInfoviewAt('#eval Lean.versionString', info, '4.0.0-nightly-')
2323

2424
// Now open a file from the other project
2525
const doc2 = await vscode.workspace.openTextDocument(path.join(multiRoot, 'foo', 'Foo.lean'))
@@ -28,7 +28,7 @@ suite('Multi-Folder Test Suite', () => {
2828
await vscode.window.showTextDocument(doc2, options)
2929

3030
logger.log(`wait for version ${version} to load...`)
31-
await assertStringInInfoview(info, version)
31+
await assertStringInInfoviewAt('#eval', info, version)
3232

3333
// Now verify we have 2 LeanClients running.
3434
const clients = features.clientProvider

vscode-lean4/test/suite/restarts/restarts.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import { logger } from '../../../src/utils/logger'
77
import { displayNotification } from '../../../src/utils/notifs'
88
import {
99
assertStringInInfoview,
10+
assertStringInInfoviewAt,
1011
closeAllEditors,
1112
deleteAllText,
1213
extractPhrase,
1314
initLean4,
1415
initLean4Untitled,
1516
insertText,
17+
insertTextAfter,
1618
restartFile,
1719
restartLeanServer,
1820
waitForActiveClient,
@@ -29,18 +31,19 @@ suite('Lean Server Restart Test Suite', () => {
2931

3032
// add normal values to initialize lean4 file
3133
const hello = 'Hello World'
32-
const features = await initLean4Untitled(`#eval "${hello}"`)
34+
const evalLine = `#eval "${hello}"`
35+
const features = await initLean4Untitled(evalLine)
3336
const info = features.infoProvider
3437
assert(info, 'No InfoProvider export')
3538

3639
logger.log('make sure language server is up and running.')
37-
await assertStringInInfoview(info, hello)
40+
await assertStringInInfoviewAt('#eval', info, hello)
3841

3942
const clients = features.clientProvider
4043
assert(clients, 'No LeanClientProvider export')
4144

4245
logger.log('Insert eval that causes crash.')
43-
await insertText('\n\n#eval (unsafeCast 0 : String)')
46+
await insertTextAfter(evalLine, '\n\n#eval (unsafeCast 0 : String)')
4447

4548
const expectedMessage = 'The Lean Server has stopped processing this file'
4649
await assertStringInInfoview(info, expectedMessage)
@@ -60,7 +63,7 @@ suite('Lean Server Restart Test Suite', () => {
6063
await restartLeanServer(client)
6164

6265
logger.log('checking that Hello World comes back after restart')
63-
await assertStringInInfoview(info, hello)
66+
await assertStringInInfoviewAt('#eval', info, hello)
6467

6568
// make sure test is always run in predictable state, which is no file or folder open
6669
await closeAllEditors()
@@ -74,18 +77,19 @@ suite('Lean Server Restart Test Suite', () => {
7477

7578
// add normal values to initialize lean4 file
7679
const hello = 'Hello World'
77-
const features = await initLean4Untitled(`#eval "${hello}"`)
80+
const evalLine = `#eval "${hello}"`
81+
const features = await initLean4Untitled(evalLine)
7882
const info = features.infoProvider
7983
assert(info, 'No InfoProvider export')
8084

8185
logger.log('make sure language server is up and running.')
82-
await assertStringInInfoview(info, hello)
86+
await assertStringInInfoviewAt('#eval', info, hello)
8387

8488
const clients = features.clientProvider
8589
assert(clients, 'No LeanClientProvider export')
8690

8791
logger.log('Insert eval that causes crash.')
88-
await insertText('\n\n#eval (unsafeCast 0 : String)')
92+
await insertTextAfter(evalLine, '\n\n#eval (unsafeCast 0 : String)')
8993

9094
const expectedMessage = 'The Lean Server has stopped processing this file'
9195
await assertStringInInfoview(info, expectedMessage)
@@ -105,7 +109,7 @@ suite('Lean Server Restart Test Suite', () => {
105109
await restartFile()
106110

107111
logger.log('checking that Hello World comes back after restart')
108-
await assertStringInInfoview(info, hello)
112+
await assertStringInInfoviewAt('#eval', info, hello)
109113

110114
// make sure test is always run in predictable state, which is no file or folder open
111115
await closeAllEditors()

vscode-lean4/test/suite/simple/simple.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { elanInstalledToolchains } from '../../../src/utils/elan'
66
import { logger } from '../../../src/utils/logger'
77
import { displayNotification } from '../../../src/utils/notifs'
88
import {
9-
assertStringInInfoview,
9+
assertStringInInfoviewAt,
1010
closeAllEditors,
1111
extractPhrase,
1212
gotoDefinition,
1313
initLean4,
1414
initLean4Untitled,
1515
waitForActiveEditor,
1616
waitForInfoviewHtml,
17+
waitForInfoviewHtmlAt,
1718
} from '../utils/helpers'
1819

1920
suite('Lean4 Basics Test Suite', () => {
@@ -25,7 +26,7 @@ suite('Lean4 Basics Test Suite', () => {
2526
const info = features.infoProvider
2627
assert(info, 'No InfoProvider export')
2728

28-
await assertStringInInfoview(info, '4.0.0-nightly-')
29+
await assertStringInInfoviewAt('#eval', info, '4.0.0-nightly-')
2930

3031
// test goto definition to lean toolchain works
3132
await waitForActiveEditor()
@@ -60,7 +61,7 @@ suite('Lean4 Basics Test Suite', () => {
6061
const info = features.infoProvider
6162
assert(info, 'No InfoProvider export')
6263
const expectedVersion = '5040' // the factorial function works.
63-
const html = await waitForInfoviewHtml(info, expectedVersion)
64+
const html = await waitForInfoviewHtmlAt('#eval factorial 7', info, expectedVersion)
6465

6566
const installer = features.installer
6667
assert(installer, 'No LeanInstaller export')
@@ -73,7 +74,7 @@ suite('Lean4 Basics Test Suite', () => {
7374
defaultToolchain = defaultToolchain.replace('/', '--')
7475
defaultToolchain = defaultToolchain.replace(':', '---')
7576
// make sure this string exists in the info view.
76-
await waitForInfoviewHtml(info, defaultToolchain)
77+
await waitForInfoviewHtmlAt('#eval IO.appPath', info, defaultToolchain)
7778
}
7879

7980
// make sure test is always run in predictable state, which is no file or folder open
@@ -97,7 +98,7 @@ suite('Lean4 Basics Test Suite', () => {
9798
const info = features.infoProvider
9899
assert(info, 'No InfoProvider export')
99100
let expectedVersion = 'Hello:'
100-
let html = await waitForInfoviewHtml(info, expectedVersion)
101+
let html = await waitForInfoviewHtmlAt('#eval main', info, expectedVersion)
101102
const versionString = extractPhrase(html, 'Hello:', '<').trim()
102103
logger.log(`>>> Found "${versionString}" in infoview`)
103104

vscode-lean4/test/suite/toolchains/toolchain.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as path from 'path'
55
import { logger } from '../../../src/utils/logger'
66
import { displayNotification } from '../../../src/utils/notifs'
77
import {
8-
assertStringInInfoview,
8+
assertStringInInfoviewAt,
99
closeAllEditors,
1010
extractPhrase,
1111
getAltBuildVersion,
1212
initLean4,
13-
waitForInfoviewHtml,
13+
waitForInfoviewHtmlAt,
1414
} from '../utils/helpers'
1515

1616
// Expects to be launched with folder: ${workspaceFolder}/vscode-lean4/test/suite/simple
@@ -30,11 +30,11 @@ suite('Toolchain Test Suite', () => {
3030
assert(installer, 'No LeanInstaller export')
3131

3232
// wait for info view to show up.
33-
await assertStringInInfoview(info, 'Hello')
33+
await assertStringInInfoviewAt('#eval main', info, 'Hello')
3434

3535
// verify we have a nightly build running in this folder.
3636
const expectedVersion = '4.0.0-nightly-'
37-
const html = await waitForInfoviewHtml(info, expectedVersion)
37+
const html = await waitForInfoviewHtmlAt('#eval main', info, expectedVersion)
3838
const foundVersion = extractPhrase(html, expectedVersion, '\n')
3939

4040
// Now edit the lean-toolchain file.
@@ -48,7 +48,7 @@ suite('Toolchain Test Suite', () => {
4848

4949
try {
5050
logger.log(`verify that we switched to alt version ${version}`)
51-
const html = await assertStringInInfoview(info, version)
51+
const html = await assertStringInInfoviewAt('#eval main', info, version)
5252

5353
// check the path to lean.exe from the `eval IO.appPath`
5454
const leanPath = extractPhrase(html, 'FilePath.mk', '<').trim()
@@ -61,7 +61,7 @@ suite('Toolchain Test Suite', () => {
6161
}
6262

6363
logger.log(`Wait for version to appear, it should be ${foundVersion}`)
64-
await assertStringInInfoview(info, foundVersion)
64+
await assertStringInInfoviewAt('#eval main', info, foundVersion)
6565

6666
// make sure test is always run in predictable state, which is no file or folder open
6767
await closeAllEditors()

0 commit comments

Comments
 (0)