aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-16 17:32:47 +0200
committerGitHub <noreply@github.com>2019-12-16 17:32:47 +0200
commit3ff0feddee0f293649d87be28d3cd0cf587dd195 (patch)
treee1502c02cfe026af5390e827af637aa94ae713d3 /test
parent74396acc86a3d36dda2db43a007aa93f40cf58f8 (diff)
downloadtracifyjs-3ff0feddee0f293649d87be28d3cd0cf587dd195.tar.gz
tracifyjs-3ff0feddee0f293649d87be28d3cd0cf587dd195.zip
suppress false positives from fuzzer (#3638)
Diffstat (limited to 'test')
-rw-r--r--test/ufuzz/index.js21
-rw-r--r--test/ufuzz/job.js25
2 files changed, 35 insertions, 11 deletions
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index 05cfd5c3..dfa27ac0 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -1089,6 +1089,19 @@ function log(options) {
}
}
+function fuzzy_match(original, uglified) {
+ original = original.split(" ", 5);
+ uglified = uglified.split(" ", 5);
+ for (var i = 0; i < 5; i++) {
+ if (original[i] === uglified[i]) continue;
+ var a = +original[i];
+ var b = +uglified[i];
+ if (Math.abs((b - a) / a) < 1e-10) continue;
+ return false;
+ }
+ return true;
+}
+
var fallback_options = [ JSON.stringify({
compress: false,
mangle: false
@@ -1111,8 +1124,12 @@ for (var round = 1; round <= num_iterations; round++) {
uglify_code = uglify_code.code;
uglify_result = sandbox.run_code(uglify_code, o.toplevel);
ok = sandbox.same_stdout(original_result, uglify_result);
- if (!ok && o.compress.unsafe_math) {
- ok = sandbox.same_stdout(sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3")), uglify_result, o.toplevel);
+ if (!ok && typeof uglify_result == "string" && o.compress.unsafe_math) {
+ ok = fuzzy_match(original_result, uglify_result);
+ if (!ok) {
+ var fuzzy_result = sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3"));
+ ok = sandbox.same_stdout(fuzzy_result, uglify_result, o.toplevel);
+ }
}
} else {
uglify_code = uglify_code.error;
diff --git a/test/ufuzz/job.js b/test/ufuzz/job.js
index 921162f6..fff0e044 100644
--- a/test/ufuzz/job.js
+++ b/test/ufuzz/job.js
@@ -12,17 +12,16 @@ function spawn(endTime) {
], {
stdio: [ "ignore", "pipe", "pipe" ]
}).on("exit", respawn);
- var line = "";
+ var stdout = "";
child.stdout.on("data", function(data) {
- line += data;
+ stdout += data;
});
- child.stderr.once("data", function() {
- process.exitCode = 1;
- }).pipe(process.stdout);
+ var stderr = "";
+ child.stderr.on("data", trap).pipe(process.stdout);
var keepAlive = setInterval(function() {
- var end = line.lastIndexOf("\r");
- console.log(line.slice(line.lastIndexOf("\r", end - 1) + 1, end));
- line = line.slice(end + 1);
+ var end = stdout.lastIndexOf("\r");
+ console.log(stdout.slice(stdout.lastIndexOf("\r", end - 1) + 1, end));
+ stdout = stdout.slice(end + 1);
}, ping);
var timer = setTimeout(function() {
clearInterval(keepAlive);
@@ -31,9 +30,17 @@ function spawn(endTime) {
}, endTime - Date.now());
function respawn() {
- console.log(line);
+ console.log(stdout.replace(/[^\r\n]*\r/g, ""));
clearInterval(keepAlive);
clearTimeout(timer);
spawn(endTime);
}
+
+ function trap(data) {
+ stderr += data;
+ if (~stderr.indexOf("\nminify(options):\n")) {
+ process.exitCode = 1;
+ child.stderr.removeListener("data", trap);
+ }
+ }
}