aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/unittest
diff options
context:
space:
mode:
authorVasily Gerasimov <UgnineSirdis@gmail.com>2022-02-10 16:49:10 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:10 +0300
commit1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/testing/unittest
parent6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff)
downloadydb-1eb755fbca92172a6aec2f57371b2b3a19dfab43.tar.gz
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/testing/unittest')
-rw-r--r--library/cpp/testing/unittest/plugin.cpp94
-rw-r--r--library/cpp/testing/unittest/plugin.h52
-rw-r--r--library/cpp/testing/unittest/registar.cpp104
-rw-r--r--library/cpp/testing/unittest/registar.h344
-rw-r--r--library/cpp/testing/unittest/registar_ut.cpp400
-rw-r--r--library/cpp/testing/unittest/tests_data.cpp46
-rw-r--r--library/cpp/testing/unittest/tests_data.h22
-rw-r--r--library/cpp/testing/unittest/ut/ya.make2
-rw-r--r--library/cpp/testing/unittest/utmain.cpp78
-rw-r--r--library/cpp/testing/unittest/ya.make10
10 files changed, 576 insertions, 576 deletions
diff --git a/library/cpp/testing/unittest/plugin.cpp b/library/cpp/testing/unittest/plugin.cpp
index fd80eb48ac..543112f7ac 100644
--- a/library/cpp/testing/unittest/plugin.cpp
+++ b/library/cpp/testing/unittest/plugin.cpp
@@ -1,50 +1,50 @@
-#include "plugin.h"
-
-#include <util/generic/singleton.h>
-#include <util/generic/vector.h>
-#include <util/generic/utility.h>
-
-namespace NUnitTest {
- namespace NPlugin {
- namespace {
- class TPlugins {
- public:
- void OnStartMain(int argc, char* argv[]) const {
- for (const auto& plugin : Plugins) {
- plugin->OnStartMain(argc, argv);
- }
- }
-
- void OnStopMain(int argc, char* argv[]) const {
- for (const auto& plugin : Plugins) {
- plugin->OnStopMain(argc, argv);
- }
- }
-
- void Register(TSimpleSharedPtr<IPlugin> plugin) {
- Plugins.emplace_back(std::move(plugin));
- }
-
- static TPlugins& Instance() {
- return *Singleton<TPlugins>();
- }
-
- private:
+#include "plugin.h"
+
+#include <util/generic/singleton.h>
+#include <util/generic/vector.h>
+#include <util/generic/utility.h>
+
+namespace NUnitTest {
+ namespace NPlugin {
+ namespace {
+ class TPlugins {
+ public:
+ void OnStartMain(int argc, char* argv[]) const {
+ for (const auto& plugin : Plugins) {
+ plugin->OnStartMain(argc, argv);
+ }
+ }
+
+ void OnStopMain(int argc, char* argv[]) const {
+ for (const auto& plugin : Plugins) {
+ plugin->OnStopMain(argc, argv);
+ }
+ }
+
+ void Register(TSimpleSharedPtr<IPlugin> plugin) {
+ Plugins.emplace_back(std::move(plugin));
+ }
+
+ static TPlugins& Instance() {
+ return *Singleton<TPlugins>();
+ }
+
+ private:
TVector<TSimpleSharedPtr<IPlugin>> Plugins;
- };
- } // anonymous namespace
-
- TPluginRegistrator::TPluginRegistrator(TSimpleSharedPtr<IPlugin> plugin) {
- TPlugins::Instance().Register(std::move(plugin));
- }
-
- void OnStartMain(int argc, char* argv[]) {
- TPlugins::Instance().OnStartMain(argc, argv);
- }
-
- void OnStopMain(int argc, char* argv[]) {
- TPlugins::Instance().OnStopMain(argc, argv);
- }
-
+ };
+ } // anonymous namespace
+
+ TPluginRegistrator::TPluginRegistrator(TSimpleSharedPtr<IPlugin> plugin) {
+ TPlugins::Instance().Register(std::move(plugin));
+ }
+
+ void OnStartMain(int argc, char* argv[]) {
+ TPlugins::Instance().OnStartMain(argc, argv);
+ }
+
+ void OnStopMain(int argc, char* argv[]) {
+ TPlugins::Instance().OnStopMain(argc, argv);
+ }
+
}
}
diff --git a/library/cpp/testing/unittest/plugin.h b/library/cpp/testing/unittest/plugin.h
index 7cce973c78..102f2c1469 100644
--- a/library/cpp/testing/unittest/plugin.h
+++ b/library/cpp/testing/unittest/plugin.h
@@ -1,29 +1,29 @@
-#pragma once
-
-#include <util/generic/ptr.h>
-
-namespace NUnitTest {
+#pragma once
+
+#include <util/generic/ptr.h>
+
+namespace NUnitTest {
// Plugins are deprecated, please use Y_TEST_HOOK_* from library/cpp/hook/hook.h
- namespace NPlugin {
- class IPlugin {
- public:
- virtual ~IPlugin() {
- }
-
- virtual void OnStartMain(int /*argc*/, char* /*argv*/ []) {
- }
-
- virtual void OnStopMain(int /*argc*/, char* /*argv*/ []) {
- }
- };
-
- void OnStartMain(int argc, char* argv[]);
- void OnStopMain(int argc, char* argv[]);
-
- class TPluginRegistrator {
- public:
- TPluginRegistrator(TSimpleSharedPtr<IPlugin> plugin);
- };
-
+ namespace NPlugin {
+ class IPlugin {
+ public:
+ virtual ~IPlugin() {
+ }
+
+ virtual void OnStartMain(int /*argc*/, char* /*argv*/ []) {
+ }
+
+ virtual void OnStopMain(int /*argc*/, char* /*argv*/ []) {
+ }
+ };
+
+ void OnStartMain(int argc, char* argv[]);
+ void OnStopMain(int argc, char* argv[]);
+
+ class TPluginRegistrator {
+ public:
+ TPluginRegistrator(TSimpleSharedPtr<IPlugin> plugin);
+ };
+
}
}
diff --git a/library/cpp/testing/unittest/registar.cpp b/library/cpp/testing/unittest/registar.cpp
index fea174a65e..3679b768ed 100644
--- a/library/cpp/testing/unittest/registar.cpp
+++ b/library/cpp/testing/unittest/registar.cpp
@@ -1,13 +1,13 @@
-#include "registar.h"
-
+#include "registar.h"
+
#include <library/cpp/diff/diff.h>
#include <library/cpp/colorizer/colors.h>
-#include <util/generic/bt_exception.h>
-#include <util/random/fast.h>
+#include <util/generic/bt_exception.h>
+#include <util/random/fast.h>
#include <util/string/printf.h>
-#include <util/system/backtrace.h>
-#include <util/system/guard.h>
+#include <util/system/backtrace.h>
+#include <util/system/guard.h>
#include <util/system/tls.h>
#include <util/system/error.h>
#include <util/string/cast.h>
@@ -32,46 +32,46 @@ Y_POD_STATIC_THREAD(bool)
UnittestThread;
Y_POD_STATIC_THREAD(NUnitTest::TTestBase*)
currentTest;
-::NUnitTest::TRaiseErrorHandler RaiseErrorHandler;
+::NUnitTest::TRaiseErrorHandler RaiseErrorHandler;
void ::NUnitTest::NPrivate::RaiseError(const char* what, const TString& msg, bool fatalFailure) {
Y_VERIFY(UnittestThread, "%s in non-unittest thread with message:\n%s", what, msg.data());
- Y_VERIFY(GetCurrentTest());
-
- if (RaiseErrorHandler) {
- RaiseErrorHandler(what, msg, fatalFailure);
- return;
- }
-
- // Default handler
- TBackTrace bt;
- bt.Capture();
+ Y_VERIFY(GetCurrentTest());
+
+ if (RaiseErrorHandler) {
+ RaiseErrorHandler(what, msg, fatalFailure);
+ return;
+ }
+
+ // Default handler
+ TBackTrace bt;
+ bt.Capture();
GetCurrentTest()->AddError(msg.data(), bt.PrintToString());
- if (::NUnitTest::ContinueOnFail || !fatalFailure) {
- return;
- }
+ if (::NUnitTest::ContinueOnFail || !fatalFailure) {
+ return;
+ }
throw TAssertException();
}
-void ::NUnitTest::SetRaiseErrorHandler(::NUnitTest::TRaiseErrorHandler handler) {
- Y_VERIFY(UnittestThread);
- RaiseErrorHandler = std::move(handler);
-}
-
+void ::NUnitTest::SetRaiseErrorHandler(::NUnitTest::TRaiseErrorHandler handler) {
+ Y_VERIFY(UnittestThread);
+ RaiseErrorHandler = std::move(handler);
+}
+
void ::NUnitTest::NPrivate::SetUnittestThread(bool unittestThread) {
Y_VERIFY(UnittestThread != unittestThread, "state check");
UnittestThread = unittestThread;
}
-void ::NUnitTest::NPrivate::SetCurrentTest(TTestBase* test) {
- Y_VERIFY(!test || !currentTest, "state check");
- currentTest = test;
-}
-
-NUnitTest::TTestBase* ::NUnitTest::NPrivate::GetCurrentTest() {
- return currentTest;
-}
-
+void ::NUnitTest::NPrivate::SetCurrentTest(TTestBase* test) {
+ Y_VERIFY(!test || !currentTest, "state check");
+ currentTest = test;
+}
+
+NUnitTest::TTestBase* ::NUnitTest::NPrivate::GetCurrentTest() {
+ return currentTest;
+}
+
struct TDiffColorizer {
NColorizer::TColors Colors;
bool Reverse = false;
@@ -321,12 +321,12 @@ void NUnitTest::TTestBase::AddError(const char* msg, TTestContext* context) {
AddError(msg, TString(), context);
}
-void NUnitTest::TTestBase::RunAfterTest(std::function<void()> f) {
- with_lock (AfterTestFunctionsLock_) {
- AfterTestFunctions_.emplace_back(std::move(f));
- }
-}
-
+void NUnitTest::TTestBase::RunAfterTest(std::function<void()> f) {
+ with_lock (AfterTestFunctionsLock_) {
+ AfterTestFunctions_.emplace_back(std::move(f));
+ }
+}
+
bool NUnitTest::TTestBase::CheckAccessTest(const char* test) {
return Processor()->CheckAccessTest(Name(), test);
}
@@ -376,18 +376,18 @@ void NUnitTest::TTestBase::BeforeTest() {
void NUnitTest::TTestBase::AfterTest() {
TearDown();
-
- TVector<std::function<void()>> afterTestFunctions;
- with_lock (AfterTestFunctionsLock_) {
- afterTestFunctions.swap(AfterTestFunctions_);
- }
-
- for (auto i = afterTestFunctions.rbegin(); i != afterTestFunctions.rend(); ++i) {
- std::function<void()>& f = *i;
- if (f) {
- f();
- }
- }
+
+ TVector<std::function<void()>> afterTestFunctions;
+ with_lock (AfterTestFunctionsLock_) {
+ afterTestFunctions.swap(AfterTestFunctions_);
+ }
+
+ for (auto i = afterTestFunctions.rbegin(); i != afterTestFunctions.rend(); ++i) {
+ std::function<void()>& f = *i;
+ if (f) {
+ f();
+ }
+ }
}
bool NUnitTest::TTestBase::GetIsForked() const {
diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h
index be38300e1e..44517a0092 100644
--- a/library/cpp/testing/unittest/registar.h
+++ b/library/cpp/testing/unittest/registar.h
@@ -2,41 +2,41 @@
#include <library/cpp/dbg_output/dump.h>
-#include <util/generic/bt_exception.h>
+#include <util/generic/bt_exception.h>
#include <util/generic/hash.h>
-#include <util/generic/intrlist.h>
+#include <util/generic/intrlist.h>
#include <util/generic/map.h>
#include <util/generic/ptr.h>
#include <util/generic/set.h>
#include <util/generic/typetraits.h>
#include <util/generic/vector.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/string/builder.h>
#include <util/string/cast.h>
#include <util/string/printf.h>
-#include <util/system/defaults.h>
+#include <util/system/defaults.h>
#include <util/system/type_name.h>
-#include <util/system/spinlock.h>
-#include <util/system/src_location.h>
-
+#include <util/system/spinlock.h>
+#include <util/system/src_location.h>
+
#include <util/system/rusage.h>
#include <cmath>
#include <cstdio>
-#include <functional>
-
+#include <functional>
+
extern bool CheckExceptionMessage(const char*, TString&);
namespace NUnitTest {
class TTestBase;
-
+
namespace NPrivate {
void RaiseError(const char* what, const TString& msg, bool fatalFailure);
void SetUnittestThread(bool);
- void SetCurrentTest(TTestBase*);
- TTestBase* GetCurrentTest();
+ void SetCurrentTest(TTestBase*);
+ TTestBase* GetCurrentTest();
}
extern bool ShouldColorizeDiff;
@@ -45,21 +45,21 @@ namespace NUnitTest {
TString GetFormatTag(const char* name);
TString GetResetTag();
- // Raise error handler
+ // Raise error handler
// Used for testing library/cpp/testing/unittest macroses
- // and unittest helpers.
- // For all other unittests standard handler is used
- using TRaiseErrorHandler = std::function<void(const char*, const TString&, bool)>;
-
- void SetRaiseErrorHandler(TRaiseErrorHandler handler);
-
- inline void ClearRaiseErrorHandler() {
- SetRaiseErrorHandler(TRaiseErrorHandler());
- }
-
- class TAssertException: public yexception {
- };
-
+ // and unittest helpers.
+ // For all other unittests standard handler is used
+ using TRaiseErrorHandler = std::function<void(const char*, const TString&, bool)>;
+
+ void SetRaiseErrorHandler(TRaiseErrorHandler handler);
+
+ inline void ClearRaiseErrorHandler() {
+ SetRaiseErrorHandler(TRaiseErrorHandler());
+ }
+
+ class TAssertException: public yexception {
+ };
+
class ITestSuiteProcessor;
struct TTestContext {
@@ -97,10 +97,10 @@ namespace NUnitTest {
TTestContext* Context;
};
- struct TFinish {
+ struct TFinish {
const TTest* test;
TTestContext* Context;
- bool Success;
+ bool Success;
};
ITestSuiteProcessor();
@@ -159,9 +159,9 @@ namespace NUnitTest {
virtual void OnBeforeTest(const TTest* /*test*/);
void AddTestError(const TTest& test);
-
+
void AddTestFinish(const TTest& test);
-
+
private:
TMap<TString, size_t> TestErrors_;
TMap<TString, size_t> CurTestErrors_;
@@ -203,11 +203,11 @@ namespace NUnitTest {
virtual void TearDown();
void AddError(const char* msg, const TString& backtrace = TString(), TTestContext* context = nullptr);
-
+
void AddError(const char* msg, TTestContext* context);
-
- void RunAfterTest(std::function<void()> f); // function like atexit to run after current unit test
-
+
+ void RunAfterTest(std::function<void()> f); // function like atexit to run after current unit test
+
protected:
bool CheckAccessTest(const char* test);
@@ -243,10 +243,10 @@ namespace NUnitTest {
private:
TTestFactory* Parent_;
- size_t TestErrors_;
- const char* CurrentSubtest_;
- TAdaptiveLock AfterTestFunctionsLock_;
- TVector<std::function<void()>> AfterTestFunctions_;
+ size_t TestErrors_;
+ const char* CurrentSubtest_;
+ TAdaptiveLock AfterTestFunctionsLock_;
+ TVector<std::function<void()>> AfterTestFunctions_;
};
#define UNIT_TEST_SUITE(N) \
@@ -304,8 +304,8 @@ private: \
thiz->F(); \
} \
}; \
- this->TTestBase::Run(std::bind(&T##F##Caller::X, this, context), StaticName(), (#F), FF); \
- }
+ 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) { \
@@ -336,20 +336,20 @@ private: \
/* forked process (or main without "--fork-tests") treats some exceptions as success - it's exception test! */ \
} else { \
NUnitTest::TTestContext context(this->TTestBase::Processor()); \
- if (this->CheckAccessTest((#F))) { \
- try { \
- UNIT_TEST_RUN(F, false, context) \
- this->AddError("exception expected", &context); \
- } catch (const ::NUnitTest::TAssertException&) { \
- } catch (const E& e) { \
+ if (this->CheckAccessTest((#F))) { \
+ try { \
+ UNIT_TEST_RUN(F, false, context) \
+ this->AddError("exception expected", &context); \
+ } catch (const ::NUnitTest::TAssertException&) { \
+ } catch (const E& e) { \
TString err; \
- if (!CheckExceptionMessage(e.what(), err)) \
- this->AddError(err.c_str(), &context); \
- } catch (const std::exception& e) { \
- this->AddError(e.what(), &context); \
- } catch (...) { \
- this->AddError("non-std exception!", &context); \
- } \
+ if (!CheckExceptionMessage(e.what(), err)) \
+ this->AddError(err.c_str(), &context); \
+ } catch (const std::exception& e) { \
+ this->AddError(e.what(), &context); \
+ } catch (...) { \
+ this->AddError("non-std exception!", &context); \
+ } \
this->Finish((#F), &context); \
} \
}
@@ -366,13 +366,13 @@ public: \
::NUnitTest::NPrivate::RaiseError(R, ::TStringBuilder() << R << " at " << __LOCATION__ << ", " << __PRETTY_FUNCTION__ << ": " << M, true); \
} while (false)
-#define UNIT_FAIL_NONFATAL_IMPL(R, M) \
- do { \
+#define UNIT_FAIL_NONFATAL_IMPL(R, M) \
+ do { \
::NUnitTest::NPrivate::RaiseError(R, ::TStringBuilder() << R << " at " << __LOCATION__ << ", " << __PRETTY_FUNCTION__ << ": " << M, false); \
- } while (false)
-
+ } while (false)
+
#define UNIT_FAIL(M) UNIT_FAIL_IMPL("forced failure", M)
-#define UNIT_FAIL_NONFATAL(M) UNIT_FAIL_NONFATAL_IMPL("forced failure", M)
+#define UNIT_FAIL_NONFATAL(M) UNIT_FAIL_NONFATAL_IMPL("forced failure", M)
//types
#define UNIT_ASSERT_TYPES_EQUAL(A, B) \
@@ -536,20 +536,20 @@ public: \
#define UNIT_ASSERT_GE(A, B) UNIT_ASSERT_GE_C(A, B, "")
-#define UNIT_CHECK_GENERATED_EXCEPTION_C(A, E, C) \
+#define UNIT_CHECK_GENERATED_EXCEPTION_C(A, E, C) \
do { \
- try { \
- (void)(A); \
- } catch (const ::NUnitTest::TAssertException&) { \
- throw; \
- } catch (const E&) { \
- break; \
- } \
- UNIT_ASSERT_C(0, "Exception hasn't been thrown, but it should have happened " << C); \
+ try { \
+ (void)(A); \
+ } catch (const ::NUnitTest::TAssertException&) { \
+ throw; \
+ } catch (const E&) { \
+ break; \
+ } \
+ UNIT_ASSERT_C(0, "Exception hasn't been thrown, but it should have happened " << C); \
} while (false)
-#define UNIT_CHECK_GENERATED_EXCEPTION(A, E) UNIT_CHECK_GENERATED_EXCEPTION_C(A, E, "")
-
+#define UNIT_CHECK_GENERATED_EXCEPTION(A, E) UNIT_CHECK_GENERATED_EXCEPTION_C(A, E, "")
+
#define UNIT_CHECK_GENERATED_NO_EXCEPTION_C(A, E, C) \
do { \
try { \
@@ -562,7 +562,7 @@ public: \
} while (false)
#define UNIT_CHECK_GENERATED_NO_EXCEPTION(A, E) UNIT_CHECK_GENERATED_NO_EXCEPTION_C(A, E, "and exception message is:\n" << CurrentExceptionMessage())
-
+
// Same as UNIT_ASSERT_EXCEPTION_SATISFIES but prints additional string C when nothing was thrown
#define UNIT_ASSERT_EXCEPTION_SATISFIES_C(A, E, pred, C) \
do { \
@@ -588,7 +588,7 @@ public: \
#A << " did not throw any exception" \
<< " (expected " << #E << ") " << C); \
} \
- } while (false)
+ } while (false)
// Assert that a specific exception is thrown and satisfies predicate pred(e), where e is the exception instance.
// Example:
@@ -618,15 +618,15 @@ public: \
} while (false)
// Assert that a specific exception is thrown and CurrentExceptionMessage() contains substr
-#define UNIT_ASSERT_EXCEPTION_CONTAINS(A, E, substr) \
- UNIT_ASSERT_EXCEPTION_CONTAINS_C(A, E, substr, "")
-
+#define UNIT_ASSERT_EXCEPTION_CONTAINS(A, E, substr) \
+ UNIT_ASSERT_EXCEPTION_CONTAINS_C(A, E, substr, "")
+
// Same as UNIT_ASSERT_EXCEPTION but prints additional string C when nothing was thrown
#define UNIT_ASSERT_EXCEPTION_C(A, E, C) UNIT_ASSERT_EXCEPTION_SATISFIES_C(A, E, [](const E&){ return true; }, C)
-
+
// Assert that a specific exception is thrown
-#define UNIT_ASSERT_EXCEPTION(A, E) UNIT_ASSERT_EXCEPTION_C(A, E, "")
-
+#define UNIT_ASSERT_EXCEPTION(A, E) UNIT_ASSERT_EXCEPTION_C(A, E, "")
+
#define UNIT_ASSERT_NO_EXCEPTION_RESULT_C(A, C) \
[&] () mutable -> decltype(A) { \
static_assert(!std::is_void_v<decltype(A)>); \
@@ -653,10 +653,10 @@ public: \
} catch (...) { \
UNIT_FAIL_IMPL("exception-free assertion failed", Sprintf("%s throws %s\nException message: %s", #A, (::TStringBuilder() << C).data(), CurrentExceptionMessage().data())); \
} \
- } while (false)
+ } while (false)
+
+#define UNIT_ASSERT_NO_EXCEPTION(A) UNIT_ASSERT_NO_EXCEPTION_C(A, "")
-#define UNIT_ASSERT_NO_EXCEPTION(A) UNIT_ASSERT_NO_EXCEPTION_C(A, "")
-
namespace NPrivate {
template <class T, class U, bool Integers>
struct TCompareValuesImpl {
@@ -719,7 +719,7 @@ public: \
} \
UNIT_FAIL_IMPL("assertion failed", failMsg); \
} \
- } while (false)
+ } while (false)
#define UNIT_ASSERT_VALUES_EQUAL_C(A, B, C) \
UNIT_ASSERT_VALUES_EQUAL_IMPL(A, B, C, true, "==", "!=")
@@ -730,28 +730,28 @@ public: \
#define UNIT_ASSERT_VALUES_EQUAL(A, B) UNIT_ASSERT_VALUES_EQUAL_C(A, B, "")
#define UNIT_ASSERT_VALUES_UNEQUAL(A, B) UNIT_ASSERT_VALUES_UNEQUAL_C(A, B, "")
-// Checks that test will fail while executing given expression
-// Macro for using in unitests for ut helpers
-#define UNIT_ASSERT_TEST_FAILS_C(A, C) \
- do { \
- ::NUnitTest::TUnitTestFailChecker checker; \
- try { \
- auto guard = checker.InvokeGuard(); \
- (void)(A); \
- } catch (...) { \
- UNIT_FAIL_IMPL("fail test assertion failure", \
- "code is expected to generate test failure, " \
- "but it throws exception with message: " \
+// Checks that test will fail while executing given expression
+// Macro for using in unitests for ut helpers
+#define UNIT_ASSERT_TEST_FAILS_C(A, C) \
+ do { \
+ ::NUnitTest::TUnitTestFailChecker checker; \
+ try { \
+ auto guard = checker.InvokeGuard(); \
+ (void)(A); \
+ } catch (...) { \
+ UNIT_FAIL_IMPL("fail test assertion failure", \
+ "code is expected to generate test failure, " \
+ "but it throws exception with message: " \
<< CurrentExceptionMessage()); \
- } \
- if (!checker.Failed()) { \
- UNIT_FAIL_IMPL("fail test assertion failure", \
- "code is expected to generate test failure"); \
- } \
- } while (false)
-
-#define UNIT_ASSERT_TEST_FAILS(A) UNIT_ASSERT_TEST_FAILS_C(A, "")
-
+ } \
+ if (!checker.Failed()) { \
+ UNIT_FAIL_IMPL("fail test assertion failure", \
+ "code is expected to generate test failure"); \
+ } \
+ } while (false)
+
+#define UNIT_ASSERT_TEST_FAILS(A) UNIT_ASSERT_TEST_FAILS_C(A, "")
+
#define UNIT_ADD_METRIC(name, value) ut_context.Metrics[name] = value
class TTestFactory {
@@ -840,77 +840,77 @@ public: \
using TBaseFixture = TBaseTestCase;
- // Class for checking that code raises unittest failure
- class TUnitTestFailChecker {
- public:
- struct TInvokeGuard {
- explicit TInvokeGuard(TUnitTestFailChecker& parent)
- : Parent(&parent)
- {
- Parent->SetHandler();
- }
-
+ // Class for checking that code raises unittest failure
+ class TUnitTestFailChecker {
+ public:
+ struct TInvokeGuard {
+ explicit TInvokeGuard(TUnitTestFailChecker& parent)
+ : Parent(&parent)
+ {
+ Parent->SetHandler();
+ }
+
TInvokeGuard(TInvokeGuard&& guard) noexcept
- : Parent(guard.Parent)
- {
- guard.Parent = nullptr;
- }
-
- ~TInvokeGuard() {
- if (Parent) {
- ClearRaiseErrorHandler();
- }
- }
-
- TUnitTestFailChecker* Parent;
- };
-
- TUnitTestFailChecker() = default;
- TUnitTestFailChecker(const TUnitTestFailChecker&) = delete;
- TUnitTestFailChecker(TUnitTestFailChecker&&) = delete;
-
- TInvokeGuard InvokeGuard() {
- return TInvokeGuard(*this);
- }
-
- const TString& What() const {
- return What_;
- }
-
- const TString& Msg() const {
- return Msg_;
- }
-
- bool FatalFailure() const {
- return FatalFailure_;
- }
-
- bool Failed() const {
- return Failed_;
- }
-
- private:
- void Handler(const char* what, const TString& msg, bool fatalFailure) {
- What_ = what;
- Msg_ = msg;
- FatalFailure_ = fatalFailure;
- Failed_ = true;
- }
-
- void SetHandler() {
- TRaiseErrorHandler handler = [this](const char* what, const TString& msg, bool fatalFailure) {
- Handler(what, msg, fatalFailure);
- };
- SetRaiseErrorHandler(std::move(handler));
- }
-
- private:
- TString What_;
- TString Msg_;
- bool FatalFailure_ = false;
- bool Failed_ = false;
- };
-
+ : Parent(guard.Parent)
+ {
+ guard.Parent = nullptr;
+ }
+
+ ~TInvokeGuard() {
+ if (Parent) {
+ ClearRaiseErrorHandler();
+ }
+ }
+
+ TUnitTestFailChecker* Parent;
+ };
+
+ TUnitTestFailChecker() = default;
+ TUnitTestFailChecker(const TUnitTestFailChecker&) = delete;
+ TUnitTestFailChecker(TUnitTestFailChecker&&) = delete;
+
+ TInvokeGuard InvokeGuard() {
+ return TInvokeGuard(*this);
+ }
+
+ const TString& What() const {
+ return What_;
+ }
+
+ const TString& Msg() const {
+ return Msg_;
+ }
+
+ bool FatalFailure() const {
+ return FatalFailure_;
+ }
+
+ bool Failed() const {
+ return Failed_;
+ }
+
+ private:
+ void Handler(const char* what, const TString& msg, bool fatalFailure) {
+ What_ = what;
+ Msg_ = msg;
+ FatalFailure_ = fatalFailure;
+ Failed_ = true;
+ }
+
+ void SetHandler() {
+ TRaiseErrorHandler handler = [this](const char* what, const TString& msg, bool fatalFailure) {
+ Handler(what, msg, fatalFailure);
+ };
+ SetRaiseErrorHandler(std::move(handler));
+ }
+
+ private:
+ TString What_;
+ TString Msg_;
+ bool FatalFailure_ = false;
+ bool Failed_ = false;
+ };
+
#define UNIT_TEST_SUITE_REGISTRATION(T) \
static const ::NUnitTest::TTestBaseFactory<T> Y_GENERATE_UNIQUE_ID(UTREG_);
diff --git a/library/cpp/testing/unittest/registar_ut.cpp b/library/cpp/testing/unittest/registar_ut.cpp
index 9442eb3d0a..1f36d53abb 100644
--- a/library/cpp/testing/unittest/registar_ut.cpp
+++ b/library/cpp/testing/unittest/registar_ut.cpp
@@ -1,132 +1,132 @@
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(TUnitTestMacroTest) {
Y_UNIT_TEST(Assert) {
- auto unitAssert = [] {
- UNIT_ASSERT(false);
- };
- UNIT_ASSERT_TEST_FAILS(unitAssert());
-
- UNIT_ASSERT(true);
- }
-
+ auto unitAssert = [] {
+ UNIT_ASSERT(false);
+ };
+ UNIT_ASSERT_TEST_FAILS(unitAssert());
+
+ UNIT_ASSERT(true);
+ }
+
Y_UNIT_TEST(TypesEqual) {
- auto typesEqual = [] {
- UNIT_ASSERT_TYPES_EQUAL(int, long);
- };
- UNIT_ASSERT_TEST_FAILS(typesEqual());
-
- UNIT_ASSERT_TYPES_EQUAL(TString, TString);
- }
-
+ auto typesEqual = [] {
+ UNIT_ASSERT_TYPES_EQUAL(int, long);
+ };
+ UNIT_ASSERT_TEST_FAILS(typesEqual());
+
+ UNIT_ASSERT_TYPES_EQUAL(TString, TString);
+ }
+
Y_UNIT_TEST(DoublesEqual) {
- auto doublesEqual = [](double d1, double d2, double precision) {
- UNIT_ASSERT_DOUBLES_EQUAL(d1, d2, precision);
- };
- UNIT_ASSERT_TEST_FAILS(doublesEqual(0.0, 0.5, 0.1));
- UNIT_ASSERT_TEST_FAILS(doublesEqual(0.1, -0.1, 0.1));
-
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, 0.01, 0.1);
- UNIT_ASSERT_DOUBLES_EQUAL(0.01, 0.0, 0.1);
+ auto doublesEqual = [](double d1, double d2, double precision) {
+ UNIT_ASSERT_DOUBLES_EQUAL(d1, d2, precision);
+ };
+ UNIT_ASSERT_TEST_FAILS(doublesEqual(0.0, 0.5, 0.1));
+ UNIT_ASSERT_TEST_FAILS(doublesEqual(0.1, -0.1, 0.1));
+
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, 0.01, 0.1);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.01, 0.0, 0.1);
constexpr auto nan = std::numeric_limits<double>::quiet_NaN();
UNIT_ASSERT_TEST_FAILS(doublesEqual(nan, 0.5, 0.1));
UNIT_ASSERT_TEST_FAILS(doublesEqual(0.5, nan, 0.1));
UNIT_ASSERT_DOUBLES_EQUAL(nan, nan, 0.1);
- }
-
+ }
+
Y_UNIT_TEST(StringsEqual) {
- auto stringsEqual = [](auto s1, auto s2) {
- UNIT_ASSERT_STRINGS_EQUAL(s1, s2);
- };
- UNIT_ASSERT_TEST_FAILS(stringsEqual("q", "w"));
- UNIT_ASSERT_TEST_FAILS(stringsEqual("q", TString("w")));
- UNIT_ASSERT_TEST_FAILS(stringsEqual(TString("q"), "w"));
- UNIT_ASSERT_TEST_FAILS(stringsEqual(TString("a"), TString("b")));
+ auto stringsEqual = [](auto s1, auto s2) {
+ UNIT_ASSERT_STRINGS_EQUAL(s1, s2);
+ };
+ UNIT_ASSERT_TEST_FAILS(stringsEqual("q", "w"));
+ UNIT_ASSERT_TEST_FAILS(stringsEqual("q", TString("w")));
+ UNIT_ASSERT_TEST_FAILS(stringsEqual(TString("q"), "w"));
+ UNIT_ASSERT_TEST_FAILS(stringsEqual(TString("a"), TString("b")));
UNIT_ASSERT_TEST_FAILS(stringsEqual(TString("a"), TStringBuf("b")));
UNIT_ASSERT_TEST_FAILS(stringsEqual("a", TStringBuf("b")));
UNIT_ASSERT_TEST_FAILS(stringsEqual(TStringBuf("a"), "b"));
-
- TString empty;
- TStringBuf emptyBuf;
- UNIT_ASSERT_STRINGS_EQUAL("", empty);
- UNIT_ASSERT_STRINGS_EQUAL(empty, emptyBuf);
- UNIT_ASSERT_STRINGS_EQUAL("", static_cast<const char*>(nullptr));
- }
-
+
+ TString empty;
+ TStringBuf emptyBuf;
+ UNIT_ASSERT_STRINGS_EQUAL("", empty);
+ UNIT_ASSERT_STRINGS_EQUAL(empty, emptyBuf);
+ UNIT_ASSERT_STRINGS_EQUAL("", static_cast<const char*>(nullptr));
+ }
+
Y_UNIT_TEST(StringContains) {
- auto stringContains = [](auto s, auto substr) {
- UNIT_ASSERT_STRING_CONTAINS(s, substr);
- };
- UNIT_ASSERT_TEST_FAILS(stringContains("", "a"));
- UNIT_ASSERT_TEST_FAILS(stringContains("lurkmore", "moar"));
-
- UNIT_ASSERT_STRING_CONTAINS("", "");
- UNIT_ASSERT_STRING_CONTAINS("a", "");
- UNIT_ASSERT_STRING_CONTAINS("failure", "fail");
- UNIT_ASSERT_STRING_CONTAINS("lurkmore", "more");
- }
-
+ auto stringContains = [](auto s, auto substr) {
+ UNIT_ASSERT_STRING_CONTAINS(s, substr);
+ };
+ UNIT_ASSERT_TEST_FAILS(stringContains("", "a"));
+ UNIT_ASSERT_TEST_FAILS(stringContains("lurkmore", "moar"));
+
+ UNIT_ASSERT_STRING_CONTAINS("", "");
+ UNIT_ASSERT_STRING_CONTAINS("a", "");
+ UNIT_ASSERT_STRING_CONTAINS("failure", "fail");
+ UNIT_ASSERT_STRING_CONTAINS("lurkmore", "more");
+ }
+
Y_UNIT_TEST(NoDiff) {
- auto noDiff = [](auto s1, auto s2) {
- UNIT_ASSERT_NO_DIFF(s1, s2);
- };
- UNIT_ASSERT_TEST_FAILS(noDiff("q", "w"));
- UNIT_ASSERT_TEST_FAILS(noDiff("q", ""));
-
- UNIT_ASSERT_NO_DIFF("", "");
- UNIT_ASSERT_NO_DIFF("a", "a");
- }
-
+ auto noDiff = [](auto s1, auto s2) {
+ UNIT_ASSERT_NO_DIFF(s1, s2);
+ };
+ UNIT_ASSERT_TEST_FAILS(noDiff("q", "w"));
+ UNIT_ASSERT_TEST_FAILS(noDiff("q", ""));
+
+ UNIT_ASSERT_NO_DIFF("", "");
+ UNIT_ASSERT_NO_DIFF("a", "a");
+ }
+
Y_UNIT_TEST(StringsUnequal) {
- auto stringsUnequal = [](auto s1, auto s2) {
- UNIT_ASSERT_STRINGS_UNEQUAL(s1, s2);
- };
- UNIT_ASSERT_TEST_FAILS(stringsUnequal("1", "1"));
- UNIT_ASSERT_TEST_FAILS(stringsUnequal("", ""));
- UNIT_ASSERT_TEST_FAILS(stringsUnequal("42", TString("42")));
- UNIT_ASSERT_TEST_FAILS(stringsUnequal(TString("4"), "4"));
+ auto stringsUnequal = [](auto s1, auto s2) {
+ UNIT_ASSERT_STRINGS_UNEQUAL(s1, s2);
+ };
+ UNIT_ASSERT_TEST_FAILS(stringsUnequal("1", "1"));
+ UNIT_ASSERT_TEST_FAILS(stringsUnequal("", ""));
+ UNIT_ASSERT_TEST_FAILS(stringsUnequal("42", TString("42")));
+ UNIT_ASSERT_TEST_FAILS(stringsUnequal(TString("4"), "4"));
UNIT_ASSERT_TEST_FAILS(stringsUnequal("d", TStringBuf("d")));
UNIT_ASSERT_TEST_FAILS(stringsUnequal(TStringBuf("yandex"), "yandex"));
UNIT_ASSERT_TEST_FAILS(stringsUnequal(TStringBuf("index"), TString("index")));
UNIT_ASSERT_TEST_FAILS(stringsUnequal(TString("diff"), TStringBuf("diff")));
-
- UNIT_ASSERT_STRINGS_UNEQUAL("1", "2");
- UNIT_ASSERT_STRINGS_UNEQUAL("", "3");
+
+ UNIT_ASSERT_STRINGS_UNEQUAL("1", "2");
+ UNIT_ASSERT_STRINGS_UNEQUAL("", "3");
UNIT_ASSERT_STRINGS_UNEQUAL("green", TStringBuf("red"));
UNIT_ASSERT_STRINGS_UNEQUAL(TStringBuf("solomon"), "golovan");
- UNIT_ASSERT_STRINGS_UNEQUAL("d", TString("f"));
- UNIT_ASSERT_STRINGS_UNEQUAL(TString("yandex"), "index");
+ UNIT_ASSERT_STRINGS_UNEQUAL("d", TString("f"));
+ UNIT_ASSERT_STRINGS_UNEQUAL(TString("yandex"), "index");
UNIT_ASSERT_STRINGS_UNEQUAL(TString("mail"), TStringBuf("yandex"));
UNIT_ASSERT_STRINGS_UNEQUAL(TStringBuf("C++"), TString("python"));
- }
-
+ }
+
Y_UNIT_TEST(Equal) {
- auto equal = [](auto v1, auto v2) {
- UNIT_ASSERT_EQUAL(v1, v2);
- };
- UNIT_ASSERT_TEST_FAILS(equal("1", TString("2")));
- UNIT_ASSERT_TEST_FAILS(equal(1, 2));
- UNIT_ASSERT_TEST_FAILS(equal(42ul, static_cast<unsigned short>(24)));
-
- UNIT_ASSERT_EQUAL("abc", TString("abc"));
- UNIT_ASSERT_EQUAL(12l, 12);
- UNIT_ASSERT_EQUAL(55, 55);
- }
-
+ auto equal = [](auto v1, auto v2) {
+ UNIT_ASSERT_EQUAL(v1, v2);
+ };
+ UNIT_ASSERT_TEST_FAILS(equal("1", TString("2")));
+ UNIT_ASSERT_TEST_FAILS(equal(1, 2));
+ UNIT_ASSERT_TEST_FAILS(equal(42ul, static_cast<unsigned short>(24)));
+
+ UNIT_ASSERT_EQUAL("abc", TString("abc"));
+ UNIT_ASSERT_EQUAL(12l, 12);
+ UNIT_ASSERT_EQUAL(55, 55);
+ }
+
Y_UNIT_TEST(Unequal) {
- auto unequal = [](auto v1, auto v2) {
- UNIT_ASSERT_UNEQUAL(v1, v2);
- };
- UNIT_ASSERT_TEST_FAILS(unequal("x", TString("x")));
- UNIT_ASSERT_TEST_FAILS(unequal(1, 1));
- UNIT_ASSERT_TEST_FAILS(unequal(static_cast<unsigned short>(42), 42ul));
-
- UNIT_ASSERT_UNEQUAL("abc", TString("cba"));
- UNIT_ASSERT_UNEQUAL(12l, 10);
- UNIT_ASSERT_UNEQUAL(33, 50);
- }
-
+ auto unequal = [](auto v1, auto v2) {
+ UNIT_ASSERT_UNEQUAL(v1, v2);
+ };
+ UNIT_ASSERT_TEST_FAILS(unequal("x", TString("x")));
+ UNIT_ASSERT_TEST_FAILS(unequal(1, 1));
+ UNIT_ASSERT_TEST_FAILS(unequal(static_cast<unsigned short>(42), 42ul));
+
+ UNIT_ASSERT_UNEQUAL("abc", TString("cba"));
+ UNIT_ASSERT_UNEQUAL(12l, 10);
+ UNIT_ASSERT_UNEQUAL(33, 50);
+ }
+
Y_UNIT_TEST(LessThan) {
auto lt = [](auto v1, auto v2) {
UNIT_ASSERT_LT(v1, v2);
@@ -236,45 +236,45 @@ Y_UNIT_TEST_SUITE(TUnitTestMacroTest) {
}
Y_UNIT_TEST(ValuesEqual) {
- auto valuesEqual = [](auto v1, auto v2) {
- UNIT_ASSERT_VALUES_EQUAL(v1, v2);
- };
- UNIT_ASSERT_TEST_FAILS(valuesEqual(1, 2));
- UNIT_ASSERT_TEST_FAILS(valuesEqual(1l, static_cast<short>(2)));
-
- UNIT_ASSERT_VALUES_EQUAL("yandex", TString("yandex"));
- UNIT_ASSERT_VALUES_EQUAL(1.0, 1.0);
- }
-
+ auto valuesEqual = [](auto v1, auto v2) {
+ UNIT_ASSERT_VALUES_EQUAL(v1, v2);
+ };
+ UNIT_ASSERT_TEST_FAILS(valuesEqual(1, 2));
+ UNIT_ASSERT_TEST_FAILS(valuesEqual(1l, static_cast<short>(2)));
+
+ UNIT_ASSERT_VALUES_EQUAL("yandex", TString("yandex"));
+ UNIT_ASSERT_VALUES_EQUAL(1.0, 1.0);
+ }
+
Y_UNIT_TEST(ValuesUnequal) {
- auto valuesUnequal = [](auto v1, auto v2) {
- UNIT_ASSERT_VALUES_UNEQUAL(v1, v2);
- };
- UNIT_ASSERT_TEST_FAILS(valuesUnequal(5, 5));
- UNIT_ASSERT_TEST_FAILS(valuesUnequal(static_cast<char>(5), 5l));
- TString test("test");
+ auto valuesUnequal = [](auto v1, auto v2) {
+ UNIT_ASSERT_VALUES_UNEQUAL(v1, v2);
+ };
+ UNIT_ASSERT_TEST_FAILS(valuesUnequal(5, 5));
+ UNIT_ASSERT_TEST_FAILS(valuesUnequal(static_cast<char>(5), 5l));
+ TString test("test");
UNIT_ASSERT_TEST_FAILS(valuesUnequal("test", test.data()));
-
- UNIT_ASSERT_VALUES_UNEQUAL("UNIT_ASSERT_VALUES_UNEQUAL", "UNIT_ASSERT_VALUES_EQUAL");
- UNIT_ASSERT_VALUES_UNEQUAL(1.0, 1.1);
- }
-
- class TTestException: public yexception {
- public:
- TTestException(const TString& text = "test exception", bool throwMe = true)
- : ThrowMe(throwMe)
- {
- *this << text;
- }
-
- virtual ~TTestException() = default;
-
- virtual void Throw() {
- if (ThrowMe) {
- throw *this;
- }
- }
-
+
+ UNIT_ASSERT_VALUES_UNEQUAL("UNIT_ASSERT_VALUES_UNEQUAL", "UNIT_ASSERT_VALUES_EQUAL");
+ UNIT_ASSERT_VALUES_UNEQUAL(1.0, 1.1);
+ }
+
+ class TTestException: public yexception {
+ public:
+ TTestException(const TString& text = "test exception", bool throwMe = true)
+ : ThrowMe(throwMe)
+ {
+ *this << text;
+ }
+
+ virtual ~TTestException() = default;
+
+ virtual void Throw() {
+ if (ThrowMe) {
+ throw *this;
+ }
+ }
+
std::string ThrowStr() {
if (ThrowMe) {
throw *this;
@@ -283,24 +283,24 @@ Y_UNIT_TEST_SUITE(TUnitTestMacroTest) {
return {};
}
- void AssertNoException() {
- UNIT_ASSERT_NO_EXCEPTION(Throw());
- }
-
+ void AssertNoException() {
+ UNIT_ASSERT_NO_EXCEPTION(Throw());
+ }
+
void AssertNoExceptionRet() {
const TString res = UNIT_ASSERT_NO_EXCEPTION_RESULT(ThrowStr());
}
- template <class TExpectedException>
- void AssertException() {
- UNIT_ASSERT_EXCEPTION(Throw(), TExpectedException);
- }
-
- template <class TExpectedException, class T>
- void AssertExceptionContains(const T& substr) {
- UNIT_ASSERT_EXCEPTION_CONTAINS(Throw(), TExpectedException, substr);
- }
-
+ template <class TExpectedException>
+ void AssertException() {
+ UNIT_ASSERT_EXCEPTION(Throw(), TExpectedException);
+ }
+
+ template <class TExpectedException, class T>
+ void AssertExceptionContains(const T& substr) {
+ UNIT_ASSERT_EXCEPTION_CONTAINS(Throw(), TExpectedException, substr);
+ }
+
template <class TExpectedException, class P>
void AssertExceptionSatisfies(const P& predicate) {
UNIT_ASSERT_EXCEPTION_SATISFIES(Throw(), TExpectedException, predicate);
@@ -310,58 +310,58 @@ Y_UNIT_TEST_SUITE(TUnitTestMacroTest) {
return 5; // just some value for predicate testing
}
- bool ThrowMe;
- };
-
- class TOtherTestException: public TTestException {
- public:
- using TTestException::TTestException;
-
- // Throws other type of exception
- void Throw() override {
- if (ThrowMe) {
- throw *this;
- }
- }
- };
-
+ bool ThrowMe;
+ };
+
+ class TOtherTestException: public TTestException {
+ public:
+ using TTestException::TTestException;
+
+ // Throws other type of exception
+ void Throw() override {
+ if (ThrowMe) {
+ throw *this;
+ }
+ }
+ };
+
Y_UNIT_TEST(Exception) {
- UNIT_ASSERT_TEST_FAILS(TTestException("", false).AssertException<TTestException>());
- UNIT_ASSERT_TEST_FAILS(TTestException().AssertException<TOtherTestException>());
-
- UNIT_ASSERT_EXCEPTION(TOtherTestException().Throw(), TTestException);
- UNIT_ASSERT_EXCEPTION(TTestException().Throw(), TTestException);
- }
-
+ UNIT_ASSERT_TEST_FAILS(TTestException("", false).AssertException<TTestException>());
+ UNIT_ASSERT_TEST_FAILS(TTestException().AssertException<TOtherTestException>());
+
+ UNIT_ASSERT_EXCEPTION(TOtherTestException().Throw(), TTestException);
+ UNIT_ASSERT_EXCEPTION(TTestException().Throw(), TTestException);
+ }
+
Y_UNIT_TEST(ExceptionAssertionContainsOtherExceptionMessage) {
- NUnitTest::TUnitTestFailChecker checker;
- {
- auto guard = checker.InvokeGuard();
- TTestException("custom exception message").AssertException<TOtherTestException>();
- }
- UNIT_ASSERT(checker.Failed());
- UNIT_ASSERT_STRING_CONTAINS(checker.Msg(), "custom exception message");
- }
-
+ NUnitTest::TUnitTestFailChecker checker;
+ {
+ auto guard = checker.InvokeGuard();
+ TTestException("custom exception message").AssertException<TOtherTestException>();
+ }
+ UNIT_ASSERT(checker.Failed());
+ UNIT_ASSERT_STRING_CONTAINS(checker.Msg(), "custom exception message");
+ }
+
Y_UNIT_TEST(NoException) {
- UNIT_ASSERT_TEST_FAILS(TTestException().AssertNoException());
+ UNIT_ASSERT_TEST_FAILS(TTestException().AssertNoException());
UNIT_ASSERT_TEST_FAILS(TTestException().AssertNoExceptionRet());
-
- UNIT_ASSERT_NO_EXCEPTION(TTestException("", false).Throw());
- }
-
+
+ UNIT_ASSERT_NO_EXCEPTION(TTestException("", false).Throw());
+ }
+
Y_UNIT_TEST(ExceptionContains) {
- UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TTestException>("cba"));
+ UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TTestException>("cba"));
UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TTestException>(TStringBuf("cba")));
- UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TTestException>(TString("cba")));
- UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TTestException>(TStringBuilder() << "cba"));
-
- UNIT_ASSERT_TEST_FAILS(TTestException("abc", false).AssertExceptionContains<TTestException>("bc"));
-
- UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TOtherTestException>("b"));
-
- UNIT_ASSERT_EXCEPTION_CONTAINS(TTestException("abc").Throw(), TTestException, "a");
- }
+ UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TTestException>(TString("cba")));
+ UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TTestException>(TStringBuilder() << "cba"));
+
+ UNIT_ASSERT_TEST_FAILS(TTestException("abc", false).AssertExceptionContains<TTestException>("bc"));
+
+ UNIT_ASSERT_TEST_FAILS(TTestException("abc").AssertExceptionContains<TOtherTestException>("b"));
+
+ UNIT_ASSERT_EXCEPTION_CONTAINS(TTestException("abc").Throw(), TTestException, "a");
+ }
Y_UNIT_TEST(ExceptionSatisfies) {
const auto goodPredicate = [](const TTestException& e) { return e.GetValue() == 5; };
@@ -370,4 +370,4 @@ Y_UNIT_TEST_SUITE(TUnitTestMacroTest) {
UNIT_ASSERT_TEST_FAILS(TTestException().AssertExceptionSatisfies<TTestException>(badPredicate));
UNIT_ASSERT_TEST_FAILS(TTestException().AssertExceptionSatisfies<TOtherTestException>(goodPredicate));
}
-}
+}
diff --git a/library/cpp/testing/unittest/tests_data.cpp b/library/cpp/testing/unittest/tests_data.cpp
index a131a54ddf..b51cbc4b87 100644
--- a/library/cpp/testing/unittest/tests_data.cpp
+++ b/library/cpp/testing/unittest/tests_data.cpp
@@ -1,5 +1,5 @@
#include "tests_data.h"
-#include "registar.h"
+#include "registar.h"
#include <library/cpp/testing/common/network.h>
@@ -35,10 +35,10 @@ public:
return GetPort(port);
}
- ui16 GetTcpAndUdpPort(ui16 port) {
+ ui16 GetTcpAndUdpPort(ui16 port) {
return GetPort(port);
- }
-
+ }
+
ui16 GetPortsRange(const ui16 startPort, const ui16 range) {
Y_UNUSED(startPort);
auto ports = NTesting::NLegacy::GetFreePortsRange(range);
@@ -54,16 +54,16 @@ public:
private:
void ReservePortForCurrentTest(const TAtomicSharedPtr<NTesting::IPort>& portGuard) {
if (EnableReservePortsForCurrentTest) {
- TTestBase* currentTest = NUnitTest::NPrivate::GetCurrentTest();
- if (currentTest != nullptr) {
- currentTest->RunAfterTest([guard = portGuard]() mutable {
- guard = nullptr; // remove reference for allocated port
- });
- }
- }
- }
-
-private:
+ TTestBase* currentTest = NUnitTest::NPrivate::GetCurrentTest();
+ if (currentTest != nullptr) {
+ currentTest->RunAfterTest([guard = portGuard]() mutable {
+ guard = nullptr; // remove reference for allocated port
+ });
+ }
+ }
+ }
+
+private:
TMutex Lock;
TVector<TAtomicSharedPtr<NTesting::IPort>> ReservedPorts;
const bool EnableReservePortsForCurrentTest;
@@ -81,18 +81,18 @@ TPortManager::~TPortManager() {
ui16 TPortManager::GetPort(ui16 port) {
return Impl_->GetTcpPort(port);
}
-
-ui16 TPortManager::GetTcpPort(ui16 port) {
+
+ui16 TPortManager::GetTcpPort(ui16 port) {
return Impl_->GetTcpPort(port);
-}
-
-ui16 TPortManager::GetUdpPort(ui16 port) {
+}
+
+ui16 TPortManager::GetUdpPort(ui16 port) {
return Impl_->GetUdpPort(port);
-}
-
-ui16 TPortManager::GetTcpAndUdpPort(ui16 port) {
+}
+
+ui16 TPortManager::GetTcpAndUdpPort(ui16 port) {
return Impl_->GetTcpAndUdpPort(port);
-}
+}
ui16 TPortManager::GetPortsRange(const ui16 startPort, const ui16 range) {
return Impl_->GetPortsRange(startPort, range);
diff --git a/library/cpp/testing/unittest/tests_data.h b/library/cpp/testing/unittest/tests_data.h
index fcc56520bd..6536bc1ae6 100644
--- a/library/cpp/testing/unittest/tests_data.h
+++ b/library/cpp/testing/unittest/tests_data.h
@@ -31,19 +31,19 @@ class TPortManager: public TNonCopyable {
public:
TPortManager(bool reservePortsForCurrentTest = true);
~TPortManager();
-
- // Gets free TCP port
+
+ // Gets free TCP port
ui16 GetPort(ui16 port = 0);
- // Gets free TCP port
- ui16 GetTcpPort(ui16 port = 0);
-
- // Gets free UDP port
- ui16 GetUdpPort(ui16 port = 0);
-
- // Gets one free port for use in both TCP and UDP protocols
- ui16 GetTcpAndUdpPort(ui16 port = 0);
-
+ // Gets free TCP port
+ ui16 GetTcpPort(ui16 port = 0);
+
+ // Gets free UDP port
+ ui16 GetUdpPort(ui16 port = 0);
+
+ // Gets one free port for use in both TCP and UDP protocols
+ ui16 GetTcpAndUdpPort(ui16 port = 0);
+
ui16 GetPortsRange(const ui16 startPort, const ui16 range);
private:
diff --git a/library/cpp/testing/unittest/ut/ya.make b/library/cpp/testing/unittest/ut/ya.make
index b5676b187c..6d4c0959cc 100644
--- a/library/cpp/testing/unittest/ut/ya.make
+++ b/library/cpp/testing/unittest/ut/ya.make
@@ -4,7 +4,7 @@ OWNER(snowball)
SRCS(
main.cpp
- registar_ut.cpp
+ registar_ut.cpp
)
END()
diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp
index b7e1259cab..305bc6b40f 100644
--- a/library/cpp/testing/unittest/utmain.cpp
+++ b/library/cpp/testing/unittest/utmain.cpp
@@ -1,4 +1,4 @@
-#include "plugin.h"
+#include "plugin.h"
#include "registar.h"
#include "utmain.h"
@@ -8,27 +8,27 @@
#include <library/cpp/json/writer/json_value.h>
#include <library/cpp/testing/common/env.h>
#include <library/cpp/testing/hook/hook.h>
-
-#include <util/datetime/base.h>
-
+
+#include <util/datetime/base.h>
+
#include <util/generic/hash.h>
-#include <util/generic/hash_set.h>
+#include <util/generic/hash_set.h>
#include <util/generic/scope.h>
#include <util/generic/string.h>
#include <util/generic/yexception.h>
-
+
#include <util/network/init.h>
-
+
#include <util/stream/file.h>
#include <util/stream/output.h>
#include <util/string/join.h>
-#include <util/string/util.h>
+#include <util/string/util.h>
+
+#include <util/system/defaults.h>
+#include <util/system/execpath.h>
+#include <util/system/valgrind.h>
+#include <util/system/shellcommand.h>
-#include <util/system/defaults.h>
-#include <util/system/execpath.h>
-#include <util/system/valgrind.h>
-#include <util/system/shellcommand.h>
-
#if defined(_win_)
#include <fcntl.h>
#include <io.h>
@@ -141,26 +141,26 @@ private:
void OnError(const TError* descr) override {
const TString comment = BuildComment(descr->msg, descr->BackTrace.data());
- ErrorMessages.push_back(comment);
- }
-
- void OnFinish(const TFinish* descr) override {
- if (descr->Success) {
+ ErrorMessages.push_back(comment);
+ }
+
+ void OnFinish(const TFinish* descr) override {
+ if (descr->Success) {
TraceSubtestFinished(descr->test->unit->name.data(), descr->test->name, "good", "", descr->Context);
- } else {
- TStringBuilder msgs;
+ } else {
+ TStringBuilder msgs;
for (const TString& m : ErrorMessages) {
- if (msgs) {
+ if (msgs) {
msgs << TStringBuf("\n");
- }
- msgs << m;
- }
- if (msgs) {
+ }
+ msgs << m;
+ }
+ if (msgs) {
msgs << TStringBuf("\n");
- }
+ }
TraceSubtestFinished(descr->test->unit->name.data(), descr->test->name, "fail", msgs, descr->Context);
- ErrorMessages.clear();
- }
+ ErrorMessages.clear();
+ }
}
};
@@ -364,8 +364,8 @@ private:
}
}
- void OnFinish(const TFinish* descr) override {
- TraceProcessor->Finish(*descr);
+ void OnFinish(const TFinish* descr) override {
+ TraceProcessor->Finish(*descr);
if (!IsForked && ForkExitedCorrectly) {
return;
}
@@ -373,15 +373,15 @@ private:
return;
}
- if (descr->Success) {
+ if (descr->Success) {
fprintf(stderr, "[%sgood%s] %s::%s\n", LightGreenColor().data(), OldColor().data(),
descr->test->unit->name.data(),
- descr->test->name);
- NOTE_IN_VALGRIND(descr->test);
+ descr->test->name);
+ NOTE_IN_VALGRIND(descr->test);
PrintTimes(SaveTestDuration());
- if (IsForked) {
- fprintf(stderr, "%s", ForkCorrectExitMsg);
- }
+ if (IsForked) {
+ fprintf(stderr, "%s", ForkCorrectExitMsg);
+ }
}
}
@@ -613,7 +613,7 @@ static int DoUsage(const char* progname) {
<< " -h, --help print this help message\n"
<< " -l, --list print a list of available tests\n"
<< " -A --list-verbose print a list of available subtests\n"
- << " --print-before-test print each test name before running it\n"
+ << " --print-before-test print each test name before running it\n"
<< " --print-before-suite print each test suite name before running it\n"
<< " --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"
@@ -661,9 +661,9 @@ int NUnitTest::RunMain(int argc, char** argv) {
NTesting::THook::CallBeforeRun();
Y_DEFER { NTesting::THook::CallAfterRun(); };
- NPlugin::OnStartMain(argc, argv);
+ NPlugin::OnStartMain(argc, argv);
Y_DEFER { NPlugin::OnStopMain(argc, argv); };
-
+
TColoredProcessor processor(GetExecPath());
IOutputStream* listStream = &Cout;
THolder<IOutputStream> listFile;
diff --git a/library/cpp/testing/unittest/ya.make b/library/cpp/testing/unittest/ya.make
index 93d23f396f..aaa4f2ba85 100644
--- a/library/cpp/testing/unittest/ya.make
+++ b/library/cpp/testing/unittest/ya.make
@@ -2,10 +2,10 @@ LIBRARY()
PROVIDES(test_framework)
-OWNER(
- pg
- galaxycrab
-)
+OWNER(
+ pg
+ galaxycrab
+)
PEERDIR(
library/cpp/colorizer
@@ -19,7 +19,7 @@ PEERDIR(
SRCS(
gtest.cpp
checks.cpp
- plugin.cpp
+ plugin.cpp
registar.cpp
tests_data.cpp
utmain.cpp