aboutsummaryrefslogtreecommitdiff
path: root/test/ufuzz/index.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-05-20 21:00:38 +0100
committerGitHub <noreply@github.com>2020-05-21 04:00:38 +0800
commitcc6eb4b15f798dc053c85154ea089a5d1a82bb0b (patch)
tree8dca01d7f0a06953d9bf61c6a793efc53ea8587b /test/ufuzz/index.js
parent14eee81dc6afe8c26bbe4b0f2ef1ecc054bcdd13 (diff)
downloadtracifyjs-cc6eb4b15f798dc053c85154ea089a5d1a82bb0b.tar.gz
tracifyjs-cc6eb4b15f798dc053c85154ea089a5d1a82bb0b.zip
improve `ufuzz` (#3912)
- preserve test case if `beautify` suppresses bug - determine suspicious options even if `minify()` fails
Diffstat (limited to 'test/ufuzz/index.js')
-rw-r--r--test/ufuzz/index.js44
1 files changed, 40 insertions, 4 deletions
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index faa9fd53..ed687def 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -1026,8 +1026,11 @@ function log_suspects(minify_options, component) {
var o = JSON.parse(JSON.stringify(options));
o[name] = flip;
m[component] = o;
+ m.validate = true;
var result = UglifyJS.minify(original_code, m);
- if (result.error) {
+ if (typeof uglify_code != "string") {
+ return !sandbox.same_stdout(uglify_code, result.error);
+ } else if (result.error) {
errorln("Error testing options." + component + "." + name);
errorln(result.error);
} else {
@@ -1051,8 +1054,11 @@ function log_suspects_global(options, toplevel) {
}).filter(function(component) {
var m = JSON.parse(options);
m[component] = false;
+ m.validate = true;
var result = UglifyJS.minify(original_code, m);
- if (result.error) {
+ if (typeof uglify_code != "string") {
+ return !sandbox.same_stdout(uglify_code, result.error);
+ } else if (result.error) {
errorln("Error testing options." + component);
errorln(result.error);
} else {
@@ -1075,7 +1081,37 @@ function log(options) {
errorln("//=============================================================");
if (!ok) errorln("// !!!!!! Failed... round " + round);
errorln("// original code");
- try_beautify(original_code, toplevel, original_result, errorln);
+ 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);
+ }
+ }
errorln();
errorln();
errorln("//-------------------------------------------------------------");
@@ -1113,7 +1149,7 @@ function log(options) {
errorln("minify(options):");
errorln(JSON.stringify(JSON.parse(options), null, 2));
errorln();
- if (!ok && typeof uglify_code == "string") {
+ if (!ok) {
Object.keys(default_options).filter(function(component) {
var defs = default_options[component];
return defs && typeof defs == "object";