Skip to content

Commit aa3de7f

Browse files
committed
test/integration: catch failed await in lint test
Often the test failed with timeout. Catch exceptions (most likely due to unresolved promise) and fail explicitly. 1 failing 1) Go Extension Tests (GOPATH mode) Linting - lint errors with multiple open files: Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. Change-Id: I894ed74fe52442f036ac3637191b7c1d189cbcf1 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/418775 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]>
1 parent b90e57e commit aa3de7f

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

test/integration/extension.test.ts

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -436,40 +436,45 @@ It returns the number of bytes written and any write error encountered.
436436
});
437437

438438
test('Linting - lint errors with multiple open files', async () => {
439-
// handleDiagnosticErrors may adjust the lint errors' ranges to make the error more visible.
440-
// This adjustment applies only to the text documents known to vscode. This test checks
441-
// the adjustment is made consistently across multiple open text documents.
442-
const file1 = await vscode.workspace.openTextDocument(
443-
vscode.Uri.file(path.join(fixturePath, 'linterTest', 'linter_1.go'))
444-
);
445-
const file2 = await vscode.workspace.openTextDocument(
446-
vscode.Uri.file(path.join(fixturePath, 'linterTest', 'linter_2.go'))
447-
);
448-
const warnings = await goLint(
449-
file2.uri,
450-
Object.create(getGoConfig(), {
451-
lintTool: { value: 'staticcheck' },
452-
lintFlags: { value: ['-checks', 'all,-ST1000,-ST1016'] }
453-
// staticcheck skips debatable checks such as ST1003 by default,
454-
// but this test depends on ST1003 (MixedCaps package name) presented in both files
455-
// in the same package. So, enable that.
456-
}),
457-
Object.create(getGoplsConfig(), {}),
458-
'package'
459-
);
439+
try {
440+
// handleDiagnosticErrors may adjust the lint errors' ranges to make the error more visible.
441+
// This adjustment applies only to the text documents known to vscode. This test checks
442+
// the adjustment is made consistently across multiple open text documents.
443+
const file1 = await vscode.workspace.openTextDocument(
444+
vscode.Uri.file(path.join(fixturePath, 'linterTest', 'linter_1.go'))
445+
);
446+
const file2 = await vscode.workspace.openTextDocument(
447+
vscode.Uri.file(path.join(fixturePath, 'linterTest', 'linter_2.go'))
448+
);
449+
console.log('start linting');
450+
const warnings = await goLint(
451+
file2.uri,
452+
Object.create(getGoConfig(), {
453+
lintTool: { value: 'staticcheck' },
454+
lintFlags: { value: ['-checks', 'all,-ST1000,-ST1016'] }
455+
// staticcheck skips debatable checks such as ST1003 by default,
456+
// but this test depends on ST1003 (MixedCaps package name) presented in both files
457+
// in the same package. So, enable that.
458+
}),
459+
Object.create(getGoplsConfig(), {}),
460+
'package'
461+
);
460462

461-
const diagnosticCollection = vscode.languages.createDiagnosticCollection('linttest');
462-
handleDiagnosticErrors({}, file2, warnings, diagnosticCollection);
463-
464-
// The first diagnostic message for each file should be about the use of MixedCaps in package name.
465-
// Both files belong to the same package name, and we want them to be identical.
466-
const file1Diagnostics = diagnosticCollection.get(file1.uri);
467-
const file2Diagnostics = diagnosticCollection.get(file2.uri);
468-
assert(file1Diagnostics);
469-
assert(file2Diagnostics);
470-
assert(file1Diagnostics.length > 0);
471-
assert(file2Diagnostics.length > 0);
472-
assert.deepStrictEqual(file1Diagnostics[0], file2Diagnostics[0]);
463+
const diagnosticCollection = vscode.languages.createDiagnosticCollection('linttest');
464+
handleDiagnosticErrors({}, file2, warnings, diagnosticCollection);
465+
466+
// The first diagnostic message for each file should be about the use of MixedCaps in package name.
467+
// Both files belong to the same package name, and we want them to be identical.
468+
const file1Diagnostics = diagnosticCollection.get(file1.uri);
469+
const file2Diagnostics = diagnosticCollection.get(file2.uri);
470+
assert(file1Diagnostics);
471+
assert(file2Diagnostics);
472+
assert(file1Diagnostics.length > 0);
473+
assert(file2Diagnostics.length > 0);
474+
assert.deepStrictEqual(file1Diagnostics[0], file2Diagnostics[0]);
475+
} catch (e) {
476+
assert.fail(`failed to lint: ${e}`);
477+
}
473478
});
474479

475480
test('Error checking', async () => {

0 commit comments

Comments
 (0)