From e40a51574b91c2e26197342162209430739af3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 29 Apr 2015 12:00:06 +0200 Subject: [PATCH] Fix test-coverage.js script Fix test-coverage by only replacing the last occurence of `/src/` when deriving the instrumented file path from the original file path. --- tasks/test-coverage.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tasks/test-coverage.js b/tasks/test-coverage.js index 8fc0061e43..2d4152b90f 100644 --- a/tasks/test-coverage.js +++ b/tasks/test-coverage.js @@ -139,7 +139,15 @@ var foundAllJavaScriptSourceFiles = function(err, files) { files.forEach(function(file) { cnt++; var content = fs.readFileSync(file, 'utf-8'); - var outfile = file.replace(/\/src\//, '/src-instrumented/'); + // derive output file name from input file name, by replacing the *last* + // occurence of /src/ by /src-instrumented/ + var re = new RegExp('/src/', 'g'); + var m, match; + while ((m = re.exec(file)) !== null) { + match = m; + } + var outfile = file.substr(0, match.index) + '/src-instrumented/' + + file.substr(match.index + '/src/'.length); var instrumented = instrumenter.instrumentSync(content, file); fs.writeFileSync(outfile, instrumented); if (cnt % 10 === 0) {