fix issues in tests flagged by LGTM (#5150)

This commit is contained in:
Alex Lam S.L
2021-10-21 02:07:23 +08:00
committed by GitHub
parent 03aec89f60
commit 32ae994f88
10 changed files with 12 additions and 16 deletions

View File

@@ -1,7 +1,5 @@
// (beautified) // (beautified)
console.log(function() { console.log(1 + .1 + .1);
return 1 + .1 + .1;
}());
// output: 1.2000000000000002 // output: 1.2000000000000002
// //
// minify: 1.2 // minify: 1.2

View File

@@ -191,7 +191,7 @@ describe("comments", function() {
}); });
it("Should correctly preserve new lines around comments", function() { it("Should correctly preserve new lines around comments", function() {
var tests = [ [
[ [
"// foo", "// foo",
"// bar", "// bar",

View File

@@ -1,7 +1,6 @@
var assert = require("assert"); var assert = require("assert");
var exec = require("child_process").exec; var exec = require("child_process").exec;
var path = require("path"); var path = require("path");
var readFileSync = require("fs").readFileSync;
describe("bin/uglifyjs with input file globs", function() { describe("bin/uglifyjs with input file globs", function() {
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';

View File

@@ -25,7 +25,7 @@ describe("minify", function() {
if (result.error) throw result.error; if (result.error) throw result.error;
assert.strictEqual(result.code, "print(42);"); assert.strictEqual(result.code, "print(42);");
assert.strictEqual(JSON.stringify(options), value); assert.strictEqual(JSON.stringify(options), value);
}) });
it("Should skip inherited keys from `files`", function() { it("Should skip inherited keys from `files`", function() {
var files = Object.create({ skip: this }); var files = Object.create({ skip: this });
files[0] = "alert(1 + 1)"; files[0] = "alert(1 + 1)";

View File

@@ -1,5 +1,4 @@
var assert = require("assert"); var assert = require("assert");
var exec = require("child_process").exec;
var fs = require("fs"); var fs = require("fs");
var reduce_test = require("../reduce"); var reduce_test = require("../reduce");
var semver = require("semver"); var semver = require("semver");

View File

@@ -362,7 +362,7 @@ describe("sourcemaps", function() {
it("Should not modify input source map", function() { it("Should not modify input source map", function() {
var orig = get_map(); var orig = get_map();
var original = JSON.stringify(orig); var original = JSON.stringify(orig);
var map = prepare_map(orig); prepare_map(orig);
assert.strictEqual(JSON.stringify(orig), original); assert.strictEqual(JSON.stringify(orig), original);
}); });
it("Should copy over original sourcesContent", function() { it("Should copy over original sourcesContent", function() {

View File

@@ -12,7 +12,7 @@ describe("String literals", function() {
'"\u2029"', '"\u2029"',
].forEach(function(input) { ].forEach(function(input) {
assert.throws(function() { assert.throws(function() {
var ast = UglifyJS.parse(input); UglifyJS.parse(input);
}, function(e) { }, function(e) {
return e instanceof UglifyJS.JS_Parse_Error return e instanceof UglifyJS.JS_Parse_Error
&& e.message === "Unterminated string constant"; && e.message === "Unterminated string constant";
@@ -44,7 +44,7 @@ describe("String literals", function() {
'"use strict";\n"\\011"', '"use strict";\n"\\011"',
].forEach(function(input) { ].forEach(function(input) {
assert.throws(function() { assert.throws(function() {
var output = UglifyJS.parse(input); UglifyJS.parse(input);
}, function(e) { }, function(e) {
return e instanceof UglifyJS.JS_Parse_Error return e instanceof UglifyJS.JS_Parse_Error
&& e.message === "Legacy octal escape sequences are not allowed in strict mode"; && e.message === "Legacy octal escape sequences are not allowed in strict mode";

View File

@@ -215,9 +215,9 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
// hoist and return expressions from the IIFE function expression // hoist and return expressions from the IIFE function expression
var seq = []; var seq = [];
node.expression.body.forEach(function(node) { node.expression.body.forEach(function(node) {
var expr = expr instanceof U.AST_Exit ? node.value : node.body; var expr = node instanceof U.AST_Exit ? node.value : node.body;
if (expr instanceof U.AST_Node && !U.is_statement(expr) && can_hoist(expr)) { if (expr instanceof U.AST_Node && !U.is_statement(expr) && can_hoist(expr)) {
// collect expressions from each statements' body // collect expressions from each statement's body
seq.push(expr); seq.push(expr);
} }
}); });
@@ -395,7 +395,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
var expr = [ var expr = [
node.expression, // switch expression node.expression, // switch expression
node.body[0] && node.body[0].expression, // first case expression or undefined node.body[0] && node.body[0].expression, // first case expression or undefined
node.body[0] && node.body[0], // first case body or undefined node.body[0], // first case body or undefined
][ (node.start._permute * steps | 0) % 4 ]; ][ (node.start._permute * steps | 0) % 4 ];
node.start._permute += step; node.start._permute += step;
if (expr && (!(expr instanceof U.AST_Statement) || !has_loopcontrol(expr, node, parent))) { if (expr && (!(expr instanceof U.AST_Statement) || !has_loopcontrol(expr, node, parent))) {

View File

@@ -278,11 +278,11 @@ function run_code_exec(code, toplevel, timeout) {
timeout: timeout || 5000, timeout: timeout || 5000,
}); });
if (result.status === 0) return result.stdout; if (result.status === 0) return result.stdout;
var msg = ("" + result.stderr).replace(/\r\n/g, "\n");
if (result.error && result.error.code == "ETIMEDOUT" || /FATAL ERROR:/.test(msg)) { if (result.error && result.error.code == "ETIMEDOUT" || /FATAL ERROR:/.test(msg)) {
return new Error("Script execution timed out."); return new Error("Script execution timed out.");
} }
if (result.error) return result.error; if (result.error) return result.error;
var msg = result.stderr.replace(/\r\n/g, "\n");
var end = msg.indexOf("\n\n-----===== UNCAUGHT EXCEPTION =====-----\n\n"); var end = msg.indexOf("\n\n-----===== UNCAUGHT EXCEPTION =====-----\n\n");
var details; var details;
if (end >= 0) { if (end >= 0) {

View File

@@ -2078,8 +2078,8 @@ if (require.main !== module) {
return; return;
} }
function run_code(code, toplevel) { function run_code(code, toplevel, timeout) {
return sandbox.run_code(sandbox.patch_module_statements(code), toplevel); return sandbox.run_code(sandbox.patch_module_statements(code), toplevel, timeout);
} }
function writeln(stream, msg) { function writeln(stream, msg) {