aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-04-30 06:32:24 +0800
committerGitHub <noreply@github.com>2019-04-30 06:32:24 +0800
commit2ea96549c55c44935c05fcaf6c68119d0eef4c8e (patch)
tree89a3ab9e15c3b250858f9d1c590816675cf93c5f /test
parentfba008e2989de0611d144a1ec91d9eb1c9b2b479 (diff)
downloadtracifyjs-2ea96549c55c44935c05fcaf6c68119d0eef4c8e.tar.gz
tracifyjs-2ea96549c55c44935c05fcaf6c68119d0eef4c8e.zip
unify logging functionality (#3392)
fixes #3253 fixes #3254
Diffstat (limited to 'test')
-rw-r--r--test/compress/collapse_vars.js4
-rw-r--r--test/compress/drop-unused.js12
-rw-r--r--test/compress/ie8.js20
-rw-r--r--test/compress/issue-1034.js18
-rw-r--r--test/mocha/cli.js10
-rw-r--r--test/mocha/sourcemaps.js68
-rwxr-xr-xtest/run-tests.js22
7 files changed, 65 insertions, 89 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 470f3b76..6e0afc6e 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -4194,7 +4194,7 @@ may_throw_2: {
var a = x();
++b;
return b(a);
- } catch(e) {}
+ } catch (e) {}
console.log(b);
}
f(0);
@@ -4204,7 +4204,7 @@ may_throw_2: {
try {
var a = x();
return (++b)(a);
- } catch(e) {}
+ } catch (e) {}
console.log(b);
}
f(0);
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 74fe3693..9286532b 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -144,7 +144,7 @@ unused_var_in_catch: {
function foo() {
try {
foo();
- } catch(ex) {
+ } catch (ex) {
var x = 10;
}
}
@@ -153,7 +153,7 @@ unused_var_in_catch: {
function foo() {
try {
foo();
- } catch(ex) {}
+ } catch (ex) {}
}
}
}
@@ -166,7 +166,7 @@ used_var_in_catch: {
function foo() {
try {
foo();
- } catch(ex) {
+ } catch (ex) {
var x = 10;
}
return x;
@@ -176,7 +176,7 @@ used_var_in_catch: {
function foo() {
try {
foo();
- } catch(ex) {
+ } catch (ex) {
var x = 10;
}
return x;
@@ -1156,7 +1156,7 @@ var_catch_toplevel: {
try {
a++;
x();
- } catch(a) {
+ } catch (a) {
if (a) var a;
var a = 10;
}
@@ -1167,7 +1167,7 @@ var_catch_toplevel: {
!function() {
try {
x();
- } catch(a) {
+ } catch (a) {
var a;
}
}();
diff --git a/test/compress/ie8.js b/test/compress/ie8.js
index f98033e0..e81e1a01 100644
--- a/test/compress/ie8.js
+++ b/test/compress/ie8.js
@@ -59,9 +59,9 @@ do_screw_try_catch: {
input: {
good = function(e){
return function(error){
- try{
+ try {
e()
- } catch(e) {
+ } catch (e) {
error(e)
}
}
@@ -70,9 +70,9 @@ do_screw_try_catch: {
expect: {
good = function(n){
return function(t){
- try{
+ try {
n()
- } catch(n) {
+ } catch (n) {
t(n)
}
}
@@ -93,9 +93,9 @@ dont_screw_try_catch: {
input: {
bad = function(e){
return function(error){
- try{
+ try {
e()
- } catch(e) {
+ } catch (e) {
error(e)
}
}
@@ -104,9 +104,9 @@ dont_screw_try_catch: {
expect: {
bad = function(t){
return function(n){
- try{
+ try {
t()
- } catch(t) {
+ } catch (t) {
n(t)
}
}
@@ -137,7 +137,7 @@ do_screw_try_catch_undefined: {
}
expect: {
function a(o){
- try{
+ try {
throw "Stuff"
} catch (o) {
console.log("caught: "+o)
@@ -172,7 +172,7 @@ dont_screw_try_catch_undefined: {
}
expect: {
function a(n){
- try{
+ try {
throw "Stuff"
} catch (undefined) {
console.log("caught: " + undefined)
diff --git a/test/compress/issue-1034.js b/test/compress/issue-1034.js
index f2a89e33..e8b69187 100644
--- a/test/compress/issue-1034.js
+++ b/test/compress/issue-1034.js
@@ -59,7 +59,6 @@ non_hoisted_function_after_return_2a: {
passes: 2,
side_effects: true,
unused: true,
- warnings: "verbose",
}
input: {
function foo(x) {
@@ -91,13 +90,13 @@ non_hoisted_function_after_return_2a: {
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
"WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]",
"WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]",
- "WARN: pass 0: last_count: Infinity, count: 37",
+ "INFO: pass 0: last_count: Infinity, count: 37",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
- "WARN: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
- "WARN: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
- "WARN: pass 1: last_count: 37, count: 18",
+ "INFO: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
+ "INFO: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
+ "INFO: pass 1: last_count: 37, count: 18",
]
}
@@ -213,7 +212,6 @@ non_hoisted_function_after_return_2a_strict: {
passes: 2,
side_effects: true,
unused: true,
- warnings: "verbose",
}
input: {
"use strict";
@@ -250,13 +248,13 @@ non_hoisted_function_after_return_2a_strict: {
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,16]",
"WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]",
"WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]",
- "WARN: pass 0: last_count: Infinity, count: 48",
+ "INFO: pass 0: last_count: Infinity, count: 48",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:10,12]",
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
- "WARN: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
- "WARN: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
- "WARN: pass 1: last_count: 48, count: 29",
+ "INFO: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
+ "INFO: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
+ "INFO: pass 1: last_count: 48, count: 29",
]
}
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index 811c493f..6d6e1e80 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -47,7 +47,7 @@ describe("bin/uglifyjs", function() {
});
});
it("Should give sensible error against invalid input source map", function(done) {
- var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline";
+ var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline --verbose";
exec(command, function(err, stdout, stderr) {
assert.ok(err);
assert.deepEqual(stderr.split(/\n/).slice(0, 2), [
@@ -83,6 +83,7 @@ describe("bin/uglifyjs", function() {
"test/input/issue-2082/sample.js",
"--source-map", "content=test/input/issue-2082/sample.js.map",
"--source-map", "url=inline",
+ "--verbose",
].join(" ");
exec(command, function(err, stdout, stderr) {
if (err) throw err;
@@ -202,7 +203,7 @@ describe("bin/uglifyjs", function() {
});
});
it("Should warn for missing inline source map", function(done) {
- var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline";
+ var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline --warn";
exec(command, function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, [
@@ -221,6 +222,7 @@ describe("bin/uglifyjs", function() {
"test/input/issue-520/input.js",
"test/input/issue-1323/sample.js",
"--source-map", "content=inline,url=inline",
+ "--warn",
].join(" ");
exec(command, function(err, stdout, stderr) {
if (err) throw err;
@@ -466,7 +468,7 @@ describe("bin/uglifyjs", function() {
done();
});
});
- it("Should throw syntax error (catch(eval))", function(done) {
+ it("Should throw syntax error (catch (eval))", function(done) {
var command = uglifyjscmd + ' test/input/invalid/try.js';
exec(command, function(err, stdout, stderr) {
assert.ok(err);
@@ -647,7 +649,7 @@ describe("bin/uglifyjs", function() {
exec(command, function(err, stdout, stderr) {
assert.ok(err);
assert.strictEqual(stdout, "");
- assert.strictEqual(stderr, "Error parsing arguments for 'define': a-b\n");
+ assert.strictEqual(stderr, "ERROR: cannot parse arguments for 'define': a-b\n");
done();
});
});
diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js
index ccaa68e1..f625b227 100644
--- a/test/mocha/sourcemaps.js
+++ b/test/mocha/sourcemaps.js
@@ -118,51 +118,33 @@ describe("sourcemaps", function() {
assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-520/output.js", "utf8"));
});
it("Should warn for missing inline source map", function() {
- var warn_function = UglifyJS.AST_Node.warn_function;
- var warnings = [];
- UglifyJS.AST_Node.warn_function = function(txt) {
- warnings.push(txt);
- };
- try {
- var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), {
- mangle: false,
- sourceMap: {
- content: "inline"
- }
- });
- assert.strictEqual(result.code, "var bar=function(bar){return bar};");
- assert.strictEqual(warnings.length, 1);
- assert.strictEqual(warnings[0], "inline source map not found: 0");
- } finally {
- UglifyJS.AST_Node.warn_function = warn_function;
- }
+ var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), {
+ mangle: false,
+ sourceMap: {
+ content: "inline"
+ },
+ warnings: true,
+ });
+ assert.strictEqual(result.code, "var bar=function(bar){return bar};");
+ assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 0" ]);
});
it("Should handle multiple input and inline source map", function() {
- var warn_function = UglifyJS.AST_Node.warn_function;
- var warnings = [];
- UglifyJS.AST_Node.warn_function = function(txt) {
- warnings.push(txt);
- };
- try {
- var result = UglifyJS.minify([
- read("./test/input/issue-520/input.js"),
- read("./test/input/issue-1323/sample.js"),
- ], {
- sourceMap: {
- content: "inline",
- url: "inline",
- }
- });
- if (result.error) throw result.error;
- assert.strictEqual(result.code, [
- "var Foo=function(){console.log(3)};new Foo;var bar=function(o){return o};",
- "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElBQVMsSUFBSUYsSUNBbkQsSUFBSUcsSUFDQSxTQUFjQSxHQUNWLE9BQU9BIn0=",
- ].join("\n"));
- assert.strictEqual(warnings.length, 1);
- assert.strictEqual(warnings[0], "inline source map not found: 1");
- } finally {
- UglifyJS.AST_Node.warn_function = warn_function;
- }
+ var result = UglifyJS.minify([
+ read("./test/input/issue-520/input.js"),
+ read("./test/input/issue-1323/sample.js"),
+ ], {
+ sourceMap: {
+ content: "inline",
+ url: "inline",
+ },
+ warnings: true,
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, [
+ "var Foo=function(){console.log(3)};new Foo;var bar=function(o){return o};",
+ "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElBQVMsSUFBSUYsSUNBbkQsSUFBSUcsSUFDQSxTQUFjQSxHQUNWLE9BQU9BIn0=",
+ ].join("\n"));
+ assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 1" ]);
});
it("Should drop source contents for includeSources=false", function() {
var result = UglifyJS.minify(read("./test/input/issue-520/input.js"), {
diff --git a/test/run-tests.js b/test/run-tests.js
index f78deb31..aa415ec9 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -231,16 +231,15 @@ function run_compress_tests() {
});
return false;
}
- var options = U.defaults(test.options, {
- warnings: false
- });
var warnings_emitted = [];
- var original_warn_function = U.AST_Node.warn_function;
if (test.expect_warnings) {
- U.AST_Node.warn_function = function(text) {
- warnings_emitted.push("WARN: " + text);
- };
- if (!options.warnings) options.warnings = true;
+ var expected_warnings = make_code(test.expect_warnings, {
+ beautify: false,
+ quote_style: 2, // force double quote to match JSON
+ });
+ U.AST_Node.log_function(function(text) {
+ warnings_emitted.push(text);
+ }, /"INFO: /.test(expected_warnings));
}
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
var quoted_props = test.mangle.properties.reserved;
@@ -252,7 +251,7 @@ function run_compress_tests() {
input.figure_out_scope(test.mangle);
input.expand_names(test.mangle);
}
- var cmp = new U.Compressor(options, true);
+ var cmp = new U.Compressor(test.options, true);
var output = cmp.compress(input);
output.figure_out_scope(test.mangle);
if (test.mangle) {
@@ -283,11 +282,6 @@ function run_compress_tests() {
return false;
}
if (test.expect_warnings) {
- U.AST_Node.warn_function = original_warn_function;
- var expected_warnings = make_code(test.expect_warnings, {
- beautify: false,
- quote_style: 2, // force double quote to match JSON
- });
warnings_emitted = warnings_emitted.map(function(input) {
return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/");
});