aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/hook
diff options
context:
space:
mode:
authorbulatman <bulatman@yandex-team.ru>2022-02-10 16:45:50 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:50 +0300
commit6560e4993b14d193f8c879e33a3de5e5eba6e21d (patch)
treecfd2e2baa05c3196f2caacbb63c32e1df40bc3de /library/cpp/testing/hook
parent7489e4682331202b9c7d863c0898eb83d7b12c2b (diff)
downloadydb-6560e4993b14d193f8c879e33a3de5e5eba6e21d.tar.gz
Restoring authorship annotation for <bulatman@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/testing/hook')
-rw-r--r--library/cpp/testing/hook/README.md50
-rw-r--r--library/cpp/testing/hook/hook.cpp90
-rw-r--r--library/cpp/testing/hook/hook.h256
-rw-r--r--library/cpp/testing/hook/ya.make26
4 files changed, 211 insertions, 211 deletions
diff --git a/library/cpp/testing/hook/README.md b/library/cpp/testing/hook/README.md
index fac8b32ef5..ffab40a960 100644
--- a/library/cpp/testing/hook/README.md
+++ b/library/cpp/testing/hook/README.md
@@ -1,25 +1,25 @@
-# Hook for google benchmark and gtest
-
-Y_TEST_HOOK_BEFORE_INIT - вызывается перед инициализацией соотвествующего фреймворка
-Y_TEST_HOOK_BEFORE_RUN - вызывается перед запуском тестов
-Y_TEST_HOOK_AFTER_RUN - вызывается всегда после завершения выполнения тестов,
- если этап инициализации был успешным
-
-## Примеры:
-
-```
-Y_TEST_HOOK_BEFORE_INIT(SetupMyApp) {
- // ваш код для выполнения перед инициализацией фреймворка
-}
-
-Y_TEST_HOOK_BEFORE_RUN(InitMyApp) {
- // ваш код для выполнения перед запуском тестов
-}
-
-Y_TEST_HOOK_AFTER_RUN(CleanMyApp) {
- // ваш код для выполнения после завершения тестов
-}
-```
-
-## Тесты:
-тесты лаунчерах соотвествующих фреймворков (gtest, gbenchmark и unittest)
+# Hook for google benchmark and gtest
+
+Y_TEST_HOOK_BEFORE_INIT - вызывается перед инициализацией соотвествующего фреймворка
+Y_TEST_HOOK_BEFORE_RUN - вызывается перед запуском тестов
+Y_TEST_HOOK_AFTER_RUN - вызывается всегда после завершения выполнения тестов,
+ если этап инициализации был успешным
+
+## Примеры:
+
+```
+Y_TEST_HOOK_BEFORE_INIT(SetupMyApp) {
+ // ваш код для выполнения перед инициализацией фреймворка
+}
+
+Y_TEST_HOOK_BEFORE_RUN(InitMyApp) {
+ // ваш код для выполнения перед запуском тестов
+}
+
+Y_TEST_HOOK_AFTER_RUN(CleanMyApp) {
+ // ваш код для выполнения после завершения тестов
+}
+```
+
+## Тесты:
+тесты лаунчерах соотвествующих фреймворков (gtest, gbenchmark и unittest)
diff --git a/library/cpp/testing/hook/hook.cpp b/library/cpp/testing/hook/hook.cpp
index b3c599da89..f5daca11cb 100644
--- a/library/cpp/testing/hook/hook.cpp
+++ b/library/cpp/testing/hook/hook.cpp
@@ -1,45 +1,45 @@
-#include "hook.h"
-
-namespace {
- NTesting::THook* BeforeInitHead = nullptr;
- NTesting::THook* BeforeRunHead = nullptr;
- NTesting::THook* AfterRunHead = nullptr;
-
- void RegisterHook(NTesting::THook*& head, NTesting::THook* hook) {
- hook->Next = head;
- head = hook;
- }
-
- void CallHooks(NTesting::THook* head) {
- while (nullptr != head) {
- if (nullptr != head->Fn) {
- (*head->Fn)();
- }
- head = head->Next;
- }
- }
-}
-
-void NTesting::THook::RegisterBeforeInit(NTesting::THook* hook) noexcept {
- RegisterHook(BeforeInitHead, hook);
-}
-
-void NTesting::THook::CallBeforeInit() {
- CallHooks(BeforeInitHead);
-}
-
-void NTesting::THook::RegisterBeforeRun(NTesting::THook* hook) noexcept {
- RegisterHook(BeforeRunHead, hook);
-}
-
-void NTesting::THook::CallBeforeRun() {
- CallHooks(BeforeRunHead);
-}
-
-void NTesting::THook::RegisterAfterRun(NTesting::THook* hook) noexcept {
- RegisterHook(AfterRunHead, hook);
-}
-
-void NTesting::THook::CallAfterRun() {
- CallHooks(AfterRunHead);
-}
+#include "hook.h"
+
+namespace {
+ NTesting::THook* BeforeInitHead = nullptr;
+ NTesting::THook* BeforeRunHead = nullptr;
+ NTesting::THook* AfterRunHead = nullptr;
+
+ void RegisterHook(NTesting::THook*& head, NTesting::THook* hook) {
+ hook->Next = head;
+ head = hook;
+ }
+
+ void CallHooks(NTesting::THook* head) {
+ while (nullptr != head) {
+ if (nullptr != head->Fn) {
+ (*head->Fn)();
+ }
+ head = head->Next;
+ }
+ }
+}
+
+void NTesting::THook::RegisterBeforeInit(NTesting::THook* hook) noexcept {
+ RegisterHook(BeforeInitHead, hook);
+}
+
+void NTesting::THook::CallBeforeInit() {
+ CallHooks(BeforeInitHead);
+}
+
+void NTesting::THook::RegisterBeforeRun(NTesting::THook* hook) noexcept {
+ RegisterHook(BeforeRunHead, hook);
+}
+
+void NTesting::THook::CallBeforeRun() {
+ CallHooks(BeforeRunHead);
+}
+
+void NTesting::THook::RegisterAfterRun(NTesting::THook* hook) noexcept {
+ RegisterHook(AfterRunHead, hook);
+}
+
+void NTesting::THook::CallAfterRun() {
+ CallHooks(AfterRunHead);
+}
diff --git a/library/cpp/testing/hook/hook.h b/library/cpp/testing/hook/hook.h
index c45289cb22..1287e946c0 100644
--- a/library/cpp/testing/hook/hook.h
+++ b/library/cpp/testing/hook/hook.h
@@ -1,128 +1,128 @@
-#pragma once
-
-namespace NTesting {
- /**
- * Hook class and registration system.
- *
- * Default implementation of the `main` function for G_BENCHMARK and GTEST calls these hooks when executing.
- * This is a useful feature if you want to customize behaviour of the `main` function,
- * but you don't want to write `main` yourself.
- *
- * Hooks form an intrusive linked list that's built at application startup. Note that hooks execute
- * in arbitrary order.
- *
- * Use macros below to define hooks.
- */
- struct THook {
- using TFn = void (*)();
-
- TFn Fn = nullptr;
- THook* Next = nullptr;
-
- static void RegisterBeforeInit(THook* hook) noexcept;
-
- static void CallBeforeInit();
-
- struct TRegisterBeforeInit {
- explicit TRegisterBeforeInit(THook* hook) noexcept {
- THook::RegisterBeforeInit(hook);
- }
- };
-
- static void RegisterBeforeRun(THook* hook) noexcept;
-
- static void CallBeforeRun();
-
- struct TRegisterBeforeRun {
- explicit TRegisterBeforeRun(THook* hook) noexcept {
- THook::RegisterBeforeRun(hook);
- }
- };
-
- static void RegisterAfterRun(THook* hook) noexcept;
-
- static void CallAfterRun();
-
- struct TRegisterAfterRun {
- explicit TRegisterAfterRun(THook* hook) noexcept {
- THook::RegisterAfterRun(hook);
- }
- };
- };
-
- /**
- * Called right before initializing test programm
- *
- * This hook is intended for setting up default parameters. If you're doing initialization, consider
- * using `Y_TEST_HOOK_BEFORE_RUN` instead.
- *
- * *Note:* hooks execute in arbitrary order.
- *
- *
- * # Usage
- *
- * Instantiate this class in a cpp file. Pass a unique name for your hook,
- * implement body right after macro instantiation:
- *
- * ```
- * Y_TEST_HOOK_BEFORE_INIT(SetupParams) {
- * // hook code
- * }
- * ```
- */
-#define Y_TEST_HOOK_BEFORE_INIT(N) \
- void N(); \
- ::NTesting::THook N##Hook{&N, nullptr}; \
- ::NTesting::THook::TRegisterBeforeInit N##HookReg{&N##Hook}; \
- void N()
-
- /**
- * Called right before launching tests.
- *
- * Hooks execute in arbitrary order. As such, we recommend using this hook to set up an event listener,
- * and performing initialization and cleanup in the corresponding event handlers. This is better than performing
- * initialization and cleanup directly in the hook's code because it gives more control over
- * order in which initialization is performed.
- *
- *
- * # Usage
- *
- * Instantiate this class in a cpp file. Pass a unique name for your hook,
- * implement body right after macro instantiation:
- *
- * ```
- * Y_TEST_HOOK_BEFORE_RUN(InitMyApp) {
- * // hook code
- * }
- * ```
- */
-#define Y_TEST_HOOK_BEFORE_RUN(N) \
- void N(); \
- ::NTesting::THook N##Hook{&N, nullptr}; \
- ::NTesting::THook::TRegisterBeforeRun N##HookReg{&N##Hook}; \
- void N()
-
- /**
- * Called after all tests has finished, just before program exit.
- *
- * This hook is intended for simple cleanup routines that don't care about order in which hooks are executed.
- * For more complex cases, we recommend using `Y_TEST_HOOK_BEFORE_RUN`.
- *
- *
- * # Usage
- *
- * Instantiate this class in a cpp file. Pass a unique name for your hook,
- * implement body right after macro instantiation:
- *
- * ```
- * Y_TEST_HOOK_AFTER_RUN(StopMyApp) {
- * // hook code
- * }
- * ```
- */
-#define Y_TEST_HOOK_AFTER_RUN(N) \
- void N(); \
- ::NTesting::THook N##Hook{&N, nullptr}; \
- ::NTesting::THook::TRegisterAfterRun N##HookReg{&N##Hook}; \
- void N()
-}
+#pragma once
+
+namespace NTesting {
+ /**
+ * Hook class and registration system.
+ *
+ * Default implementation of the `main` function for G_BENCHMARK and GTEST calls these hooks when executing.
+ * This is a useful feature if you want to customize behaviour of the `main` function,
+ * but you don't want to write `main` yourself.
+ *
+ * Hooks form an intrusive linked list that's built at application startup. Note that hooks execute
+ * in arbitrary order.
+ *
+ * Use macros below to define hooks.
+ */
+ struct THook {
+ using TFn = void (*)();
+
+ TFn Fn = nullptr;
+ THook* Next = nullptr;
+
+ static void RegisterBeforeInit(THook* hook) noexcept;
+
+ static void CallBeforeInit();
+
+ struct TRegisterBeforeInit {
+ explicit TRegisterBeforeInit(THook* hook) noexcept {
+ THook::RegisterBeforeInit(hook);
+ }
+ };
+
+ static void RegisterBeforeRun(THook* hook) noexcept;
+
+ static void CallBeforeRun();
+
+ struct TRegisterBeforeRun {
+ explicit TRegisterBeforeRun(THook* hook) noexcept {
+ THook::RegisterBeforeRun(hook);
+ }
+ };
+
+ static void RegisterAfterRun(THook* hook) noexcept;
+
+ static void CallAfterRun();
+
+ struct TRegisterAfterRun {
+ explicit TRegisterAfterRun(THook* hook) noexcept {
+ THook::RegisterAfterRun(hook);
+ }
+ };
+ };
+
+ /**
+ * Called right before initializing test programm
+ *
+ * This hook is intended for setting up default parameters. If you're doing initialization, consider
+ * using `Y_TEST_HOOK_BEFORE_RUN` instead.
+ *
+ * *Note:* hooks execute in arbitrary order.
+ *
+ *
+ * # Usage
+ *
+ * Instantiate this class in a cpp file. Pass a unique name for your hook,
+ * implement body right after macro instantiation:
+ *
+ * ```
+ * Y_TEST_HOOK_BEFORE_INIT(SetupParams) {
+ * // hook code
+ * }
+ * ```
+ */
+#define Y_TEST_HOOK_BEFORE_INIT(N) \
+ void N(); \
+ ::NTesting::THook N##Hook{&N, nullptr}; \
+ ::NTesting::THook::TRegisterBeforeInit N##HookReg{&N##Hook}; \
+ void N()
+
+ /**
+ * Called right before launching tests.
+ *
+ * Hooks execute in arbitrary order. As such, we recommend using this hook to set up an event listener,
+ * and performing initialization and cleanup in the corresponding event handlers. This is better than performing
+ * initialization and cleanup directly in the hook's code because it gives more control over
+ * order in which initialization is performed.
+ *
+ *
+ * # Usage
+ *
+ * Instantiate this class in a cpp file. Pass a unique name for your hook,
+ * implement body right after macro instantiation:
+ *
+ * ```
+ * Y_TEST_HOOK_BEFORE_RUN(InitMyApp) {
+ * // hook code
+ * }
+ * ```
+ */
+#define Y_TEST_HOOK_BEFORE_RUN(N) \
+ void N(); \
+ ::NTesting::THook N##Hook{&N, nullptr}; \
+ ::NTesting::THook::TRegisterBeforeRun N##HookReg{&N##Hook}; \
+ void N()
+
+ /**
+ * Called after all tests has finished, just before program exit.
+ *
+ * This hook is intended for simple cleanup routines that don't care about order in which hooks are executed.
+ * For more complex cases, we recommend using `Y_TEST_HOOK_BEFORE_RUN`.
+ *
+ *
+ * # Usage
+ *
+ * Instantiate this class in a cpp file. Pass a unique name for your hook,
+ * implement body right after macro instantiation:
+ *
+ * ```
+ * Y_TEST_HOOK_AFTER_RUN(StopMyApp) {
+ * // hook code
+ * }
+ * ```
+ */
+#define Y_TEST_HOOK_AFTER_RUN(N) \
+ void N(); \
+ ::NTesting::THook N##Hook{&N, nullptr}; \
+ ::NTesting::THook::TRegisterAfterRun N##HookReg{&N##Hook}; \
+ void N()
+}
diff --git a/library/cpp/testing/hook/ya.make b/library/cpp/testing/hook/ya.make
index db58f4e0ae..9f15673651 100644
--- a/library/cpp/testing/hook/ya.make
+++ b/library/cpp/testing/hook/ya.make
@@ -1,13 +1,13 @@
-LIBRARY()
-OWNER(
- amatanhead
- bulatman
- thegeorg
- g:cpp-contrib
-)
-
-SRCS(
- hook.cpp
-)
-
-END()
+LIBRARY()
+OWNER(
+ amatanhead
+ bulatman
+ thegeorg
+ g:cpp-contrib
+)
+
+SRCS(
+ hook.cpp
+)
+
+END()