diff options
| author | bkuchin <[email protected]> | 2022-02-10 16:46:29 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:46:29 +0300 | 
| commit | 2c6ec4e7012419466156d8eb2394a888cccaa800 (patch) | |
| tree | 9e80d045a72a2eb2c74ea86becc855a1fa35dcf7 /library/cpp | |
| parent | 1c8fad4dbdab65ce5d4d0740cd02f90c069b4f17 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/testing/unittest/gtest.cpp | 2 | ||||
| -rw-r--r-- | library/cpp/testing/unittest/registar.h | 100 | ||||
| -rw-r--r-- | library/cpp/testing/unittest/simple.h | 14 | ||||
| -rw-r--r-- | library/cpp/testing/unittest/ut/main.cpp | 48 | 
4 files changed, 82 insertions, 82 deletions
| diff --git a/library/cpp/testing/unittest/gtest.cpp b/library/cpp/testing/unittest/gtest.cpp index ebad1ea4d67..f414ffd0f17 100644 --- a/library/cpp/testing/unittest/gtest.cpp +++ b/library/cpp/testing/unittest/gtest.cpp @@ -47,7 +47,7 @@ namespace {          }          void AddTest(const char* name, void (*body)(TTestContext&), bool forceFork) override { -            Test.Tests.push_back(TBaseTestCase(name, body, forceFork)); +            Test.Tests.push_back(TBaseTestCase(name, body, forceFork));           }          TCurrentTest Test; diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index 44517a00924..9994ec027dc 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -794,25 +794,25 @@ public:                       \          }      }; -    struct TBaseTestCase { +    struct TBaseTestCase {           // NOTE: since EACH test case is instantiated for listing tests, its          // ctor/dtor are not the best place to do heavy preparations in test fixtures.          //          // Consider using SetUp()/TearDown() methods instead -        inline TBaseTestCase() -            : TBaseTestCase(nullptr, nullptr, false) +        inline TBaseTestCase()  +            : TBaseTestCase(nullptr, nullptr, false)           {          }          inline TBaseTestCase(const char* name, std::function<void(TTestContext&)> body, bool forceFork) -            : Name_(name) +            : Name_(name)               , Body_(std::move(body)) -            , ForceFork_(forceFork) +            , ForceFork_(forceFork)           {          } -        virtual ~TBaseTestCase() = default; +        virtual ~TBaseTestCase() = default;           // Each test case is executed in 3 steps:          // @@ -822,24 +822,24 @@ public:                       \          //          // Both SetUp() and TearDown() may use UNIT_* check macros and are only          // called when the test is executed. - +           virtual void SetUp(TTestContext& /* context */) {          }          virtual void TearDown(TTestContext& /* context */) {          } -        virtual void Execute_(TTestContext& context) { -            Body_(context); -        } - -        const char* Name_; -        std::function<void(TTestContext&)> Body_; -        bool ForceFork_; +        virtual void Execute_(TTestContext& context) {  +            Body_(context);  +        }  +  +        const char* Name_;  +        std::function<void(TTestContext&)> Body_;  +        bool ForceFork_;       }; -    using TBaseFixture = TBaseTestCase; - +    using TBaseFixture = TBaseTestCase;  +       // Class for checking that code raises unittest failure      class TUnitTestFailChecker {      public: @@ -916,12 +916,12 @@ public:                       \  #define Y_UNIT_TEST_SUITE_IMPL_F(N, T, F)                                                                          \      namespace NTestSuite##N {                                                                                           \ -        class TCurrentTestCase: public F {                                                                              \ -        };                                                                                                              \ +        class TCurrentTestCase: public F {                                                                              \  +        };                                                                                                              \           class TCurrentTest: public T {                                                                                  \          private:                                                                                                        \ -            typedef std::function<THolder<NUnitTest::TBaseTestCase>()> TTestCaseFactory;                                \ -            typedef TVector<TTestCaseFactory> TTests;                                                                   \ +            typedef std::function<THolder<NUnitTest::TBaseTestCase>()> TTestCaseFactory;                                \  +            typedef TVector<TTestCaseFactory> TTests;                                                                   \                                                                                                                           \              static TTests& Tests() {                                                                                    \                  static TTests tests;                                                                                    \ @@ -942,20 +942,20 @@ public:                       \                  Tests().push_back([=]{ return MakeHolder<NUnitTest::TBaseTestCase>(name, body, forceFork); });          \              }                                                                                                           \                                                                                                                          \ -            static void AddTest(TTestCaseFactory testCaseFactory) {                                                     \ -                Tests().push_back(std::move(testCaseFactory));                                                          \ -            }                                                                                                           \ -                                                                                                                        \ +            static void AddTest(TTestCaseFactory testCaseFactory) {                                                     \  +                Tests().push_back(std::move(testCaseFactory));                                                          \  +            }                                                                                                           \  +                                                                                                                        \               virtual void Execute() {                                                                                    \                  this->AtStart();                                                                                        \ -                for (TTests::iterator it = Tests().begin(), ie = Tests().end(); it != ie; ++it) {                       \ -                    const auto i = (*it)();                                                                             \ -                    if (!this->CheckAccessTest(i->Name_)) {                                                             \ +                for (TTests::iterator it = Tests().begin(), ie = Tests().end(); it != ie; ++it) {                       \  +                    const auto i = (*it)();                                                                             \  +                    if (!this->CheckAccessTest(i->Name_)) {                                                             \                           continue;                                                                                       \                      }                                                                                                   \                      NUnitTest::TTestContext context(this->TTestBase::Processor());                                      \                      try {                                                                                               \ -                        this->BeforeTest(i->Name_);                                                                     \ +                        this->BeforeTest(i->Name_);                                                                     \                           {                                                                                               \                              TCleanUp cleaner(this);                                                                     \                              auto testCase = [&i, &context] {                                                            \ @@ -967,13 +967,13 @@ public:                       \                          }                                                                                               \                      } catch (const ::NUnitTest::TAssertException&) {                                                    \                      } catch (const yexception& e) {                                                                     \ -                        CATCH_REACTION_BT(i->Name_, e, &context);                                                       \ +                        CATCH_REACTION_BT(i->Name_, e, &context);                                                       \                       } catch (const std::exception& e) {                                                                 \ -                        CATCH_REACTION(i->Name_, e, &context);                                                          \ +                        CATCH_REACTION(i->Name_, e, &context);                                                          \                       } catch (...) {                                                                                     \                          this->AddError("non-std exception!", &context);                                                 \                      }                                                                                                   \ -                    this->Finish(i->Name_, &context);                                                                   \ +                    this->Finish(i->Name_, &context);                                                                   \                   }                                                                                                       \                  this->AtEnd();                                                                                          \              }                                                                                                           \ @@ -988,23 +988,23 @@ public:                       \  #define RUSAGE_UNIT_TEST_SUITE(N) Y_UNIT_TEST_SUITE_IMPL(N, NUnitTest::TRusageTest, ::NUnitTest::TBaseTestCase)  #define Y_UNIT_TEST_IMPL_REGISTER(N, FF, F)            \ -    struct TTestCase##N : public F {                        \ -        TTestCase##N()                                      \ -            : F()                                           \ -        {                                                   \ -            Name_ = #N;                                     \ -            ForceFork_ = FF;                                \ -        }                                                   \ -        static THolder<NUnitTest::TBaseTestCase> Create() { \ -            return ::MakeHolder<TTestCase##N>();            \ -        }                                                   \ -        void Execute_(NUnitTest::TTestContext&) override;   \ -    };                                                      \ -    struct TTestRegistration##N {                           \ -        TTestRegistration##N() {                            \ -            TCurrentTest::AddTest(TTestCase##N::Create);    \ -        }                                                   \ -    };                                                      \ +    struct TTestCase##N : public F {                        \  +        TTestCase##N()                                      \  +            : F()                                           \  +        {                                                   \  +            Name_ = #N;                                     \  +            ForceFork_ = FF;                                \  +        }                                                   \  +        static THolder<NUnitTest::TBaseTestCase> Create() { \  +            return ::MakeHolder<TTestCase##N>();            \  +        }                                                   \  +        void Execute_(NUnitTest::TTestContext&) override;   \  +    };                                                      \  +    struct TTestRegistration##N {                           \  +        TTestRegistration##N() {                            \  +            TCurrentTest::AddTest(TTestCase##N::Create);    \  +        }                                                   \  +    };                                                      \       static const TTestRegistration##N testRegistration##N;  #define Y_UNIT_TEST_IMPL(N, FF, F)      \ @@ -1019,10 +1019,10 @@ public:                       \      namespace NTestSuite##N  #define Y_UNIT_TEST_DECLARE(N) \ -    struct TTestCase##N +    struct TTestCase##N   #define Y_UNIT_TEST_FRIEND(N, T) \ -    friend NTestSuite##N::TTestCase##T \ +    friend NTestSuite##N::TTestCase##T \       TString RandomString(size_t len, ui32 seed = 0);  } diff --git a/library/cpp/testing/unittest/simple.h b/library/cpp/testing/unittest/simple.h index 2a5300d886e..7fd97e8d165 100644 --- a/library/cpp/testing/unittest/simple.h +++ b/library/cpp/testing/unittest/simple.h @@ -4,7 +4,7 @@  namespace NUnitTest {      struct TSimpleTestExecutor: public TTestBase { -        typedef TVector<TBaseTestCase> TTests; +        typedef TVector<TBaseTestCase> TTests;           TTests Tests; @@ -12,25 +12,25 @@ namespace NUnitTest {              AtStart();              for (typename TTests::iterator i = Tests.begin(), ie = Tests.end(); i != ie; ++i) { -                if (!CheckAccessTest(i->Name_)) { +                if (!CheckAccessTest(i->Name_)) {                       continue;                  }                  TTestContext context(this->Processor());                  try { -                    BeforeTest(i->Name_); +                    BeforeTest(i->Name_);                       {                          TCleanUp cleaner(this); -                        TTestBase::Run([i, &context] { i->Body_(context); }, Name(), i->Name_, i->ForceFork_); +                        TTestBase::Run([i, &context] { i->Body_(context); }, Name(), i->Name_, i->ForceFork_);                       }                  } catch (const ::NUnitTest::TAssertException&) {                  } catch (const yexception& e) { -                    CATCH_REACTION_BT(i->Name_, e, &context); +                    CATCH_REACTION_BT(i->Name_, e, &context);                   } catch (const std::exception& e) { -                    CATCH_REACTION(i->Name_, e, &context); +                    CATCH_REACTION(i->Name_, e, &context);                   } catch (...) {                      AddError("non-std exception!", &context);                  } -                Finish(i->Name_, &context); +                Finish(i->Name_, &context);               }              AtEnd(); diff --git a/library/cpp/testing/unittest/ut/main.cpp b/library/cpp/testing/unittest/ut/main.cpp index e303e21e30a..90575043974 100644 --- a/library/cpp/testing/unittest/ut/main.cpp +++ b/library/cpp/testing/unittest/ut/main.cpp @@ -28,14 +28,14 @@ namespace {          int I;      }; - -    struct TSimpleFixture : public NUnitTest::TBaseFixture { -        size_t Value = 24; -    }; - -    struct TOtherFixture : public NUnitTest::TBaseFixture { -        size_t TheAnswer = 42; -    }; +  +    struct TSimpleFixture : public NUnitTest::TBaseFixture {  +        size_t Value = 24;  +    };  +  +    struct TOtherFixture : public NUnitTest::TBaseFixture {  +        size_t TheAnswer = 42;  +    };       struct TSetUpTearDownFixture : public NUnitTest::TBaseFixture {          int Magic = 3; @@ -62,27 +62,27 @@ TEST(ETest, Test1) {  }  Y_UNIT_TEST_SUITE(TestSingleTestFixture) -{ +{       Y_UNIT_TEST_F(Test3, TSimpleFixture) { -        UNIT_ASSERT_EQUAL(Value, 24); -    } -} - +        UNIT_ASSERT_EQUAL(Value, 24);  +    }  +}  +   Y_UNIT_TEST_SUITE_F(TestSuiteFixture, TSimpleFixture) -{ +{       Y_UNIT_TEST(Test1) { -        UNIT_ASSERT(Value == 24); -        Value = 25; -    } - +        UNIT_ASSERT(Value == 24);  +        Value = 25;  +    }  +       Y_UNIT_TEST(Test2) { -        UNIT_ASSERT_EQUAL(Value, 24); -    } - +        UNIT_ASSERT_EQUAL(Value, 24);  +    }  +       Y_UNIT_TEST_F(Test3, TOtherFixture) { -        UNIT_ASSERT_EQUAL(TheAnswer, 42); -    } -} +        UNIT_ASSERT_EQUAL(TheAnswer, 42);  +    }  +}   Y_UNIT_TEST_SUITE(TestSetUpTearDownFixture)  { | 
