Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
add /*solcov ignore next*/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewingrj committed Jun 25, 2018
1 parent 1a4e994 commit 92cb9c3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/sol-cov/test/collect_coverage_entries_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});

it('correctly ignores all coverage entries for Ignore contract', () => {
const solcovIgnoreContractBaseName = 'SolcovIgnore.sol';
const solcovIgnoreContractFileName = path.resolve(
__dirname,
'fixtures/contracts',
solcovIgnoreContractBaseName,
);
const solcovIgnoreContract = fs.readFileSync(solcovIgnoreContractFileName).toString();
const coverageEntries = collectCoverageEntries(solcovIgnoreContract);
const fnIds = _.keys(coverageEntries.fnMap);

expect(fnIds.length).to.be.equal(1);
expect(coverageEntries.fnMap[fnIds[0]].name).to.be.equal('set');
// tslint:disable-next-line:custom-no-magic-numbers
expect(coverageEntries.fnMap[fnIds[0]].line).to.be.equal(6);
const setFunction = `function set(uint x) public {
/* solcov ignore next */
storedData = x;
}`;
expect(utils.getRange(solcovIgnoreContract, coverageEntries.fnMap[fnIds[0]].loc)).to.be.equal(setFunction);

expect(coverageEntries.branchMap).to.be.deep.equal({});
const statementIds = _.keys(coverageEntries.statementMap);
expect(utils.getRange(solcovIgnoreContract, coverageEntries.statementMap[statementIds[0]])).to.be.equal(
setFunction,
);
expect(statementIds.length).to.be.equal(1);
expect(coverageEntries.modifiersStatementIds.length).to.be.equal(0);
});
});
});
22 changes: 22 additions & 0 deletions packages/sol-cov/test/fixtures/contracts/SolcovIgnore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pragma solidity ^0.4.21;

contract SolcovIgnore {
uint public storedData;

function set(uint x) public {
/* solcov ignore next */
storedData = x;
}

/* solcov ignore next */
function get() constant public returns (uint retVal) {
return storedData;
}
}

/* solcov ignore next */
contract Ignore {
function ignored() public returns (bool) {
return false;
}
}

0 comments on commit 92cb9c3

Please sign in to comment.