From 67cca43358cfcf7ff2e7c9e5532bc975fb2591d0 Mon Sep 17 00:00:00 2001 From: kzc Date: Fri, 22 Jul 2016 10:44:29 -0400 Subject: [PATCH] Test reparsing test/compress/*.js output --- test/run-tests.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/test/run-tests.js b/test/run-tests.js index 0fdee6f1..4063870a 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -132,25 +132,39 @@ function run_compress_tests() { failures++; failed_files[file] = 1; } - else if (test.expect_warnings) { - U.AST_Node.warn_function = original_warn_function; - var expected_warnings = make_code(test.expect_warnings, { - beautify: false, - quote_style: 2, // force double quote to match JSON - }); - warnings_emitted = warnings_emitted.map(function(input) { - return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/"); - }); - var actual_warnings = JSON.stringify(warnings_emitted); - if (expected_warnings != actual_warnings) { - log("!!! failed\n---INPUT---\n{input}\n---EXPECTED WARNINGS---\n{expected_warnings}\n---ACTUAL WARNINGS---\n{actual_warnings}\n\n", { + else { + // expect == output + try { + var reparsed_ast = U.parse(output); + } catch (ex) { + log("!!! Test matched expected result but cannot parse output\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--REPARSE ERROR--\n{error}\n\n", { input: input_code, - expected_warnings: expected_warnings, - actual_warnings: actual_warnings, + output: output, + error: ex.toString(), }); failures++; failed_files[file] = 1; } + if (test.expect_warnings) { + U.AST_Node.warn_function = original_warn_function; + var expected_warnings = make_code(test.expect_warnings, { + beautify: false, + quote_style: 2, // force double quote to match JSON + }); + warnings_emitted = warnings_emitted.map(function(input) { + return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/"); + }); + var actual_warnings = JSON.stringify(warnings_emitted); + if (expected_warnings != actual_warnings) { + log("!!! failed\n---INPUT---\n{input}\n---EXPECTED WARNINGS---\n{expected_warnings}\n---ACTUAL WARNINGS---\n{actual_warnings}\n\n", { + input: input_code, + expected_warnings: expected_warnings, + actual_warnings: actual_warnings, + }); + failures++; + failed_files[file] = 1; + } + } } } var tests = parse_test(path.resolve(dir, file)); -- 2.34.1