diff options
author | nkozlovskiy <nmk@ydb.tech> | 2023-05-24 17:11:30 +0300 |
---|---|---|
committer | nkozlovskiy <nmk@ydb.tech> | 2023-05-24 17:11:30 +0300 |
commit | 6fa2337893a12eba9eaffd7bc1490f2f6dd5bb96 (patch) | |
tree | 64245b756f1a315dc6b2fae48307368d64373ef3 | |
parent | 37bea40da40c70c43021ed1b178ed36005cf3da8 (diff) | |
download | ydb-6fa2337893a12eba9eaffd7bc1490f2f6dd5bb96.tar.gz |
add ability to use test filter list from file
для opensource YDB очень важно иметь возможность не запускать некоторые тесты. Сейчас это можно сделать через аргументы командой строки, но это для нас не удобно по причине того, что нам необходимо будет для включения/исключения теста запускать cmake, и конфиг для исключения тестов с CMake получается очень раздутый и не удобный.
я предлагаю добавить опцию и переменную окружения, в котором будет передаваться имя файла со списком enabled/disabled тестов.
-rw-r--r-- | library/cpp/testing/unittest/junit.cpp | 1 | ||||
-rw-r--r-- | library/cpp/testing/unittest/junit.h | 1 | ||||
-rw-r--r-- | library/cpp/testing/unittest/utmain.cpp | 31 |
3 files changed, 32 insertions, 1 deletions
diff --git a/library/cpp/testing/unittest/junit.cpp b/library/cpp/testing/unittest/junit.cpp index e4a400dad2..41e571d11f 100644 --- a/library/cpp/testing/unittest/junit.cpp +++ b/library/cpp/testing/unittest/junit.cpp @@ -24,6 +24,7 @@ namespace NUnitTest { extern const TString Y_UNITTEST_OUTPUT_CMDLINE_OPTION = "Y_UNITTEST_OUTPUT"; +extern const TString Y_UNITTEST_TEST_FILTER_OPTION = "Y_TEST_FILTER"; static bool IsAllowedInXml(wchar32 c) { // https://en.wikipedia.org/wiki/Valid_characters_in_XML diff --git a/library/cpp/testing/unittest/junit.h b/library/cpp/testing/unittest/junit.h index 05982a37c3..23cb68ee71 100644 --- a/library/cpp/testing/unittest/junit.h +++ b/library/cpp/testing/unittest/junit.h @@ -7,6 +7,7 @@ namespace NUnitTest { extern const TString Y_UNITTEST_OUTPUT_CMDLINE_OPTION; +extern const TString Y_UNITTEST_TEST_FILTER_OPTION; class TJUnitProcessor : public ITestSuiteProcessor { struct TFailure { diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index 9d52b89cd7..53797b23d2 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -274,6 +274,20 @@ public: } } + inline void FilterFromFile(TString filename) { + TString filterLine; + + TFileInput filtersStream(filename); + + while (filtersStream.ReadLine(filterLine)) { + if (filterLine.StartsWith("-")) { + Disable(filterLine.c_str() + 1); + } else if(filterLine.StartsWith("+")) { + Enable(filterLine.c_str() + 1); + } + } + } + inline void SetPrintBeforeSuite(bool print) { PrintBeforeSuite_ = print; } @@ -529,6 +543,7 @@ private: .SetLatency(1); PushDownEnvVar(&options, Y_UNITTEST_OUTPUT_CMDLINE_OPTION); + PushDownEnvVar(&options, Y_UNITTEST_TEST_FILTER_OPTION); PushDownEnvVar(&options, "TMPDIR"); TShellCommand cmd(AppName, args, options); @@ -677,7 +692,8 @@ static int DoUsage(const char* progname) { << " --print-times print wall clock duration of each test\n" << " --fork-tests run each test in a separate process\n" << " --trace-path path to the trace file to be generated\n" - << " --trace-path-append path to the trace file to be appended\n"; + << " --trace-path-append path to the trace file to be appended\n" + << " --test-filter path to the test filters ([+|-]test) file (" << Y_UNITTEST_TEST_FILTER_OPTION << ")\n"; return 0; } @@ -741,6 +757,15 @@ int NUnitTest::RunMain(int argc, char** argv) { bool isForked = false; std::vector<std::shared_ptr<ITestSuiteProcessor>> traceProcessors; + + // load filters from environment variable + TString filterFn = GetEnv(Y_UNITTEST_TEST_FILTER_OPTION); + if (!filterFn.empty()) { + processor.FilterFromFile(filterFn); + } + + + for (size_t i = 1; i < (size_t)argc; ++i) { const char* name = argv[i]; @@ -807,6 +832,10 @@ int NUnitTest::RunMain(int argc, char** argv) { traceProcessors.push_back(std::make_shared<TJUnitProcessor>(TString(fileName), argv[0])); } hasJUnitProcessor = true; + } else if (strcmp(name, "--test-filter") == 0) { + ++i; + TString filename(argv[i]); + processor.FilterFromFile(filename); } else if (TString(name).StartsWith("--")) { return DoUsage(argv[0]), 1; } else if (*name == '-') { |