aboutsummaryrefslogtreecommitdiffstats
path: root/test/boostTest.cpp
blob: 145be6e44892049398b9d779a8c32545ec292015 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
    This file is part of solidity.

    solidity is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    solidity is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with solidity.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file boostTest.cpp
 * @author Marko Simovic <markobarko@gmail.com>
 * @date 2014
 * Stub for generating main boost.test module.
 * Original code taken from boost sources.
 */

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4535) // calling _set_se_translator requires /EHa
#endif
#include <boost/test/included/unit_test.hpp>
#if defined(_MSC_VER)
#pragma warning(pop)
#endif

#pragma GCC diagnostic pop

#include <test/Options.h>
#include <test/libsolidity/SyntaxTest.h>

#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>

using namespace boost::unit_test;
using namespace dev::solidity::test;
namespace fs = boost::filesystem;
using namespace std;

#if BOOST_VERSION < 105900
test_case *make_test_case(
    function<void()> const& _fn,
    string const& _name,
    string const& /* _filename */,
    size_t /* _line */
)
{
    return make_test_case(_fn, _name);
}
#endif

namespace
{
void removeTestSuite(std::string const& _name)
{
    master_test_suite_t& master = framework::master_test_suite();
    auto id = master.get(_name);
    assert(id != INV_TEST_UNIT_ID);
    master.remove(id);
}

int registerTests(
    boost::unit_test::test_suite& _suite,
    boost::filesystem::path const& _basepath,
    boost::filesystem::path const& _path,
    TestCase::TestCaseCreator _testCaseCreator
)
{
    int numTestsAdded = 0;
    fs::path fullpath = _basepath / _path;
    if (fs::is_directory(fullpath))
    {
        test_suite* sub_suite = BOOST_TEST_SUITE(_path.filename().string());
        for (auto const& entry: boost::iterator_range<fs::directory_iterator>(
            fs::directory_iterator(fullpath),
            fs::directory_iterator()
        ))
            if (fs::is_directory(entry.path()) || TestCase::isTestFilename(entry.path().filename()))
                numTestsAdded += registerTests(*sub_suite, _basepath, _path / entry.path().filename(), _testCaseCreator);
        _suite.add(sub_suite);
    }
    else
    {
        static vector<unique_ptr<string>> filenames;

        filenames.emplace_back(new string(_path.string()));
        _suite.add(make_test_case(
            [fullpath, _testCaseCreator]
            {
                BOOST_REQUIRE_NO_THROW({
                    try
                    {
                        stringstream errorStream;
                        if (!_testCaseCreator(fullpath.string())->run(errorStream))
                            BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str());
                    }
                    catch (boost::exception const& _e)
                    {
                        BOOST_ERROR("Exception during extracted test: " << boost::diagnostic_information(_e));
                    }
               });
            },
            _path.stem().string(),
            *filenames.back(),
            0
        ));
        numTestsAdded = 1;
    }
    return numTestsAdded;
}
}

test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
{
    master_test_suite_t& master = framework::master_test_suite();
    master.p_name.value = "SolidityTests";
    dev::test::Options::get().validate();
    solAssert(registerTests(
        master,
        dev::test::Options::get().testPath / "libsolidity",
        "syntaxTests",
        SyntaxTest::create
    ) > 0, "no syntax tests found");
    if (dev::test::Options::get().disableIPC)
    {
        for (auto suite: {
            "ABIDecoderTest",
            "ABIEncoderTest",
            "SolidityAuctionRegistrar",
            "SolidityFixedFeeRegistrar",
            "SolidityWallet",
            "LLLERC20",
            "LLLENS",
            "LLLEndToEndTest",
            "GasMeterTests",
            "SolidityEndToEndTest",
            "SolidityOptimizer"
        })
            removeTestSuite(suite);
    }
    if (dev::test::Options::get().disableSMT)
        removeTestSuite("SMTChecker");

    return 0;
}