From 9802bae15fb4ca90198204c18803bf00ae240c65 Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Tue, 24 Oct 2017 15:26:31 +0100 Subject: [PATCH] test/impact: Add compatibility for older bin files This ensures the impact test doesn't throw when testing against older commits that contain the bin files at their orignal locations. --- test/impact | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/test/impact b/test/impact index 69dc530..ebbaa3b 100644 --- a/test/impact +++ b/test/impact @@ -15,6 +15,27 @@ let os = require("os"); let path = require("path"); let glob = require("glob"); +// Current Working Directory + +let cwd = path.join(__dirname, ".."); + +if (process.cwd() !== cwd) { + process.chdir(cwd); +} + +// Execution Files + +let PEGJS_BIN = "bin/peg.js"; +let BENCHMARK_BIN = "test/benchmark/run"; + +if (!fs.existsSync(PEGJS_BIN)) { + PEGJS_BIN = "bin/pegjs"; +} + +if (!fs.existsSync(BENCHMARK_BIN)) { + BENCHMARK_BIN = "benchmark/run"; +} + // Utils let print = console.log; @@ -33,7 +54,7 @@ function prepare(commit) { function runBenchmark() { return parseFloat( - exec("node test/benchmark/run") + exec("node " + BENCHMARK_BIN) // Split by table seprator, reverse and return the total bytes per second .split("│") .reverse()[1] @@ -52,7 +73,7 @@ function measureSize() { glob.sync("examples/*.pegjs") .forEach(example => { - exec("node bin/peg.js " + example); + exec(`node ${PEGJS_BIN} ${example}`); example = example.slice(0, -5) + "js"; size += fs.statSync(example).size; fs.unlinkSync(example); @@ -68,7 +89,6 @@ function difference($1, $2) { // Prepare let argv = process.argv.slice(2); -let cwd = path.join(__dirname, ".."); let commit_before, commit_after; if (argv.length === 1) { @@ -89,10 +109,6 @@ if (argv.length === 1) { process.exit(1); } -if (process.cwd() !== cwd) { - process.chdir(cwd); -} - // Measure let branch = exec("git rev-parse --abbrev-ref HEAD");