Merge branch 'main' into nickfyson/error_wrapper

# Conflicts:
#	lib/codeql.js
#	lib/codeql.js.map
#	src/codeql.ts
This commit is contained in:
Nick Fyson 2020-09-07 23:55:32 +01:00
commit 3cd41279f2
3466 changed files with 8685 additions and 446173 deletions

View file

@ -1,4 +1,5 @@
import * as exec from '@actions/exec';
import * as toolrunnner from '@actions/exec/lib/toolrunner';
import test from 'ava';
import { ErrorMatcher } from './error-matcher';
@ -9,26 +10,26 @@ setupTests(test);
test('matchers are never applied if non-error exit', async t => {
const testCommand = buildDummyCommand("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
const testArgs = buildDummyArgs("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), 'error!!!']];
t.deepEqual(await exec.exec(testCommand), 0);
t.deepEqual(await exec.exec('node', testArgs), 0);
t.deepEqual(await execErrorCatcher(testCommand, [], matchers), 0);
t.deepEqual(await execErrorCatcher('node', testArgs, matchers), 0);
});
test('regex matchers are applied to stdout for non-zero exit code', async t => {
const testCommand = buildDummyCommand("foo bar\\nblort qux", '', '', 1);
const testArgs = buildDummyArgs("foo bar\\nblort qux", '', '', 1);
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄']];
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
execErrorCatcher(testCommand, [], matchers),
execErrorCatcher('node', testArgs, matchers),
{instanceOf: Error, message: '🦄'}
);
@ -36,14 +37,14 @@ test('regex matchers are applied to stdout for non-zero exit code', async t => {
test('regex matchers are applied to stderr for non-zero exit code', async t => {
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 1);
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄']];
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
execErrorCatcher(testCommand, [], matchers),
execErrorCatcher('node', testArgs, matchers),
{instanceOf: Error, message: '🦄'}
);
@ -51,16 +52,16 @@ test('regex matchers are applied to stderr for non-zero exit code', async t => {
test('matcher returns correct error message when multiple matchers defined', async t => {
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 1);
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers: ErrorMatcher[] = [[456, new RegExp("lorem ipsum"), '😩'],
[123, new RegExp("foo bar"), '🦄'],
[789, new RegExp("blah blah"), '🤦‍♂️']];
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
execErrorCatcher(testCommand, [], matchers),
execErrorCatcher('node', testArgs, matchers),
{instanceOf: Error, message: '🦄'}
);
@ -68,16 +69,16 @@ test('matcher returns correct error message when multiple matchers defined', asy
test('matcher returns first match to regex when multiple matches', async t => {
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 1);
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄'],
[789, new RegExp("blah blah"), '🤦‍♂️'],
[987, new RegExp("foo bar"), '🚫']];
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
execErrorCatcher(testCommand, [], matchers),
execErrorCatcher('node', testArgs, matchers),
{instanceOf: Error, message: '🦄'}
);
@ -85,25 +86,25 @@ test('matcher returns first match to regex when multiple matches', async t => {
test('exit code matchers are applied', async t => {
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 123);
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 123);
const matchers: ErrorMatcher[] = [[123, new RegExp("this will not match"), '🦄']];
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 123'});
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 123'});
await t.throwsAsync(
execErrorCatcher(testCommand, [], matchers),
execErrorCatcher('node', testArgs, matchers),
{instanceOf: Error, message: '🦄'}
);
});
test('execErrorCatcher respects the ignoreReturnValue option', async t => {
const testCommand = buildDummyCommand("standard output", 'error output', '', 199);
const testArgs = buildDummyArgs("standard output", 'error output', '', 199);
await t.throwsAsync(execErrorCatcher(testCommand, [], [], {ignoreReturnCode: false}), {instanceOf: Error});
await t.throwsAsync(execErrorCatcher('node', testArgs, [], {ignoreReturnCode: false}), {instanceOf: Error});
t.deepEqual(await execErrorCatcher(testCommand, [], [], {ignoreReturnCode: true}), 199);
t.deepEqual(await execErrorCatcher('node', testArgs, [], {ignoreReturnCode: true}), 199);
});
@ -124,17 +125,17 @@ test('execErrorCatcher preserves behavior of provided listeners', async t => {
}
};
const testCommand = buildDummyCommand(stdoutExpected, stderrExpected, '', 0);
const testArgs = buildDummyArgs(stdoutExpected, stderrExpected, '', 0);
t.deepEqual(await execErrorCatcher(testCommand, [], [], {listeners: listeners}), 0);
t.deepEqual(await execErrorCatcher('node', testArgs, [], {listeners: listeners}), 0);
t.deepEqual(stdoutActual, stdoutExpected + "\n");
t.deepEqual(stderrActual, stderrExpected + "\n");
});
function buildDummyCommand(stdoutContents: string, stderrContents: string,
desiredErrorMessage?: string, desiredExitCode?: number): string {
function buildDummyArgs(stdoutContents: string, stderrContents: string,
desiredErrorMessage?: string, desiredExitCode?: number): string[] {
let command = '';
@ -146,5 +147,5 @@ function buildDummyCommand(stdoutContents: string, stderrContents: string,
if (desiredErrorMessage) command += 'throw new Error(\\"' + desiredErrorMessage + '\\");';
if (desiredExitCode) command += 'process.exitCode = ' + desiredExitCode + ';';
return 'node -e "' + command + '"';
return toolrunnner.argStringToArray('-e "' + command + '"');
}