diff --git a/tools/ecmaTester.js b/tools/ecmaTester.js index 22a79aac..fa753fcf 100644 --- a/tools/ecmaTester.js +++ b/tools/ecmaTester.js @@ -4,6 +4,9 @@ // It is expected to minify and execute the script without problems // as a failed test is indicated by throwing an exception. +// How to use (assuming the current working directory is a checkout of the test262 repo): +// [path to python2 executable] .\tools\packaging\test262.py --command "node \UglifyJS2\tools\ecmaTester.js" [add some words as filter (like 'language')] + // argv number 2 is assumed to be the input file var file = process.argv[2]; @@ -11,41 +14,63 @@ var fs = require("fs"); var vm = require("vm"); var UglifyJS = require("./node.js"); -console.log("Using node " + process.versions.node); -console.log(process.versions); +console.log("Using ", process.versions); + +var minified = "[Nothing]"; +var source; +var issues = false; +var unminifiedError = ""; +var sameError = false; -var result = "[Nothing]"; try { // Compress file - result = UglifyJS.minify(file).code; - // Run result to make sure the script is still runable - vm.runInNewContext(result, {}); + minified = UglifyJS.minify(file).code; + // Run the minified code to check if the script is still runable + vm.runInNewContext(minified, {}); } catch(e) { - // Report - console.log("A minified script failed to run"); - console.log("file: " + file); - console.log("minified output:"); - console.log(result); - console.log(); - console.log("=========="); - console.log(e); - console.log(e.stack); - console.log(); - console.log("Now running script without minification..."); - console.log(); - // Make sure script runs fine without compiling as well - input = fs.readFileSync(file, {encoding: 'utf8'}); - try { - vm.runInNewContext(input, {}); - console.log("Ran without problems unminified"); - } catch (e2) { - console.log("Failed to run script unminified as well"); - console.log(e2.stack); + source = fs.readFileSync(file, {encoding: 'utf8'}); + issues = true; - process.exit(2); // Nope... + // Investigate if an error occurs unminified as well + try { + vm.runInNewContext(source, {}); + issues = false; + unminifiedError += "Ran unminified without problems"; + + } catch (e2) { + unminifiedError = "Error while running the unminified version:\n"; + unminifiedError += "Error: " + e2 + "\n"; + unminifiedError += "Stack: " + e2.stack; + if (e2 + "" == e + "") { + sameError = true; + } } - process.exit(1); // We found a great mystery to solve + // Report + console.log("A minified script failed to run " + + (issues ? + "both minified and minified. This is likely an invalid js file" + + " or has code the interpreter engine doesn't understand." : + "after being minified. Please report node version, test" + + " and error to the maintainer of the minifier tool." + ) + ); + console.log("Version: Node " + process.versions.node); + console.log("File (may be a temp file): " + file); + console.log("Error: ", e); + console.log("Stack: ", e.stack); + console.log("\n\n"); + console.log(unminifiedError); + console.log(); + if (!sameError) { + console.log("Minified output:"); + console.log(minified); + console.log(); + } + console.log("==========\n"); + + // Exit 1 if its our fault, exit 2 if the interpreter fails as well + process.exit(issues ? 2 : 1); } \ No newline at end of file