aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-03-02 19:38:30 +0800
committerGitHub <noreply@github.com>2020-03-02 19:38:30 +0800
commitd6d31cbb5a4e6bcf69e79260578e2040d6787a38 (patch)
treec753a2c50e8b4e6febe45bb985e48c316b7f9826
parenta051846d2275de75c72b69063a6b75ee0d302a8c (diff)
downloadtracifyjs-d6d31cbb5a4e6bcf69e79260578e2040d6787a38.tar.gz
tracifyjs-d6d31cbb5a4e6bcf69e79260578e2040d6787a38.zip
improve AST fuzzing (#3740)
-rw-r--r--test/mozilla-ast.js39
1 files changed, 23 insertions, 16 deletions
diff --git a/test/mozilla-ast.js b/test/mozilla-ast.js
index 4f17c892..c94ae438 100644
--- a/test/mozilla-ast.js
+++ b/test/mozilla-ast.js
@@ -44,30 +44,37 @@ function test(original, estree, description) {
try_beautify(transformed.code);
}
console.log("!!!!!! Failed... round", round);
- process.exit(1);
+ return false;
}
+ return true;
}
var num_iterations = ufuzz.num_iterations;
+var minify_options = require("./ufuzz/options.json").map(JSON.stringify);
+minify_options.unshift(null);
for (var round = 1; round <= num_iterations; round++) {
process.stdout.write(round + " of " + num_iterations + "\r");
var code = ufuzz.createTopLevelCode();
- var uglified = UglifyJS.minify(code, {
- compress: false,
- mangle: false,
- output: {
- ast: true
+ minify_options.forEach(function(options) {
+ var input = options ? UglifyJS.minify(code, JSON.parse(options)).code : code;
+ var uglified = UglifyJS.minify(input, {
+ compress: false,
+ mangle: false,
+ output: {
+ ast: true
+ }
+ });
+ var ok = test(uglified.code, uglified.ast.to_mozilla_ast(), "AST_Node.to_mozilla_ast()");
+ try {
+ ok = test(uglified.code, acorn.parse(input), "acorn.parse()") && ok;
+ } catch (e) {
+ console.log("//=============================================================");
+ console.log("// acorn parser failed... round", round);
+ console.log(e);
+ console.log("// original code");
+ console.log(input);
}
+ if (!ok) process.exit(1);
});
- test(uglified.code, uglified.ast.to_mozilla_ast(), "AST_Node.to_mozilla_ast()");
- try {
- test(uglified.code, acorn.parse(code), "acorn.parse()");
- } catch (e) {
- console.log("//=============================================================");
- console.log("// acorn parser failed... round", round);
- console.log(e);
- console.log("// original code");
- console.log(code);
- }
}
console.log();