aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/unittest
diff options
context:
space:
mode:
authorf0b0s <f0b0s@yandex-team.ru>2022-02-10 16:46:51 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:51 +0300
commitdeabc5260ac2e17b8f5152ee060bec1740613540 (patch)
treebc498b2fe3c447d13c2abea85b429fee8dd485ef /library/cpp/testing/unittest
parent2e6009493e74f88988b81f219b301f450331648d (diff)
downloadydb-deabc5260ac2e17b8f5152ee060bec1740613540.tar.gz
Restoring authorship annotation for <f0b0s@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/testing/unittest')
-rw-r--r--library/cpp/testing/unittest/registar.h28
-rw-r--r--library/cpp/testing/unittest/utmain.cpp74
2 files changed, 51 insertions, 51 deletions
diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h
index 44517a0092..e6f96c5dc2 100644
--- a/library/cpp/testing/unittest/registar.h
+++ b/library/cpp/testing/unittest/registar.h
@@ -136,13 +136,13 @@ namespace NUnitTest {
virtual bool CheckAccessTest(TString /*suite*/, const char* /*name*/);
virtual void Run(std::function<void()> f, const TString& /*suite*/, const char* /*name*/, bool /*forceFork*/);
-
- // This process is forked for current test
+
+ // This process is forked for current test
virtual bool GetIsForked() const;
- // --fork-tests is set (warning: this may be false, but never the less test will be forked if called inside UNIT_FORKED_TEST)
+ // --fork-tests is set (warning: this may be false, but never the less test will be forked if called inside UNIT_FORKED_TEST)
virtual bool GetForkTests() const;
-
+
private:
virtual void OnStart();
@@ -236,7 +236,7 @@ namespace NUnitTest {
void AfterTest();
bool GetIsForked() const;
-
+
bool GetForkTests() const;
ITestSuiteProcessor* Processor() const noexcept;
@@ -290,11 +290,11 @@ private: \
#endif
#define UNIT_TEST_CHECK_TEST_IS_DECLARED_ONLY_ONCE(F) \
- /* If you see this message - delete multiple UNIT_TEST(TestName) with same TestName. */ \
+ /* If you see this message - delete multiple UNIT_TEST(TestName) with same TestName. */ \
/* It's forbidden to declare same test twice because it breaks --fork-tests logic. */ \
int You_have_declared_test_##F##_multiple_times_This_is_forbidden; \
Y_UNUSED(You_have_declared_test_##F##_multiple_times_This_is_forbidden);
-
+
#define UNIT_TEST_RUN(F, FF, context) \
this->BeforeTest((#F)); \
{ \
@@ -306,7 +306,7 @@ private: \
}; \
this->TTestBase::Run(std::bind(&T##F##Caller::X, this, context), StaticName(), (#F), FF); \
}
-
+
#define UNIT_TEST_IMPL(F, FF) \
UNIT_TEST_CHECK_TEST_IS_DECLARED_ONLY_ONCE(F) { \
NUnitTest::TTestContext context(this->TTestBase::Processor()); \
@@ -325,10 +325,10 @@ private: \
} \
}
-#define UNIT_TEST(F) UNIT_TEST_IMPL(F, false)
-
-#define UNIT_FORKED_TEST(F) UNIT_TEST_IMPL(F, true)
+#define UNIT_TEST(F) UNIT_TEST_IMPL(F, false)
+#define UNIT_FORKED_TEST(F) UNIT_TEST_IMPL(F, true)
+
#define UNIT_TEST_EXCEPTION(F, E) \
/* main process with "--fork-tests" flag treats exceptions as errors - it's result of forked test run */ \
if (this->GetForkTests() && !this->GetIsForked()) { \
@@ -811,7 +811,7 @@ public: \
, ForceFork_(forceFork)
{
}
-
+
virtual ~TBaseTestCase() = default;
// Each test case is executed in 3 steps:
@@ -837,7 +837,7 @@ public: \
std::function<void(TTestContext&)> Body_;
bool ForceFork_;
};
-
+
using TBaseFixture = TBaseTestCase;
// Class for checking that code raises unittest failure
@@ -1014,7 +1014,7 @@ public: \
#define Y_UNIT_TEST(N) Y_UNIT_TEST_IMPL(N, false, TCurrentTestCase)
#define Y_UNIT_TEST_F(N, F) Y_UNIT_TEST_IMPL(N, false, F)
#define SIMPLE_UNIT_FORKED_TEST(N) Y_UNIT_TEST_IMPL(N, true, TCurrentTestCase)
-
+
#define Y_UNIT_TEST_SUITE_IMPLEMENTATION(N) \
namespace NTestSuite##N
diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp
index 305bc6b40f..122ff6d9ea 100644
--- a/library/cpp/testing/unittest/utmain.cpp
+++ b/library/cpp/testing/unittest/utmain.cpp
@@ -269,20 +269,20 @@ public:
inline void SetForkTests(bool val) {
ForkTests = val;
}
-
+
inline bool GetForkTests() const override {
return ForkTests;
}
-
+
inline void SetIsForked(bool val) {
IsForked = val;
SetIsTTY(IsForked || CalcIsTTY(stderr));
}
-
+
inline bool GetIsForked() const override {
return IsForked;
}
-
+
inline void SetLoop(bool loop) {
Loop = loop;
}
@@ -469,47 +469,47 @@ private:
TList<TString> args(1, "--is-forked-internal");
args.push_back(Sprintf("+%s::%s", suite.data(), name));
-
+
// stdin is ignored - unittest should not need them...
TShellCommand cmd(AppName, args,
TShellCommandOptions().SetUseShell(false).SetCloseAllFdsOnExec(true).SetAsync(false).SetLatency(1));
cmd.Run();
-
+
const TString& err = cmd.GetError();
const size_t msgIndex = err.find(ForkCorrectExitMsg);
-
+
// everything is printed by parent process except test's result output ("good" or "fail")
// which is printed by child. If there was no output - parent process prints default message.
ForkExitedCorrectly = msgIndex != TString::npos;
-
+
// TODO: stderr output is always printed after stdout
Cout.Write(cmd.GetOutput());
Cerr.Write(err.c_str(), Min(msgIndex, err.size()));
-
+
// do not use default case, so gcc will warn if new element in enum will be added
switch (cmd.GetStatus()) {
- case TShellCommand::SHELL_FINISHED: {
- // test could fail with zero status if it calls exit(0) in the middle.
- if (ForkExitedCorrectly)
- break;
+ case TShellCommand::SHELL_FINISHED: {
+ // test could fail with zero status if it calls exit(0) in the middle.
+ if (ForkExitedCorrectly)
+ break;
[[fallthrough]];
- }
- case TShellCommand::SHELL_ERROR: {
- ythrow yexception() << "Forked test failed";
- }
-
- case TShellCommand::SHELL_NONE: {
- ythrow yexception() << "Forked test finished with unknown status";
- }
- case TShellCommand::SHELL_RUNNING: {
+ }
+ case TShellCommand::SHELL_ERROR: {
+ ythrow yexception() << "Forked test failed";
+ }
+
+ case TShellCommand::SHELL_NONE: {
+ ythrow yexception() << "Forked test finished with unknown status";
+ }
+ case TShellCommand::SHELL_RUNNING: {
Y_VERIFY(false, "This can't happen, we used sync mode, it's a bug!");
- }
- case TShellCommand::SHELL_INTERNAL_ERROR: {
- ythrow yexception() << "Forked test failed with internal error: " << cmd.GetInternalError();
- }
- }
+ }
+ case TShellCommand::SHELL_INTERNAL_ERROR: {
+ ythrow yexception() << "Forked test failed with internal error: " << cmd.GetInternalError();
+ }
+ }
}
-
+
private:
bool PrintBeforeSuite_;
bool PrintBeforeTest_;
@@ -618,7 +618,7 @@ static int DoUsage(const char* progname) {
<< " --show-fails print a list of all failed tests at the end\n"
<< " --dont-show-fails do not print a list of all failed tests at the end\n"
<< " --continue-on-fail print a message and continue running test suite instead of break\n"
- << " --print-times print wall clock duration of each test\n"
+ << " --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";
@@ -664,7 +664,7 @@ int NUnitTest::RunMain(int argc, char** argv) {
NPlugin::OnStartMain(argc, argv);
Y_DEFER { NPlugin::OnStopMain(argc, argv); };
- TColoredProcessor processor(GetExecPath());
+ TColoredProcessor processor(GetExecPath());
IOutputStream* listStream = &Cout;
THolder<IOutputStream> listFile;
@@ -689,10 +689,10 @@ int NUnitTest::RunMain(int argc, char** argv) {
processor.SetPrintBeforeSuite(false);
} else if (strcmp(name, "--print-before-test=false") == 0) {
processor.SetPrintBeforeTest(false);
- } else if (strcmp(name, "--print-before-suite") == 0) {
- processor.SetPrintBeforeSuite(true);
- } else if (strcmp(name, "--print-before-test") == 0) {
- processor.SetPrintBeforeTest(true);
+ } else if (strcmp(name, "--print-before-suite") == 0) {
+ processor.SetPrintBeforeSuite(true);
+ } else if (strcmp(name, "--print-before-test") == 0) {
+ processor.SetPrintBeforeTest(true);
} else if (strcmp(name, "--show-fails") == 0) {
processor.SetShowFails(true);
} else if (strcmp(name, "--dont-show-fails") == 0) {
@@ -707,10 +707,10 @@ int NUnitTest::RunMain(int argc, char** argv) {
} else if (strcmp(name, "--to") == 0) {
++i;
processor.SetEnd(FromString<size_t>(argv[i]));
- } else if (strcmp(name, "--fork-tests") == 0) {
- processor.SetForkTests(true);
+ } else if (strcmp(name, "--fork-tests") == 0) {
+ processor.SetForkTests(true);
} else if (strcmp(name, "--is-forked-internal") == 0) {
- processor.SetIsForked(true);
+ processor.SetIsForked(true);
} else if (strcmp(name, "--loop") == 0) {
processor.SetLoop(true);
} else if (strcmp(name, "--trace-path") == 0) {