-
Notifications
You must be signed in to change notification settings - Fork 465
[sol-cov] add ability to ignore covering specific code blocks #766
[sol-cov] add ability to ignore covering specific code blocks #766
Conversation
packages/sol-cov/src/ast_visitor.ts
Outdated
@@ -23,8 +23,11 @@ export class ASTVisitor { | |||
private _modifiersStatementIds: number[] = []; | |||
private _statementMap: StatementMap = {}; | |||
private _locationByOffset: LocationByOffset; | |||
constructor(locationByOffset: LocationByOffset) { | |||
private _ignoreRangesBeginingAt: number[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Beginning
This looks good. Can we add some tests for it? |
@perissology I tried using this PR on the |
I added support for ignoring contracts, as well as tests |
packages/sol-cov/src/ast_visitor.ts
Outdated
@@ -42,6 +47,11 @@ export class ASTVisitor { | |||
public FunctionDefinition(ast: Parser.FunctionDefinition): void { | |||
this._visitFunctionLikeDefinition(ast); | |||
} | |||
public ContractDefinition(ast: Parser.ContractDefinition): void { | |||
if (this._ignoreExpression(ast)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename _ignoreExpression
to _shouldIgnoreExpression
parser.visit(ast, visitor); | ||
coverageEntriesBySourceHash[sourceHash] = visitor.getCollectedCoverageEntries(); | ||
} | ||
const coverageEntriesDescription = coverageEntriesBySourceHash[sourceHash]; | ||
return coverageEntriesDescription; | ||
}; | ||
|
||
const IGNORE_RE = /\/\*\s*solcov\s+ignore\s+next\s*\*\/\s*/gm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put constants at top of the file.
const setFunction = `function set(uint x) public { | ||
/* solcov ignore next */ | ||
storedData = x; | ||
}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If indentation doesn't matter here, let's indent this further so that it's easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does matter here
@@ -121,5 +121,35 @@ describe('Collect coverage entries', () => { | |||
const branchTypes = _.map(branchDescriptions, branchDescription => branchDescription.type); | |||
expect(branchTypes).to.be.deep.equal(['if', 'if', 'if', 'if', 'binary-expr', 'if']); | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove excess new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier adds that line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes!
Description
Adds functionality similar to istanbul's ignore to exclude a block of code from the coverage report
Testing instructions
add
/* solcov ignore next */
before any block of code in the solidity source to exclude that block from the coverage reportTypes of changes
Checklist: