mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-11 22:44:45 +00:00
Merge pull request #912 from embark-framework/bugfix/coverage-statementless-if
Support if statements without a list of statements
This commit is contained in:
commit
af36b5e31e
@ -102,7 +102,7 @@ class ContractSource {
|
|||||||
Object.values(this.contractBytecode).every((contractBytecode) => { return (Object.values(contractBytecode).length <= 1); });
|
Object.values(this.contractBytecode).every((contractBytecode) => { return (Object.values(contractBytecode).length <= 1); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/*eslint complexity: ["error", 38]*/
|
/*eslint complexity: ["error", 39]*/
|
||||||
generateCodeCoverage(trace) {
|
generateCodeCoverage(trace) {
|
||||||
if(!this.ast || !this.contractBytecode) throw new Error('Error generating coverage: solc output was not assigned');
|
if(!this.ast || !this.contractBytecode) throw new Error('Error generating coverage: solc output was not assigned');
|
||||||
|
|
||||||
@ -162,19 +162,19 @@ class ContractSource {
|
|||||||
line: location.start.line
|
line: location.start.line
|
||||||
};
|
};
|
||||||
|
|
||||||
children = [node.condition]
|
|
||||||
.concat(node.trueBody.statements);
|
|
||||||
|
|
||||||
if(node.falseBody) children = children.concat(node.falseBody.statements);
|
|
||||||
|
|
||||||
markLocations = [declarationLocation];
|
markLocations = [declarationLocation];
|
||||||
|
children = [node.condition];
|
||||||
|
|
||||||
if(node.trueBody.statements[0]) {
|
let trueExpression = (node.trueBody && node.trueBody.statements && node.trueBody.statements[0]) || node.trueBody;
|
||||||
node.trueBody.statements[0]._parent = {type: 'b', id: node.id, idx: 0};
|
if(trueExpression) {
|
||||||
|
children = children.concat(trueExpression);
|
||||||
|
trueExpression._parent = {type: 'b', id: node.id, idx: 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(node.falseBody && node.falseBody.statements[0]) {
|
let falseExpression = (node.falseBody && node.falseBody.statements && node.falseBody.statements[0]) || node.falseBody;
|
||||||
node.falseBody.statements[0]._parent = {type: 'b', id: node.id, idx: 1};
|
if(falseExpression) {
|
||||||
|
children = children.concat(falseExpression);
|
||||||
|
falseExpression._parent = {type: 'b', id: node.id, idx: 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceMapToNodeType[node.src] = [{type: 'b', id: node.id, body: {loc: location}}];
|
sourceMapToNodeType[node.src] = [{type: 'b', id: node.id, body: {loc: location}}];
|
||||||
|
@ -32,4 +32,9 @@ contract Branches {
|
|||||||
function get() public view returns (uint retVal) {
|
function get() public view returns (uint retVal) {
|
||||||
return storedData;
|
return storedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function smallFunctionWithoutStatements() public view returns (uint retVal) {
|
||||||
|
if(false) return storedData * 10;
|
||||||
|
if(true) return storedData * 20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,4 +28,8 @@ contract("Branches", function() {
|
|||||||
it("should return the smaller number", function(done) {
|
it("should return the smaller number", function(done) {
|
||||||
Branches.methods.smaller(10).send().then(() => { done(); });
|
Branches.methods.smaller(10).send().then(() => { done(); });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not crash code coverage on `if` without statements", function(done) {
|
||||||
|
Branches.methods.smallFunctionWithoutStatements().call().then(() => { done(); });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user