[Pkg-javascript-commits] [uglifyjs] 393/491: reminify tests upon `expect_stdout` (#2716)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:56 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 6f3f21233f61fbb014f5e5029baa1e4a8a91e0e7
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Jan 4 20:13:05 2018 +0800

    reminify tests upon `expect_stdout` (#2716)
---
 test/run-tests.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/test/run-tests.js b/test/run-tests.js
index e5f7967..5dcacd8 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;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list