enhance `test/ufuzz.js` (#2808)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 18 Jan 2018 06:08:05 +0000 (14:08 +0800)
committerGitHub <noreply@github.com>
Thu, 18 Jan 2018 06:08:05 +0000 (14:08 +0800)
- standalone test for `rename`
- handle `keep_fargs` & `rename` upon failure

test/ufuzz.js
test/ufuzz.json

index d02e9f7..07b67a8 100644 (file)
@@ -998,10 +998,11 @@ function log_suspects(minify_options, component) {
     if (typeof options != "object") options = {};
     var defs = default_options[component];
     var suspects = Object.keys(defs).filter(function(name) {
-        if ((name in options ? options : defs)[name]) {
+        var flip = name == "keep_fargs";
+        if (flip ? name in options : (name in options ? options : defs)[name]) {
             var m = JSON.parse(JSON.stringify(minify_options));
             var o = JSON.parse(JSON.stringify(options));
-            o[name] = false;
+            o[name] = flip;
             m[component] = o;
             var result = UglifyJS.minify(original_code, m);
             if (result.error) {
@@ -1022,6 +1023,24 @@ function log_suspects(minify_options, component) {
     }
 }
 
+function log_rename(options) {
+    if (!options.rename) return;
+    var m = JSON.parse(JSON.stringify(minify_options));
+    m.rename = false;
+    var result = UglifyJS.minify(original_code, m);
+    if (result.error) {
+        errorln("Error testing options.rename");
+        errorln(result.error.stack);
+    } else {
+        var r = sandbox.run_code(result.code);
+        if (sandbox.same_stdout(original_result, r)) {
+            errorln("Suspicious options:");
+            errorln("  rename");
+            errorln();
+        }
+    }
+}
+
 function log(options) {
     if (!ok) errorln('\n\n\n\n\n\n!!!!!!!!!!\n\n\n');
     errorln("//=============================================================");
@@ -1056,6 +1075,7 @@ function log(options) {
     errorln();
     if (!ok && typeof uglify_code == "string") {
         Object.keys(default_options).forEach(log_suspects.bind(null, options));
+        log_rename(options);
         errorln("!!!!!! Failed... round " + round);
     }
 }
index 4057a35..f04b641 100644 (file)
@@ -5,7 +5,8 @@
         "output": {
             "beautify": true,
             "bracketize": true
-        }
+        },
+        "rename": true
     },
     {
         "compress": false