From 05a339023b85f2a5c5d12368461c8951b4a35945 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Thu, 16 Mar 2017 14:09:38 +0800 Subject: [PATCH] implement `expect_stdout: true` --- test/compress/issue-1588.js | 58 +++++++++++++++++++++++++++++++++++++ test/run-tests.js | 13 +++++++-- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/test/compress/issue-1588.js b/test/compress/issue-1588.js index fe36fcfd..ff25635c 100644 --- a/test/compress/issue-1588.js +++ b/test/compress/issue-1588.js @@ -27,3 +27,61 @@ support_ie8: { expect_exact: 'try{throw"foo"}catch(x){console.log(x)}' expect_stdout: "foo" } + +safe_undefined: { + options = { + conditionals: true, + if_return: true, + unsafe: false, + } + mangle = {} + input: { + var a, c; + console.log(function(undefined) { + return function() { + if (a) + return b; + if (c) + return d; + }; + }(1)()); + } + expect: { + var a, c; + console.log(function(n) { + return function() { + return a ? b : c ? d : void 0; + }; + }(1)()); + } + expect_stdout: true +} + +unsafe_undefined: { + options = { + conditionals: true, + if_return: true, + unsafe: true, + } + mangle = {} + input: { + var a, c; + console.log(function(undefined) { + return function() { + if (a) + return b; + if (c) + return d; + }; + }()()); + } + expect: { + var a, c; + console.log(function(n) { + return function() { + return a ? b : c ? d : n; + }; + }()()); + } + expect_stdout: true +} diff --git a/test/run-tests.js b/test/run-tests.js index 661dc8e1..898bb793 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -169,6 +169,9 @@ function run_compress_tests() { if (test.expect_stdout) { try { var stdout = run_code(input_code); + if (test.expect_stdout === true) { + test.expect_stdout = stdout; + } if (test.expect_stdout != stdout) { log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED STDOUT---\n{expected}\n---ACTUAL STDOUT---\n{actual}\n\n", { input: input_code, @@ -258,9 +261,9 @@ function parse_test(file) { } function read_string(stat) { - if (stat.TYPE === "SimpleStatement") { + if (stat.TYPE == "SimpleStatement") { var body = stat.body; - out: switch(body.TYPE) { + switch(body.TYPE) { case "String": return body.value; case "Array": @@ -303,7 +306,11 @@ function parse_test(file) { if (label.name == "expect_exact") { test[label.name] = read_string(stat); } else if (label.name == "expect_stdout") { - test[label.name] = read_string(stat) + "\n"; + if (stat.TYPE == "SimpleStatement" && stat.body instanceof U.AST_Boolean) { + test[label.name] = stat.body.value; + } else { + test[label.name] = read_string(stat) + "\n"; + } } else { test[label.name] = stat; }