diff options
author | amatanhead <amatanhead@yandex-team.ru> | 2022-02-10 16:50:04 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:04 +0300 |
commit | 8879605a63ac17539be5b3bd41b529791f4d4b02 (patch) | |
tree | 5739c7303cbe09d02b881e25bb294a4a173422a0 /library/cpp/testing/gtest_extensions | |
parent | 830fe7ae4073c2707f3f3138303ccc56052c0327 (diff) | |
download | ydb-8879605a63ac17539be5b3bd41b529791f4d4b02.tar.gz |
Restoring authorship annotation for <amatanhead@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/testing/gtest_extensions')
-rw-r--r-- | library/cpp/testing/gtest_extensions/README.md | 8 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/assertions.cpp | 176 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/assertions.h | 218 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/gtest_extensions.cpp | 2 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/gtest_extensions.h | 6 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/matchers.cpp | 2 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/matchers.h | 220 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/pretty_printers.cpp | 2 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/pretty_printers.h | 144 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/ut/README.md | 2 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp | 620 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/ut/ya.make | 10 | ||||
-rw-r--r-- | library/cpp/testing/gtest_extensions/ya.make | 14 |
13 files changed, 712 insertions, 712 deletions
diff --git a/library/cpp/testing/gtest_extensions/README.md b/library/cpp/testing/gtest_extensions/README.md index 5445c7a464..ab9b3dfe4f 100644 --- a/library/cpp/testing/gtest_extensions/README.md +++ b/library/cpp/testing/gtest_extensions/README.md @@ -1,5 +1,5 @@ -# Extensions for Gtest and Gmock - -Extensions that enable better support of util types in gtest and gmock: pretty printers, matchers, some convenience macros. - +# Extensions for Gtest and Gmock + +Extensions that enable better support of util types in gtest and gmock: pretty printers, matchers, some convenience macros. + If you're using `GTEST`, include `library/cpp/testing/gtest/gtest.h` and it will automatically enable these extensions. This is the preferred way to include gtest and gmock as opposed to including gtest, gmock and extensions directly. It eliminates chances of forgetting to include extensions. diff --git a/library/cpp/testing/gtest_extensions/assertions.cpp b/library/cpp/testing/gtest_extensions/assertions.cpp index f390409d1b..14416daed3 100644 --- a/library/cpp/testing/gtest_extensions/assertions.cpp +++ b/library/cpp/testing/gtest_extensions/assertions.cpp @@ -1,90 +1,90 @@ -#include "assertions.h" - -#include <util/string/builder.h> -#include <util/string/split.h> +#include "assertions.h" + +#include <util/string/builder.h> +#include <util/string/split.h> #include <util/system/type_name.h> - -namespace NGTest::NInternal { - namespace { - void FormatActual(const std::exception& err, const TBackTrace* bt, TStringBuilder& out) { + +namespace NGTest::NInternal { + namespace { + void FormatActual(const std::exception& err, const TBackTrace* bt, TStringBuilder& out) { out << "an exception of type " << TypeName(err) << " " - << "with message " << TString(err.what()).Quote() << "."; - if (bt) { - out << "\n Trace: "; - for (auto& line: StringSplitter(bt->PrintToString()).Split('\n')) { - out << " " << line.Token() << "\n"; - } - } - } - - void FormatActual(TStringBuilder& out) { - out << " Actual: it throws "; - auto exceptionPtr = std::current_exception(); - if (exceptionPtr) { - try { - std::rethrow_exception(exceptionPtr); - } catch (const yexception& err) { - FormatActual(err, err.BackTrace(), out); - return; - } catch (const std::exception& err) { - FormatActual(err, nullptr, out); - return; - } catch (...) { - out << "an unknown exception."; - return; - } - } - out << "nothing."; - } - - void FormatExpected(const char* statement, const char* type, const TString& contains, TStringBuilder& out) { - out << "Expected: "; - if (TStringBuf(statement).size() > 80) { - out << "statement"; - } else { - out << statement; - } - out << " throws an exception of type " << type; - - if (!contains.empty()) { - out << " with message containing " << contains.Quote(); - } - - out << "."; - } - } - - TString FormatErrorWrongException(const char* statement, const char* type) { - return FormatErrorWrongException(statement, type, ""); - } - - TString FormatErrorWrongException(const char* statement, const char* type, TString contains) { - TStringBuilder out; - - FormatExpected(statement, type, contains, out); - out << "\n"; - FormatActual(out); - - return out; - } - - TString FormatErrorUnexpectedException(const char* statement) { - TStringBuilder out; - - out << "Expected: "; - if (TStringBuf(statement).size() > 80) { - out << "statement"; - } else { - out << statement; - } - out << " doesn't throw an exception.\n "; - - FormatActual(out); - - return out; - } - - bool ExceptionMessageContains(const std::exception& err, TString contains) { - return TStringBuf(err.what()).Contains(contains); - } -} + << "with message " << TString(err.what()).Quote() << "."; + if (bt) { + out << "\n Trace: "; + for (auto& line: StringSplitter(bt->PrintToString()).Split('\n')) { + out << " " << line.Token() << "\n"; + } + } + } + + void FormatActual(TStringBuilder& out) { + out << " Actual: it throws "; + auto exceptionPtr = std::current_exception(); + if (exceptionPtr) { + try { + std::rethrow_exception(exceptionPtr); + } catch (const yexception& err) { + FormatActual(err, err.BackTrace(), out); + return; + } catch (const std::exception& err) { + FormatActual(err, nullptr, out); + return; + } catch (...) { + out << "an unknown exception."; + return; + } + } + out << "nothing."; + } + + void FormatExpected(const char* statement, const char* type, const TString& contains, TStringBuilder& out) { + out << "Expected: "; + if (TStringBuf(statement).size() > 80) { + out << "statement"; + } else { + out << statement; + } + out << " throws an exception of type " << type; + + if (!contains.empty()) { + out << " with message containing " << contains.Quote(); + } + + out << "."; + } + } + + TString FormatErrorWrongException(const char* statement, const char* type) { + return FormatErrorWrongException(statement, type, ""); + } + + TString FormatErrorWrongException(const char* statement, const char* type, TString contains) { + TStringBuilder out; + + FormatExpected(statement, type, contains, out); + out << "\n"; + FormatActual(out); + + return out; + } + + TString FormatErrorUnexpectedException(const char* statement) { + TStringBuilder out; + + out << "Expected: "; + if (TStringBuf(statement).size() > 80) { + out << "statement"; + } else { + out << statement; + } + out << " doesn't throw an exception.\n "; + + FormatActual(out); + + return out; + } + + bool ExceptionMessageContains(const std::exception& err, TString contains) { + return TStringBuf(err.what()).Contains(contains); + } +} diff --git a/library/cpp/testing/gtest_extensions/assertions.h b/library/cpp/testing/gtest_extensions/assertions.h index e8ea07b5df..9532b5ed96 100644 --- a/library/cpp/testing/gtest_extensions/assertions.h +++ b/library/cpp/testing/gtest_extensions/assertions.h @@ -1,111 +1,111 @@ -#pragma once - -#include <util/generic/string.h> - +#pragma once + +#include <util/generic/string.h> + #include <gtest/gtest.h> #include <gmock/gmock.h> - -/** - * Check that the given statement throws an exception of the given type, - * and that the thrown exception message contains the given substring. - */ -#define EXPECT_THROW_MESSAGE_HAS_SUBSTR(statement, expectedException, substring) \ - _Y_GTEST_EXPECT_THROW_MESSAGE_HAS_SUBSTR_IMPL_(statement, expectedException, substring, GTEST_NONFATAL_FAILURE_) - -/** - * Check that the given statement throws an exception of the given type, - * and that the thrown exception message contains the given substring. - */ -#define ASSERT_THROW_MESSAGE_HAS_SUBSTR(statement, expectedException, substring) \ - _Y_GTEST_EXPECT_THROW_MESSAGE_HAS_SUBSTR_IMPL_(statement, expectedException, substring, GTEST_FATAL_FAILURE_) - - -// Improve default macros. New implementation shows better exception messages. -// See https://github.com/google/googletest/issues/2878 - -#undef EXPECT_THROW -#define EXPECT_THROW(statement, expectedException) \ - _Y_GTEST_EXPECT_THROW_IMPL_(statement, expectedException, GTEST_NONFATAL_FAILURE_) - -#undef ASSERT_THROW -#define ASSERT_THROW(statement, expectedException) \ - _Y_GTEST_EXPECT_THROW_IMPL_(statement, expectedException, GTEST_FATAL_FAILURE_) - -#undef EXPECT_NO_THROW -#define EXPECT_NO_THROW(statement) \ - _Y_GTEST_EXPECT_NO_THROW_IMPL_(statement, GTEST_NONFATAL_FAILURE_) - -#undef ASSERT_NO_THROW -#define ASSERT_NO_THROW(statement) \ - _Y_GTEST_EXPECT_NO_THROW_IMPL_(statement, GTEST_FATAL_FAILURE_) - - -// Implementation details - -namespace NGTest::NInternal { - TString FormatErrorWrongException(const char* statement, const char* type); - TString FormatErrorWrongException(const char* statement, const char* type, TString contains); - TString FormatErrorUnexpectedException(const char* statement); - bool ExceptionMessageContains(const std::exception& err, TString contains); -} - -#define _Y_GTEST_EXPECT_THROW_IMPL_(statement, expectedException, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::TString gtestMsg = ""; ::testing::internal::AlwaysTrue()) { \ - bool gtestCaughtExpected = false; \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } catch (expectedException const&) { \ - gtestCaughtExpected = true; \ - } catch (...) { \ - gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ - #statement, #expectedException); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } if (!gtestCaughtExpected) { \ - gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ - #statement, #expectedException); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ - fail(gtestMsg.c_str()) - -#define _Y_GTEST_EXPECT_THROW_MESSAGE_HAS_SUBSTR_IMPL_(statement, expectedException, substring, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::TString gtestMsg = ""; ::testing::internal::AlwaysTrue()) { \ - bool gtestCaughtExpected = false; \ - ::TString gtestSubstring{substring}; \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } catch (expectedException const& gtestError) { \ - if (!::NGTest::NInternal::ExceptionMessageContains(gtestError, gtestSubstring)) { \ - gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ - #statement, #expectedException, gtestSubstring); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__); \ - } \ - gtestCaughtExpected = true; \ - } catch (...) { \ - gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ - #statement, #expectedException, gtestSubstring); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__); \ - } if (!gtestCaughtExpected) { \ - gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ - #statement, #expectedException, gtestSubstring); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__): \ - fail(gtestMsg.c_str()) - -#define _Y_GTEST_EXPECT_NO_THROW_IMPL_(statement, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::TString gtestMsg = ""; ::testing::internal::AlwaysTrue()) { \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } catch (...) { \ - gtestMsg = ::NGTest::NInternal::FormatErrorUnexpectedException(#statement); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ - fail(gtestMsg.c_str()) + +/** + * Check that the given statement throws an exception of the given type, + * and that the thrown exception message contains the given substring. + */ +#define EXPECT_THROW_MESSAGE_HAS_SUBSTR(statement, expectedException, substring) \ + _Y_GTEST_EXPECT_THROW_MESSAGE_HAS_SUBSTR_IMPL_(statement, expectedException, substring, GTEST_NONFATAL_FAILURE_) + +/** + * Check that the given statement throws an exception of the given type, + * and that the thrown exception message contains the given substring. + */ +#define ASSERT_THROW_MESSAGE_HAS_SUBSTR(statement, expectedException, substring) \ + _Y_GTEST_EXPECT_THROW_MESSAGE_HAS_SUBSTR_IMPL_(statement, expectedException, substring, GTEST_FATAL_FAILURE_) + + +// Improve default macros. New implementation shows better exception messages. +// See https://github.com/google/googletest/issues/2878 + +#undef EXPECT_THROW +#define EXPECT_THROW(statement, expectedException) \ + _Y_GTEST_EXPECT_THROW_IMPL_(statement, expectedException, GTEST_NONFATAL_FAILURE_) + +#undef ASSERT_THROW +#define ASSERT_THROW(statement, expectedException) \ + _Y_GTEST_EXPECT_THROW_IMPL_(statement, expectedException, GTEST_FATAL_FAILURE_) + +#undef EXPECT_NO_THROW +#define EXPECT_NO_THROW(statement) \ + _Y_GTEST_EXPECT_NO_THROW_IMPL_(statement, GTEST_NONFATAL_FAILURE_) + +#undef ASSERT_NO_THROW +#define ASSERT_NO_THROW(statement) \ + _Y_GTEST_EXPECT_NO_THROW_IMPL_(statement, GTEST_FATAL_FAILURE_) + + +// Implementation details + +namespace NGTest::NInternal { + TString FormatErrorWrongException(const char* statement, const char* type); + TString FormatErrorWrongException(const char* statement, const char* type, TString contains); + TString FormatErrorUnexpectedException(const char* statement); + bool ExceptionMessageContains(const std::exception& err, TString contains); +} + +#define _Y_GTEST_EXPECT_THROW_IMPL_(statement, expectedException, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::TString gtestMsg = ""; ::testing::internal::AlwaysTrue()) { \ + bool gtestCaughtExpected = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (expectedException const&) { \ + gtestCaughtExpected = true; \ + } catch (...) { \ + gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ + #statement, #expectedException); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } if (!gtestCaughtExpected) { \ + gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ + #statement, #expectedException); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ + fail(gtestMsg.c_str()) + +#define _Y_GTEST_EXPECT_THROW_MESSAGE_HAS_SUBSTR_IMPL_(statement, expectedException, substring, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::TString gtestMsg = ""; ::testing::internal::AlwaysTrue()) { \ + bool gtestCaughtExpected = false; \ + ::TString gtestSubstring{substring}; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (expectedException const& gtestError) { \ + if (!::NGTest::NInternal::ExceptionMessageContains(gtestError, gtestSubstring)) { \ + gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ + #statement, #expectedException, gtestSubstring); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__); \ + } \ + gtestCaughtExpected = true; \ + } catch (...) { \ + gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ + #statement, #expectedException, gtestSubstring); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__); \ + } if (!gtestCaughtExpected) { \ + gtestMsg = ::NGTest::NInternal::FormatErrorWrongException( \ + #statement, #expectedException, gtestSubstring); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testthrowsubstr_, __LINE__): \ + fail(gtestMsg.c_str()) + +#define _Y_GTEST_EXPECT_NO_THROW_IMPL_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::TString gtestMsg = ""; ::testing::internal::AlwaysTrue()) { \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (...) { \ + gtestMsg = ::NGTest::NInternal::FormatErrorUnexpectedException(#statement); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ + fail(gtestMsg.c_str()) diff --git a/library/cpp/testing/gtest_extensions/gtest_extensions.cpp b/library/cpp/testing/gtest_extensions/gtest_extensions.cpp index 1277a804bc..d8631e97ea 100644 --- a/library/cpp/testing/gtest_extensions/gtest_extensions.cpp +++ b/library/cpp/testing/gtest_extensions/gtest_extensions.cpp @@ -1 +1 @@ -#include "gtest_extensions.h" +#include "gtest_extensions.h" diff --git a/library/cpp/testing/gtest_extensions/gtest_extensions.h b/library/cpp/testing/gtest_extensions/gtest_extensions.h index e20532241e..c90a59bf13 100644 --- a/library/cpp/testing/gtest_extensions/gtest_extensions.h +++ b/library/cpp/testing/gtest_extensions/gtest_extensions.h @@ -1,6 +1,6 @@ #pragma once -#include "assertions.h" -#include "matchers.h" -#include "pretty_printers.h" +#include "assertions.h" +#include "matchers.h" +#include "pretty_printers.h" #include "probe.h" diff --git a/library/cpp/testing/gtest_extensions/matchers.cpp b/library/cpp/testing/gtest_extensions/matchers.cpp index 7da7be8b3c..7eff491aec 100644 --- a/library/cpp/testing/gtest_extensions/matchers.cpp +++ b/library/cpp/testing/gtest_extensions/matchers.cpp @@ -1 +1 @@ -#include "matchers.h" +#include "matchers.h" diff --git a/library/cpp/testing/gtest_extensions/matchers.h b/library/cpp/testing/gtest_extensions/matchers.h index 044c1c3ee4..042baa0764 100644 --- a/library/cpp/testing/gtest_extensions/matchers.h +++ b/library/cpp/testing/gtest_extensions/matchers.h @@ -1,132 +1,132 @@ -#pragma once - -#include <util/generic/string.h> - +#pragma once + +#include <util/generic/string.h> + #include <gtest/gtest.h> #include <gmock/gmock.h> - -namespace testing { - /** - * When matching `const TStringBuf&`, implicitly convert other strings and string views to `Eq` matchers. - */ - template <typename T, typename TT> - class Matcher<const TBasicStringBuf<T, TT>&>: public internal::MatcherBase<const TBasicStringBuf<T, TT>&> { - public: - Matcher() { - } - - explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl) - : internal::MatcherBase<const TBasicStringBuf<T, TT>&>(impl) { - } - + +namespace testing { + /** + * When matching `const TStringBuf&`, implicitly convert other strings and string views to `Eq` matchers. + */ + template <typename T, typename TT> + class Matcher<const TBasicStringBuf<T, TT>&>: public internal::MatcherBase<const TBasicStringBuf<T, TT>&> { + public: + Matcher() { + } + + explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl) + : internal::MatcherBase<const TBasicStringBuf<T, TT>&>(impl) { + } + template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher> Matcher(M&& m) : internal::MatcherBase<const TBasicStringBuf<T, TT>&>(std::forward<M>(m)) { } - Matcher(const TBasicString<T, TT>& s) { - *this = Eq(TBasicStringBuf<T, TT>(s)); - } - - Matcher(const T* s) { - *this = Eq(TBasicStringBuf<T, TT>(s)); - } - - Matcher(TBasicStringBuf<T, TT> s) { - *this = Eq(s); - } - }; - - /** - * When matching `TBasicBuf`, implicitly convert other strings and string views to `Eq` matchers. - */ - template <typename T, typename TT> - class Matcher<TBasicStringBuf<T, TT>>: public internal::MatcherBase<TBasicStringBuf<T, TT>> { - public: - Matcher() { - } - - explicit Matcher(const MatcherInterface <TBasicStringBuf<T, TT>>* impl) - : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) { - } - - explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl) - : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) { - } - + Matcher(const TBasicString<T, TT>& s) { + *this = Eq(TBasicStringBuf<T, TT>(s)); + } + + Matcher(const T* s) { + *this = Eq(TBasicStringBuf<T, TT>(s)); + } + + Matcher(TBasicStringBuf<T, TT> s) { + *this = Eq(s); + } + }; + + /** + * When matching `TBasicBuf`, implicitly convert other strings and string views to `Eq` matchers. + */ + template <typename T, typename TT> + class Matcher<TBasicStringBuf<T, TT>>: public internal::MatcherBase<TBasicStringBuf<T, TT>> { + public: + Matcher() { + } + + explicit Matcher(const MatcherInterface <TBasicStringBuf<T, TT>>* impl) + : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) { + } + + explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl) + : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) { + } + template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher> Matcher(M&& m) : internal::MatcherBase<TBasicStringBuf<T, TT>>(std::forward<M>(m)) { } - Matcher(const TBasicString<T, TT>& s) { - *this = Eq(TBasicString<T, TT>(s)); - } - - Matcher(const T* s) { - *this = Eq(TBasicString<T, TT>(s)); - } - - Matcher(TBasicStringBuf<T, TT> s) { - *this = Eq(s); - } - }; - - /** - * When matching `const TString&`, implicitly convert other strings and string views to `Eq` matchers. - */ - template <typename T, typename TT> - class Matcher<const TBasicString<T, TT>&>: public internal::MatcherBase<const TBasicString<T, TT>&> { - public: - Matcher() { - } - - explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl) - : internal::MatcherBase<const TBasicString<T, TT>&>(impl) { - } - - Matcher(const TBasicString<T, TT>& s) { - *this = Eq(s); - } - + Matcher(const TBasicString<T, TT>& s) { + *this = Eq(TBasicString<T, TT>(s)); + } + + Matcher(const T* s) { + *this = Eq(TBasicString<T, TT>(s)); + } + + Matcher(TBasicStringBuf<T, TT> s) { + *this = Eq(s); + } + }; + + /** + * When matching `const TString&`, implicitly convert other strings and string views to `Eq` matchers. + */ + template <typename T, typename TT> + class Matcher<const TBasicString<T, TT>&>: public internal::MatcherBase<const TBasicString<T, TT>&> { + public: + Matcher() { + } + + explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl) + : internal::MatcherBase<const TBasicString<T, TT>&>(impl) { + } + + Matcher(const TBasicString<T, TT>& s) { + *this = Eq(s); + } + template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher> Matcher(M&& m) : internal::MatcherBase<const TBasicString<T, TT>&>(std::forward<M>(m)) { } - Matcher(const T* s) { - *this = Eq(TBasicString<T, TT>(s)); - } - }; - - /** - * When matching `TString`, implicitly convert other strings and string views to `Eq` matchers. - */ - template <typename T, typename TT> - class Matcher<TBasicString<T, TT>>: public internal::MatcherBase<TBasicString<T, TT>> { - public: - Matcher() { - } - - explicit Matcher(const MatcherInterface <TBasicString<T, TT>>* impl) - : internal::MatcherBase<TBasicString<T, TT>>(impl) { - } - - explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl) - : internal::MatcherBase<TBasicString<T, TT>>(impl) { - } - + Matcher(const T* s) { + *this = Eq(TBasicString<T, TT>(s)); + } + }; + + /** + * When matching `TString`, implicitly convert other strings and string views to `Eq` matchers. + */ + template <typename T, typename TT> + class Matcher<TBasicString<T, TT>>: public internal::MatcherBase<TBasicString<T, TT>> { + public: + Matcher() { + } + + explicit Matcher(const MatcherInterface <TBasicString<T, TT>>* impl) + : internal::MatcherBase<TBasicString<T, TT>>(impl) { + } + + explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl) + : internal::MatcherBase<TBasicString<T, TT>>(impl) { + } + template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher> Matcher(M&& m) : internal::MatcherBase<TBasicString<T, TT>>(std::forward<M>(m)) { } - Matcher(const TBasicString<T, TT>& s) { - *this = Eq(s); - } - - Matcher(const T* s) { - *this = Eq(TBasicString<T, TT>(s)); - } - }; -} + Matcher(const TBasicString<T, TT>& s) { + *this = Eq(s); + } + + Matcher(const T* s) { + *this = Eq(TBasicString<T, TT>(s)); + } + }; +} diff --git a/library/cpp/testing/gtest_extensions/pretty_printers.cpp b/library/cpp/testing/gtest_extensions/pretty_printers.cpp index 401745cbcb..588584303b 100644 --- a/library/cpp/testing/gtest_extensions/pretty_printers.cpp +++ b/library/cpp/testing/gtest_extensions/pretty_printers.cpp @@ -1 +1 @@ -#include "pretty_printers.h" +#include "pretty_printers.h" diff --git a/library/cpp/testing/gtest_extensions/pretty_printers.h b/library/cpp/testing/gtest_extensions/pretty_printers.h index 14d8284446..28e51700f6 100644 --- a/library/cpp/testing/gtest_extensions/pretty_printers.h +++ b/library/cpp/testing/gtest_extensions/pretty_printers.h @@ -1,84 +1,84 @@ -#pragma once - -#include <util/generic/string.h> -#include <util/generic/strbuf.h> -#include <util/generic/maybe.h> -#include <util/generic/variant.h> -#include <util/stream/output.h> -#include <util/stream/str.h> -#include <util/datetime/base.h> - +#pragma once + +#include <util/generic/string.h> +#include <util/generic/strbuf.h> +#include <util/generic/maybe.h> +#include <util/generic/variant.h> +#include <util/stream/output.h> +#include <util/stream/str.h> +#include <util/datetime/base.h> + #include <gtest/gtest.h> #include <gmock/gmock.h> - -/** - * Automatically define GTest pretty printer for type that can print itself to util's `IOutputStream`. - * - * Note that this macro should be instantiated in the same namespace as the type you're printing, otherwise - * ADL will not find it. - * - * Example: - * - * We define a struct `TMyContainer` and an output operator that works with `IOutputStream`. We then use this macro - * to automatically define GTest pretty printer: - * - * ``` - * namespace NMy { - * struct TMyContainer { - * int x, y; - * }; - * } - * - * template <> - * inline void Out<NMy::TMyContainer>(IOutputStream& stream, TTypeTraits<NMy::TMyContainer>::TFuncParam value) { - * stream << "{ x=" << value.x << ", y=" << value.y << " }"; - * } - * - * namespace NMy { - * Y_GTEST_ARCADIA_PRINTER(TMyContainer) - * } - * ``` - */ + +/** + * Automatically define GTest pretty printer for type that can print itself to util's `IOutputStream`. + * + * Note that this macro should be instantiated in the same namespace as the type you're printing, otherwise + * ADL will not find it. + * + * Example: + * + * We define a struct `TMyContainer` and an output operator that works with `IOutputStream`. We then use this macro + * to automatically define GTest pretty printer: + * + * ``` + * namespace NMy { + * struct TMyContainer { + * int x, y; + * }; + * } + * + * template <> + * inline void Out<NMy::TMyContainer>(IOutputStream& stream, TTypeTraits<NMy::TMyContainer>::TFuncParam value) { + * stream << "{ x=" << value.x << ", y=" << value.y << " }"; + * } + * + * namespace NMy { + * Y_GTEST_ARCADIA_PRINTER(TMyContainer) + * } + * ``` + */ #define Y_GTEST_ARCADIA_PRINTER(T) \ void PrintTo(const T& value, std::ostream* stream) { \ - ::TString ss; \ - ::TStringOutput s{ss}; \ - s << value; \ - *stream << ss; \ - } - - + ::TString ss; \ + ::TStringOutput s{ss}; \ + s << value; \ + *stream << ss; \ + } + + template <typename TCharType, typename TCharTraits> void PrintTo(const TBasicString<TCharType, TCharTraits>& value, std::ostream* stream) { - *stream << value.Quote().c_str(); -} - + *stream << value.Quote().c_str(); +} + template <typename TCharType, typename TCharTraits> void PrintTo(TBasicStringBuf<TCharType, TCharTraits> value, std::ostream* stream) { *stream << TBasicString<TCharType, TCharTraits>{value}.Quote().c_str(); -} - -template <typename T, typename P> +} + +template <typename T, typename P> void PrintTo(const TMaybe<T, P>& value, std::ostream* stream) { - if (value.Defined()) { - ::testing::internal::UniversalPrint(value.GetRef(), stream); - } else { - *stream << "nothing"; - } -} - + if (value.Defined()) { + ::testing::internal::UniversalPrint(value.GetRef(), stream); + } else { + *stream << "nothing"; + } +} + inline void PrintTo(TNothing /* value */, std::ostream* stream) { - *stream << "nothing"; -} - + *stream << "nothing"; +} + inline void PrintTo(std::monostate /* value */, std::ostream* stream) { - *stream << "monostate"; -} - -inline void PrintTo(TInstant value, std::ostream* stream) { - *stream << value.ToString(); -} - -inline void PrintTo(TDuration value, std::ostream* stream) { - *stream << value.ToString(); -} + *stream << "monostate"; +} + +inline void PrintTo(TInstant value, std::ostream* stream) { + *stream << value.ToString(); +} + +inline void PrintTo(TDuration value, std::ostream* stream) { + *stream << value.ToString(); +} diff --git a/library/cpp/testing/gtest_extensions/ut/README.md b/library/cpp/testing/gtest_extensions/ut/README.md index ee8d212c18..71fff4e8d3 100644 --- a/library/cpp/testing/gtest_extensions/ut/README.md +++ b/library/cpp/testing/gtest_extensions/ut/README.md @@ -1 +1 @@ -Note: integration tests are located in */devtools/ya/test/tests/gtest_beta*. Launch them as well after changing this library. +Note: integration tests are located in */devtools/ya/test/tests/gtest_beta*. Launch them as well after changing this library. diff --git a/library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp b/library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp index 81cdfd0427..de39aeeb2e 100644 --- a/library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp +++ b/library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp @@ -1,9 +1,9 @@ -#include <library/cpp/testing/gtest/gtest.h> +#include <library/cpp/testing/gtest/gtest.h> -#include <util/generic/string.h> -#include <util/generic/maybe.h> -#include <util/stream/output.h> -#include <util/stream/str.h> +#include <util/generic/string.h> +#include <util/generic/maybe.h> +#include <util/stream/output.h> +#include <util/stream/str.h> namespace { class IMock { @@ -24,323 +24,323 @@ namespace { } -TEST(MatchersSpecializations, String) { - TSampleMock mock; +TEST(MatchersSpecializations, String) { + TSampleMock mock; - TStringBuf simpleStringBuf = "SimpleStringBuf"; - const TStringBuf constSimpleStringBuf = "ConstSimpleStringBuf"; + TStringBuf simpleStringBuf = "SimpleStringBuf"; + const TStringBuf constSimpleStringBuf = "ConstSimpleStringBuf"; - TString simpleString = "SimpleString"; - const TString constSimpleString = "ConstSimpleString"; + TString simpleString = "SimpleString"; + const TString constSimpleString = "ConstSimpleString"; - EXPECT_CALL(mock, M1("ConstSimpleStringBuf")).Times(1); - EXPECT_CALL(mock, M2("SimpleStringBuf")).Times(1); - EXPECT_CALL(mock, M3("ConstSimpleString")).Times(1); - EXPECT_CALL(mock, M4("SimpleString")).Times(1); + EXPECT_CALL(mock, M1("ConstSimpleStringBuf")).Times(1); + EXPECT_CALL(mock, M2("SimpleStringBuf")).Times(1); + EXPECT_CALL(mock, M3("ConstSimpleString")).Times(1); + EXPECT_CALL(mock, M4("SimpleString")).Times(1); - mock.M1(constSimpleStringBuf); - mock.M2(simpleStringBuf); - mock.M3(constSimpleString); - mock.M4(simpleString); -} - -template <typename T, typename M> -std::pair<bool, std::string> Match(T&& t, M&& m) { - testing::StringMatchResultListener listener; - auto matches = testing::SafeMatcherCast<T>(std::forward<M>(m)).MatchAndExplain(std::forward<T>(t), &listener); - return {matches, listener.str()}; -} + mock.M1(constSimpleStringBuf); + mock.M2(simpleStringBuf); + mock.M3(constSimpleString); + mock.M4(simpleString); +} -TEST(Matchers, Throws) { +template <typename T, typename M> +std::pair<bool, std::string> Match(T&& t, M&& m) { + testing::StringMatchResultListener listener; + auto matches = testing::SafeMatcherCast<T>(std::forward<M>(m)).MatchAndExplain(std::forward<T>(t), &listener); + return {matches, listener.str()}; +} + +TEST(Matchers, Throws) { auto matcher = testing::Throws<std::runtime_error>(); - - { - std::stringstream ss; - testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); - auto explanation = ss.str(); - - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - } - - { - auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); - EXPECT_TRUE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - } - - { - auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); - } - - { - auto [matched, explanation] = Match([]() { throw 10; }, matcher); - EXPECT_FALSE(matched); + + { + std::stringstream ss; + testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); + auto explanation = ss.str(); + + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + } + + { + auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); + EXPECT_TRUE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + } + + { + auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); + } + + { + auto [matched, explanation] = Match([]() { throw 10; }, matcher); + EXPECT_FALSE(matched); EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type")); - } - - { - auto [matched, explanation] = Match([]() { (void)0; }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); - } -} - -TEST(Matchers, ThrowsMessage) { + } + + { + auto [matched, explanation] = Match([]() { (void)0; }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); + } +} + +TEST(Matchers, ThrowsMessage) { auto matcher = testing::ThrowsMessage<std::runtime_error>(testing::HasSubstr("error message")); - - { - std::stringstream ss; - testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); - auto explanation = ss.str(); - - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); - } - - { - auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); - EXPECT_TRUE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - } - - { - auto [matched, explanation] = Match([]() { throw std::runtime_error("message error"); }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - } - - { - auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); - } - - { - auto [matched, explanation] = Match([]() { throw 10; }, matcher); - EXPECT_FALSE(matched); + + { + std::stringstream ss; + testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); + auto explanation = ss.str(); + + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); + } + + { + auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); + EXPECT_TRUE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + } + + { + auto [matched, explanation] = Match([]() { throw std::runtime_error("message error"); }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + } + + { + auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); + } + + { + auto [matched, explanation] = Match([]() { throw 10; }, matcher); + EXPECT_FALSE(matched); EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type")); - } - - { - auto [matched, explanation] = Match([]() { (void)0; }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); - } -} - -TEST(Matchers, ThrowsMessageHasSubstr) { + } + + { + auto [matched, explanation] = Match([]() { (void)0; }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); + } +} + +TEST(Matchers, ThrowsMessageHasSubstr) { auto matcher = testing::ThrowsMessage<std::runtime_error>(testing::HasSubstr("error message")); - - { - std::stringstream ss; - testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); - auto explanation = ss.str(); - - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); - } - - { - auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); - EXPECT_TRUE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - } - - { - auto [matched, explanation] = Match([]() { throw std::runtime_error("message error"); }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - } - - { - auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); - } - - { - auto [matched, explanation] = Match([]() { throw 10; }, matcher); - EXPECT_FALSE(matched); + + { + std::stringstream ss; + testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); + auto explanation = ss.str(); + + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); + } + + { + auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); + EXPECT_TRUE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + } + + { + auto [matched, explanation] = Match([]() { throw std::runtime_error("message error"); }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + } + + { + auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); + } + + { + auto [matched, explanation] = Match([]() { throw 10; }, matcher); + EXPECT_FALSE(matched); EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type")); - } - - { - auto [matched, explanation] = Match([]() { (void)0; }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); - } -} - -TEST(Matchers, ThrowsCondition) { + } + + { + auto [matched, explanation] = Match([]() { (void)0; }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); + } +} + +TEST(Matchers, ThrowsCondition) { auto matcher = testing::Throws<std::runtime_error>( - testing::Property(&std::exception::what, testing::HasSubstr("error message"))); - - { - std::stringstream ss; - testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); - auto explanation = ss.str(); - - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); - } - - { - auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); - EXPECT_TRUE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - } - - { - auto [matched, explanation] = Match([]() { throw std::runtime_error("message error"); }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"message error\"")); - } - - { - auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); - EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); - } - - { - auto [matched, explanation] = Match([]() { throw 10; }, matcher); - EXPECT_FALSE(matched); + testing::Property(&std::exception::what, testing::HasSubstr("error message"))); + + { + std::stringstream ss; + testing::SafeMatcherCast<void(*)()>(matcher).DescribeTo(&ss); + auto explanation = ss.str(); + + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); + } + + { + auto [matched, explanation] = Match([]() { throw std::runtime_error("error message"); }, matcher); + EXPECT_TRUE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + } + + { + auto [matched, explanation] = Match([]() { throw std::runtime_error("message error"); }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::runtime_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"message error\"")); + } + + { + auto [matched, explanation] = Match([]() { throw std::logic_error("error message"); }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("std::logic_error")); + EXPECT_THAT(explanation, testing::HasSubstr("\"error message\"")); + } + + { + auto [matched, explanation] = Match([]() { throw 10; }, matcher); + EXPECT_FALSE(matched); EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type")); + } + + { + auto [matched, explanation] = Match([]() { (void)0; }, matcher); + EXPECT_FALSE(matched); + EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); + } +} + +template <typename T> +std::string GtestPrint(T&& v) { + std::stringstream ss; + testing::internal::UniversalPrint(std::forward<T>(v), &ss); + return ss.str(); +} + +struct TThrowsOnMove { + TThrowsOnMove() = default; + TThrowsOnMove(TThrowsOnMove&&) { + ythrow yexception() << "move failed"; } - - { - auto [matched, explanation] = Match([]() { (void)0; }, matcher); - EXPECT_FALSE(matched); - EXPECT_THAT(explanation, testing::HasSubstr("does not throw any exception")); - } -} - -template <typename T> -std::string GtestPrint(T&& v) { - std::stringstream ss; - testing::internal::UniversalPrint(std::forward<T>(v), &ss); - return ss.str(); -} - -struct TThrowsOnMove { - TThrowsOnMove() = default; - TThrowsOnMove(TThrowsOnMove&&) { - ythrow yexception() << "move failed"; - } -}; - -TEST(PrettyPrinters, String) { - EXPECT_EQ(GtestPrint(TString("hello world")), "\"hello world\""); - EXPECT_EQ(GtestPrint(TStringBuf("hello world")), "\"hello world\""); -} - -TEST(PrettyPrinters, Maybe) { - EXPECT_EQ(GtestPrint(TMaybe<TString>("hello world")), "\"hello world\""); - EXPECT_EQ(GtestPrint(TMaybe<TString>()), "nothing"); - EXPECT_EQ(GtestPrint(Nothing()), "nothing"); -} - -struct T1 { - int x; -}; - +}; + +TEST(PrettyPrinters, String) { + EXPECT_EQ(GtestPrint(TString("hello world")), "\"hello world\""); + EXPECT_EQ(GtestPrint(TStringBuf("hello world")), "\"hello world\""); +} + +TEST(PrettyPrinters, Maybe) { + EXPECT_EQ(GtestPrint(TMaybe<TString>("hello world")), "\"hello world\""); + EXPECT_EQ(GtestPrint(TMaybe<TString>()), "nothing"); + EXPECT_EQ(GtestPrint(Nothing()), "nothing"); +} + +struct T1 { + int x; +}; + void PrintTo(T1 value, std::ostream* stream) { - *stream << "T1{" << value.x << "}"; -} - -struct T2 { - int x; -}; - -Y_DECLARE_OUT_SPEC(inline, T2, stream, value) { - stream << "T2{" << value.x << "}"; -} - -Y_GTEST_ARCADIA_PRINTER(T2) - -TEST(PrettyPrinters, Custom) { - EXPECT_EQ(GtestPrint(T1{10}), "T1{10}"); -} - -TEST(PrettyPrinters, CustomArcadia) { - EXPECT_EQ(GtestPrint(T2{10}), "T2{10}"); -} - -TEST(Exceptions, ExpectThrow) { - EXPECT_THROW(ythrow yexception() << "msg", yexception); -} - -TEST(Exceptions, ExpectThrowStructuredBindings) { - auto [a, b] = std::make_pair("a", "b"); - EXPECT_THROW(throw yexception() << a << "-" << b, yexception); -} - -TEST(Exceptions, ExpectThrowSkipInThrowTest) { - // this test should be skipped, not failed - EXPECT_THROW(GTEST_SKIP(), yexception); -} - -TEST(Exceptions, AssertThrow) { - ASSERT_THROW(ythrow yexception() << "msg", yexception); -} - -TEST(Exceptions, AssertThrowStructuredBindings) { - auto [a, b] = std::make_pair("a", "b"); - ASSERT_THROW(throw yexception() << a << "-" << b, yexception); -} - -TEST(Exceptions, AssertThrowSkipInThrowTest) { - // this test should be skipped, not failed - ASSERT_THROW(GTEST_SKIP(), yexception); -} - -TEST(Exceptions, ExpectThrowMessageHasSubstr) { - EXPECT_THROW_MESSAGE_HAS_SUBSTR(ythrow yexception() << "msg", yexception, "msg"); -} - -TEST(Exceptions, ExpectThrowMessageHasSubstrStructuredBindings) { - auto [a, b] = std::make_pair("a", "b"); - EXPECT_THROW_MESSAGE_HAS_SUBSTR(throw yexception() << a << "-" << b, yexception, "-"); -} - -TEST(Exceptions, ExpectThrowMessageHasSubstrSkipInThrowTest) { - // this test should be skipped, not failed - EXPECT_THROW_MESSAGE_HAS_SUBSTR(GTEST_SKIP(), yexception, "-"); -} - -TEST(Exceptions, AssertThrowMessageHasSubstr) { - ASSERT_THROW_MESSAGE_HAS_SUBSTR(ythrow yexception() << "msg", yexception, "msg"); -} - -TEST(Exceptions, AssertThrowMessageHasSubstrStructuredBindings) { - auto [a, b] = std::make_pair("a", "b"); - ASSERT_THROW_MESSAGE_HAS_SUBSTR(throw yexception() << a << "-" << b, yexception, "-"); -} - -TEST(Exceptions, AssertThrowMessageHasSubstrSkipInThrowTest) { - // this test should be skipped, not failed - ASSERT_THROW_MESSAGE_HAS_SUBSTR(GTEST_SKIP(), yexception, "-"); -} - -TEST(Exceptions, ExpectNoThrow) { - EXPECT_NO_THROW((void)0); -} - -TEST(Exceptions, AssertNoThrow) { - ASSERT_NO_THROW((void)0); -} - -TEST(Exceptions, ExpectAnyThrow) { - EXPECT_ANY_THROW(ythrow yexception() << "msg"); -} - -TEST(Exceptions, AssertAnyThrow) { - ASSERT_ANY_THROW(ythrow yexception() << "msg"); -} + *stream << "T1{" << value.x << "}"; +} + +struct T2 { + int x; +}; + +Y_DECLARE_OUT_SPEC(inline, T2, stream, value) { + stream << "T2{" << value.x << "}"; +} + +Y_GTEST_ARCADIA_PRINTER(T2) + +TEST(PrettyPrinters, Custom) { + EXPECT_EQ(GtestPrint(T1{10}), "T1{10}"); +} + +TEST(PrettyPrinters, CustomArcadia) { + EXPECT_EQ(GtestPrint(T2{10}), "T2{10}"); +} + +TEST(Exceptions, ExpectThrow) { + EXPECT_THROW(ythrow yexception() << "msg", yexception); +} + +TEST(Exceptions, ExpectThrowStructuredBindings) { + auto [a, b] = std::make_pair("a", "b"); + EXPECT_THROW(throw yexception() << a << "-" << b, yexception); +} + +TEST(Exceptions, ExpectThrowSkipInThrowTest) { + // this test should be skipped, not failed + EXPECT_THROW(GTEST_SKIP(), yexception); +} + +TEST(Exceptions, AssertThrow) { + ASSERT_THROW(ythrow yexception() << "msg", yexception); +} + +TEST(Exceptions, AssertThrowStructuredBindings) { + auto [a, b] = std::make_pair("a", "b"); + ASSERT_THROW(throw yexception() << a << "-" << b, yexception); +} + +TEST(Exceptions, AssertThrowSkipInThrowTest) { + // this test should be skipped, not failed + ASSERT_THROW(GTEST_SKIP(), yexception); +} + +TEST(Exceptions, ExpectThrowMessageHasSubstr) { + EXPECT_THROW_MESSAGE_HAS_SUBSTR(ythrow yexception() << "msg", yexception, "msg"); +} + +TEST(Exceptions, ExpectThrowMessageHasSubstrStructuredBindings) { + auto [a, b] = std::make_pair("a", "b"); + EXPECT_THROW_MESSAGE_HAS_SUBSTR(throw yexception() << a << "-" << b, yexception, "-"); +} + +TEST(Exceptions, ExpectThrowMessageHasSubstrSkipInThrowTest) { + // this test should be skipped, not failed + EXPECT_THROW_MESSAGE_HAS_SUBSTR(GTEST_SKIP(), yexception, "-"); +} + +TEST(Exceptions, AssertThrowMessageHasSubstr) { + ASSERT_THROW_MESSAGE_HAS_SUBSTR(ythrow yexception() << "msg", yexception, "msg"); +} + +TEST(Exceptions, AssertThrowMessageHasSubstrStructuredBindings) { + auto [a, b] = std::make_pair("a", "b"); + ASSERT_THROW_MESSAGE_HAS_SUBSTR(throw yexception() << a << "-" << b, yexception, "-"); +} + +TEST(Exceptions, AssertThrowMessageHasSubstrSkipInThrowTest) { + // this test should be skipped, not failed + ASSERT_THROW_MESSAGE_HAS_SUBSTR(GTEST_SKIP(), yexception, "-"); +} + +TEST(Exceptions, ExpectNoThrow) { + EXPECT_NO_THROW((void)0); +} + +TEST(Exceptions, AssertNoThrow) { + ASSERT_NO_THROW((void)0); +} + +TEST(Exceptions, ExpectAnyThrow) { + EXPECT_ANY_THROW(ythrow yexception() << "msg"); +} + +TEST(Exceptions, AssertAnyThrow) { + ASSERT_ANY_THROW(ythrow yexception() << "msg"); +} diff --git a/library/cpp/testing/gtest_extensions/ut/ya.make b/library/cpp/testing/gtest_extensions/ut/ya.make index 39b41cecfd..b68cb4645b 100644 --- a/library/cpp/testing/gtest_extensions/ut/ya.make +++ b/library/cpp/testing/gtest_extensions/ut/ya.make @@ -1,20 +1,20 @@ GTEST() OWNER( - amatanhead + amatanhead bulatman dancingqueue - prettyboy - thegeorg + prettyboy + thegeorg g:cpp-contrib ) SRCS( - gtest_extensions_ut.cpp + gtest_extensions_ut.cpp probe_ut.cpp ) PEERDIR( - library/cpp/testing/gtest_extensions + library/cpp/testing/gtest_extensions ) END() diff --git a/library/cpp/testing/gtest_extensions/ya.make b/library/cpp/testing/gtest_extensions/ya.make index e24e81e8bd..b4871724bb 100644 --- a/library/cpp/testing/gtest_extensions/ya.make +++ b/library/cpp/testing/gtest_extensions/ya.make @@ -1,10 +1,10 @@ LIBRARY() OWNER( - amatanhead + amatanhead bulatman dancingqueue - prettyboy - thegeorg + prettyboy + thegeorg g:cpp-contrib ) @@ -14,10 +14,10 @@ PEERDIR( ) SRCS( - assertions.cpp - gtest_extensions.cpp - matchers.cpp - pretty_printers.cpp + assertions.cpp + gtest_extensions.cpp + matchers.cpp + pretty_printers.cpp probe.cpp ) |