JoostK eeab91af4e test(compiler-cli): log unexpected compilation errors in compliance test runner (#39862)
If the testcase has not specified that errors were expected, then any
errors that have occurred should be reported. These errors may have
prevented an output file from being generated, which resulted in hard
to debug test failures due to missing files.

PR Close #39862
2020-12-02 14:56:38 -08:00

33 lines
1.1 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {inspect} from 'util';
import {ExpectedError} from './get_compliance_tests';
export function checkErrors(
testPath: string, failureMessage: string, expectedErrors: ExpectedError[],
actualErrors: string[]): void {
for (const expectedError of expectedErrors) {
if (!actualErrors.some(
actualError => expectedError.message.test(actualError) &&
expectedError.location.test(actualError))) {
throw new Error(
`When checking expected errors for test case at "${testPath}"\n` + failureMessage + '\n' +
`Expected errors: ${inspect(expectedErrors)}\n` +
`Actual errors: ${inspect(actualErrors)}.`);
}
}
}
export function checkNoUnexpectedErrors(testPath: string, actualErrors: string[]): void {
if (actualErrors.length > 0) {
throw new Error(
`Unexpected errors occurred for test case at "${testPath}"\n` +
`Errors: ${inspect(actualErrors)}.`);
}
}