From 14d0f8c2f194bfed0ae8d23042f6210cff1f93c9 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 8 Jun 2018 14:17:50 +0200 Subject: Refactor syntax test infrastructure to prepare introducing semantics tests. --- test/boostTest.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index f16973b5..145be6e4 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -38,7 +38,26 @@ #include #include +#include +#include +#include + 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 const& _fn, + string const& _name, + string const& /* _filename */, + size_t /* _line */ +) +{ + return make_test_case(_fn, _name); +} +#endif namespace { @@ -49,6 +68,56 @@ void removeTestSuite(std::string const& _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(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> 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*/[] ) @@ -56,10 +125,11 @@ 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(dev::solidity::test::SyntaxTest::registerTests( + solAssert(registerTests( master, dev::test::Options::get().testPath / "libsolidity", - "syntaxTests" + "syntaxTests", + SyntaxTest::create ) > 0, "no syntax tests found"); if (dev::test::Options::get().disableIPC) { -- cgit v1.2.3 From f31989c02220cb8367da1f361f964d91962b4ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 25 Jul 2018 09:17:53 +0200 Subject: Do not include single-header boost_unit_test Do not mix 2 different usage variants of boost_unit_test. If you link with static libs do not include the single-header variant. See https://www.boost.org/doc/libs/1_67_0/libs/test/doc/html/boost_test/usage_variants.html#boost_test.usage_variants.single_header --- test/boostTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index 145be6e4..6c68100c 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -28,7 +28,7 @@ #pragma warning(push) #pragma warning(disable:4535) // calling _set_se_translator requires /EHa #endif -#include +#include #if defined(_MSC_VER) #pragma warning(pop) #endif -- cgit v1.2.3 From b89365282bb047756f1cc52587a60766a7fe2f02 Mon Sep 17 00:00:00 2001 From: mingchuan Date: Thu, 26 Jul 2018 22:23:53 +0800 Subject: Fix shared boost test library build by customizing main --- test/boostTest.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index 6c68100c..f23355fd 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -153,3 +153,18 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) return 0; } + +// 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 -- cgit v1.2.3 From d923926ff7ceaad551fe76afb356266e28a2a1ea Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 3 Aug 2018 19:30:18 +0200 Subject: Infrastructure for extracting JSON AST tests. --- test/boostTest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index 6c68100c..cef3b06f 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -36,6 +36,7 @@ #pragma GCC diagnostic pop #include +#include #include #include @@ -131,6 +132,12 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) "syntaxTests", SyntaxTest::create ) > 0, "no syntax tests found"); + solAssert(registerTests( + master, + dev::test::Options::get().testPath / "libsolidity", + "ASTJSON", + ASTJSONTest::create + ) > 0, "no JSON AST tests found"); if (dev::test::Options::get().disableIPC) { for (auto suite: { -- cgit v1.2.3 From 4607118d2e9bbf59707b48f177aff54ac99163b8 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 9 Oct 2018 15:43:55 +0200 Subject: Add Yul optimizer test framework. --- test/boostTest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index d9e939eb..cbbf586f 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -138,6 +139,12 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) "ASTJSON", ASTJSONTest::create ) > 0, "no JSON AST tests found"); + solAssert(registerTests( + master, + dev::test::Options::get().testPath / "libjulia", + "yulOptimizerTests", + dev::julia::test::YulOptimizerTest::create + ) > 0, "no Yul Optimizer tests found"); if (dev::test::Options::get().disableIPC) { for (auto suite: { -- cgit v1.2.3 From 9a4bec7e474a310c7f93ff3b84928e0e9ba9cce6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 15 Oct 2018 11:52:35 +0200 Subject: Renaming libjulia to libyul --- test/boostTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index cbbf586f..c199535a 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include @@ -141,7 +141,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) ) > 0, "no JSON AST tests found"); solAssert(registerTests( master, - dev::test::Options::get().testPath / "libjulia", + dev::test::Options::get().testPath / "libyul", "yulOptimizerTests", dev::julia::test::YulOptimizerTest::create ) > 0, "no Yul Optimizer tests found"); -- cgit v1.2.3 From 1304361b9c48438d5c55903492b5f11c3dac73e5 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 15 Oct 2018 11:58:51 +0200 Subject: Renaming namespace dev::julia to dev::yul. --- test/boostTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index c199535a..d27ba1f6 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -143,7 +143,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) master, dev::test::Options::get().testPath / "libyul", "yulOptimizerTests", - dev::julia::test::YulOptimizerTest::create + dev::yul::test::YulOptimizerTest::create ) > 0, "no Yul Optimizer tests found"); if (dev::test::Options::get().disableIPC) { -- cgit v1.2.3 From e4851cf59eed8d39a4b95e1ce8181b52e5c66d78 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Wed, 10 Oct 2018 14:31:49 +0200 Subject: [SMTChecker] Inline calls to internal functions --- test/boostTest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/boostTest.cpp') diff --git a/test/boostTest.cpp b/test/boostTest.cpp index d27ba1f6..34eeaec9 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -145,6 +145,13 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) "yulOptimizerTests", dev::yul::test::YulOptimizerTest::create ) > 0, "no Yul Optimizer tests found"); + if (!dev::test::Options::get().disableSMT) + solAssert(registerTests( + master, + dev::test::Options::get().testPath / "libsolidity", + "smtCheckerTests", + SyntaxTest::create + ) > 0, "no SMT checker tests found"); if (dev::test::Options::get().disableIPC) { for (auto suite: { -- cgit v1.2.3