|
| 1 | +/* |
| 2 | + This file is part of solidity. |
| 3 | +
|
| 4 | + solidity is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + solidity is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with solidity. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | +/** |
| 18 | + * Unit tests for Solidity's test expectation parser. |
| 19 | + */ |
| 20 | + |
| 21 | +#include <functional> |
| 22 | +#include <string> |
| 23 | +#include <tuple> |
| 24 | +#include <boost/test/unit_test.hpp> |
| 25 | +#include <liblangutil/Exceptions.h> |
| 26 | +#include <test/libsolidity/SolidityExecutionFramework.h> |
| 27 | + |
| 28 | +#include <test/libsolidity/util/TestFileParser.h> |
| 29 | + |
| 30 | +using namespace std; |
| 31 | +using namespace dev::test; |
| 32 | + |
| 33 | +namespace dev |
| 34 | +{ |
| 35 | +namespace solidity |
| 36 | +{ |
| 37 | +namespace test |
| 38 | +{ |
| 39 | + |
| 40 | +using FunctionCall = TestFileParser::FunctionCall; |
| 41 | +using Expectation = TestFileParser::FunctionCallExpectations; |
| 42 | + |
| 43 | +vector<FunctionCall> parse(string const& _source) |
| 44 | +{ |
| 45 | + istringstream stream{_source, ios_base::out}; |
| 46 | + TestFileParser parser{stream}; |
| 47 | + return parser.parseFunctionCalls(); |
| 48 | +} |
| 49 | + |
| 50 | +BOOST_AUTO_TEST_SUITE(TestFileParserTest) |
| 51 | + |
| 52 | +BOOST_AUTO_TEST_CASE(smoke_test) |
| 53 | +{ |
| 54 | + char const* source = R"()"; |
| 55 | + BOOST_CHECK_EQUAL(parse(source).size(), 0); |
| 56 | +} |
| 57 | + |
| 58 | +BOOST_AUTO_TEST_CASE(simple_function_call_success) |
| 59 | +{ |
| 60 | + char const* source = R"( |
| 61 | + // f() |
| 62 | + // -> 1 |
| 63 | + )"; |
| 64 | + BOOST_CHECK_EQUAL(parse(source).size(), 1); |
| 65 | + BOOST_CHECK_EQUAL(parse(source).at(0).signature, "f()"); |
| 66 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.output, "-> 1"); |
| 67 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.raw, "1"); |
| 68 | +} |
| 69 | + |
| 70 | +BOOST_AUTO_TEST_CASE(simple_function_call_revert) |
| 71 | +{ |
| 72 | + char const* source = R"( |
| 73 | + // i_am_not_there() |
| 74 | + // REVERT |
| 75 | + )"; |
| 76 | + BOOST_CHECK_EQUAL(parse(source).size(), 1); |
| 77 | + BOOST_CHECK_EQUAL(parse(source).at(0).signature, "i_am_not_there()"); |
| 78 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.output, "REVERT"); |
| 79 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.raw, ""); |
| 80 | +} |
| 81 | + |
| 82 | +BOOST_AUTO_TEST_CASE(simple_function_call_comments) |
| 83 | +{ |
| 84 | + char const* source = R"( |
| 85 | + // f() # This is a comment |
| 86 | + // -> 1 # This is another comment |
| 87 | + )"; |
| 88 | + BOOST_CHECK_EQUAL(parse(source).size(), 1); |
| 89 | + BOOST_CHECK_EQUAL(parse(source).at(0).signature, "f()"); |
| 90 | + BOOST_CHECK_EQUAL(parse(source).at(0).arguments.comment, "This is a comment"); |
| 91 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.output, "-> 1"); |
| 92 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.raw, "1"); |
| 93 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.comment, "This is another comment"); |
| 94 | +} |
| 95 | + |
| 96 | +BOOST_AUTO_TEST_CASE(function_call_arguments) |
| 97 | +{ |
| 98 | + char const* source = R"( |
| 99 | + // f(uint256): 1 |
| 100 | + // -> 1 |
| 101 | + )"; |
| 102 | + BOOST_CHECK_EQUAL(parse(source).size(), 1); |
| 103 | + BOOST_CHECK_EQUAL(parse(source).at(0).signature, "f(uint256)"); |
| 104 | + BOOST_CHECK_EQUAL(parse(source).at(0).arguments.raw, "1"); |
| 105 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.output, "-> 1"); |
| 106 | + BOOST_CHECK_EQUAL(parse(source).at(0).expectations.raw, "1"); |
| 107 | +} |
| 108 | + |
| 109 | + |
| 110 | +BOOST_AUTO_TEST_SUITE_END() |
| 111 | + |
| 112 | +} |
| 113 | +} |
| 114 | +} |
0 commit comments