diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/node_version.js | 12 | ||||
-rwxr-xr-x | test/run-tests.js | 15 | ||||
-rw-r--r-- | test/sandbox.js | 3 |
3 files changed, 26 insertions, 4 deletions
diff --git a/test/compress/node_version.js b/test/compress/node_version.js new file mode 100644 index 00000000..ad0bfa15 --- /dev/null +++ b/test/compress/node_version.js @@ -0,0 +1,12 @@ +eval_let: { + input: { + eval("let a;"); + console.log(); + } + expect: { + eval("let a;"); + console.log(); + } + expect_stdout: "" + node_version: ">=6" +} diff --git a/test/run-tests.js b/test/run-tests.js index edcd7cc9..8427d4a8 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -5,6 +5,7 @@ var path = require("path"); var fs = require("fs"); var assert = require("assert"); var sandbox = require("./sandbox"); +var semver = require("semver"); var tests_dir = path.dirname(module.filename); var failures = 0; @@ -164,7 +165,8 @@ function run_compress_tests() { failed_files[file] = 1; } } - if (test.expect_stdout) { + if (test.expect_stdout + && (!test.node_version || semver.satisfies(process.version, test.node_version))) { var stdout = sandbox.run_code(input_code); if (test.expect_stdout === true) { test.expect_stdout = stdout; @@ -274,7 +276,14 @@ function parse_test(file) { if (node instanceof U.AST_LabeledStatement) { var label = node.label; assert.ok( - ["input", "expect", "expect_exact", "expect_warnings", "expect_stdout"].indexOf(label.name) >= 0, + [ + "input", + "expect", + "expect_exact", + "expect_warnings", + "expect_stdout", + "node_version", + ].indexOf(label.name) >= 0, tmpl("Unsupported label {name} [{line},{col}]", { name: label.name, line: label.start.line, @@ -282,7 +291,7 @@ function parse_test(file) { }) ); var stat = node.body; - if (label.name == "expect_exact") { + 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) { diff --git a/test/sandbox.js b/test/sandbox.js index c155f91c..974f5211 100644 --- a/test/sandbox.js +++ b/test/sandbox.js @@ -1,3 +1,4 @@ +var semver = require("semver"); var vm = require("vm"); function safe_log(arg, level) { @@ -63,7 +64,7 @@ exports.run_code = function(code) { process.stdout.write = original_write; } }; -exports.same_stdout = ~process.version.lastIndexOf("v0.12.", 0) ? function(expected, actual) { +exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) { if (typeof expected != typeof actual) return false; if (typeof expected != "string") { if (expected.name != actual.name) return false; |