allow `expect_stdout` to specify `Error` (#2087)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 12 Jun 2017 20:57:26 +0000 (04:57 +0800)
committerGitHub <noreply@github.com>
Mon, 12 Jun 2017 20:57:26 +0000 (04:57 +0800)
test/compress/node_version.js
test/run-tests.js

index ad0bfa1..ef62fd7 100644 (file)
@@ -1,4 +1,4 @@
-eval_let: {
+eval_let_6: {
     input: {
         eval("let a;");
         console.log();
@@ -10,3 +10,29 @@ eval_let: {
     expect_stdout: ""
     node_version: ">=6"
 }
+
+eval_let_4: {
+    input: {
+        eval("let a;");
+        console.log();
+    }
+    expect: {
+        eval("let a;");
+        console.log();
+    }
+    expect_stdout: SyntaxError("Block-scoped declarations (let, const, function, class) not yet supported outside strict mode")
+    node_version: "4"
+}
+
+eval_let_0: {
+    input: {
+        eval("let a;");
+        console.log();
+    }
+    expect: {
+        eval("let a;");
+        console.log();
+    }
+    expect_stdout: SyntaxError("Unexpected identifier")
+    node_version: "<=0.12"
+}
index 8427d4a..188532e 100755 (executable)
@@ -294,8 +294,24 @@ function parse_test(file) {
                 if (label.name == "expect_exact" || label.name == "node_version") {
                     test[label.name] = read_string(stat);
                 } else if (label.name == "expect_stdout") {
-                    if (stat.TYPE == "SimpleStatement" && stat.body instanceof U.AST_Boolean) {
-                        test[label.name] = stat.body.value;
+                    if (stat.TYPE == "SimpleStatement") {
+                        var body = stat.body;
+                        if (body instanceof U.AST_Boolean) {
+                            test[label.name] = body.value;
+                        } else if (body instanceof U.AST_Call) {
+                            var ctor = global[body.expression.name];
+                            assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
+                                line: label.start.line,
+                                col: label.start.col
+                            }));
+                            test[label.name] = ctor.apply(null, body.args.map(function(node) {
+                                assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
+                                    line: label.start.line,
+                                    col: label.start.col
+                                }));
+                                return node.value;
+                            }));
+                        }
                     } else {
                         test[label.name] = read_string(stat) + "\n";
                     }