From 018cef9534f7e30bf700d84689a0b53382caa06c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 21 Jun 2018 12:11:41 -0400 Subject: [PATCH 1/2] fix to avoiding duplicate passing or failing tests due to multiple asserts --- src/testRunner.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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!') From cbeda1f3dce69d4de11ffc5433c903dd26185c50 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 30 Jul 2018 17:05:34 -0400 Subject: [PATCH 2/2] add test case --- tests/examples_1/simple_storage_test.sol | 11 ++++++++++- tests/testRunner.js | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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' } ])