diff --git a/src/compiler.js b/src/compiler.js index f6fc4698a9..e7de72c36f 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -68,7 +68,7 @@ function compileContractSources (sources, importFileCb, cb) { compiler.compile(sources, filepath) } ], function (err, result) { - let errors = (result.errors || []).filter((e) => e.type === 'Error') + let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { console.dir(errors) return cb(new Error('errors compiling')) diff --git a/src/testRunner.js b/src/testRunner.js index 6b2444fd3e..e1ffac490f 100644 --- a/src/testRunner.js +++ b/src/testRunner.js @@ -61,19 +61,26 @@ function runTest (testName, testObject, testCallback, resultsCallback) { let time = Math.ceil((Date.now() - startTime) / 1000.0) let topic = Web3.utils.sha3('AssertionEvent(bool,string)') + let testPassed = false + for (let i in receipt.events) { let event = receipt.events[i] if (event.raw.topics.indexOf(topic) >= 0) { var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) - if (testEvent[0]) { - testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName}) - passingNum += 1 - } else { + if (!testEvent[0]) { testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: testEvent[1], context: testName}) failureNum += 1 + return next() } + testPassed = true } } + + if (testPassed) { + testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName}) + passingNum += 1 + } + return next() } catch (err) { console.log('error!') diff --git a/tests/examples_1/simple_storage_test.sol b/tests/examples_1/simple_storage_test.sol index 2bab305c4f..896970933f 100644 --- a/tests/examples_1/simple_storage_test.sol +++ b/tests/examples_1/simple_storage_test.sol @@ -1,5 +1,5 @@ pragma solidity ^0.4.7; -import "./tests.sol"; +import "remix_tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -19,5 +19,14 @@ contract MyTest { return foo.get() == 200; } + function shouldTriggerOneFail() public { + Assert.equal(uint(1), uint(2), "the test 1 fails"); + Assert.equal(uint(1), uint(2), "the test 2 fails"); + } + + function shouldTriggerOnePass() public { + Assert.equal(uint(1), uint(1), "the test 3 fails"); + } + } diff --git a/tests/testRunner.js b/tests/testRunner.js index d5529050d0..b6426f5ce5 100644 --- a/tests/testRunner.js +++ b/tests/testRunner.js @@ -43,16 +43,18 @@ describe('testRunner', function () { }) it('should 1 passing test', function () { - assert.equal(results.passingNum, 1) + assert.equal(results.passingNum, 2) }) it('should 1 failing test', function () { - assert.equal(results.failureNum, 1) + assert.equal(results.failureNum, 2) }) it('should returns 3 messages', function () { assert.deepEqual(tests, [ { type: 'contract', value: 'MyTest', filename: 'simple_storage_test.sol' }, + { type: 'testFailure', value: 'Should trigger one fail', time: 1, context: 'MyTest', errMsg: 'the test 1 fails' }, + { type: 'testPass', value: 'Should trigger one pass', time: 1, context: 'MyTest'}, { type: 'testPass', value: 'Initial value should be100', time: 1, context: 'MyTest' }, { type: 'testFailure', value: 'Initial value should be200', time: 1, context: 'MyTest', errMsg: 'function returned false' } ])