[Pkg-javascript-commits] [uglifyjs] 118/228: handle runtime errors in `expect_stdout` (#1618)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:22 UTC 2017


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

js pushed a commit to branch master
in repository uglifyjs.

commit 0489d6de6499154c758a6464387546ec5a060f67
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Mar 18 02:33:51 2017 +0800

    handle runtime errors in `expect_stdout` (#1618)
    
    allow test to pass if both `input` and `expect` throws the same kind of error
---
 test/compress/issue-1588.js | 12 +++++++++
 test/run-tests.js           | 61 +++++++++++++++++++--------------------------
 2 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/test/compress/issue-1588.js b/test/compress/issue-1588.js
index ff25635..fce9ba5 100644
--- a/test/compress/issue-1588.js
+++ b/test/compress/issue-1588.js
@@ -85,3 +85,15 @@ unsafe_undefined: {
     }
     expect_stdout: true
 }
+
+runtime_error: {
+    input: {
+        const a = 1;
+        console.log(a++);
+    }
+    expect: {
+        const a = 1;
+        console.log(a++);
+    }
+    expect_stdout: true
+}
diff --git a/test/run-tests.js b/test/run-tests.js
index c3c142d..7f3256e 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -172,48 +172,33 @@ 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", {
+                    var stdout = run_code(input_code);
+                    if (test.expect_stdout === true) {
+                        test.expect_stdout = stdout;
+                    }
+                    if (!same_stdout(test.expect_stdout, stdout)) {
+                        log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
+                            input: input_code,
+                            expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
+                            expected: test.expect_stdout,
+                            actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
+                            actual: stdout,
+                        });
+                        failures++;
+                        failed_files[file] = 1;
+                    } else {
+                        stdout = run_code(output);
+                        if (!same_stdout(test.expect_stdout, stdout)) {
+                            log("!!! failed\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
                                 input: input_code,
+                                expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
                                 expected: test.expect_stdout,
+                                actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
                                 actual: stdout,
                             });
                             failures++;
                             failed_files[file] = 1;
-                        } else {
-                            try {
-                                stdout = run_code(output);
-                                if (test.expect_stdout != stdout) {
-                                    log("!!! failed\n---INPUT---\n{input}\n---EXPECTED STDOUT---\n{expected}\n---ACTUAL STDOUT---\n{actual}\n\n", {
-                                        input: input_code,
-                                        expected: test.expect_stdout,
-                                        actual: stdout,
-                                    });
-                                    failures++;
-                                    failed_files[file] = 1;
-                                }
-                            } catch (ex) {
-                                log("!!! Execution of output failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--ERROR--\n{error}\n\n", {
-                                    input: input_code,
-                                    output: output,
-                                    error: ex.toString(),
-                                });
-                                failures++;
-                                failed_files[file] = 1;
-                            }
                         }
-                    } catch (ex) {
-                        log("!!! Execution of input failed\n---INPUT---\n{input}\n--ERROR--\n{error}\n\n", {
-                            input: input_code,
-                            error: ex.toString(),
-                        });
-                        failures++;
-                        failed_files[file] = 1;
                     }
                 }
             }
@@ -345,7 +330,13 @@ function run_code(code) {
     try {
         new vm.Script(code).runInNewContext({ console: console }, { timeout: 5000 });
         return stdout;
+    } catch (ex) {
+        return ex;
     } finally {
         process.stdout.write = original_write;
     }
 }
+
+function same_stdout(expected, actual) {
+    return typeof expected == typeof actual && expected.toString() == actual.toString();
+}

-- 
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