From 57e8a6aa67c935c157e2a1e1ef20831b95ccb646 Mon Sep 17 00:00:00 2001 From: joeduffy Date: Tue, 10 Jan 2017 12:40:59 -0800 Subject: [PATCH] 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. --- tools/mujs/tests/output/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/mujs/tests/output/index.ts b/tools/mujs/tests/output/index.ts index 338ed2690..e8dc32feb 100644 --- a/tools/mujs/tests/output/index.ts +++ b/tools/mujs/tests/output/index.ts @@ -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");