in src/bazel/bazelRun.ts [84:172]
protected async runGoTest(config: RunConfig): Promise<boolean> {
const { run, pkg, functions, record, concat, ...rest } = config;
if (Object.keys(functions).length === 0) return true;
const complete = new Set<TestItem>();
const outputChannel = new TestRunOutput(run);
const runFunctions: string[] = [];
// Convert Testify suite methods into subtest format (e.g. MyTestSuite/TestCase1).
Object.keys(functions).forEach((testFunctionName: string) => {
const currentTestCase = functions[testFunctionName];
runFunctions.push(this.formatTestCaseForFilter(testFunctionName, currentTestCase));
});
const testOutcome = await goTestWithBazel(
{
...rest,
outputChannel,
dir: pkg.uri?.fsPath ?? '',
functions: runFunctions,
goTestOutputConsumer: !rest.isBenchmark
? (e) => this.consumeGoTestEvent(run, functions, record, complete, concat, e)
: undefined,
applyCodeCoverage: this.goCtx.coverageEnabled
},
undefined,
this.coverageHandler
);
// One-time-use wrapper around showErrorMessage. Displays a message only on its first call.
const showErrorOnce = (() => {
let shown = false;
return (message: string) => {
!shown && window.showErrorMessage(message);
shown = true;
};
})();
switch (testOutcome.exitCode) {
case ExitCode.Success:
if (rest.isBenchmark) {
window.showInformationMessage('Benchmark complete. See terminal for results.');
this.markComplete(functions, complete, (x) => run.passed(x));
return true;
}
this.markComplete(functions, complete, (x) => {
showErrorOnce(
'Some test cases were skipped. If you renamed or removed a subtest, please re-run the whole test case to update all subtests.'
);
run.skipped(x);
});
return true;
case ExitCode.BuildFailed:
window.showErrorMessage('Unable to run selected tests due to build errors.');
this.markComplete(functions, complete, (item) => {
run.errored(item, {
message: testOutcome.message || 'Build error. Please see console output for further details.'
});
item.error = 'Build errors';
});
break;
case ExitCode.Interrupted:
window.showWarningMessage('Bazel interrupted during test run. Incomplete tests marked as skipped.');
this.markComplete(functions, complete, (x) => run.skipped(x));
break;
case ExitCode.CommandLineProblem:
window.showWarningMessage(
'Bazel argument error. Please check the following VS Code settings for any values that are incompatible with Bazel: go.testFlags, go.testEnvVars.'
);
this.markComplete(functions, complete, (x) => run.skipped(x));
break;
default:
// Remaining tests will be marked as errored so that they are flagged with an error message and console link.
// If all tests were already marked during the GoTestWithBazel call above, then no actual updates will occur here.
this.markComplete(functions, complete, (item) => {
showErrorOnce(`Bazel Exit Code: ${testOutcome.exitCode}. This test run is incomplete.`);
outputChannel.show();
run.errored(item, {
message:
testOutcome.message || 'Other Bazel error. Please see console output for further details.'
});
item.error = 'Bazel errors';
});
break;
}
return false;
}