diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-03-17 11:33:07 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-03-17 11:33:07 +0300 |
commit | 4f4d932dd1fea2a03e04f3838ecd406224dde81b (patch) | |
tree | de0f78b4e86e8813b07ad8dbb2642e23be2ee87f /library/cpp/testing | |
parent | 8475dd9deb086f897d0899215377ee7667f7893e (diff) | |
download | ydb-4f4d932dd1fea2a03e04f3838ecd406224dde81b.tar.gz |
fix writing to junitxml set by an env var from a forked test
Diffstat (limited to 'library/cpp/testing')
-rw-r--r-- | library/cpp/testing/unittest/junit.cpp | 2 | ||||
-rw-r--r-- | library/cpp/testing/unittest/utmain.cpp | 30 |
2 files changed, 22 insertions, 10 deletions
diff --git a/library/cpp/testing/unittest/junit.cpp b/library/cpp/testing/unittest/junit.cpp index f5fe84a937..984f1ec5ea 100644 --- a/library/cpp/testing/unittest/junit.cpp +++ b/library/cpp/testing/unittest/junit.cpp @@ -50,7 +50,7 @@ void TJUnitProcessor::Save() { } } if (!lockFile.IsOpen()) { - Cerr << "Could not find a vacant file name to write report, maximum number of reports: " << MaxReps << Endl; + Cerr << "Could not find a vacant file name to write report for path " << path << ", maximum number of reports: " << MaxReps << Endl; Y_FAIL("Cannot write report"); } path = reportFileName; diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index 4e10da24e5..62968de3df 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -30,6 +30,8 @@ #include <util/system/valgrind.h> #include <util/system/shellcommand.h> +#include <filesystem> + #if defined(_win_) #include <fcntl.h> #include <io.h> @@ -669,15 +671,8 @@ int NUnitTest::RunMain(int argc, char** argv) { }; EListType listTests = DONT_LIST; - TString oo(getenv("Y_UNITTEST_OUTPUT")); - if (oo.StartsWith("xml:")) { - TStringBuf fileName = oo; - fileName = fileName.SubString(4, TStringBuf::npos); - processor.BeQuiet(); - NUnitTest::ShouldColorizeDiff = false; - processor.SetTraceProcessor(new TJUnitProcessor(TString(fileName), argv[0])); - } - + bool processorSet = false; + bool isForked = false; for (size_t i = 1; i < (size_t)argc; ++i) { const char* name = argv[i]; @@ -713,6 +708,7 @@ int NUnitTest::RunMain(int argc, char** argv) { processor.SetForkTests(true); } else if (strcmp(name, "--is-forked-internal") == 0) { processor.SetIsForked(true); + isForked = true; } else if (strcmp(name, "--loop") == 0) { processor.SetLoop(true); } else if (strcmp(name, "--trace-path") == 0) { @@ -720,11 +716,13 @@ int NUnitTest::RunMain(int argc, char** argv) { processor.BeQuiet(); NUnitTest::ShouldColorizeDiff = false; processor.SetTraceProcessor(new TTraceWriterProcessor(argv[i], CreateAlways)); + processorSet = true; } else if (strcmp(name, "--trace-path-append") == 0) { ++i; processor.BeQuiet(); NUnitTest::ShouldColorizeDiff = false; processor.SetTraceProcessor(new TTraceWriterProcessor(argv[i], OpenAlways | ForAppend)); + processorSet = true; } else if (strcmp(name, "--list-path") == 0) { ++i; listFile = MakeHolder<TFixedBufferFileOutput>(argv[i]); @@ -745,6 +743,7 @@ int NUnitTest::RunMain(int argc, char** argv) { NUnitTest::ShouldColorizeDiff = false; processor.SetTraceProcessor(new TJUnitProcessor(TString(fileName), argv[0])); } + processorSet = true; } else if (TString(name).StartsWith("--")) { return DoUsage(argv[0]), 1; } else if (*name == '-') { @@ -760,6 +759,19 @@ int NUnitTest::RunMain(int argc, char** argv) { return DoList(listTests == LIST_VERBOSE, *listStream); } + if (!processorSet && !isForked) { + TString oo(getenv("Y_UNITTEST_OUTPUT")); + if (oo.StartsWith("xml:")) { + TStringBuf fileName = oo; + fileName = fileName.SubString(4, TStringBuf::npos); + processor.BeQuiet(); + NUnitTest::ShouldColorizeDiff = false; + processor.SetTraceProcessor(new TJUnitProcessor(TString(fileName), + std::filesystem::path(argv[0]).stem().string())); + } + } + + TTestFactory::Instance().SetProcessor(&processor); unsigned ret; |