aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/unittest/junit.h
diff options
context:
space:
mode:
authorgalaxycrab <UgnineSirdis@ydb.tech>2023-08-04 13:13:41 +0300
committergalaxycrab <UgnineSirdis@ydb.tech>2023-08-04 14:42:46 +0300
commit0378da6ac1a3be2823cd3031fbf0ae403d962995 (patch)
treebb4a84db2196119cf270670b446c875e7a4d0e50 /library/cpp/testing/unittest/junit.h
parentcf273f7a9b5bb6d23c1f3c8ab236a4af1f511724 (diff)
downloadydb-0378da6ac1a3be2823cd3031fbf0ae403d962995.tar.gz
KIKIMR-18702 JUnit tests. Save captured test output even when abort happened
Diffstat (limited to 'library/cpp/testing/unittest/junit.h')
-rw-r--r--library/cpp/testing/unittest/junit.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/library/cpp/testing/unittest/junit.h b/library/cpp/testing/unittest/junit.h
index 1797055877..27b73013ca 100644
--- a/library/cpp/testing/unittest/junit.h
+++ b/library/cpp/testing/unittest/junit.h
@@ -4,6 +4,8 @@
#include <util/generic/maybe.h>
#include <util/system/tempfile.h>
+#include <optional>
+
namespace NUnitTest {
extern const TString Y_UNITTEST_OUTPUT_CMDLINE_OPTION;
@@ -52,6 +54,26 @@ class TJUnitProcessor : public ITestSuiteProcessor {
}
};
+ // Holds a copy of TTest structure for current test
+ class TCurrentTest {
+ public:
+ TCurrentTest(const TTest* test)
+ : TestName(test->name)
+ , Unit(*test->unit)
+ , Test{&Unit, TestName.c_str()}
+ {
+ }
+
+ operator const TTest*() const {
+ return &Test;
+ }
+
+ private:
+ TString TestName;
+ TUnit Unit;
+ TTest Test;
+ };
+
struct TOutputCapturer;
public:
@@ -96,6 +118,10 @@ private:
void MakeTmpFileNameForForkedTests();
static void TransferFromCapturer(THolder<TJUnitProcessor::TOutputCapturer>& capturer, TString& out, IOutputStream& outStream);
+ static void CaptureSignal(TJUnitProcessor* processor);
+ static void UncaptureSignal();
+ static void SignalHandler(int signal);
+
private:
const TString FileName; // cmd line param
const TString ExecName; // cmd line param
@@ -105,6 +131,9 @@ private:
THolder<TOutputCapturer> StdErrCapturer;
THolder<TOutputCapturer> StdOutCapturer;
TInstant StartCurrentTestTime;
+ void (*PrevAbortHandler)(int) = nullptr;
+ void (*PrevSegvHandler)(int) = nullptr;
+ std::optional<TCurrentTest> CurrentTest;
};
} // namespace NUnitTest