Skip to content

Commit

Permalink
Locate .coverage_contracts correctly for subfolder paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Nov 16, 2020
1 parent f5ed5e5 commit 423a9c2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugins/resources/plugin.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const PluginUI = require('./truffle.ui');
const path = require('path');
const fs = require('fs-extra');
const shell = require('shelljs');
const util = require('util')

// ===
// UI
Expand Down Expand Up @@ -93,12 +92,13 @@ function toRelativePath(pathToFile, pathToParent){
* @return {Object} temp paths
*/
function getTempLocations(config){
const contractsRoot = path.parse(config.contractsDir).dir
const cwd = config.workingDir;
const contractsDirName = '.coverage_contracts';
const artifactsDirName = config.temp || '.coverage_artifacts';

return {
tempContractsDir: path.join(cwd, contractsDirName),
tempContractsDir: path.join(contractsRoot, contractsDirName),
tempArtifactsDir: path.join(cwd, artifactsDirName)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity ^0.5.0;

import "./../B/ContractB.sol";

contract ContractA is ContractB {
uint x;
constructor() public {
}

function sendFn() public {
x = 5;
}

function callFn() public pure returns (uint){
uint y = 5;
return y;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.5.0;


contract ContractB {
uint x;
constructor() public {
}

function sendFnB() public {
x = 5;
}

function callFnB() public pure returns (uint){
uint y = 5;
return y;
}
}
17 changes: 17 additions & 0 deletions test/integration/projects/contract-subfolders/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../plugins/nomiclabs.plugin");

module.exports={
networks: {
hardhat: {
gasPrice: 2
}
},
solidity: {
version: "0.5.15"
},
paths: {
contracts: 'contracts/A'
},
logger: process.env.SILENT ? { log: () => {} } : console,
};
17 changes: 17 additions & 0 deletions test/integration/projects/contract-subfolders/test/contracta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const ContractA = artifacts.require("ContractA");

contract("contracta", function(accounts) {
let instance;

before(async () => instance = await ContractA.new())

it('sends', async function(){
await instance.sendFn();
await instance.sendFnB();
});

it('calls', async function(){
await instance.callFn();
await instance.callFnB();
})
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
contracts_directory: "contracts/A",
networks: {},
mocha: {},
compilers: {
solc: {}
}
}
10 changes: 10 additions & 0 deletions test/units/truffle/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ describe('Truffle Plugin: standard use cases', function() {
verify.lineCoverage(expected);
});

it('locates .coverage_contracts correctly when dir is subfolder', async function(){
solcoverConfig = {
silent: process.env.SILENT ? true : false,
istanbulReporter: ['json-summary', 'text']
};

mock.installFullProject('contract-subfolders');
await plugin(truffleConfig);
})

// This test tightly coupled to the ganache version in production deps
// "test-files" project solcoverjs includes `client: require('ganache-cli')`
it('config: client', async function(){
Expand Down

0 comments on commit 423a9c2

Please sign in to comment.