diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-21 23:32:12 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-21 23:32:12 +0800 |
commit | e5c4390489b02f87a4d497095ea83d0737047afc (patch) | |
tree | 7dc58aed853a38a99a42d589802fba13b183ddea /packages | |
parent | 61910f264c4671f057f774a415c673f10c09ddb1 (diff) | |
download | dexon-0x-contracts-e5c4390489b02f87a4d497095ea83d0737047afc.tar.gz dexon-0x-contracts-e5c4390489b02f87a4d497095ea83d0737047afc.tar.zst dexon-0x-contracts-e5c4390489b02f87a4d497095ea83d0737047afc.zip |
Fix a bug when some parts of the profiling report were missing because of the coverage ignore lines
Diffstat (limited to 'packages')
-rw-r--r-- | packages/sol-coverage/src/coverage_subprovider.ts | 4 | ||||
-rw-r--r-- | packages/sol-profiler/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/collect_coverage_entries.ts | 12 |
3 files changed, 18 insertions, 7 deletions
diff --git a/packages/sol-coverage/src/coverage_subprovider.ts b/packages/sol-coverage/src/coverage_subprovider.ts index d03963ed6..2d92b25ca 100644 --- a/packages/sol-coverage/src/coverage_subprovider.ts +++ b/packages/sol-coverage/src/coverage_subprovider.ts @@ -50,6 +50,8 @@ export class CoverageSubprovider extends TraceInfoSubprovider { } } +const IGNORE_REGEXP = /\/\*\s*solcov\s+ignore\s+next\s*\*\/\s*/gm; + /** * Computed partial coverage for a single file & subtrace. * @param contractData Contract metadata (source, srcMap, bytecode) @@ -65,7 +67,7 @@ export const coverageHandler: SingleFileSubtraceHandler = ( fileIndex: number, ): Coverage => { const absoluteFileName = contractData.sources[fileIndex]; - const coverageEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex]); + const coverageEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex], IGNORE_REGEXP); // if the source wasn't provided for the fileIndex, we can't cover the file if (_.isUndefined(coverageEntriesDescription)) { diff --git a/packages/sol-profiler/CHANGELOG.json b/packages/sol-profiler/CHANGELOG.json index 550ca2feb..de1f09fa8 100644 --- a/packages/sol-profiler/CHANGELOG.json +++ b/packages/sol-profiler/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.1", + "changes": [ + { + "note": "Fix a bug when some parts of the profiling report were missing because of the coverage ignore lines", + "pr": "TODO" + } + ] + }, + { "version": "2.0.0", "changes": [ { diff --git a/packages/sol-tracing-utils/src/collect_coverage_entries.ts b/packages/sol-tracing-utils/src/collect_coverage_entries.ts index 9e3591d74..964095b53 100644 --- a/packages/sol-tracing-utils/src/collect_coverage_entries.ts +++ b/packages/sol-tracing-utils/src/collect_coverage_entries.ts @@ -5,17 +5,17 @@ import * as parser from 'solidity-parser-antlr'; import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor'; import { getOffsetToLocation } from './source_maps'; -const IGNORE_RE = /\/\*\s*solcov\s+ignore\s+next\s*\*\/\s*/gm; - // Parsing source code for each transaction/code is slow and therefore we cache it const sourceHashToCoverageEntries: { [sourceHash: string]: CoverageEntriesDescription } = {}; -export const collectCoverageEntries = (contractSource: string) => { +export const collectCoverageEntries = (contractSource: string, ignoreRegexp?: RegExp) => { const sourceHash = ethUtil.sha3(contractSource).toString('hex'); if (_.isUndefined(sourceHashToCoverageEntries[sourceHash]) && !_.isUndefined(contractSource)) { const ast = parser.parse(contractSource, { range: true }); const offsetToLocation = getOffsetToLocation(contractSource); - const ignoreRangesBegingingAt = gatherRangesToIgnore(contractSource); + const ignoreRangesBegingingAt = _.isUndefined(ignoreRegexp) + ? [] + : gatherRangesToIgnore(contractSource, ignoreRegexp as RegExp); const visitor = new ASTVisitor(offsetToLocation, ignoreRangesBegingingAt); parser.visit(ast, visitor); sourceHashToCoverageEntries[sourceHash] = visitor.getCollectedCoverageEntries(); @@ -25,12 +25,12 @@ export const collectCoverageEntries = (contractSource: string) => { }; // Gather the start index of all code blocks preceeded by "/* solcov ignore next */" -function gatherRangesToIgnore(contractSource: string): number[] { +function gatherRangesToIgnore(contractSource: string, ignoreRegexp: RegExp): number[] { const ignoreRangesStart = []; let match; do { - match = IGNORE_RE.exec(contractSource); + match = ignoreRegexp.exec(contractSource); if (match) { const matchLen = match[0].length; ignoreRangesStart.push(match.index + matchLen); |