extend test/run-tests.js to optionally execute uglified output
fixes #1588
This commit is contained in:
parent
cf4bf4ceb1
commit
cca2337d3d
29
test/compress/issue-1588.js
Normal file
29
test/compress/issue-1588.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
screw_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try { throw "foo"; } catch (x) { console.log(x); }
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"foo"}catch(o){console.log(o)}'
|
||||||
|
expect_stdout: [
|
||||||
|
"foo"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
support_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try { throw "foo"; } catch (x) { console.log(x); }
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"foo"}catch(x){console.log(x)}'
|
||||||
|
expect_stdout: "foo"
|
||||||
|
}
|
||||||
|
|
@ -6,28 +6,28 @@ var U = require("../tools/node");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
var execFile = require("child_process").execFile;
|
||||||
|
|
||||||
var tests_dir = path.dirname(module.filename);
|
var tests_dir = path.dirname(module.filename);
|
||||||
var failures = 0;
|
|
||||||
var failed_files = {};
|
|
||||||
|
|
||||||
run_compress_tests();
|
run_compress_tests(function(failures, failed_files) {
|
||||||
if (failures) {
|
if (failures) {
|
||||||
console.error("\n!!! Failed " + failures + " test cases.");
|
console.error("\n!!! Failed " + failures + " test cases.");
|
||||||
console.error("!!! " + Object.keys(failed_files).join(", "));
|
console.error("!!! " + Object.keys(failed_files).join(", "));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mocha_tests = require("./mocha.js");
|
var mocha_tests = require("./mocha.js");
|
||||||
mocha_tests();
|
mocha_tests();
|
||||||
|
|
||||||
var run_sourcemaps_tests = require('./sourcemaps');
|
var run_sourcemaps_tests = require('./sourcemaps');
|
||||||
run_sourcemaps_tests();
|
run_sourcemaps_tests();
|
||||||
|
|
||||||
var run_ast_conversion_tests = require("./mozilla-ast");
|
var run_ast_conversion_tests = require("./mozilla-ast");
|
||||||
|
|
||||||
run_ast_conversion_tests({
|
run_ast_conversion_tests({
|
||||||
iterations: 1000
|
iterations: 1000
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -----[ utils ]----- */
|
/* -----[ utils ]----- */
|
||||||
|
|
@ -79,13 +79,20 @@ function as_toplevel(input, mangle_options) {
|
||||||
return toplevel;
|
return toplevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_compress_tests() {
|
function run_compress_tests(done) {
|
||||||
|
var failures = 0;
|
||||||
|
var failed_files = {};
|
||||||
var dir = test_directory("compress");
|
var dir = test_directory("compress");
|
||||||
log_directory("compress");
|
log_directory("compress");
|
||||||
var files = find_test_files(dir);
|
var files = find_test_files(dir);
|
||||||
function test_file(file) {
|
!function test_file() {
|
||||||
|
var file = files.shift();
|
||||||
|
if (!file) return done(failures, failed_files);
|
||||||
log_start_file(file);
|
log_start_file(file);
|
||||||
function test_case(test) {
|
var tests = parse_test(path.resolve(dir, file));
|
||||||
|
!function test_case() {
|
||||||
|
var test = tests.shift();
|
||||||
|
if (!test) return test_file();
|
||||||
log_test(test.name);
|
log_test(test.name);
|
||||||
U.base54.reset();
|
U.base54.reset();
|
||||||
var options = U.defaults(test.options, {
|
var options = U.defaults(test.options, {
|
||||||
|
|
@ -165,16 +172,32 @@ function run_compress_tests() {
|
||||||
failed_files[file] = 1;
|
failed_files[file] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (test.expect_stdout) {
|
||||||
|
return execFile(process.argv[0], ["-e", output], function(ex, stdout, stderr) {
|
||||||
|
if (ex || stderr) {
|
||||||
|
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: stderr || ex.toString(),
|
||||||
|
});
|
||||||
|
failures++;
|
||||||
|
failed_files[file] = 1;
|
||||||
|
} else if (test.expect_stdout != stdout.replace(/\n$/, "")) {
|
||||||
|
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED STDOUT---\n{expected_warnings}\n---ACTUAL STDOUT---\n{actual_warnings}\n\n", {
|
||||||
|
input: input_code,
|
||||||
|
expected_warnings: test.expect_stdout,
|
||||||
|
actual_warnings: stdout,
|
||||||
|
});
|
||||||
|
failures++;
|
||||||
|
failed_files[file] = 1;
|
||||||
|
}
|
||||||
|
test_case();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
test_case();
|
||||||
var tests = parse_test(path.resolve(dir, file));
|
}();
|
||||||
for (var i in tests) if (tests.hasOwnProperty(i)) {
|
}();
|
||||||
test_case(tests[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
files.forEach(function(file){
|
|
||||||
test_file(file);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_test(file) {
|
function parse_test(file) {
|
||||||
|
|
@ -189,7 +212,7 @@ function parse_test(file) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
var tests = {};
|
var tests = Object.create(null);
|
||||||
var tw = new U.TreeWalker(function(node, descend){
|
var tw = new U.TreeWalker(function(node, descend){
|
||||||
if (node instanceof U.AST_LabeledStatement
|
if (node instanceof U.AST_LabeledStatement
|
||||||
&& tw.parent() instanceof U.AST_Toplevel) {
|
&& tw.parent() instanceof U.AST_Toplevel) {
|
||||||
|
|
@ -203,7 +226,9 @@ function parse_test(file) {
|
||||||
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
||||||
});
|
});
|
||||||
ast.walk(tw);
|
ast.walk(tw);
|
||||||
return tests;
|
return Object.keys(tests).map(function(name) {
|
||||||
|
return tests[name];
|
||||||
|
});
|
||||||
|
|
||||||
function croak(node) {
|
function croak(node) {
|
||||||
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
||||||
|
|
@ -243,12 +268,13 @@ function parse_test(file) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof U.AST_LabeledStatement) {
|
if (node instanceof U.AST_LabeledStatement) {
|
||||||
|
var label = node.label;
|
||||||
assert.ok(
|
assert.ok(
|
||||||
["input", "expect", "expect_exact", "expect_warnings"].indexOf(node.label.name) >= 0,
|
["input", "expect", "expect_exact", "expect_warnings", "expect_stdout"].indexOf(label.name) >= 0,
|
||||||
tmpl("Unsupported label {name} [{line},{col}]", {
|
tmpl("Unsupported label {name} [{line},{col}]", {
|
||||||
name: node.label.name,
|
name: label.name,
|
||||||
line: node.label.start.line,
|
line: label.start.line,
|
||||||
col: node.label.start.col
|
col: label.start.col
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
var stat = node.body;
|
var stat = node.body;
|
||||||
|
|
@ -256,10 +282,10 @@ function parse_test(file) {
|
||||||
if (stat.body.length == 1) stat = stat.body[0];
|
if (stat.body.length == 1) stat = stat.body[0];
|
||||||
else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
|
else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
|
||||||
}
|
}
|
||||||
if (node.label.name === "expect_exact") {
|
if (label.name === "expect_exact" || label.name === "expect_stdout") {
|
||||||
test[node.label.name] = read_string(stat);
|
test[label.name] = read_string(stat);
|
||||||
} else {
|
} else {
|
||||||
test[node.label.name] = stat;
|
test[label.name] = stat;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user