Skip to content

Commit 0618373

Browse files
committed
[GTest] fix for should
1 parent d60c6d2 commit 0618373

File tree

2 files changed

+21
-41
lines changed

2 files changed

+21
-41
lines changed

include/GUnit/GTest.h

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ bool FilterMatchesShould(const std::string& name, const std::string &should) {
8181

8282
struct TestRun {
8383
std::string should = GetShouldParam();
84-
bool once = false;
84+
bool once = true;
8585

8686
static std::string GetShouldParam() {
8787
const std::string filter = "--should=";
@@ -95,14 +95,14 @@ struct TestRun {
9595

9696
bool run(const std::string& name, int line) {
9797
if (once) {
98-
return false;
98+
return once;
9999
}
100100
const auto result = line > test_line && FilterMatchesShould(name, should);
101101
if (result) {
102102
std::cout << "[ SHOULD ] " << name << std::endl;
103+
test_line = line;
104+
once = true;
103105
}
104-
test_line = line;
105-
once = true;
106106
return result;
107107
}
108108

@@ -141,21 +141,6 @@ class GTestAutoRegister {
141141
return str;
142142
}
143143

144-
//bool RegisterShouldParamTestCase() {
145-
//auto registered = false;
146-
//for (const auto& ti : tests()) {
147-
//if (GetTypeName(detail::type<typename T::TEST_TYPE>{}) == ti.type && T::TEST_NAME::c_str() == ti.name) {
148-
//UnitTest::GetInstance()
149-
//->parameterized_test_registry()
150-
//.GetTestCasePatternHolder<T>(ti.type.c_str(), {ti.file, ti.line})
151-
//->AddTestPattern((IsDisabled(ti.disabled) + ti.type).c_str(), std::string{GUNIT_SHOULD_PREFIX + ti.should}.c_str(),
152-
//new internal::TestMetaFactory<T>());
153-
//registered = true;
154-
//}
155-
//}
156-
//return registered;
157-
//}
158-
159144
public:
160145
GTestAutoRegister() {
161146
MakeAndRegisterTestInfo(DISABLED,
@@ -168,21 +153,17 @@ class GTestAutoRegister {
168153

169154
template <class TEval, class TGenerateNames>
170155
GTestAutoRegister(const TEval& eval, const TGenerateNames& genNames) {
171-
(void)eval;
172-
(void)genNames;
173-
//if (!RegisterShouldParamTestCase()) {
174-
//UnitTest::GetInstance()
175-
//->parameterized_test_registry()
176-
//.GetTestCasePatternHolder<T>(GetTypeName(detail::type<typename T::TEST_TYPE>{}), {T::TEST_FILE, T::TEST_LINE})
177-
//->AddTestPattern(GetTypeName(detail::type<typename T::TEST_TYPE>{}),
178-
//GetTypeName(detail::type<typename T::TEST_TYPE>{}), new internal::TestMetaFactory<T>());
179-
//}
180-
181-
//UnitTest::GetInstance()
182-
//->parameterized_test_registry()
183-
//.GetTestCasePatternHolder<T>(GetTypeName(detail::type<typename T::TEST_TYPE>{}), {T::TEST_FILE, T::TEST_LINE})
184-
//->AddTestCaseInstantiation((std::string{IsDisabled(DISABLED)} + T::TEST_NAME::c_str()).c_str(), eval, genNames,
185-
//T::TEST_FILE, T::TEST_LINE);
156+
UnitTest::GetInstance()
157+
->parameterized_test_registry()
158+
.GetTestCasePatternHolder<T>(GetTypeName(detail::type<typename T::TEST_TYPE>{}), {T::TEST_FILE, T::TEST_LINE})
159+
->AddTestPattern(GetTypeName(detail::type<typename T::TEST_TYPE>{}),
160+
GetTypeName(detail::type<typename T::TEST_TYPE>{}), new internal::TestMetaFactory<T>());
161+
162+
UnitTest::GetInstance()
163+
->parameterized_test_registry()
164+
.GetTestCasePatternHolder<T>(GetTypeName(detail::type<typename T::TEST_TYPE>{}), {T::TEST_FILE, T::TEST_LINE})
165+
->AddTestCaseInstantiation((std::string{IsDisabled(DISABLED)} + T::TEST_NAME::c_str()).c_str(), eval, genNames,
166+
T::TEST_FILE, T::TEST_LINE);
186167
}
187168
};
188169

@@ -250,7 +231,10 @@ class GTest : public detail::GTest<T, TParamType> {};
250231
::testing::detail::TestRun tr; \
251232
while(tr.once) {\
252233
tr.once = false; \
253-
TestBodyImpl(tr);\
234+
GTEST t;\
235+
t.SetUp();\
236+
t.TestBodyImpl(tr);\
237+
t.TearDown();\
254238
}; \
255239
} \
256240
}; \

test/GTest.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ GTEST(longest_ctor_force) {
706706
GTEST(complex_example) {
707707
using namespace testing;
708708

709-
std::cout << "setup" << std::endl;
710709
// setup
711710
std::tie(sut, mocks) = testing::make<SUT, testing::NiceGMock>();
712711
EXPECT_CALL(mock<interface>(), (get)(_)).WillOnce(Return(123));
@@ -740,8 +739,6 @@ GTEST(complex_example) {
740739

741740
sut->update();
742741
}
743-
744-
std::cout << "teardown" << std::endl;
745742
}
746743

747744
struct is_default_constructible {};
@@ -757,9 +754,8 @@ GTEST(is_default_constructible) {
757754

758755
GTEST(example, "[should create sut with a mock]") {
759756
using namespace testing;
760-
//TODO
761-
//ASSERT_TRUE(nullptr == sut.get());
762-
//EXPECT_EQ(0u, mocks.size());
757+
ASSERT_TRUE(nullptr == sut.get());
758+
EXPECT_EQ(0u, mocks.size());
763759

764760
SHOULD("override sut and pass polymorphic type") {
765761
StrictGMock<interface> i;

0 commit comments

Comments
 (0)