Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 3dcd67e

Browse files
committed
Support "undefined" CSV files
1 parent 78cbc8c commit 3dcd67e

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

codeql-learninglab-check/package/src/check.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export interface Result {
3838
}
3939

4040
export type ResultsCheck = {
41+
// CSV file has not been defined for this query yet
42+
status: 'undefined';
43+
} | {
4144
status: 'correct';
4245
count: number;
4346
} | {

codeql-learninglab-check/package/src/index.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Config = {
5555
/**
5656
* Mapping from query filename to expected results csv file
5757
*/
58-
expectedResults: {[id: string]: string};
58+
expectedResults: {[id: string]: string | false};
5959
};
6060

6161
function isConfig(config: any): config is Config {
@@ -74,7 +74,7 @@ function isConfig(config: any): config is Config {
7474
throw new Error('Configuration property locationPaths must have the placeholder "{line-start}"');
7575
}
7676
for (const k of Object.keys(config.expectedResults)) {
77-
if (typeof config.expectedResults[k] !== 'string') {
77+
if (typeof config.expectedResults[k] !== 'string' && config.expectedResults[k] !== false) {
7878
throw new Error(`Confiuration property "expectedResults" -> "${k}" must be a string`);
7979
}
8080
}
@@ -319,8 +319,13 @@ function isConfig(config: any): config is Config {
319319
console.log(result.stdout);
320320
const csvOutput = csvPath(query);
321321
await execFile('codeql', ['bqrs', 'decode', '--entities=url,string', bqrsOutput, '--format=csv', `--output=${csvOutput}`]);
322-
const expectedCSV = path.join(CONFIG_PATH, config.expectedResults[query]);
323-
results.set(query, await checkResults(expectedCSV, csvOutput));
322+
const relativeExpectedCSV = config.expectedResults[query];
323+
if (relativeExpectedCSV) {
324+
const expectedCSV = path.join(CONFIG_PATH, relativeExpectedCSV);
325+
results.set(query, await checkResults(expectedCSV, csvOutput));
326+
} else {
327+
results.set(query, {status: 'undefined'});
328+
}
324329
}
325330

326331
for(const entry of results.entries()) {
@@ -330,18 +335,22 @@ function isConfig(config: any): config is Config {
330335
if (r.status === 'correct') {
331336
comment += ` (${pluralize(r.count, 'result')})`;
332337
} else {
333-
if (r.results) {
334-
comment += ` (${pluralize(r.results.actualCount, 'result')}):\n\n`;
335-
comment += r.explanation;
336-
comment += `\nExpected query to produce ${r.results.expectedCount} results`;
337-
comment += formatResults(config.locationPaths, r.results.missingResults, 'Missing results');
338-
comment += formatResults(config.locationPaths, r.results.unexpectedResults, 'Unexpected results');
339-
comment += formatResults(config.locationPaths, r.results.extraResults, 'Results selected too many times');
338+
if (r.status === 'incorrect') {
339+
if (r.results) {
340+
comment += ` (${pluralize(r.results.actualCount, 'result')}):\n\n`;
341+
comment += r.explanation;
342+
comment += `\nExpected query to produce ${r.results.expectedCount} results`;
343+
comment += formatResults(config.locationPaths, r.results.missingResults, 'Missing results');
344+
comment += formatResults(config.locationPaths, r.results.unexpectedResults, 'Unexpected results');
345+
comment += formatResults(config.locationPaths, r.results.extraResults, 'Results selected too many times');
346+
} else {
347+
comment += r.explanation;
348+
}
349+
core.setFailed(`Incorrect results for ${query}`);
340350
} else {
341-
comment += r.explanation;
351+
console.log(`No CSV defined for ${query}:`);
342352
}
343353
// Print CSV in console
344-
core.setFailed(`Incorrect results for ${query}`);
345354
core.startGroup('Actual Results CSV:');
346355
console.log((await (readFile(csvPath(query)))).toString());
347356
core.endGroup();

courses/template/image/config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"locationPaths": "https://github.com/<org>/<repo>/blob/<sha>{path}#L{line-start}-L{line-end}",
44
"expectedResults": {
55
"step-01.ql": "step-01.csv",
6-
"step-02.ql": "step-02.csv"
6+
"step-02.ql": false
77
}
88
}

0 commit comments

Comments
 (0)