add test for initial error matcher
This commit is contained in:
parent
7dbaff09b6
commit
3e6d23928b
8 changed files with 95 additions and 16 deletions
4
lib/codeql.js
generated
4
lib/codeql.js
generated
|
|
@ -297,7 +297,7 @@ function getCodeQLForCmd(cmd) {
|
||||||
databasePath,
|
databasePath,
|
||||||
'--',
|
'--',
|
||||||
traceCommand
|
traceCommand
|
||||||
], error_matcher_1.error_matchers);
|
], error_matcher_1.errorMatchers);
|
||||||
},
|
},
|
||||||
finalizeDatabase: async function (databasePath) {
|
finalizeDatabase: async function (databasePath) {
|
||||||
await exec_wrapper_1.exec_wrapper(cmd, [
|
await exec_wrapper_1.exec_wrapper(cmd, [
|
||||||
|
|
@ -305,7 +305,7 @@ function getCodeQLForCmd(cmd) {
|
||||||
'finalize',
|
'finalize',
|
||||||
...getExtraOptionsFromEnv(['database', 'finalize']),
|
...getExtraOptionsFromEnv(['database', 'finalize']),
|
||||||
databasePath
|
databasePath
|
||||||
], error_matcher_1.error_matchers);
|
], error_matcher_1.errorMatchers);
|
||||||
},
|
},
|
||||||
resolveQueries: async function (queries, extraSearchPath) {
|
resolveQueries: async function (queries, extraSearchPath) {
|
||||||
const codeqlArgs = [
|
const codeqlArgs = [
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
18
lib/error_matcher.js
generated
18
lib/error_matcher.js
generated
|
|
@ -1,6 +1,18 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.error_matchers = [
|
// exported only for testing purposes
|
||||||
[32, new RegExp("No JavaScript or TypeScript code found\\."), 'foo bar']
|
exports.namedMatchersForTesting = {
|
||||||
];
|
/*
|
||||||
|
In due course it may be possible to remove the regex, if/when javascript also exits with code 32.
|
||||||
|
For context see https://github.com/github/semmle-code/pull/36921
|
||||||
|
*/
|
||||||
|
noSourceCodeFound: [
|
||||||
|
32,
|
||||||
|
new RegExp("No JavaScript or TypeScript code found\\."),
|
||||||
|
`No source code was seen during the build. Please see...
|
||||||
|
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
|
||||||
|
],
|
||||||
|
};
|
||||||
|
// we collapse the matches into an array for use in exec_wrapper
|
||||||
|
exports.errorMatchers = Object.values(exports.namedMatchersForTesting);
|
||||||
//# sourceMappingURL=error_matcher.js.map
|
//# sourceMappingURL=error_matcher.js.map
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"error_matcher.js","sourceRoot":"","sources":["../src/error_matcher.ts"],"names":[],"mappings":";;AAGa,QAAA,cAAc,GAAmB;IAC5C,CAAC,EAAE,EAAE,IAAI,MAAM,CAAC,2CAA2C,CAAC,EAAE,SAAS,CAAC;CACzE,CAAC"}
|
{"version":3,"file":"error_matcher.js","sourceRoot":"","sources":["../src/error_matcher.ts"],"names":[],"mappings":";;AAGA,qCAAqC;AACxB,QAAA,uBAAuB,GAAoC;IACtE;;;MAGE;IACF,iBAAiB,EAAE;QACjB,EAAE;QACF,IAAI,MAAM,CAAC,2CAA2C,CAAC;QACvD;wJACoJ;KACrJ;CACF,CAAC;AAEF,gEAAgE;AACnD,QAAA,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,+BAAuB,CAAC,CAAC"}
|
||||||
33
lib/error_matcher.test.js
generated
Normal file
33
lib/error_matcher.test.js
generated
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const ava_1 = __importDefault(require("ava"));
|
||||||
|
const error_matcher_1 = require("./error_matcher");
|
||||||
|
/*
|
||||||
|
NB We test the regexes for all the matchers against example log output snippets.
|
||||||
|
*/
|
||||||
|
ava_1.default('noSourceCodeFound matches against example javascript output', async (t) => {
|
||||||
|
t.assert(testErrorMatcher("noSourceCodeFound", `
|
||||||
|
2020-09-07T17:39:53.9050522Z [2020-09-07 17:39:53] [build] Done extracting /opt/hostedtoolcache/CodeQL/0.0.0-20200630/x64/codeql/javascript/tools/data/externs/web/ie_vml.js (3 ms)
|
||||||
|
2020-09-07T17:39:53.9051849Z [2020-09-07 17:39:53] [build-err] No JavaScript or TypeScript code found.
|
||||||
|
2020-09-07T17:39:53.9052444Z [2020-09-07 17:39:53] [build-err] No JavaScript or TypeScript code found.
|
||||||
|
2020-09-07T17:39:53.9251124Z [2020-09-07 17:39:53] [ERROR] Spawned process exited abnormally (code 255; tried to run: [/opt/hostedtoolcache/CodeQL/0.0.0-20200630/x64/codeql/javascript/tools/autobuild.sh])
|
||||||
|
`));
|
||||||
|
});
|
||||||
|
function testErrorMatcher(matcherName, logSample) {
|
||||||
|
const regex = error_matcher_1.namedMatchersForTesting[matcherName] ? error_matcher_1.namedMatchersForTesting[matcherName][1] : null;
|
||||||
|
if (regex) {
|
||||||
|
return regex.test(logSample);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (error_matcher_1.namedMatchersForTesting[matcherName]) {
|
||||||
|
throw new Error(`Cannot test matcher ${matcherName} with null regex`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error(`Unknown matcher ${matcherName}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=error_matcher.test.js.map
|
||||||
1
lib/error_matcher.test.js.map
Normal file
1
lib/error_matcher.test.js.map
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"error_matcher.test.js","sourceRoot":"","sources":["../src/error_matcher.test.ts"],"names":[],"mappings":";;;;;AACA,8CAAuB;AAEvB,mDAA0D;AAE1D;;EAEE;AAEF,aAAI,CAAC,6DAA6D,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAC5E,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,EAAE;;;;;GAK9C,CAAC,CAAC,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,SAAS,gBAAgB,CAAC,WAAmB,EAAE,SAAiB;IAE9D,MAAM,KAAK,GAAG,uCAAuB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,uCAAuB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpG,IAAI,KAAK,EAAE;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC9B;SAAM;QACL,IAAI,uCAAuB,CAAC,WAAW,CAAC,EAAE;YACxC,MAAM,IAAI,KAAK,CAAC,uBAAuB,WAAW,kBAAkB,CAAC,CAAC;SACvE;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,mBAAmB,WAAW,EAAE,CAAC,CAAC;SACnD;KACF;AAEH,CAAC"}
|
||||||
33
src/error_matcher.test.ts
Normal file
33
src/error_matcher.test.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
import test from 'ava';
|
||||||
|
|
||||||
|
import { namedMatchersForTesting } from './error_matcher';
|
||||||
|
|
||||||
|
/*
|
||||||
|
NB We test the regexes for all the matchers against example log output snippets.
|
||||||
|
*/
|
||||||
|
|
||||||
|
test('noSourceCodeFound matches against example javascript output', async t => {
|
||||||
|
t.assert(testErrorMatcher("noSourceCodeFound", `
|
||||||
|
2020-09-07T17:39:53.9050522Z [2020-09-07 17:39:53] [build] Done extracting /opt/hostedtoolcache/CodeQL/0.0.0-20200630/x64/codeql/javascript/tools/data/externs/web/ie_vml.js (3 ms)
|
||||||
|
2020-09-07T17:39:53.9051849Z [2020-09-07 17:39:53] [build-err] No JavaScript or TypeScript code found.
|
||||||
|
2020-09-07T17:39:53.9052444Z [2020-09-07 17:39:53] [build-err] No JavaScript or TypeScript code found.
|
||||||
|
2020-09-07T17:39:53.9251124Z [2020-09-07 17:39:53] [ERROR] Spawned process exited abnormally (code 255; tried to run: [/opt/hostedtoolcache/CodeQL/0.0.0-20200630/x64/codeql/javascript/tools/autobuild.sh])
|
||||||
|
`));
|
||||||
|
});
|
||||||
|
|
||||||
|
function testErrorMatcher(matcherName: string, logSample: string): boolean {
|
||||||
|
|
||||||
|
const regex = namedMatchersForTesting[matcherName] ? namedMatchersForTesting[matcherName][1] : null;
|
||||||
|
|
||||||
|
if (regex) {
|
||||||
|
return regex.test(logSample);
|
||||||
|
} else {
|
||||||
|
if (namedMatchersForTesting[matcherName]) {
|
||||||
|
throw new Error(`Cannot test matcher ${matcherName} with null regex`);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unknown matcher ${matcherName}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
|
|
||||||
export type ErrorMatcher = [number|null, RegExp|null, string];
|
export type ErrorMatcher = [number|null, RegExp|null, string];
|
||||||
|
|
||||||
const namedMatchers: { [key: string]: ErrorMatcher } = {
|
// exported only for testing purposes
|
||||||
|
export const namedMatchersForTesting: { [key: string]: ErrorMatcher } = {
|
||||||
|
/*
|
||||||
|
In due course it may be possible to remove the regex, if/when javascript also exits with code 32.
|
||||||
|
For context see https://github.com/github/semmle-code/pull/36921
|
||||||
|
*/
|
||||||
noSourceCodeFound: [
|
noSourceCodeFound: [
|
||||||
32,
|
32,
|
||||||
null,
|
|
||||||
`No source code was seen during the build. Please see...
|
|
||||||
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
|
|
||||||
],
|
|
||||||
noSourceCodeFoundJavascript: [
|
|
||||||
null,
|
|
||||||
new RegExp("No JavaScript or TypeScript code found\\."),
|
new RegExp("No JavaScript or TypeScript code found\\."),
|
||||||
`No source code was seen during the build. Please see...
|
`No source code was seen during the build. Please see...
|
||||||
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
|
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const errorMatchers = Object.values(namedMatchers);
|
// we collapse the matches into an array for use in exec_wrapper
|
||||||
|
export const errorMatchers = Object.values(namedMatchersForTesting);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue