Skip to content

Commit d14c7b4

Browse files
committed
Show test results for tests with warnings
1 parent ab36153 commit d14c7b4

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,17 @@ type ResolvedQueries = string[];
156156
type ResolvedTests = string[];
157157

158158
/**
159-
* A compilation message for a test message (either an error or a warning)
159+
* The severity of a compilation message for a test message.
160160
*/
161-
interface CompilationMessage {
161+
export enum CompilationMessageSeverity {
162+
Error = "ERROR",
163+
Warning = "WARNING",
164+
}
165+
166+
/**
167+
* A compilation message for a test message (either an error or a warning).
168+
*/
169+
export interface CompilationMessage {
162170
/**
163171
* The text of the message
164172
*/
@@ -170,7 +178,7 @@ interface CompilationMessage {
170178
/**
171179
* The severity of the message
172180
*/
173-
severity: number;
181+
severity: CompilationMessageSeverity;
174182
}
175183

176184
/**

extensions/ql-vscode/src/query-testing/test-manager.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
} from "vscode";
2222
import { DisposableObject } from "../common/disposable-object";
2323
import { QLTestDiscovery } from "./qltest-discovery";
24-
import type { CodeQLCliServer } from "../codeql-cli/cli";
24+
import type { CodeQLCliServer, CompilationMessage } from "../codeql-cli/cli";
25+
import { CompilationMessageSeverity } from "../codeql-cli/cli";
2526
import { getErrorMessage } from "../common/helpers-pure";
2627
import type { BaseLogger, LogOptions } from "../common/logging";
2728
import type { TestRunner } from "./test-runner";
@@ -66,6 +67,23 @@ function changeExtension(p: string, ext: string): string {
6667
return p.slice(0, -extname(p).length) + ext;
6768
}
6869

70+
function compilationMessageToTestMessage(
71+
compilationMessage: CompilationMessage,
72+
): TestMessage {
73+
const location = new Location(
74+
Uri.file(compilationMessage.position.fileName),
75+
new Range(
76+
compilationMessage.position.line - 1,
77+
compilationMessage.position.column - 1,
78+
compilationMessage.position.endLine - 1,
79+
compilationMessage.position.endColumn - 1,
80+
),
81+
);
82+
const testMessage = new TestMessage(compilationMessage.message);
83+
testMessage.location = location;
84+
return testMessage;
85+
}
86+
6987
/**
7088
* Returns the complete text content of the specified file. If there is an error reading the file,
7189
* an error message is added to `testMessages` and this function returns undefined.
@@ -398,23 +416,15 @@ export class TestManager extends DisposableObject {
398416
);
399417
}
400418
}
401-
if (event.messages?.length > 0) {
419+
const errorMessages = event.messages.filter(
420+
(m) => m.severity === CompilationMessageSeverity.Error,
421+
);
422+
if (errorMessages.length > 0) {
402423
// The test didn't make it far enough to produce results. Transform any error messages
403424
// into `TestMessage`s and report the test as "errored".
404-
const testMessages = event.messages.map((m) => {
405-
const location = new Location(
406-
Uri.file(m.position.fileName),
407-
new Range(
408-
m.position.line - 1,
409-
m.position.column - 1,
410-
m.position.endLine - 1,
411-
m.position.endColumn - 1,
412-
),
413-
);
414-
const testMessage = new TestMessage(m.message);
415-
testMessage.location = location;
416-
return testMessage;
417-
});
425+
const testMessages = event.messages.map(
426+
compilationMessageToTestMessage,
427+
);
418428
testRun.errored(testItem, testMessages, duration);
419429
} else {
420430
// Results didn't match expectations. Report the test as "failed".
@@ -423,6 +433,12 @@ export class TestManager extends DisposableObject {
423433
// here. Any failed test needs at least one message.
424434
testMessages.push(new TestMessage("Test failed"));
425435
}
436+
437+
// Add any warnings produced by the test to the test messages.
438+
testMessages.push(
439+
...event.messages.map(compilationMessageToTestMessage),
440+
);
441+
426442
testRun.failed(testItem, testMessages, duration);
427443
}
428444
}

0 commit comments

Comments
 (0)