solidity-coverage
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -14,2 +14,9 @@ const instrumenter = {}; | ||
instrumenter.prePosition = function prePosition(expression){ | ||
if (expression.right.type === 'ConditionalExpression' && | ||
expression.left.type === 'MemberExpression'){ | ||
expression.start -= 2; | ||
} | ||
} | ||
instrumenter.instrumentAssignmentExpression = function instrumentAssignmentExpression(contract, expression) { | ||
@@ -26,4 +33,13 @@ // The only time we instrument an assignment expression is if there's a conditional expression on | ||
instrumenter.instrumentConditionalExpression(contract, expression.right); | ||
} else if (expression.left.type === 'MemberExpression'){ | ||
createOrAppendInjectionPoint(contract, expression.left.start, { | ||
type: 'literal', string: '(,', | ||
}); | ||
createOrAppendInjectionPoint(contract, expression.left.end, { | ||
type: 'literal', string: ')', | ||
}); | ||
instrumenter.instrumentConditionalExpression(contract, expression.right); | ||
} else { | ||
console.log(contract, expression.left); | ||
const err = 'Error instrumenting assignment expression @ solidity-coverage/lib/instrumenter.js'; | ||
console.log(err, contract, expression.left); | ||
process.exit(); | ||
@@ -30,0 +46,0 @@ } |
@@ -13,2 +13,3 @@ /* eslint no-unused-expressions: ["error", { "allowShortCircuit": true }]*/ | ||
parse.AssignmentExpression = function parseAssignmentExpression(contract, expression) { | ||
instrumenter.prePosition(expression); | ||
instrumenter.instrumentStatement(contract, expression); | ||
@@ -49,9 +50,9 @@ instrumenter.instrumentAssignmentExpression(contract, expression); | ||
// From the start of this contract statement, find the first '{', and inject there. | ||
const injectionPoint = expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 2; | ||
const injectionPoint = expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 1; | ||
if (contract.injectionPoints[injectionPoint]) { | ||
contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 2].push({ | ||
contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 1].push({ | ||
type: 'eventDefinition', | ||
}); | ||
} else { | ||
contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 2] = [{ | ||
contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 1] = [{ | ||
type: 'eventDefinition', | ||
@@ -58,0 +59,0 @@ }]; |
{ | ||
"name": "solidity-coverage", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -162,2 +162,26 @@ /* eslint-env node, mocha */ | ||
it('should cover an assignment to a member expression (reaches the alternate)', done => { | ||
const contract = util.getCode('conditional/mapping-assignment.sol'); | ||
const info = getInstrumentedVersion(contract, filePath); | ||
const coverage = new CoverageMap(); | ||
coverage.addContract(info, filePath); | ||
vm.execute(info.contract, 'a', []).then(events => { | ||
const mapping = coverage.generate(events, pathPrefix); | ||
assert.deepEqual(mapping[filePath].l, { | ||
'11': 1, '12': 1, | ||
}); | ||
assert.deepEqual(mapping[filePath].b, { | ||
1: [0, 1], | ||
}); | ||
assert.deepEqual(mapping[filePath].s, { | ||
'1': 1, '2': 1, | ||
}); | ||
assert.deepEqual(mapping[filePath].f, { | ||
1: 1, | ||
}); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// Solcover has trouble with this case. The conditional coverage strategy relies on being able to | ||
@@ -164,0 +188,0 @@ // reference the left-hand variable before its value is assigned. Solidity doesn't allow this |
@@ -49,2 +49,10 @@ /* eslint-env node, mocha */ | ||
}); | ||
it('should compile after instrumenting an empty-contract-body', () => { | ||
const contract = util.getCode('statements/empty-contract-ala-melonport.sol'); | ||
const info = getInstrumentedVersion(contract, filePath); | ||
const output = solc.compile(info.contract, 1); | ||
util.report(output.errors); | ||
}); | ||
it('should cover a statement following a close brace', done => { | ||
@@ -51,0 +59,0 @@ const contract = util.getCode('statements/post-close-brace.sol'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147899
106
2491