diff --git a/lib/instrumenter.js b/lib/instrumenter.js index 9b8aa4f..0ef8f5b 100644 --- a/lib/instrumenter.js +++ b/lib/instrumenter.js @@ -60,7 +60,7 @@ class Instrumenter { this._initializeCoverageFields(contract); // First, we run over the original contract to get the source mapping. - let ast = SolidityParser.parse(contract.source, {range: true}); + let ast = SolidityParser.parse(contract.source, {loc: true, range: true}); parse[ast.type](contract, ast); const retValue = JSON.parse(JSON.stringify(contract)); // Possibly apotropaic. @@ -69,7 +69,7 @@ class Instrumenter { contract.instrumented = preprocess(contract.source); // Walk the AST, recording injection points - ast = SolidityParser.parse(contract.instrumented, {range: true}); + ast = SolidityParser.parse(contract.instrumented, {loc: true, range: true}); const root = ast.children.filter(node => this._isRootNode(node)); diff --git a/lib/registrar.js b/lib/registrar.js index 8ba7884..1e54f2d 100644 --- a/lib/registrar.js +++ b/lib/registrar.js @@ -125,17 +125,12 @@ class Registrar { start, start + endlineDelta ); - const endline = startline + (functionDefinition.match(/\n/g) || []).length; - const endcol = functionDefinition.length - functionDefinition.lastIndexOf('\n'); contract.fnId += 1; contract.fnMap[contract.fnId] = { name: expression.isConstructor ? 'constructor' : expression.name, line: startline, - loc: { - start: { line: startline, column: startcol }, - end: { line: endline, column: endcol }, - }, + loc: expression.loc }; this._createInjectionPoint( diff --git a/package.json b/package.json index cd2aebb..51aad15 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "nyc": "SILENT=true nyc --exclude '**/sc_temp/**' --exclude '**/test/**'", "test": "SILENT=true node --max-old-space-size=4096 ./node_modules/.bin/nyc --exclude '**/sc_temp/**' --exclude '**/test/**/' -- mocha test/units/* --timeout 100000 --no-warnings --exit", "test:ci": "SILENT=true node --max-old-space-size=4096 ./node_modules/.bin/nyc --reporter=lcov --exclude '**/sc_temp/**' --exclude '**/test/**/' -- mocha test/units/* --timeout 100000 --no-warnings --exit", - "test:debug": "node --max-old-space-size=4096 ./node_modules/.bin/mocha test/units/* --timeout 100000 --no-warnings --exit" + "test:debug": "node --max-old-space-size=4096 ./node_modules/.bin/mocha test/units/* --timeout 100000 --no-warnings --exit", + "netlify": "./scripts/run-netlify.sh" }, "homepage": "https://github.com/sc-forks/solidity-coverage", "repository": { diff --git a/scripts/run-netlify.sh b/scripts/run-netlify.sh new file mode 100755 index 0000000..0ccdede --- /dev/null +++ b/scripts/run-netlify.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# +# E2E: runs sc-forks/hegic/contracts-v1 coverage and publishes html report in netlify +# for CI deployment preview. This is the netlify "build" step. +# + +set -o errexit + +# Clone target +git clone https://github.com/sc-forks/contracts-v1.git +cd contracts-v1 + +# Install solidity-coverage @ current commit +yarn +yarn add --dev https://github.com/sc-forks/solidity-coverage.git#$COMMIT_REF + +cat package.json + +npm run coverage