diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-13 06:26:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-13 14:26:45 +0800 |
commit | b309527264ff7aea380df98021133bb3ff591a2d (patch) | |
tree | a82e250862e1e75be54fa8724ba639c85e0dad2e /test | |
parent | 5d19bb8d5d087c6e7a383974024c67e11b6334a1 (diff) | |
download | tracifyjs-b309527264ff7aea380df98021133bb3ff591a2d.tar.gz tracifyjs-b309527264ff7aea380df98021133bb3ff591a2d.zip |
maintain compatibility options when testing (#4376)
Diffstat (limited to 'test')
-rw-r--r-- | test/reduce.js | 27 | ||||
-rw-r--r-- | test/ufuzz/index.js | 78 |
2 files changed, 53 insertions, 52 deletions
diff --git a/test/reduce.js b/test/reduce.js index 3cd7f67d..40c447b2 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -18,9 +18,18 @@ var sandbox = require("./sandbox"); Error.stackTraceLimit = Infinity; module.exports = function reduce_test(testcase, minify_options, reduce_options) { - if (testcase instanceof U.AST_Node) testcase = testcase.print_to_string(); minify_options = minify_options || {}; reduce_options = reduce_options || {}; + var print_options = {}; + [ + "ie8", + "v8", + "webkit", + ].forEach(function(name) { + var value = minify_options[name] || minify_options.output && minify_options.output[name]; + if (value) print_options[name] = value; + }); + if (testcase instanceof U.AST_Node) testcase = testcase.print_to_string(print_options); var max_iterations = reduce_options.max_iterations || 1000; var max_timeout = reduce_options.max_timeout || 10000; var warnings = []; @@ -459,7 +468,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) return node; } })); - var code = testcase_ast.print_to_string(); + var code = testcase_ast.print_to_string(print_options); var diff = test_for_diff(code, minify_options, result_cache, max_timeout); if (diff && !diff.timed_out && !diff.error) { testcase = code; @@ -483,7 +492,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) var code_ast = testcase_ast.clone(true).transform(tt); if (!CHANGED) break; try { - var code = code_ast.print_to_string(); + var code = code_ast.print_to_string(print_options); } catch (ex) { // AST is not well formed. // no harm done - just log the error, ignore latest change and continue iterating. @@ -525,11 +534,13 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) var beautified = U.minify(testcase, { compress: false, mangle: false, - output: { - beautify: true, - braces: true, - comments: true, - }, + output: function() { + var options = JSON.parse(JSON.stringify(print_options)); + options.beautify = true; + options.braces = true; + options.comments = true; + return options; + }(), }); testcase = { code: testcase, diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index 0b16a590..976fc44a 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -1445,25 +1445,35 @@ function errorln(msg) { writeln(process.stderr, msg); } -function try_beautify(code, toplevel, result, printfn) { - var beautified = UglifyJS.minify(code, { - compress: false, - mangle: false, - output: { - beautify: true, - braces: true, - }, - }); +function try_beautify(code, toplevel, result, printfn, options) { + var beautified = UglifyJS.minify(code, JSON.parse(beautify_options)); if (beautified.error) { printfn("// !!! beautify failed !!!"); printfn(beautified.error); - } else if (sandbox.same_stdout(sandbox.run_code(beautified.code, toplevel), result)) { + beautified = null; + } else if (!sandbox.same_stdout(sandbox.run_code(beautified.code, toplevel), result)) { + beautified = null; + } else if (options) { + var uglified = UglifyJS.minify(beautified.code, JSON.parse(options)); + var expected, actual; + if (typeof uglify_code != "string" || uglified.error) { + expected = uglify_code; + actual = uglified.error; + } else { + expected = uglify_result; + actual = sandbox.run_code(uglified.code, toplevel); + } + if (!sandbox.same_stdout(expected, actual)) { + beautified = null; + } + } + if (beautified) { printfn("// (beautified)"); printfn(beautified.code); - return; + } else { + printfn("//"); + printfn(code); } - printfn("//"); - printfn(code); } var default_options = UglifyJS.default_options(); @@ -1536,37 +1546,7 @@ function log(options) { errorln("//============================================================="); if (!ok) errorln("// !!!!!! Failed... round " + round); errorln("// original code"); - var beautified = UglifyJS.minify(original_code, { - compress: false, - mangle: false, - output: { - beautify: true, - braces: true, - }, - }); - if (beautified.error) { - errorln("// !!! beautify failed !!!"); - errorln(beautified.error); - errorln("//"); - errorln(original_code); - } else { - var uglified = UglifyJS.minify(beautified.code, JSON.parse(options)); - var expected, actual; - if (typeof uglify_code != "string" || uglified.error) { - expected = uglify_code; - actual = uglified.error; - } else { - expected = uglify_result; - actual = sandbox.run_code(uglified.code, toplevel); - } - if (sandbox.same_stdout(expected, actual)) { - errorln("// (beautified)"); - errorln(beautified.code); - } else { - errorln("//"); - errorln(original_code); - } - } + try_beautify(original_code, toplevel, original_result, errorln, options); errorln(); errorln(); errorln("//-------------------------------------------------------------"); @@ -1698,13 +1678,23 @@ function patch_try_catch(orig, toplevel) { } } +var beautify_options = { + compress: false, + mangle: false, + output: { + beautify: true, + braces: true, + }, +}; var minify_options = require("./options.json"); if (SUPPORT.destructuring && typeof sandbox.run_code("console.log([ 1 ], {} = 2);") != "string") { + beautify_options.output.v8 = true; minify_options.forEach(function(o) { if (!("output" in o)) o.output = {}; o.output.v8 = true; }); } +beautify_options = JSON.stringify(beautify_options); minify_options = minify_options.map(JSON.stringify); var original_code, original_result, errored; var uglify_code, uglify_result, ok; |