diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-06-25 13:29:21 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-06-26 08:54:37 +0000 |
commit | fb6db2f639381f384807aaac0ec2701c4e4013fb (patch) | |
tree | 369ce0084ec3a5cc4289537557934ad56903c5fb /vdstestlib/src | |
parent | 3de18f8a3dbeb0cda98fd3f86920784be154cb9a (diff) |
Remove CppUnit dependencies in modules
Move test config helpers out of cppunit submodule.
Diffstat (limited to 'vdstestlib/src')
14 files changed, 5 insertions, 439 deletions
diff --git a/vdstestlib/src/tests/cppunit/.gitignore b/vdstestlib/src/tests/cppunit/.gitignore deleted file mode 100644 index ec991c2f0cd..00000000000 --- a/vdstestlib/src/tests/cppunit/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -testrunner -vdstestlib_testrunner_app diff --git a/vdstestlib/src/tests/cppunit/CMakeLists.txt b/vdstestlib/src/tests/cppunit/CMakeLists.txt deleted file mode 100644 index 1b8e857fe30..00000000000 --- a/vdstestlib/src/tests/cppunit/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vdstestlib_testrunner_app TEST - SOURCES - testrunner.cpp - cppunittest.cpp - DEPENDS - vdstestlib -) - -vespa_add_test( - NAME vdstestlib_testrunner_app - NO_VALGRIND - COMMAND vdstestlib_testrunner_app -) diff --git a/vdstestlib/src/tests/cppunit/cppunittest.cpp b/vdstestlib/src/tests/cppunit/cppunittest.cpp deleted file mode 100644 index bf8b38e696e..00000000000 --- a/vdstestlib/src/tests/cppunit/cppunittest.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vdstestlib/cppunit/macros.h> - -namespace vespalib { - -struct CppunitTest : public CppUnit::TestFixture { - - void testSomething(); - - CPPUNIT_TEST_SUITE(CppunitTest); - CPPUNIT_TEST(testSomething); - CPPUNIT_TEST_SUITE_END(); - -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CppunitTest); - -void -CppunitTest::testSomething() -{ - CPPUNIT_ASSERT_EQUAL_MESSAGE("hmm", "foo", "foo"); -} - -} // vespalib diff --git a/vdstestlib/src/tests/cppunit/testrunner.cpp b/vdstestlib/src/tests/cppunit/testrunner.cpp deleted file mode 100644 index 3b686d132bb..00000000000 --- a/vdstestlib/src/tests/cppunit/testrunner.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/vdstestlib/cppunit/cppunittestrunner.h> - -int main(int argc, const char *argv[]) -{ - vdstestlib::CppUnitTestRunner testRunner; - return testRunner.run(argc, argv); -} - diff --git a/vdstestlib/src/tests/dirconfig/dirconfigtest.cpp b/vdstestlib/src/tests/dirconfig/dirconfigtest.cpp index 9d8e5c47143..f985150e497 100644 --- a/vdstestlib/src/tests/dirconfig/dirconfigtest.cpp +++ b/vdstestlib/src/tests/dirconfig/dirconfigtest.cpp @@ -2,7 +2,7 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/exceptions.h> -#include <vespa/vdstestlib/cppunit/dirconfig.h> +#include <vespa/vdstestlib/config/dirconfig.h> #include <fstream> #include <iostream> diff --git a/vdstestlib/src/vespa/vdstestlib/CMakeLists.txt b/vdstestlib/src/vespa/vdstestlib/CMakeLists.txt index ce80f8dd644..86ca3461302 100644 --- a/vdstestlib/src/vespa/vdstestlib/CMakeLists.txt +++ b/vdstestlib/src/vespa/vdstestlib/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(vdstestlib SOURCES - $<TARGET_OBJECTS:vdstestlib_vdstestlib_cppunit> + $<TARGET_OBJECTS:vdstestlib_vdstestlib_config> INSTALL lib64 - DEPENDS - cppunit ) diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/.gitignore b/vdstestlib/src/vespa/vdstestlib/config/.gitignore index 583460ae288..583460ae288 100644 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/.gitignore +++ b/vdstestlib/src/vespa/vdstestlib/config/.gitignore diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/CMakeLists.txt b/vdstestlib/src/vespa/vdstestlib/config/CMakeLists.txt index e7d8705b07d..90b7c95fe50 100644 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/CMakeLists.txt +++ b/vdstestlib/src/vespa/vdstestlib/config/CMakeLists.txt @@ -1,7 +1,6 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_library(vdstestlib_vdstestlib_cppunit OBJECT +vespa_add_library(vdstestlib_vdstestlib_config OBJECT SOURCES - cppunittestrunner.cpp dirconfig.cpp DEPENDS ) diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/dirconfig.cpp b/vdstestlib/src/vespa/vdstestlib/config/dirconfig.cpp index 3a26ed9dec8..3a26ed9dec8 100644 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/dirconfig.cpp +++ b/vdstestlib/src/vespa/vdstestlib/config/dirconfig.cpp diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/dirconfig.h b/vdstestlib/src/vespa/vdstestlib/config/dirconfig.h index 388348c880e..c0a1571f52c 100644 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/dirconfig.h +++ b/vdstestlib/src/vespa/vdstestlib/config/dirconfig.h @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. /** * \class vdstestlib::DirConfig - * \ingroup cppunit + * \ingroup config * * \brief Helper class for generating dir config * diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/dirconfig.hpp b/vdstestlib/src/vespa/vdstestlib/config/dirconfig.hpp index f5d886c089a..5d127879e34 100644 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/dirconfig.hpp +++ b/vdstestlib/src/vespa/vdstestlib/config/dirconfig.hpp @@ -2,7 +2,7 @@ #pragma once -#include <vespa/vdstestlib/cppunit/dirconfig.h> +#include <vespa/vdstestlib/config/dirconfig.h> #include <sstream> #include <boost/lexical_cast.hpp> diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/cppunittestrunner.cpp b/vdstestlib/src/vespa/vdstestlib/cppunit/cppunittestrunner.cpp deleted file mode 100644 index dbedf1ee900..00000000000 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/cppunittestrunner.cpp +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/vdstestlib/cppunit/cppunittestrunner.h> - -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <cppunit/ui/text/TestRunner.h> -#include <cppunit/TextTestProgressListener.h> -#include <vespa/log/log.h> -#include <iostream> - -LOG_SETUP(".cppunittestrunner"); - -using CppUnit::Test; -using CppUnit::TestSuite; - -namespace vdstestlib { - -namespace { - struct WantedTestList : public CppUnit::Test::Filter { - std::vector<std::string> _wanted; - bool _includeStressTests; - - WantedTestList(int argc, const char *argv[], - bool includeStressTests) - : _wanted(), - _includeStressTests(includeStressTests) - { - for (int i=1; i<argc; ++i) { - if (argv[i][0] != '-') { - std::cerr << "Running tests matching '*" - << argv[i] << "*'.\n"; - _wanted.push_back(argv[i]); - } - } - char* testpat = getenv("TEST_SUBSET"); - if (testpat != 0) { - std::string pat = std::string("*") + testpat; - if (pat[pat.size() - 1] != '$') pat += "*"; - std::cerr << "Running tests matching '" << pat << "'." - " (Taken from TEST_SUBSET environment variable)\n"; - _wanted.push_back(testpat); - } - if (CppUnit::Test::disabledCount > 0) { - std::cerr << CppUnit::Test::disabledCount - << " tests are currently disabled and won't be " - << "attempted run.\n"; - } - if (CppUnit::Test::ignoredCount > 0) { - std::cerr << CppUnit::Test::ignoredCount - << " tests are currently set to ignore failures.\n"; - } - } - - std::string getWantedString(uint32_t index) const { - std::string s = _wanted[index]; - if (s[s.size() - 1] == '$') { - return s.substr(0, s.size() - 1); - } - return s; - } - - bool requiresTailMatch(uint32_t index) const { - std::string s = _wanted[index]; - return (s[s.size() - 1] == '$'); - } - - bool include(const std::string& name) const override { - if ((name.find("stress") != std::string::npos || - name.find("Stress") != std::string::npos) - && !_includeStressTests) - { - std::cerr << "Excluding stress test " << name << "\n"; - } else { - if (_wanted.size() == 0) return true; - for (uint32_t i=0; i<_wanted.size(); ++i) { - std::string::size_type pos = name.rfind(getWantedString(i)); - if (pos == std::string::npos) continue; - if (!requiresTailMatch(i) - || pos == name.size() - getWantedString(i).size()) - { - return true; - } - } - } - return false; - } - }; - - struct LogHook : public CppUnit::TextTestProgressListener::TestStartHook { - std::string lastTest; - void startedTest(const std::string& testName) override { - LOG(info, "Starting test: %s", testName.c_str()); - lastTest = testName; - } - void stoppedTest() override { - LOG(info, "Stopped test: %s", lastTest.c_str()); - } - }; -} - -void CppUnitTestRunner::listTests(const TestSuite *tests) { - for (const auto & test : tests->getTests()) { - std::cout << test->getName() << std::endl; - } -} - -CppUnitTestRunner::CppUnitTestRunner() -{ - std::ios::sync_with_stdio(); -} - -int -CppUnitTestRunner::run(int argc, const char *argv[]) -{ - CppUnit::TextUi::TestRunner runner; - CppUnit::TestFactoryRegistry& registry( - CppUnit::TestFactoryRegistry::getRegistry()); - - Test *tests = registry.makeTest(); - TestSuite *suite = dynamic_cast<TestSuite *>(tests); - - bool includeStressTests = false; - bool logStartStop = false; - bool verbose = false; - if (getenv("TEST_VERBOSE") != 0) { - verbose = true; - } - - for (int i=1; i<argc; ++i) { - std::string arg(argv[i]); - if (arg == "--verbose") { - verbose = true; - logStartStop = true; - } else if (arg == "--includestress") { - includeStressTests = true; - } else if (arg == "--list") { - listTests(suite); - exit(0); - } else if (argv[i][0] == '-') { - std::cerr << "Illegal option " << arg << "\n"; - exit(1); - } else { - // Arguments will be passed as patterns - } - } - - WantedTestList wantedList(argc, argv, includeStressTests); - suite->filter(wantedList); - runner.addTest(tests); - CppUnit::TextTestProgressListener::verboseProgress = verbose; - if (logStartStop) { - CppUnit::TextTestProgressListener::startHook.reset(new LogHook); - } - return (runner.run("", false) ? 0 : -1); -} - -} // vdstestlib diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/cppunittestrunner.h b/vdstestlib/src/vespa/vdstestlib/cppunit/cppunittestrunner.h deleted file mode 100644 index 057f116a7d2..00000000000 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/cppunittestrunner.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * @class CppUnitTestRunner - * @ingroup cppunit - * - * @brief Application for running cppunit tests. - * - * This is an application to use when running cppunit tests, currently used - * in document,vdslib,storageapi and storage. - * - * It is built like a library, as one need to create one per project, but the - * cppunit test application file in each project can now only contain a little - * main method, creating an instance of this class and calling run. - * - * See storage/src/cpp/tests/testrunner.h for an example of simple app using - * this. - * - * When using this test binary you have the following options. - * - * If the TEST_SUBSET environment variable is set, only tests matching the - * pattern given in the environment is run. For instance, by doing - * TEST_SUBSET=foo ./testrunner, only tests that match the regular expression - * .*foo.* will be run. Optionally you can postfix your expression with a - * dollar, to only run tests that end with the given string. You can match - * against any part of the function shown in verbose mode. For instance - * TEST_SUBSET=foo::bar$ will run tests whose test class ends in foo, and - * having test name bar. - * - * You can specify --verbose mode. In verbose mode, each test name is printed - * to stdout when started, and after completion, the runtime of the test is - * shown. This is very useful to identify slow unit tests which should be - * improved, and also to see in what test the system might be hung up in. In - * addition, in verbose mode, a vespa log entry is given at the start and end - * of each test, such that one can identify which parts of the vespa log belongs - * to each test, in case you are redirecting the log to a file. - * - * You can also use the --includestress option to also include tests that match - * the regular expression '.*[sS]tress.*'. These are excluded by default, such - * that regular test runs can be quick. - */ - -#pragma once - -#include <cppunit/TestSuite.h> - -namespace vdstestlib { - -class CppUnitTestRunner { -public: - CppUnitTestRunner(); - - void listTests(const CppUnit::TestSuite *tests); - int run(int argc, const char * argv[]); - -}; - -} // vdstestlib - diff --git a/vdstestlib/src/vespa/vdstestlib/cppunit/macros.h b/vdstestlib/src/vespa/vdstestlib/cppunit/macros.h deleted file mode 100644 index fdde94bbbd6..00000000000 --- a/vdstestlib/src/vespa/vdstestlib/cppunit/macros.h +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * This file contains additional CPPUNIT macros to simplify tests. - */ -#pragma once -#include <cppunit/extensions/HelperMacros.h> -#include <vespa/vespalib/test/insertion_operators.h> - - -// Wrapper for CPPUNIT_ASSERT_EQUAL_MESSAGE to prevent it from evaluating -// message if val1 is equal to val2 -#define CPPUNIT_ASSERT_EQUAL_MSG(message, val1, val2) \ - { \ - if (!((val1) == (val2))) { \ - CPPUNIT_ASSERT_EQUAL_MESSAGE(message, val1, val2); \ - } \ - } - -#define CPPUNIT_ASSERT_EQUAL_ESCAPED(val1, val2) \ - { \ - if (!((val1) == (val2))) { \ - std::ostringstream out1; \ - std::ostringstream out2; \ - out1 << "[" << val1 << "]"; \ - out2 << "[" << val2 << "]"; \ - CPPUNIT_ASSERT_EQUAL( \ - document::StringUtil::escape(out1.str()), \ - document::StringUtil::escape(out2.str())); \ - } \ - } - -// Wrapper for CPPUNIT_ASSERT_MESSAGE to prevent it from evaluating message if -// val is true -#define CPPUNIT_ASSERT_MSG(message, val) \ - { \ - if (!(val)) { \ - CPPUNIT_ASSERT_MESSAGE(message, val); \ - } \ - } - -// Assert that value starts with prefix -#define CPPUNIT_ASSERT_PREFIX(prefix, value) \ - { \ - std::ostringstream pre; \ - pre << prefix; \ - std::ostringstream val; \ - val << value; \ - if (val.str().find(pre.str()) != 0) { \ - CPPUNIT_FAIL("Value of '" + val.str() + "' does not contain " \ - "prefix '" + pre.str() + "'."); \ - } \ - } - -// Assert that value contains given substring -#define CPPUNIT_ASSERT_CONTAIN(contained, value) \ - { \ - std::ostringstream cont; \ - cont << contained; \ - std::ostringstream val; \ - val << value; \ - if (val.str().find(cont.str()) == std::string::npos) { \ - CPPUNIT_FAIL("Value of '" + val.str() + "' does not contain '" \ - + cont.str() + "'."); \ - } \ - } - -// Assert that value contains given substring, add message to output on error -#define CPPUNIT_ASSERT_CONTAIN_MESSAGE(message, contained, value) \ - { \ - std::ostringstream cont; \ - cont << contained; \ - std::ostringstream val; \ - val << value; \ - std::string mess = message; \ - if (val.str().find(cont.str()) == std::string::npos) { \ - CPPUNIT_FAIL(mess + ": Value of '" + val.str() \ - + "' does not contain '" + cont.str() + "'."); \ - } \ - } - -// Assert that given expression matches the given regular expression. -#include <vespa/vespalib/util/regexp.h> -#define CPPUNIT_ASSERT_MATCH_REGEX(expression, value) \ - { \ - std::ostringstream _ost_; \ - _ost_ << value; \ - std::string _s_(_ost_.str()); \ - vespalib::Regexp _myregex_(expression); \ - if (!_myregex_.match(_s_)) { \ - CPPUNIT_FAIL("Value of '" + _s_ + "' does not match regex '" \ - + expression + "'."); \ - } \ - } - -// Assert that given expression matches the given regular expression. -#include <vespa/vespalib/util/regexp.h> -#define CPPUNIT_ASSERT_MATCH_REGEX_MSG(message, expression, value) \ - { \ - std::ostringstream _ost_; \ - _ost_ << value; \ - std::string _s_(_ost_.str()); \ - vespalib::Regexp _myregex_(expression); \ - std::string mess = message; \ - if (!_myregex_.match(_s_)) { \ - CPPUNIT_FAIL("Value of '" + _s_ + "' does not match regex '" \ - + expression + "'. Message: '" + mess + "'"); \ - } \ - } - -#define CPPUNIT_ASSERT_FILE_CONTAINS(expected, filename) \ - { \ - std::ostringstream value; \ - value << expected; \ - std::ostringstream ost; \ - std::string line; \ - std::ifstream input(filename); \ - while (std::getline(input, line, '\n')) { \ - ost << line << '\n'; \ - } \ - CPPUNIT_ASSERT_EQUAL(value.str(), ost.str()); \ - } - -#define CPPUNIT_ASSERT_SUBSTRING_COUNT(source, expectedCount, substring) \ - { \ - uint32_t count = 0; \ - std::ostringstream value; /* Let value be non-strings */ \ - value << source; \ - std::string s(value.str()); \ - std::string::size_type pos = s.find(substring); \ - while (pos != std::string::npos) { \ - ++count; \ - pos = s.find(substring, pos+1); \ - } \ - if (count != (uint32_t) expectedCount) { \ - std::ostringstream error; \ - error << "Value of '" << s << "' contained " << count \ - << " instances of substring '" << substring << "', not " \ - << expectedCount << " as expected."; \ - CPPUNIT_FAIL(error.str()); \ - } \ - } - -#include <ostream> -#include <map> -#include <unordered_map> -#include <vector> - -// Create output operator for containers. -// Needed so we can use CPPUNIT_ASSERT_EQUAL with them. - -template<typename S, typename T> -std::ostream& -operator<<(std::ostream& out, const std::unordered_map<S, T>& umap) -{ - out << "std::unordered_map(" << umap.size() << ") {"; - for (auto keyValue : umap) { - out << "\n " << keyValue.first << ": " << keyValue.second; - } - if (!umap.empty()) { - out << "\n"; - } - out << "}"; - return out; -} |