diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:25 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:25 +0300 |
commit | 344ea37b4a345701ab0e67de2266a1c1bd7baf2d (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library/cpp/testing/unittest | |
parent | 706b83ed7de5a473436620367af31fc0ceecde07 (diff) | |
download | ydb-344ea37b4a345701ab0e67de2266a1c1bd7baf2d.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/testing/unittest')
-rw-r--r-- | library/cpp/testing/unittest/checks.cpp | 4 | ||||
-rw-r--r-- | library/cpp/testing/unittest/gtest.cpp | 14 | ||||
-rw-r--r-- | library/cpp/testing/unittest/gtest.h | 4 | ||||
-rw-r--r-- | library/cpp/testing/unittest/plugin.cpp | 2 | ||||
-rw-r--r-- | library/cpp/testing/unittest/registar.cpp | 22 | ||||
-rw-r--r-- | library/cpp/testing/unittest/registar.h | 36 | ||||
-rw-r--r-- | library/cpp/testing/unittest/tests_data.h | 2 | ||||
-rw-r--r-- | library/cpp/testing/unittest/utmain.cpp | 76 |
8 files changed, 80 insertions, 80 deletions
diff --git a/library/cpp/testing/unittest/checks.cpp b/library/cpp/testing/unittest/checks.cpp index 0f4b3dae9d..c5712ae9d2 100644 --- a/library/cpp/testing/unittest/checks.cpp +++ b/library/cpp/testing/unittest/checks.cpp @@ -1,7 +1,7 @@ #include <util/generic/string.h> #include <util/string/type.h> -bool CheckExceptionMessage(const char* msg, TString& err) { +bool CheckExceptionMessage(const char* msg, TString& err) { static const char* badMsg[] = { // Операция успешно завершена [cp1251] "\xce\xef\xe5\xf0\xe0\xf6\xe8\xff\x20\xf3\xf1\xef\xe5\xf8\xed\xee\x20\xe7\xe0\xe2\xe5\xf0\xf8\xe5\xed\xe0", @@ -22,7 +22,7 @@ bool CheckExceptionMessage(const char* msg, TString& err) { for (auto& i : badMsg) { if (strstr(msg, i) != nullptr) { - err = "Invalid error message: " + TString(msg); + err = "Invalid error message: " + TString(msg); return false; } } diff --git a/library/cpp/testing/unittest/gtest.cpp b/library/cpp/testing/unittest/gtest.cpp index 6aded3e085..ebad1ea4d6 100644 --- a/library/cpp/testing/unittest/gtest.cpp +++ b/library/cpp/testing/unittest/gtest.cpp @@ -8,7 +8,7 @@ using namespace NUnitTest; using namespace NUnitTest::NPrivate; -IGTestFactory::~IGTestFactory() { +IGTestFactory::~IGTestFactory() { } namespace { @@ -18,12 +18,12 @@ namespace { { } - TString TypeId() const override { + TString TypeId() const override { return TypeName(*this) + "-" + MyName; } - TString Name() const noexcept override { - return TString(MyName); + TString Name() const noexcept override { + return TString(MyName); } const TStringBuf MyName; @@ -35,10 +35,10 @@ namespace { { } - ~TGTestFactory() override { + ~TGTestFactory() override { } - TString Name() const noexcept override { + TString Name() const noexcept override { return Test.Name(); } @@ -55,7 +55,7 @@ namespace { } IGTestFactory* NUnitTest::NPrivate::ByName(const char* name) { - static TMap<TStringBuf, TAutoPtr<TGTestFactory>> tests; + static TMap<TStringBuf, TAutoPtr<TGTestFactory>> tests; auto& ret = tests[name]; diff --git a/library/cpp/testing/unittest/gtest.h b/library/cpp/testing/unittest/gtest.h index 15e71cc495..b6768b1bf0 100644 --- a/library/cpp/testing/unittest/gtest.h +++ b/library/cpp/testing/unittest/gtest.h @@ -13,7 +13,7 @@ namespace NUnitTest { namespace NPrivate { struct IGTestFactory: public ITestBaseFactory { - ~IGTestFactory() override; + ~IGTestFactory() override; virtual void AddTest(const char* name, void (*body)(TTestContext&), bool forceFork) = 0; }; @@ -30,7 +30,7 @@ namespace NTesting { virtual void TearDown() { } - inline TTest* _This() noexcept { + inline TTest* _This() noexcept { return this; } }; diff --git a/library/cpp/testing/unittest/plugin.cpp b/library/cpp/testing/unittest/plugin.cpp index 194de77254..543112f7ac 100644 --- a/library/cpp/testing/unittest/plugin.cpp +++ b/library/cpp/testing/unittest/plugin.cpp @@ -30,7 +30,7 @@ namespace NUnitTest { } private: - TVector<TSimpleSharedPtr<IPlugin>> Plugins; + TVector<TSimpleSharedPtr<IPlugin>> Plugins; }; } // anonymous namespace diff --git a/library/cpp/testing/unittest/registar.cpp b/library/cpp/testing/unittest/registar.cpp index 9b75850e97..3679b768ed 100644 --- a/library/cpp/testing/unittest/registar.cpp +++ b/library/cpp/testing/unittest/registar.cpp @@ -15,9 +15,9 @@ bool NUnitTest::ShouldColorizeDiff = true; bool NUnitTest::ContinueOnFail = false; -TString NUnitTest::RandomString(size_t len, ui32 seed) { +TString NUnitTest::RandomString(size_t len, ui32 seed) { TReallyFastRng32 rand(seed); - TString ret; + TString ret; ret.reserve(len); @@ -34,7 +34,7 @@ Y_POD_STATIC_THREAD(NUnitTest::TTestBase*) currentTest; ::NUnitTest::TRaiseErrorHandler RaiseErrorHandler; -void ::NUnitTest::NPrivate::RaiseError(const char* what, const TString& msg, bool fatalFailure) { +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()); @@ -119,7 +119,7 @@ struct TTraceDiffFormatter { } TString Common(TArrayRef<const char> str) const { - return TString(str.begin(), str.end()); + return TString(str.begin(), str.end()); } TString Left(TArrayRef<const char> str) const { @@ -135,17 +135,17 @@ struct TTraceDiffFormatter { } }; -TString NUnitTest::GetFormatTag(const char* name) { +TString NUnitTest::GetFormatTag(const char* name) { return Sprintf("[[%s]]", name); } -TString NUnitTest::GetResetTag() { - return TString("[[rst]]"); +TString NUnitTest::GetResetTag() { + return TString("[[rst]]"); } -TString NUnitTest::ColoredDiff(TStringBuf s1, TStringBuf s2, const TString& delims, bool reverse) { +TString NUnitTest::ColoredDiff(TStringBuf s1, TStringBuf s2, const TString& delims, bool reverse) { TStringStream res; - TVector<NDiff::TChunk<char>> chunks; + TVector<NDiff::TChunk<char>> chunks; NDiff::InlineDiff(chunks, s1, s2, delims); if (NUnitTest::ShouldColorizeDiff) { NDiff::PrintChunks(res, TDiffColorizer(reverse), chunks); @@ -160,7 +160,7 @@ static TString MakeTestName(const NUnitTest::ITestSuiteProcessor::TTest& test) { return TStringBuilder() << test.unit->name << "::" << test.name; } -static size_t CountTests(const TMap<TString, size_t>& testErrors, bool succeeded) { +static size_t CountTests(const TMap<TString, size_t>& testErrors, bool succeeded) { size_t cnt = 0; for (const auto& t : testErrors) { if (succeeded && t.second == 0) { @@ -465,7 +465,7 @@ unsigned NUnitTest::TTestFactory::Execute() { Items_.QuickSort(TCmp()); Processor_->Start(); - TSet<TString> types; + TSet<TString> types; size_t cnt = 0; for (TIntrusiveList<ITestBaseFactory>::TIterator factory = Items_.Begin(); factory != Items_.End(); ++factory) { diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index a02b5ffe90..44517a0092 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -27,13 +27,13 @@ #include <cstdio> #include <functional> -extern bool CheckExceptionMessage(const char*, TString&); +extern bool CheckExceptionMessage(const char*, TString&); namespace NUnitTest { class TTestBase; namespace NPrivate { - void RaiseError(const char* what, const TString& msg, bool fatalFailure); + void RaiseError(const char* what, const TString& msg, bool fatalFailure); void SetUnittestThread(bool); void SetCurrentTest(TTestBase*); TTestBase* GetCurrentTest(); @@ -41,9 +41,9 @@ namespace NUnitTest { extern bool ShouldColorizeDiff; extern bool ContinueOnFail; - TString ColoredDiff(TStringBuf s1, TStringBuf s2, const TString& delims = TString(), bool reverse = false); - TString GetFormatTag(const char* name); - TString GetResetTag(); + TString ColoredDiff(TStringBuf s1, TStringBuf s2, const TString& delims = TString(), bool reverse = false); + TString GetFormatTag(const char* name); + TString GetResetTag(); // Raise error handler // Used for testing library/cpp/testing/unittest macroses @@ -73,7 +73,7 @@ namespace NUnitTest { { } - using TMetrics = THashMap<TString, double>; + using TMetrics = THashMap<TString, double>; TMetrics Metrics; ITestSuiteProcessor* Processor; @@ -82,7 +82,7 @@ namespace NUnitTest { class ITestSuiteProcessor { public: struct TUnit { - const TString name; + const TString name; }; struct TTest { @@ -93,7 +93,7 @@ namespace NUnitTest { struct TError { const TTest* test; const char* msg; - TString BackTrace; + TString BackTrace; TTestContext* Context; }; @@ -163,8 +163,8 @@ namespace NUnitTest { void AddTestFinish(const TTest& test); private: - TMap<TString, size_t> TestErrors_; - TMap<TString, size_t> CurTestErrors_; + TMap<TString, size_t> TestErrors_; + TMap<TString, size_t> CurTestErrors_; }; class TTestBase; @@ -177,7 +177,7 @@ namespace NUnitTest { virtual ~ITestBaseFactory(); // name of test suite - virtual TString Name() const noexcept = 0; + virtual TString Name() const noexcept = 0; virtual TTestBase* ConstructTest() = 0; private: @@ -195,7 +195,7 @@ namespace NUnitTest { virtual TString TypeId() const; - virtual TString Name() const noexcept = 0; + virtual TString Name() const noexcept = 0; virtual void Execute() = 0; virtual void SetUp(); @@ -431,7 +431,7 @@ public: \ const TString _b(B); \ if (_a != _b) { \ auto&& failMsg = Sprintf("%s != %s %s", ToString(_a).data(), ToString(_b).data(), (::TStringBuilder() << C).data()); \ - UNIT_FAIL_IMPL("strings equal assertion failed", failMsg); \ + UNIT_FAIL_IMPL("strings equal assertion failed", failMsg); \ } \ } while (false) @@ -686,7 +686,7 @@ public: \ // helper method to avoid double evaluation of A and B expressions in UNIT_ASSERT_VALUES_EQUAL_C template <typename T, typename U> - static inline bool CompareAndMakeStrings(const T& a, const U& b, TString& as, TString& asInd, TString& bs, TString& bsInd, bool& usePlainDiff, bool want) { + static inline bool CompareAndMakeStrings(const T& a, const U& b, TString& as, TString& asInd, TString& bs, TString& bsInd, bool& usePlainDiff, bool want) { const bool have = CompareEqual(a, b); usePlainDiff = std::is_integral<T>::value && std::is_integral<U>::value; @@ -714,10 +714,10 @@ public: \ if (!::NUnitTest::NPrivate::CompareAndMakeStrings(A, B, _as, _asInd, _bs, _bsInd, _usePlainDiff, EQflag)) { \ auto&& failMsg = Sprintf("(%s %s %s) failed: (%s %s %s) %s", #A, EQstr, #B, _as.data(), NEQstr, _bs.data(), (::TStringBuilder() << C).data()); \ if (EQflag && !_usePlainDiff) { \ - failMsg += ", with diff:\n"; \ - failMsg += ::NUnitTest::ColoredDiff(_asInd, _bsInd); \ + failMsg += ", with diff:\n"; \ + failMsg += ::NUnitTest::ColoredDiff(_asInd, _bsInd); \ } \ - UNIT_FAIL_IMPL("assertion failed", failMsg); \ + UNIT_FAIL_IMPL("assertion failed", failMsg); \ } \ } while (false) @@ -1024,7 +1024,7 @@ public: \ #define Y_UNIT_TEST_FRIEND(N, T) \ friend NTestSuite##N::TTestCase##T \ - TString RandomString(size_t len, ui32 seed = 0); + TString RandomString(size_t len, ui32 seed = 0); } using ::NUnitTest::TTestBase; diff --git a/library/cpp/testing/unittest/tests_data.h b/library/cpp/testing/unittest/tests_data.h index 14ea88eb7c..6536bc1ae6 100644 --- a/library/cpp/testing/unittest/tests_data.h +++ b/library/cpp/testing/unittest/tests_data.h @@ -4,7 +4,7 @@ #include <util/generic/noncopyable.h> #include <util/generic/ptr.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/network/sock.h> class TInet6StreamSocket; diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index b2e9d67690..305bc6b40f 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -14,7 +14,7 @@ #include <util/generic/hash.h> #include <util/generic/hash_set.h> #include <util/generic/scope.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/yexception.h> #include <util/network/init.h> @@ -58,16 +58,16 @@ public: inline TTraceWriterProcessor(const char* traceFilePath, EOpenMode mode) : PrevTime(TInstant::Now()) { - TraceFile = new TUnbufferedFileOutput(TFile(traceFilePath, mode | WrOnly | Seq)); + TraceFile = new TUnbufferedFileOutput(TFile(traceFilePath, mode | WrOnly | Seq)); } private: - TAutoPtr<TUnbufferedFileOutput> TraceFile; - TString TraceFilePath; + TAutoPtr<TUnbufferedFileOutput> TraceFile; + TString TraceFilePath; TInstant PrevTime; - TVector<TString> ErrorMessages; + TVector<TString> ErrorMessages; - inline void Trace(const TString eventName, const NJson::TJsonValue eventValue) { + inline void Trace(const TString eventName, const NJson::TJsonValue eventValue) { NJsonWriter::TBuf json(NJsonWriter::HEM_UNSAFE); json.BeginObject(); @@ -81,7 +81,7 @@ private: *TraceFile << "\n"; } - inline void TraceSubtestFinished(const char* className, const char* subtestName, const char* status, const TString comment, const TTestContext* context) { + inline void TraceSubtestFinished(const char* className, const char* subtestName, const char* status, const TString comment, const TTestContext* context) { const TInstant now = TInstant::Now(); NJson::TJsonValue event; event.InsertValue("class", className); @@ -97,7 +97,7 @@ private: Trace("subtest-finished", event); PrevTime = now; - TString marker = Join("", "\n###subtest-finished:", className, "::", subtestName, "\n"); + TString marker = Join("", "\n###subtest-finished:", className, "::", subtestName, "\n"); Cout << marker; Cout.Flush(); Cerr << comment; @@ -105,7 +105,7 @@ private: Cerr.Flush(); } - virtual TString BuildComment(const char* message, const char* backTrace) { + virtual TString BuildComment(const char* message, const char* backTrace) { return NUnitTest::GetFormatTag("bad") + TString(message).substr(0, MAX_COMMENT_MESSAGE_LENGTH) + NUnitTest::GetResetTag() + @@ -120,7 +120,7 @@ private: event.InsertValue("class", test->unit->name); event.InsertValue("subtest", test->name); Trace("subtest-started", event); - TString marker = Join("", "\n###subtest-started:", test->unit->name, "::", test->name, "\n"); + TString marker = Join("", "\n###subtest-started:", test->unit->name, "::", test->name, "\n"); Cout << marker; Cout.Flush(); Cerr << marker; @@ -149,7 +149,7 @@ private: TraceSubtestFinished(descr->test->unit->name.data(), descr->test->name, "good", "", descr->Context); } else { TStringBuilder msgs; - for (const TString& m : ErrorMessages) { + for (const TString& m : ErrorMessages) { if (msgs) { msgs << TStringBuf("\n"); } @@ -166,7 +166,7 @@ private: class TColoredProcessor: public ITestSuiteProcessor, public NColorizer::TColors { public: - inline TColoredProcessor(const TString& appName) + inline TColoredProcessor(const TString& appName) : PrintBeforeSuite_(true) , PrintBeforeTest_(true) , PrintAfterTest_(true) @@ -186,30 +186,30 @@ public: { } - ~TColoredProcessor() override { + ~TColoredProcessor() override { } inline void Disable(const char* name) { - size_t colon = TString(name).find("::"); - if (colon == TString::npos) { + size_t colon = TString(name).find("::"); + if (colon == TString::npos) { DisabledSuites_.insert(name); } else { - TString suite = TString(name).substr(0, colon); + TString suite = TString(name).substr(0, colon); DisabledTests_.insert(name); } } inline void Enable(const char* name) { - size_t colon = TString(name).rfind("::"); - if (colon == TString::npos) { + size_t colon = TString(name).rfind("::"); + if (colon == TString::npos) { EnabledSuites_.insert(name); - EnabledTests_.insert(TString() + name + "::*"); + EnabledTests_.insert(TString() + name + "::*"); } else { - TString suite = TString(name).substr(0, colon); + TString suite = TString(name).substr(0, colon); EnabledSuites_.insert(suite); EnabledSuites_.insert(name); EnabledTests_.insert(name); - EnabledTests_.insert(TString() + name + "::*"); + EnabledTests_.insert(TString() + name + "::*"); } } @@ -425,7 +425,7 @@ private: } } - bool CheckAccess(TString name, size_t num) override { + bool CheckAccess(TString name, size_t num) override { if (num < Start) { return false; } @@ -445,8 +445,8 @@ private: return EnabledSuites_.find(name.data()) != EnabledSuites_.end(); } - bool CheckAccessTest(TString suite, const char* test) override { - TString name = suite + "::" + test; + bool CheckAccessTest(TString suite, const char* test) override { + TString name = suite + "::" + test; if (DisabledTests_.find(name) != DisabledTests_.end()) { return false; } @@ -455,7 +455,7 @@ private: return true; } - if (EnabledTests_.find(TString() + suite + "::*") != EnabledTests_.end()) { + if (EnabledTests_.find(TString() + suite + "::*") != EnabledTests_.end()) { return true; } @@ -467,7 +467,7 @@ private: return f(); } - TList<TString> args(1, "--is-forked-internal"); + TList<TString> args(1, "--is-forked-internal"); args.push_back(Sprintf("+%s::%s", suite.data(), name)); // stdin is ignored - unittest should not need them... @@ -475,12 +475,12 @@ private: TShellCommandOptions().SetUseShell(false).SetCloseAllFdsOnExec(true).SetAsync(false).SetLatency(1)); cmd.Run(); - const TString& err = cmd.GetError(); + 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; + ForkExitedCorrectly = msgIndex != TString::npos; // TODO: stderr output is always printed after stdout Cout.Write(cmd.GetOutput()); @@ -517,16 +517,16 @@ private: bool PrintAfterSuite_; bool PrintTimes_; bool PrintSummary_; - THashSet<TString> DisabledSuites_; - THashSet<TString> EnabledSuites_; - THashSet<TString> DisabledTests_; - THashSet<TString> EnabledTests_; + THashSet<TString> DisabledSuites_; + THashSet<TString> EnabledSuites_; + THashSet<TString> DisabledTests_; + THashSet<TString> EnabledTests_; TInstant PrevTime_; bool ShowFails; - TVector<TString> Fails; + TVector<TString> Fails; size_t Start; size_t End; - TString AppName; + TString AppName; bool ForkTests; bool IsForked; bool Loop; @@ -545,10 +545,10 @@ public: { } - ~TEnumeratingProcessor() override { + ~TEnumeratingProcessor() override { } - bool CheckAccess(TString name, size_t /*num*/) override { + bool CheckAccess(TString name, size_t /*num*/) override { if (Verbose_) { return true; } else { @@ -557,7 +557,7 @@ public: } } - bool CheckAccessTest(TString suite, const char* name) override { + bool CheckAccessTest(TString suite, const char* name) override { Stream_ << suite << "::" << name << "\n"; return false; } @@ -732,7 +732,7 @@ int NUnitTest::RunMain(int argc, char** argv) { TString param(argv[i]); size_t assign = param.find('='); Singleton<::NPrivate::TTestEnv>()->AddTestParam(param.substr(0, assign), param.substr(assign + 1)); - } else if (TString(name).StartsWith("--")) { + } else if (TString(name).StartsWith("--")) { return DoUsage(argv[0]), 1; } else if (*name == '-') { processor.Disable(name + 1); |