aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/gtest_extensions
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
commit2f6ca198245aeffd5e2d82b65927c2465b68b4f5 (patch)
tree9142afc54d335ea52910662635b898e79e192e49 /library/cpp/testing/gtest_extensions
parent6560e4993b14d193f8c879e33a3de5e5eba6e21d (diff)
downloadydb-2f6ca198245aeffd5e2d82b65927c2465b68b4f5.tar.gz
Restoring authorship annotation for <bulatman@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/testing/gtest_extensions')
-rw-r--r--library/cpp/testing/gtest_extensions/assertions.h4
-rw-r--r--library/cpp/testing/gtest_extensions/gtest_extensions.h2
-rw-r--r--library/cpp/testing/gtest_extensions/matchers.h44
-rw-r--r--library/cpp/testing/gtest_extensions/pretty_printers.h4
-rw-r--r--library/cpp/testing/gtest_extensions/probe.cpp22
-rw-r--r--library/cpp/testing/gtest_extensions/probe.h94
-rw-r--r--library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp16
-rw-r--r--library/cpp/testing/gtest_extensions/ut/probe_ut.cpp108
-rw-r--r--library/cpp/testing/gtest_extensions/ut/ya.make2
-rw-r--r--library/cpp/testing/gtest_extensions/ya.make6
10 files changed, 151 insertions, 151 deletions
diff --git a/library/cpp/testing/gtest_extensions/assertions.h b/library/cpp/testing/gtest_extensions/assertions.h
index 30b9c645ff..e8ea07b5df 100644
--- a/library/cpp/testing/gtest_extensions/assertions.h
+++ b/library/cpp/testing/gtest_extensions/assertions.h
@@ -2,8 +2,8 @@
#include <util/generic/string.h>
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
/**
* Check that the given statement throws an exception of the given type,
diff --git a/library/cpp/testing/gtest_extensions/gtest_extensions.h b/library/cpp/testing/gtest_extensions/gtest_extensions.h
index 3c2800c2b6..e20532241e 100644
--- a/library/cpp/testing/gtest_extensions/gtest_extensions.h
+++ b/library/cpp/testing/gtest_extensions/gtest_extensions.h
@@ -3,4 +3,4 @@
#include "assertions.h"
#include "matchers.h"
#include "pretty_printers.h"
-#include "probe.h"
+#include "probe.h"
diff --git a/library/cpp/testing/gtest_extensions/matchers.h b/library/cpp/testing/gtest_extensions/matchers.h
index 01f26f54e4..044c1c3ee4 100644
--- a/library/cpp/testing/gtest_extensions/matchers.h
+++ b/library/cpp/testing/gtest_extensions/matchers.h
@@ -2,8 +2,8 @@
#include <util/generic/string.h>
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
namespace testing {
/**
@@ -19,11 +19,11 @@ namespace testing {
: 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)) {
- }
-
+ 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));
}
@@ -54,11 +54,11 @@ namespace testing {
: 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)) {
- }
-
+ 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));
}
@@ -89,11 +89,11 @@ namespace testing {
*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)) {
- }
-
+ 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));
}
@@ -116,11 +116,11 @@ namespace testing {
: 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)) {
- }
-
+ 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);
}
diff --git a/library/cpp/testing/gtest_extensions/pretty_printers.h b/library/cpp/testing/gtest_extensions/pretty_printers.h
index 15f07e4fe8..14d8284446 100644
--- a/library/cpp/testing/gtest_extensions/pretty_printers.h
+++ b/library/cpp/testing/gtest_extensions/pretty_printers.h
@@ -8,8 +8,8 @@
#include <util/stream/str.h>
#include <util/datetime/base.h>
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
/**
* Automatically define GTest pretty printer for type that can print itself to util's `IOutputStream`.
diff --git a/library/cpp/testing/gtest_extensions/probe.cpp b/library/cpp/testing/gtest_extensions/probe.cpp
index f8d59ebd6b..c3a49b9323 100644
--- a/library/cpp/testing/gtest_extensions/probe.cpp
+++ b/library/cpp/testing/gtest_extensions/probe.cpp
@@ -1,13 +1,13 @@
-#include "probe.h"
-
-#include <ostream>
-
+#include "probe.h"
+
+#include <ostream>
+
namespace testing {
- void PrintTo(const TProbeState& state, ::std::ostream* os) {
- int copies = state.CopyConstructors + state.CopyAssignments;
- int moves = state.MoveConstructors + state.MoveAssignments;
- *os << state.Constructors << " ctors, " << state.Destructors << " dtors; "
- << "copies: " << copies << " = " << state.CopyConstructors << " + " << state.CopyAssignments << "; "
- << "moves: " << moves << " = " << state.MoveConstructors << " + " << state.MoveAssignments;
- }
+ void PrintTo(const TProbeState& state, ::std::ostream* os) {
+ int copies = state.CopyConstructors + state.CopyAssignments;
+ int moves = state.MoveConstructors + state.MoveAssignments;
+ *os << state.Constructors << " ctors, " << state.Destructors << " dtors; "
+ << "copies: " << copies << " = " << state.CopyConstructors << " + " << state.CopyAssignments << "; "
+ << "moves: " << moves << " = " << state.MoveConstructors << " + " << state.MoveAssignments;
+ }
} // namespace testing
diff --git a/library/cpp/testing/gtest_extensions/probe.h b/library/cpp/testing/gtest_extensions/probe.h
index 3b18502555..7d1fee83d3 100644
--- a/library/cpp/testing/gtest_extensions/probe.h
+++ b/library/cpp/testing/gtest_extensions/probe.h
@@ -1,81 +1,81 @@
#pragma once
-#include <util/system/yassert.h>
+#include <util/system/yassert.h>
#include <library/cpp/testing/common/probe.h>
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
namespace testing {
using NTesting::TProbe;
using NTesting::TProbeState;
using NTesting::TCoercibleToProbe;
- // A helper functor which extracts from probe-like objectss their state.
- struct TProbableTraits {
- static const TProbeState& ExtractState(const TProbeState& probe) {
- return probe;
- }
+ // A helper functor which extracts from probe-like objectss their state.
+ struct TProbableTraits {
+ static const TProbeState& ExtractState(const TProbeState& probe) {
+ return probe;
+ }
- static const TProbeState& ExtractState(const TProbeState* probe) {
- return *probe;
- }
+ static const TProbeState& ExtractState(const TProbeState* probe) {
+ return *probe;
+ }
- static const TProbeState& ExtractState(const TProbe& probe) {
- return *probe.State;
- }
+ static const TProbeState& ExtractState(const TProbe& probe) {
+ return *probe.State;
+ }
- static const TProbeState& ExtractState(const TCoercibleToProbe& probe) {
- return *probe.State;
- }
- };
+ static const TProbeState& ExtractState(const TCoercibleToProbe& probe) {
+ return *probe.State;
+ }
+ };
- void PrintTo(const TProbeState& state, ::std::ostream* os);
+ void PrintTo(const TProbeState& state, ::std::ostream* os);
- inline void PrintTo(const TProbe& probe, ::std::ostream* os) {
- PrintTo(TProbableTraits::ExtractState(probe), os);
+ inline void PrintTo(const TProbe& probe, ::std::ostream* os) {
+ PrintTo(TProbableTraits::ExtractState(probe), os);
}
- inline void PrintTo(const TCoercibleToProbe& probe, ::std::ostream* os) {
- PrintTo(TProbableTraits::ExtractState(probe), os);
+ inline void PrintTo(const TCoercibleToProbe& probe, ::std::ostream* os) {
+ PrintTo(TProbableTraits::ExtractState(probe), os);
}
- MATCHER(IsAlive, "is alive") {
- Y_UNUSED(result_listener);
+ MATCHER(IsAlive, "is alive") {
+ Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
- return state.Destructors < state.Constructors + state.CopyConstructors + state.CopyAssignments;
+ return state.Destructors < state.Constructors + state.CopyConstructors + state.CopyAssignments;
}
- MATCHER(IsDead, "is dead") {
- Y_UNUSED(result_listener);
+ MATCHER(IsDead, "is dead") {
+ Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
- return state.Destructors == state.Constructors + state.CopyConstructors + state.CopyAssignments;
+ return state.Destructors == state.Constructors + state.CopyConstructors + state.CopyAssignments;
}
- MATCHER_P2(HasCopyMoveCounts, copyCount, moveCount, "" + \
- PrintToString(copyCount) + " copy constructors and " + \
- PrintToString(moveCount) + " move constructors were called") {
- Y_UNUSED(result_listener);
+ MATCHER_P2(HasCopyMoveCounts, copyCount, moveCount, "" + \
+ PrintToString(copyCount) + " copy constructors and " + \
+ PrintToString(moveCount) + " move constructors were called") {
+ Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
- return state.CopyConstructors == copyCount && state.MoveConstructors == moveCount;
- }
+ return state.CopyConstructors == copyCount && state.MoveConstructors == moveCount;
+ }
- MATCHER(NoCopies, "no copies were made") {
- Y_UNUSED(result_listener);
+ MATCHER(NoCopies, "no copies were made") {
+ Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
- return 0 == state.CopyConstructors && 0 == state.CopyAssignments;
- }
+ return 0 == state.CopyConstructors && 0 == state.CopyAssignments;
+ }
- MATCHER(NoMoves, "no moves were made") {
- Y_UNUSED(result_listener);
+ MATCHER(NoMoves, "no moves were made") {
+ Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
- return 0 == state.MoveConstructors && 0 == state.MoveAssignments;
- }
+ return 0 == state.MoveConstructors && 0 == state.MoveAssignments;
+ }
- MATCHER(NoAssignments, "no assignments were made") {
- Y_UNUSED(result_listener);
+ MATCHER(NoAssignments, "no assignments were made") {
+ Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
- return 0 == state.CopyAssignments && 0 == state.MoveAssignments;
- }
+ return 0 == state.CopyAssignments && 0 == state.MoveAssignments;
+ }
}
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 7fb0fd7a21..81cdfd0427 100644
--- a/library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp
+++ b/library/cpp/testing/gtest_extensions/ut/gtest_extensions_ut.cpp
@@ -52,7 +52,7 @@ std::pair<bool, std::string> Match(T&& t, M&& m) {
}
TEST(Matchers, Throws) {
- auto matcher = testing::Throws<std::runtime_error>();
+ auto matcher = testing::Throws<std::runtime_error>();
{
std::stringstream ss;
@@ -78,7 +78,7 @@ TEST(Matchers, Throws) {
{
auto [matched, explanation] = Match([]() { throw 10; }, matcher);
EXPECT_FALSE(matched);
- EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
+ EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
}
{
@@ -89,7 +89,7 @@ TEST(Matchers, Throws) {
}
TEST(Matchers, ThrowsMessage) {
- auto matcher = testing::ThrowsMessage<std::runtime_error>(testing::HasSubstr("error message"));
+ auto matcher = testing::ThrowsMessage<std::runtime_error>(testing::HasSubstr("error message"));
{
std::stringstream ss;
@@ -122,7 +122,7 @@ TEST(Matchers, ThrowsMessage) {
{
auto [matched, explanation] = Match([]() { throw 10; }, matcher);
EXPECT_FALSE(matched);
- EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
+ EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
}
{
@@ -133,7 +133,7 @@ TEST(Matchers, ThrowsMessage) {
}
TEST(Matchers, ThrowsMessageHasSubstr) {
- auto matcher = testing::ThrowsMessage<std::runtime_error>(testing::HasSubstr("error message"));
+ auto matcher = testing::ThrowsMessage<std::runtime_error>(testing::HasSubstr("error message"));
{
std::stringstream ss;
@@ -166,7 +166,7 @@ TEST(Matchers, ThrowsMessageHasSubstr) {
{
auto [matched, explanation] = Match([]() { throw 10; }, matcher);
EXPECT_FALSE(matched);
- EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
+ EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
}
{
@@ -177,7 +177,7 @@ TEST(Matchers, ThrowsMessageHasSubstr) {
}
TEST(Matchers, ThrowsCondition) {
- auto matcher = testing::Throws<std::runtime_error>(
+ auto matcher = testing::Throws<std::runtime_error>(
testing::Property(&std::exception::what, testing::HasSubstr("error message")));
{
@@ -212,7 +212,7 @@ TEST(Matchers, ThrowsCondition) {
{
auto [matched, explanation] = Match([]() { throw 10; }, matcher);
EXPECT_FALSE(matched);
- EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
+ EXPECT_THAT(explanation, testing::HasSubstr("throws an exception of an unknown type"));
}
{
diff --git a/library/cpp/testing/gtest_extensions/ut/probe_ut.cpp b/library/cpp/testing/gtest_extensions/ut/probe_ut.cpp
index 428f313b9e..a9d53f896a 100644
--- a/library/cpp/testing/gtest_extensions/ut/probe_ut.cpp
+++ b/library/cpp/testing/gtest_extensions/ut/probe_ut.cpp
@@ -1,54 +1,54 @@
-#include <library/cpp/testing/gtest/gtest.h>
-
-using namespace testing;
-
-TEST(ProbeStateTest, Example) {
- // check that our test function does not make a copy of passed argument
- auto copyless = [](auto&& x) {
- TProbe p(std::move(x));
- p.Touch();
- return p;
- };
-
- TProbeState state;
- auto probe = copyless(TProbe(&state));
- EXPECT_EQ(1, state.Touches);
- EXPECT_THAT(state, HasCopyMoveCounts(0, 2));
-}
-
-TEST(ProbeTest, Construct) {
- TProbeState state;
- {
- TProbe probe(&state);
- EXPECT_THAT(state, IsAlive());
- }
- EXPECT_THAT(state, IsDead());
-}
-
-TEST(ProbeTest, Copy) {
- TProbeState state;
-
- TProbe probe(&state);
- TProbe copy(probe);
- EXPECT_THAT(state, HasCopyMoveCounts(1, 0));
- EXPECT_THAT(state, NoAssignments());
- EXPECT_THAT(state, NoMoves());
-
- TProbe copy2 = TProbe::ExplicitlyCreateInvalidProbe();
- copy2 = probe;
- EXPECT_EQ(1, state.CopyAssignments);
-}
-
-TEST(ProbeTest, Move) {
- TProbeState state;
- TProbe probe(&state);
- TProbe probe2(std::move(probe));
- EXPECT_FALSE(probe.IsValid());
- EXPECT_THAT(state, NoCopies());
-
- EXPECT_THAT(state, HasCopyMoveCounts(0, 1));
-
- TProbe probe3 = TProbe::ExplicitlyCreateInvalidProbe();
- probe3 = std::move(probe2);
- EXPECT_EQ(1, state.MoveAssignments);
-}
+#include <library/cpp/testing/gtest/gtest.h>
+
+using namespace testing;
+
+TEST(ProbeStateTest, Example) {
+ // check that our test function does not make a copy of passed argument
+ auto copyless = [](auto&& x) {
+ TProbe p(std::move(x));
+ p.Touch();
+ return p;
+ };
+
+ TProbeState state;
+ auto probe = copyless(TProbe(&state));
+ EXPECT_EQ(1, state.Touches);
+ EXPECT_THAT(state, HasCopyMoveCounts(0, 2));
+}
+
+TEST(ProbeTest, Construct) {
+ TProbeState state;
+ {
+ TProbe probe(&state);
+ EXPECT_THAT(state, IsAlive());
+ }
+ EXPECT_THAT(state, IsDead());
+}
+
+TEST(ProbeTest, Copy) {
+ TProbeState state;
+
+ TProbe probe(&state);
+ TProbe copy(probe);
+ EXPECT_THAT(state, HasCopyMoveCounts(1, 0));
+ EXPECT_THAT(state, NoAssignments());
+ EXPECT_THAT(state, NoMoves());
+
+ TProbe copy2 = TProbe::ExplicitlyCreateInvalidProbe();
+ copy2 = probe;
+ EXPECT_EQ(1, state.CopyAssignments);
+}
+
+TEST(ProbeTest, Move) {
+ TProbeState state;
+ TProbe probe(&state);
+ TProbe probe2(std::move(probe));
+ EXPECT_FALSE(probe.IsValid());
+ EXPECT_THAT(state, NoCopies());
+
+ EXPECT_THAT(state, HasCopyMoveCounts(0, 1));
+
+ TProbe probe3 = TProbe::ExplicitlyCreateInvalidProbe();
+ probe3 = std::move(probe2);
+ EXPECT_EQ(1, state.MoveAssignments);
+}
diff --git a/library/cpp/testing/gtest_extensions/ut/ya.make b/library/cpp/testing/gtest_extensions/ut/ya.make
index ca333b4905..39b41cecfd 100644
--- a/library/cpp/testing/gtest_extensions/ut/ya.make
+++ b/library/cpp/testing/gtest_extensions/ut/ya.make
@@ -10,7 +10,7 @@ OWNER(
SRCS(
gtest_extensions_ut.cpp
- probe_ut.cpp
+ probe_ut.cpp
)
PEERDIR(
diff --git a/library/cpp/testing/gtest_extensions/ya.make b/library/cpp/testing/gtest_extensions/ya.make
index 4537d0153f..e24e81e8bd 100644
--- a/library/cpp/testing/gtest_extensions/ya.make
+++ b/library/cpp/testing/gtest_extensions/ya.make
@@ -9,8 +9,8 @@ OWNER(
)
PEERDIR(
- contrib/restricted/googletest/googlemock
- contrib/restricted/googletest/googletest
+ contrib/restricted/googletest/googlemock
+ contrib/restricted/googletest/googletest
)
SRCS(
@@ -18,7 +18,7 @@ SRCS(
gtest_extensions.cpp
matchers.cpp
pretty_printers.cpp
- probe.cpp
+ probe.cpp
)
END()