From c00b6a62c3f42a19c80aa41a6af09706899ca934 Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Thu, 23 Aug 2018 00:42:30 +0530 Subject: [PATCH] improve string tests --- tests/examples_3/simple_string.sol | 6 +----- tests/examples_3/simple_string_test.sol | 8 ++++++-- tests/testRunner.js | 17 +++++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/examples_3/simple_string.sol b/tests/examples_3/simple_string.sol index 597c15afb0..25773f148c 100644 --- a/tests/examples_3/simple_string.sol +++ b/tests/examples_3/simple_string.sol @@ -3,11 +3,7 @@ contract SimpleString { string public storedData; function SimpleString() public { - storedData = "Hello"; - } - - function set(string x) public { - storedData = x; + storedData = "Hello world!"; } function get() public view returns (string retVal) { diff --git a/tests/examples_3/simple_string_test.sol b/tests/examples_3/simple_string_test.sol index 415ea17165..4f8109764a 100644 --- a/tests/examples_3/simple_string_test.sol +++ b/tests/examples_3/simple_string_test.sol @@ -2,7 +2,7 @@ pragma solidity ^0.4.7; import "./tests.sol"; import "./simple_string.sol"; -contract MyTest { +contract StringTest { SimpleString foo; function beforeAll() { @@ -10,6 +10,10 @@ contract MyTest { } function initialValueShouldBeHello() public constant returns (bool) { - return Assert.equal(foo.get(), "Hello", "initial value is not correct"); + return Assert.equal(foo.get(), "Hello world!", "initial value is not correct"); + } + + function valueShouldBeHelloWorld() public constant returns (bool) { + return Assert.equal(foo.get(), "Hello wordl!", "initial value is not correct"); } } diff --git a/tests/testRunner.js b/tests/testRunner.js index 4dcb7ca261..2eda171678 100644 --- a/tests/testRunner.js +++ b/tests/testRunner.js @@ -50,7 +50,7 @@ describe('testRunner', function () { assert.equal(results.failureNum, 2) }) - it('should returns 3 messages', function () { + it('should returns 5 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' }, @@ -107,10 +107,10 @@ describe('testRunner', function () { } var resultsCallback = function (_err, _results) { results = _results - console.log(results) done() } - TestRunner.runTest('MyTest', contracts.MyTest, testCallback, resultsCallback) + TestRunner.runTest('StringTest', contracts.StringTest, testCallback, resultsCallback) + TestRunner.runTest('StringTest2', contracts.StringTest2, testCallback, resultsCallback) }) }) @@ -118,14 +118,15 @@ describe('testRunner', function () { assert.equal(results.passingNum, 1) }) - it('should 0 failing tests', function () { - assert.equal(results.failureNum, 0) + it('should 1 failing tests', function () { + assert.equal(results.failureNum, 1) }) - it('should returns 2 messages', function () { + it('should returns 3 messages', function () { assert.deepEqual(tests, [ - { type: 'contract', value: 'MyTest', filename: 'simple_string_test.sol' }, - { type: 'testPass', value: 'Initial value should be hello', time: 1, context: 'MyTest' } + { type: 'contract', value: 'StringTest', filename: 'simple_string_test.sol' }, + { type: 'testFailure', value: 'Value should be hello world', time: 1, context: 'StringTest', "errMsg": "function returned false" }, + { type: 'testPass', value: 'Initial value should be hello', time: 1, context: 'StringTest' }, ]) }) })