diff options
author | Yuri Gorshenin <y@maps.me> | 2015-02-04 18:44:37 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:37:08 +0300 |
commit | 8def34ee82187d504828ebc9595e8f9fb691257e (patch) | |
tree | d38f11d9e5bf9a1b93772222bd5996802f9a31dd /testing | |
parent | c4cdb670d4ce1db298bf2ca0190749b7cc6a7ce7 (diff) |
[testing] Added regexp-based filter for tests.
When --filter=regex option is specified, only tests corresponding to regex are run.
For example, following command will run only tests from bookmarks_test.cpp file:
$ out/release/map_tests --filter=bookmarks_test.cpp::.*
Diffstat (limited to 'testing')
-rw-r--r-- | testing/testingmain.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/testing/testingmain.cpp b/testing/testingmain.cpp index dda353a36e..58c3d6032d 100644 --- a/testing/testingmain.cpp +++ b/testing/testingmain.cpp @@ -2,6 +2,8 @@ #include "testing.hpp" #include "../base/logging.hpp" +#include "../base/string_utils.hpp" +#include "../base/regexp.hpp" #include "../std/iostream.hpp" #include "../std/string.hpp" @@ -43,6 +45,20 @@ int main(int argc, char * argv[]) vector<bool> testResults; int numFailedTests = 0; + char const filterOptionPrefix[] = "--filter="; + char const * testsFilter = nullptr; + + regexp::RegExpT testsFilterRegExp; + + for (int arg = 1; arg < argc; ++arg) + { + if (strings::StartsWith(argv[arg], filterOptionPrefix)) + testsFilter = argv[arg] + sizeof(filterOptionPrefix) - 1; + } + + if (testsFilter) + regexp::Create(testsFilter, testsFilterRegExp); + for (TestRegister * pTest = TestRegister::FirstRegister(); pTest; pTest = pTest->m_pNext) { string fileName(pTest->m_FileName); @@ -63,6 +79,8 @@ int main(int argc, char * argv[]) int iTest = 0; for (TestRegister * pTest = TestRegister::FirstRegister(); pTest; ++iTest, pTest = pTest->m_pNext) { + if (testsFilter && !regexp::Matches(testNames[iTest], testsFilterRegExp)) + continue; cerr << "Running " << testNames[iTest] << endl << flush; if (!g_bLastTestOK) { |