pulumi/tools/mujs/tests/util.ts
joeduffy 89f2424df1 Add a new harness for test cases
This adds a new test harness that will be used to run baseline-style
tests.  Each subdirectory underneath tests/output will be interpreted as
a test case, each of which can contain an optional `messages.txt` file
which will be compared as the expected output against the compiler's error
and warning messages, and/or an optional `Mu.out.json` file which will be
compared as the expected output against the compiler's output tree.

There's just a single "empty" test case for now.  I will start getting in
the habit of checking in a companion test for each AST kind we lower.
2017-01-08 15:20:46 -06:00

38 lines
1 KiB
TypeScript

// Copyright 2017 Marapongo, Inc. All rights reserved.
import * as assert from "assert";
export type MochaFunc = (err: Error) => void;
// A helper function for wrapping some of the boilerplate goo necessary to interface between Mocha's asynchronous
// testing and our TypeScript async tests.
export function asyncTest(test: () => Promise<void>): (func: MochaFunc) => void {
return (done: (err: Error | undefined) => void) => {
let go = async () => {
let caught: Error | undefined;
try {
await test();
}
catch (err) {
caught = err;
}
finally {
done(caught);
}
};
go();
};
}
// A helper function for asynchronous tests that throw.
export async function assertAsyncThrows(test: () => Promise<void>): Promise<void> {
let thrown: boolean = false;
try {
await test();
}
catch (err) {
thrown = true;
}
assert(thrown, "Function was expected to throw, but didn't");
}