solcover fail to generate test coverage with my simple add contract

715 views Asked by At

I want to use solcover to generate test coverage of my contract.

https://github.com/JoinColony/solcover

I test it with the simple one:

contract Add {
    function Add() {
    }
    function sum(uint x, uint y) returns (uint) {
        return (x+y);
    }
}

And here is my test code:

contract('Add', function(accounts) {
  it("should return 5 when add 2 and 3", function() {
    var add = Add.deployed();
    return add.sum.call(2,3).then(function(res){
      assert.equal(res.valueOf(), 5, "add result is 5");
    });   
  });
});

But there are some errs when compile it.

Add.sol:2:1: Warning: Source file does not specify required compiler version!Consider adding "pragma solidity ^0.4.6 contract Add { ^ Spanning multiple lines. Compilation failed. See above. fs.js:549

Then i add compile version like this:

pragma solidity ^0.4.6;
contract Add {

    function Add() {
    }

    function sum(uint x, uint y) returns (uint) {
        return (x+y);
    }
}

And now it pass the compile. But this time I got the error:

cp: no such file or directory: ./../originalContracts/Migrations.sol rm: no such file or directory: ./allFiredEvents Compiling Add.sol... Contract: Add ✓ should return 5 when add 2 and 3 1 passing (15s) fs.js:549 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ Error: ENOENT: no such file or directory, open './allFiredEvents' at Error (native) at Object.fs.openSync (fs.js:549:18) at Object.fs.readFileSync (fs.js:397:15) at Object.<anonymous> (/Users/maiffany/graduate/mytest/solcover/runCoveredTests.js:60:13) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18)

And in the runCoveredTests.js I found this:

55:shell.cp("./../originalContracts/Migrations.sol",./../contracts/Migrations.sol"); 56: 57:shell.rm('./allFiredEvents'); //Delete previous results 58:shell.exec('truffle test --network coverage'); 59: 60:events = fs.readFileSync('./allFiredEvents').toString().split('\n')

I guess maybe it is this command that generate file "allFiredEvents". So i try this in my command line:

truffle test --network coverage Compiling Add.sol... Contract: Add ✓ should return 5 when add 2 and 3 1 passing (24s)

But i still can't find the file "allFiredEvents".

So where did i get wrong?

0

There are 0 answers