Skip to content

Commit

Permalink
allow expect_stdout to specify Error (#2087)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Jun 12, 2017
1 parent 2bdc880 commit fed0096
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
28 changes: 27 additions & 1 deletion test/compress/node_version.js
@@ -1,4 +1,4 @@
eval_let: {
eval_let_6: {
input: {
eval("let a;");
console.log();
Expand All @@ -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"
}
20 changes: 18 additions & 2 deletions test/run-tests.js
Expand Up @@ -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";
}
Expand Down

0 comments on commit fed0096

Please sign in to comment.