Do a line-by-line comparison for AST checking

This changes the test harness to do a line-by-line comparison, rather than
full text comparison, for AST checking.  This is a bit nicer to diagnose, because
failures will specifically point out the line that deviates, rather than dumping
the (possibly huge) string containing the full expected/actual ASTs.
This commit is contained in:
joeduffy 2017-01-10 12:40:59 -08:00
parent f2f6826f5b
commit 57e8a6aa67

View file

@ -62,9 +62,17 @@ describe("outputs", () => {
if (output.tree) {
if (expectedOutputTree) {
let mupackTree: pack.Package = compiler.transform(output.tree);
let mupackTreeText: string = JSON.stringify(mupackTree, null, 4) + os.EOL;
assert.strictEqual(mupackTreeText, expectedOutputTree, "Expected program trees to match");
let muMeta: pack.Metadata = await compiler.discover(output.root);
let mupackTree: pack.Package = compiler.transform(muMeta, output.tree);
let mupackTreeText: string = JSON.stringify(mupackTree, null, 4) + "\n";
// Do a line-by-line comparison to make debugging failures nicer.
let actualLines: string[] = mupackTreeText.split("\n");
let expectLines: string[] = expectedOutputTree.split("\n");
assert.strictEqual(actualLines.length, expectLines.length, "Expected tree line count to match");
for (let i = 0; i < actualLines.length && i < expectLines.length; i++) {
assert.strictEqual(actualLines[i], expectLines[i], `Expected tree line #${i} to match`);
}
}
else {
assert(false, "Expected an empty program tree, but one was returned");