[Pkg-javascript-commits] [uglifyjs] 80/491: make `expect_stdout` node version specific (#1963)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:23 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 efcf167e5efc95a82678db2056396dcf94993641
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Thu May 18 11:28:35 2017 +0800
make `expect_stdout` node version specific (#1963)
... via semver string on `node_version` label.
---
package.json | 3 ++-
test/compress/node_version.js | 12 ++++++++++++
test/run-tests.js | 15 ++++++++++++---
test/sandbox.js | 3 ++-
4 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/package.json b/package.json
index a241a3c..ef88340 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,8 @@
},
"devDependencies": {
"acorn": "~5.0.3",
- "mocha": "~2.3.4"
+ "mocha": "~2.3.4",
+ "semver": "~5.3.0"
},
"scripts": {
"test": "node test/run-tests.js"
diff --git a/test/compress/node_version.js b/test/compress/node_version.js
new file mode 100644
index 0000000..ad0bfa1
--- /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 edcd7cc..8427d4a 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 c155f91..974f521 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;
--
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