2014-03-19 04:35:16 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2014-03-19 04:35:16 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2014-03-19 04:35:16 +00:00
|
|
|
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.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2014-03-19 04:35:16 +00:00
|
|
|
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
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-19 04:35:16 +00:00
|
|
|
*/
|
|
|
|
/** @file boostTest.cpp
|
|
|
|
* @author Marko Simovic <markobarko@gmail.com>
|
|
|
|
* @date 2014
|
|
|
|
* Stub for generating main boost.test module.
|
2015-08-13 10:27:47 +00:00
|
|
|
* Original code taken from boost sources.
|
2014-03-19 04:35:16 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-04 20:01:56 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
2016-03-21 23:05:30 +00:00
|
|
|
|
2016-08-06 09:37:52 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4535) // calling _set_se_translator requires /EHa
|
|
|
|
#endif
|
2018-07-25 07:17:53 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2016-08-06 09:37:52 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma GCC diagnostic pop
|
2017-04-26 09:53:44 +00:00
|
|
|
|
2018-12-05 17:00:23 +00:00
|
|
|
#include <test/InteractiveTests.h>
|
2018-03-14 11:04:04 +00:00
|
|
|
#include <test/Options.h>
|
2019-07-16 17:05:13 +00:00
|
|
|
#include <test/EVMHost.h>
|
2017-04-26 09:53:44 +00:00
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
#include <boost/filesystem.hpp>
|
2018-12-05 17:00:23 +00:00
|
|
|
#include <string>
|
2018-06-08 12:17:50 +00:00
|
|
|
|
2017-04-26 09:53:44 +00:00
|
|
|
using namespace boost::unit_test;
|
2018-06-08 12:17:50 +00:00
|
|
|
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
|
2017-04-26 09:53:44 +00:00
|
|
|
|
2017-09-28 08:28:41 +00:00
|
|
|
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);
|
|
|
|
}
|
2018-06-08 12:17:50 +00:00
|
|
|
|
|
|
|
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;
|
2019-07-17 08:24:23 +00:00
|
|
|
TestCase::Config config{fullpath.string(), dev::test::Options::get().evmVersion()};
|
2018-06-08 12:17:50 +00:00
|
|
|
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()))
|
2019-07-17 08:24:23 +00:00
|
|
|
numTestsAdded += registerTests(*sub_suite, _basepath, _path / entry.path().filename(), _testCaseCreator);
|
2018-06-08 12:17:50 +00:00
|
|
|
_suite.add(sub_suite);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static vector<unique_ptr<string>> filenames;
|
|
|
|
|
|
|
|
filenames.emplace_back(new string(_path.string()));
|
|
|
|
_suite.add(make_test_case(
|
2019-02-06 11:10:48 +00:00
|
|
|
[config, _testCaseCreator]
|
2018-06-08 12:17:50 +00:00
|
|
|
{
|
|
|
|
BOOST_REQUIRE_NO_THROW({
|
|
|
|
try
|
|
|
|
{
|
|
|
|
stringstream errorStream;
|
2019-03-15 16:22:04 +00:00
|
|
|
auto testCase = _testCaseCreator(config);
|
2019-04-01 13:31:48 +00:00
|
|
|
if (testCase->validateSettings(dev::test::Options::get().evmVersion()))
|
2019-05-07 13:33:22 +00:00
|
|
|
switch (testCase->run(errorStream))
|
|
|
|
{
|
|
|
|
case TestCase::TestResult::Success:
|
|
|
|
break;
|
|
|
|
case TestCase::TestResult::Failure:
|
|
|
|
BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str());
|
|
|
|
break;
|
|
|
|
case TestCase::TestResult::FatalError:
|
|
|
|
BOOST_ERROR("Fatal error during test.\n" + errorStream.str());
|
|
|
|
break;
|
|
|
|
}
|
2018-06-08 12:17:50 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2017-09-28 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 09:53:44 +00:00
|
|
|
test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
|
|
|
|
{
|
|
|
|
master_test_suite_t& master = framework::master_test_suite();
|
|
|
|
master.p_name.value = "SolidityTests";
|
2018-03-14 11:04:04 +00:00
|
|
|
dev::test::Options::get().validate();
|
2018-12-05 17:00:23 +00:00
|
|
|
|
2019-07-17 08:24:23 +00:00
|
|
|
bool disableSemantics = !dev::test::EVMHost::getVM(dev::test::Options::get().evmonePath.string());
|
|
|
|
if (disableSemantics)
|
2019-07-16 17:05:13 +00:00
|
|
|
{
|
2019-09-11 11:01:51 +00:00
|
|
|
cout << "Unable to find " << dev::test::evmoneFilename << ". Please provide the path using -- --evmonepath <path>." << endl;
|
2019-07-16 17:05:13 +00:00
|
|
|
cout << "You can download it at" << endl;
|
2019-09-11 11:01:51 +00:00
|
|
|
cout << dev::test::evmoneDownloadLink << endl;
|
2019-07-16 17:05:13 +00:00
|
|
|
cout << endl << "--- SKIPPING ALL SEMANTICS TESTS ---" << endl << endl;
|
|
|
|
}
|
2018-12-05 17:00:23 +00:00
|
|
|
// Include the interactive tests in the automatic tests as well
|
|
|
|
for (auto const& ts: g_interactiveTestsuites)
|
2018-11-15 15:47:52 +00:00
|
|
|
{
|
2018-12-05 17:00:23 +00:00
|
|
|
auto const& options = dev::test::Options::get();
|
|
|
|
|
|
|
|
if (ts.smt && options.disableSMT)
|
|
|
|
continue;
|
|
|
|
|
2019-07-17 08:24:23 +00:00
|
|
|
if (ts.needsVM && disableSemantics)
|
2018-12-05 17:00:23 +00:00
|
|
|
continue;
|
2018-11-15 15:47:52 +00:00
|
|
|
|
|
|
|
solAssert(registerTests(
|
|
|
|
master,
|
2018-12-05 17:00:23 +00:00
|
|
|
options.testPath / ts.path,
|
|
|
|
ts.subpath,
|
|
|
|
ts.testCaseCreator
|
|
|
|
) > 0, std::string("no ") + ts.title + " tests found");
|
2018-11-15 15:47:52 +00:00
|
|
|
}
|
2018-12-05 17:00:23 +00:00
|
|
|
|
2019-07-17 08:24:23 +00:00
|
|
|
if (disableSemantics)
|
2017-04-26 09:53:44 +00:00
|
|
|
{
|
|
|
|
for (auto suite: {
|
2017-09-13 15:16:45 +00:00
|
|
|
"ABIDecoderTest",
|
2017-08-07 10:52:40 +00:00
|
|
|
"ABIEncoderTest",
|
2017-04-26 09:53:44 +00:00
|
|
|
"SolidityAuctionRegistrar",
|
|
|
|
"SolidityFixedFeeRegistrar",
|
|
|
|
"SolidityWallet",
|
2018-11-13 14:34:19 +00:00
|
|
|
#if HAVE_LLL
|
2017-07-11 18:59:13 +00:00
|
|
|
"LLLERC20",
|
2017-07-14 10:58:09 +00:00
|
|
|
"LLLENS",
|
2017-04-26 09:53:44 +00:00
|
|
|
"LLLEndToEndTest",
|
2018-11-13 14:34:19 +00:00
|
|
|
#endif
|
2017-04-26 09:53:44 +00:00
|
|
|
"GasMeterTests",
|
2018-12-06 14:59:58 +00:00
|
|
|
"GasCostTests",
|
2017-04-26 09:53:44 +00:00
|
|
|
"SolidityEndToEndTest",
|
|
|
|
"SolidityOptimizer"
|
|
|
|
})
|
2017-09-28 08:28:41 +00:00
|
|
|
removeTestSuite(suite);
|
2017-04-26 09:53:44 +00:00
|
|
|
}
|
2018-12-05 17:00:23 +00:00
|
|
|
|
2017-09-28 08:28:41 +00:00
|
|
|
if (dev::test::Options::get().disableSMT)
|
|
|
|
removeTestSuite("SMTChecker");
|
2017-04-26 09:53:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-26 14:23:53 +00:00
|
|
|
|
|
|
|
// BOOST_TEST_DYN_LINK should be defined if user want to link against shared boost test library
|
|
|
|
#ifdef BOOST_TEST_DYN_LINK
|
|
|
|
|
|
|
|
// Because we want to have customized initialization function and support shared boost libraries at the same time,
|
|
|
|
// we are forced to customize the entry point.
|
|
|
|
// see: https://www.boost.org/doc/libs/1_67_0/libs/test/doc/html/boost_test/adv_scenarios/shared_lib_customizations/init_func.html
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
auto init_unit_test = []() -> bool { init_unit_test_suite(0, nullptr); return true; };
|
|
|
|
return boost::unit_test::unit_test_main(init_unit_test, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|