Skip to content

Commit c88eed2

Browse files
authored
Locate .coverage_contracts correctly for subfolder paths (#570)
1 parent f5ed5e5 commit c88eed2

File tree

9 files changed

+116
-2
lines changed

9 files changed

+116
-2
lines changed

plugins/resources/plugin.utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const PluginUI = require('./truffle.ui');
88
const path = require('path');
99
const fs = require('fs-extra');
1010
const shell = require('shelljs');
11-
const util = require('util')
1211

1312
// ===
1413
// UI
@@ -93,12 +92,13 @@ function toRelativePath(pathToFile, pathToParent){
9392
* @return {Object} temp paths
9493
*/
9594
function getTempLocations(config){
95+
const contractsRoot = path.parse(config.contractsDir).dir
9696
const cwd = config.workingDir;
9797
const contractsDirName = '.coverage_contracts';
9898
const artifactsDirName = config.temp || '.coverage_artifacts';
9999

100100
return {
101-
tempContractsDir: path.join(cwd, contractsDirName),
101+
tempContractsDir: path.join(contractsRoot, contractsDirName),
102102
tempArtifactsDir: path.join(cwd, artifactsDirName)
103103
}
104104
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Testing hooks
2+
const fn = (msg, config) => config.logger.log(msg);
3+
4+
module.exports = {
5+
skipFiles: ['Migrations.sol'],
6+
silent: process.env.SILENT ? true : false,
7+
istanbulReporter: ['json-summary', 'text'],
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pragma solidity ^0.5.0;
2+
3+
import "./../B/ContractB2.sol";
4+
5+
contract ContractA is ContractB {
6+
uint x;
7+
constructor() public {
8+
}
9+
10+
function sendFn() public {
11+
x = 5;
12+
}
13+
14+
function callFn() public pure returns (uint){
15+
uint y = 5;
16+
return y;
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.5.0;
2+
3+
4+
contract ContractB {
5+
uint x;
6+
constructor() public {
7+
}
8+
9+
function sendFnB() public {
10+
x = 5;
11+
}
12+
13+
function callFnB() public pure returns (uint){
14+
uint y = 5;
15+
return y;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require("@nomiclabs/hardhat-truffle5");
2+
require(__dirname + "/../plugins/nomiclabs.plugin");
3+
4+
module.exports={
5+
networks: {
6+
hardhat: {
7+
gasPrice: 2
8+
}
9+
},
10+
solidity: {
11+
version: "0.5.15"
12+
},
13+
paths: {
14+
sources: './contracts/A'
15+
},
16+
logger: process.env.SILENT ? { log: () => {} } : console,
17+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const ContractA = artifacts.require("ContractA");
2+
3+
contract("contracta", function(accounts) {
4+
let instance;
5+
6+
before(async () => instance = await ContractA.new())
7+
8+
it('sends', async function(){
9+
await instance.sendFn();
10+
await instance.sendFnB();
11+
});
12+
13+
it('calls', async function(){
14+
await instance.callFn();
15+
await instance.callFnB();
16+
})
17+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
networks: {},
3+
mocha: {},
4+
compilers: {
5+
solc: {}
6+
}
7+
}

test/units/hardhat/standard.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,19 @@ describe('Hardhat Plugin: standard use cases', function() {
419419
verify.lineCoverage(expected);
420420
})
421421

422+
it('locates .coverage_contracts correctly when dir is subfolder', async function(){
423+
mock.installFullProject('contract-subfolders');
424+
mock.hardhatSetupEnv(this);
425+
426+
await this.env.run("coverage");
427+
428+
const expected = [
429+
{
430+
file: 'contracts/A/ContractA2.sol',
431+
pct: 100
432+
}
433+
];
434+
435+
verify.lineCoverage(expected);
436+
})
422437
})

test/units/truffle/standard.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,21 @@ describe('Truffle Plugin: standard use cases', function() {
286286
verify.lineCoverage(expected);
287287
});
288288

289+
it('locates .coverage_contracts correctly when dir is subfolder', async function(){
290+
solcoverConfig = {
291+
silent: process.env.SILENT ? true : false,
292+
istanbulReporter: ['json-summary', 'text']
293+
};
294+
295+
truffleConfig.contracts_directory = path.join(
296+
process.cwd(),
297+
mock.pathToTemp("contracts/A")
298+
);
299+
300+
mock.installFullProject('contract-subfolders');
301+
await plugin(truffleConfig);
302+
})
303+
289304
// This test tightly coupled to the ganache version in production deps
290305
// "test-files" project solcoverjs includes `client: require('ganache-cli')`
291306
it('config: client', async function(){

0 commit comments

Comments
 (0)