clean up and rename things to follow proper conventions

This commit is contained in:
Nick Fyson
2020-09-07 23:02:58 +01:00
parent 3e6d23928b
commit cc2dfaf5d8
18 changed files with 52 additions and 68 deletions

View File

@@ -12,8 +12,8 @@ import uuidV4 from 'uuid/v4';
import * as api from './api-client';
import * as defaults from './defaults.json'; // Referenced from codeql-action-sync-tool!
import { errorMatchers} from './error_matcher';
import { exec_wrapper } from './exec_wrapper';
import { errorMatchers} from './error-matcher';
import { execErrorCatcher } from './exec-wrapper';
import { Language } from './languages';
import * as util from './util';
@@ -382,7 +382,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
const traceCommand = path.resolve(JSON.parse(extractorPath), 'tools', 'autobuild' + ext);
// Run trace command
await exec_wrapper(
await execErrorCatcher(
cmd, [
'database',
'trace-command',
@@ -395,7 +395,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
);
},
finalizeDatabase: async function(databasePath: string) {
await exec_wrapper(
await execErrorCatcher(
cmd, [
'database',
'finalize',

View File

@@ -1,7 +1,7 @@
import test from 'ava';
import { namedMatchersForTesting } from './error_matcher';
import { namedMatchersForTesting } from './error-matcher';
/*
NB We test the regexes for all the matchers against example log output snippets.

View File

@@ -15,5 +15,5 @@ https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in
],
};
// we collapse the matches into an array for use in exec_wrapper
// we collapse the matches into an array for use in execErrorCatcher
export const errorMatchers = Object.values(namedMatchersForTesting);

View File

@@ -1,18 +1,9 @@
import * as exec from '@actions/exec';
import test from 'ava';
import { ErrorMatcher } from './error_matcher';
import { exec_wrapper } from './exec_wrapper';
import { ErrorMatcher } from './error-matcher';
import { execErrorCatcher } from './exec-wrapper';
import {setupTests} from './testing-utils';
// import fs from 'fs';
// import { exec_wrapper } from './exec_wrapper';
// const matchers: [[number, RegExp, string]] = [
// [-999,
// new RegExp("match this string"),
// 'No source code was found. CUSTOM ERROR MESSAGE HERE'],
// ];
setupTests(test);
@@ -24,7 +15,7 @@ test('matchers are never applied if non-error exit', async t => {
t.deepEqual(await exec.exec(testCommand), 0);
t.deepEqual(await exec_wrapper(testCommand, [], matchers), 0);
t.deepEqual(await execErrorCatcher(testCommand, [], matchers), 0);
});
@@ -37,7 +28,7 @@ test('regex matchers are applied to stdout for non-zero exit code', async t => {
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
exec_wrapper(testCommand, [], matchers),
execErrorCatcher(testCommand, [], matchers),
{instanceOf: Error, message: '🦄'}
);
@@ -52,7 +43,7 @@ test('regex matchers are applied to stderr for non-zero exit code', async t => {
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
exec_wrapper(testCommand, [], matchers),
execErrorCatcher(testCommand, [], matchers),
{instanceOf: Error, message: '🦄'}
);
@@ -69,7 +60,7 @@ test('matcher returns correct error message when multiple matchers defined', asy
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
exec_wrapper(testCommand, [], matchers),
execErrorCatcher(testCommand, [], matchers),
{instanceOf: Error, message: '🦄'}
);
@@ -86,7 +77,7 @@ test('matcher returns first match to regex when multiple matches', async t => {
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
await t.throwsAsync(
exec_wrapper(testCommand, [], matchers),
execErrorCatcher(testCommand, [], matchers),
{instanceOf: Error, message: '🦄'}
);
@@ -101,22 +92,22 @@ test('exit code matchers are applied', async t => {
await t.throwsAsync(exec.exec(testCommand), {instanceOf: Error, message: 'The process \'node\' failed with exit code 123'});
await t.throwsAsync(
exec_wrapper(testCommand, [], matchers),
execErrorCatcher(testCommand, [], matchers),
{instanceOf: Error, message: '🦄'}
);
});
test('exec_wrapper respects the ignoreReturnValue option', async t => {
test('execErrorCatcher respects the ignoreReturnValue option', async t => {
const testCommand = buildDummyCommand("standard output", 'error output', '', 199);
await t.throwsAsync(exec_wrapper(testCommand, [], [], {ignoreReturnCode: false}), {instanceOf: Error});
await t.throwsAsync(execErrorCatcher(testCommand, [], [], {ignoreReturnCode: false}), {instanceOf: Error});
t.deepEqual(await exec_wrapper(testCommand, [], [], {ignoreReturnCode: true}), 199);
t.deepEqual(await execErrorCatcher(testCommand, [], [], {ignoreReturnCode: true}), 199);
});
test('exec_wrapper preserves behavior of provided listeners', async t => {
test('execErrorCatcher preserves behavior of provided listeners', async t => {
let stdoutExpected = 'standard output';
let stderrExpected = 'error output';
@@ -135,7 +126,7 @@ test('exec_wrapper preserves behavior of provided listeners', async t => {
const testCommand = buildDummyCommand(stdoutExpected, stderrExpected, '', 0);
t.deepEqual(await exec_wrapper(testCommand, [], [], {listeners: listeners}), 0);
t.deepEqual(await execErrorCatcher(testCommand, [], [], {listeners: listeners}), 0);
t.deepEqual(stdoutActual, stdoutExpected + "\n");
t.deepEqual(stderrActual, stderrExpected + "\n");

View File

@@ -1,7 +1,7 @@
import * as exec from '@actions/exec';
import * as im from '@actions/exec/lib/interfaces';
import {ErrorMatcher} from './error_matcher';
import {ErrorMatcher} from './error-matcher';
/**
* Wrapper for exec.exec which checks for specific return code and/or regex matches in console output.
@@ -14,9 +14,9 @@ import {ErrorMatcher} from './error_matcher';
* @param options optional exec options. See ExecOptions
* @returns Promise<number> exit code
*/
export async function exec_wrapper(commandLine: string, args?: string[],
matchers?: ErrorMatcher[],
options?: im.ExecOptions): Promise<number> {
export async function execErrorCatcher(commandLine: string, args?: string[],
matchers?: ErrorMatcher[],
options?: im.ExecOptions): Promise<number> {
let stdout = '';
let stderr = '';