From: Alex Lam S.L Date: Thu, 4 Jan 2018 12:13:05 +0000 (+0800) Subject: reminify tests upon `expect_stdout` (#2716) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6f3f21233f61fbb014f5e5029baa1e4a8a91e0e7;p=UglifyJS.git reminify tests upon `expect_stdout` (#2716) --- diff --git a/test/run-tests.js b/test/run-tests.js index e5f79678..5dcacd87 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -10,6 +10,7 @@ var semver = require("semver"); var tests_dir = path.dirname(module.filename); var failures = 0; var failed_files = {}; +var minify_options = require("./ufuzz.json").map(JSON.stringify); run_compress_tests(); if (failures) { @@ -207,6 +208,9 @@ function run_compress_tests() { }); return false; } + if (!reminify(test.options, input_code, input_formatted, test.expect_stdout)) { + return false; + } } return true; } @@ -351,3 +355,46 @@ function evaluate(code) { code = make_code(code, { beautify: true }); return new Function("return(" + code + ")")(); } + +// Try to reminify original input with standard options +// to see if it matches expect_stdout. +function reminify(orig_options, input_code, input_formatted, expect_stdout) { + for (var i = 0; i < minify_options.length; i++) { + var options = JSON.parse(minify_options[i]); + if (options.compress) [ + "keep_fargs", + "keep_fnames", + ].forEach(function(name) { + if (name in orig_options) { + options.compress[name] = orig_options[name]; + } + }); + var options_formatted = JSON.stringify(options, null, 4); + var result = U.minify(input_code, options); + if (result.error) { + log("!!! failed input reminify\n---INPUT---\n{input}\n--ERROR---\n{error}\n\n", { + input: input_formatted, + error: result.error, + }); + return false; + } else { + var stdout = sandbox.run_code(result.code); + if (typeof expect_stdout != "string" && typeof stdout != "string" && expect_stdout.name == stdout.name) { + stdout = expect_stdout; + } + if (!sandbox.same_stdout(expect_stdout, stdout)) { + log("!!! failed running reminified input\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n---OUTPUT---\n{output}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", { + input: input_formatted, + options: options_formatted, + output: result.code, + expected_type: typeof expect_stdout == "string" ? "STDOUT" : "ERROR", + expected: expect_stdout, + actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR", + actual: stdout, + }); + return false; + } + } + } + return true; +}