From b2420ec1ca8971244a43e23173d4e36135a32656 Mon Sep 17 00:00:00 2001 From: Alex Rea Date: Wed, 4 Jan 2017 20:22:33 +0000 Subject: [PATCH] Allow nested contract directories --- package.json | 1 + runCoveredTests.js | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4239e80..ca0aec3 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dependencies": { "ethereumjs-testrpc": "^3.0.3", "istanbul": "^0.4.5", + "mkdirp": "^0.5.1", "shelljs": "^0.7.4", "sol-explore": "^1.6.2", "solidity-parser": "git+https://github.com/ConsenSys/solidity-parser.git#master" diff --git a/runCoveredTests.js b/runCoveredTests.js index 1fbf9aa..a343dd5 100644 --- a/runCoveredTests.js +++ b/runCoveredTests.js @@ -8,6 +8,7 @@ var path = require('path'); var getInstrumentedVersion = require('./instrumentSolidity.js'); var CoverageMap = require('./coverageMap.js'); var coverage = new CoverageMap(); +var mkdirp = require('mkdirp'); var childprocess = require('child_process'); @@ -27,14 +28,15 @@ if (shell.test('-d','../originalContracts')){ shell.mv('./../contracts/', './../originalContracts/'); shell.mkdir('./../contracts/'); //For each contract in originalContracts, get the instrumented version -shell.ls('./../originalContracts/*.sol').forEach(function(file) { +shell.ls('./../originalContracts/**/*.sol').forEach(function(file) { if (file !== 'originalContracts/Migrations.sol') { console.log("instrumenting ", file); var contract = fs.readFileSync("./" + file).toString(); var fileName = path.basename(file); - var instrumentedContractInfo = getInstrumentedVersion(contract, fileName, true); - fs.writeFileSync('./../contracts/' + path.basename(file), instrumentedContractInfo.contract); - var canonicalContractPath = path.resolve('./../originalContracts/' + path.basename(file)); + var instrumentedContractInfo = getInstrumentedVersion(contract, file, true); + mkdirp.sync(path.dirname(file.replace('originalContracts', 'contracts'))); + fs.writeFileSync(file.replace('originalContracts','contracts'), instrumentedContractInfo.contract); + var canonicalContractPath = path.resolve(file); coverage.addContract(instrumentedContractInfo, canonicalContractPath); } });