@@ -25,6 +25,7 @@ inline namespace v1 {
2525namespace detail {
2626
2727struct TestCaseInfo {
28+ bool disabled = false ;
2829 std::string symbol;
2930 std::string type;
3031 std::string name;
@@ -67,6 +68,8 @@ struct TestCaseInfoParser {
6768 };
6869
6970 std::getline (stream, token, ' <' );
71+ std::getline (stream, token, ' ,' );
72+ ti.disabled = token == " true" ;
7073 parseString (ti.name );
7174 parseString (ti.file );
7275 std::getline (stream, token, ' ,' );
@@ -85,31 +88,36 @@ inline auto& tests() {
8588 return ts;
8689}
8790
88- template <class T >
91+ template <bool DISABLED, class T >
8992class GTestAutoRegister {
93+ static auto IsDisabled (bool disabled) { return DISABLED || disabled ? " DISABLED_" : " " ; }
94+
9095 void MakeAndRegisterTestInfo (const TestCaseInfo& ti,
9196 detail::type<TestInfo*(const char *, const char *, const char *, const char *, const void *,
9297 void (*)(), void (*)(), internal::TestFactoryBase*)>) {
9398 if (ti.should .empty ()) {
94- internal::MakeAndRegisterTestInfo (ti.type .c_str (), ti.name .c_str (), nullptr , nullptr , internal::GetTestTypeId (),
95- Test::SetUpTestCase, Test::TearDownTestCase, new internal::TestFactoryImpl<T>{});
99+ internal::MakeAndRegisterTestInfo ((IsDisabled (ti.disabled ) + ti.type ).c_str (), ti.name .c_str (), nullptr , nullptr ,
100+ internal::GetTestTypeId (), Test::SetUpTestCase, Test::TearDownTestCase,
101+ new internal::TestFactoryImpl<T>{});
96102 } else {
97- internal::MakeAndRegisterTestInfo ((ti.type + ti.name ).c_str (), (std::string{GUNIT_SHOULD_PREFIX} + ti.should ).c_str (),
98- nullptr , nullptr , internal::GetTestTypeId (), Test::SetUpTestCase,
99- Test::TearDownTestCase, new internal::TestFactoryImpl<T>{});
103+ internal::MakeAndRegisterTestInfo ((IsDisabled (ti.disabled ) + ti.type + ti.name ).c_str (),
104+ (std::string{GUNIT_SHOULD_PREFIX} + ti.should ).c_str (), nullptr , nullptr ,
105+ internal::GetTestTypeId (), Test::SetUpTestCase, Test::TearDownTestCase,
106+ new internal::TestFactoryImpl<T>{});
100107 }
101108 }
102109
103110 template <class ... Ts>
104111 void MakeAndRegisterTestInfo (const TestCaseInfo& ti, detail::type<TestInfo*(Ts...)>) {
105112 if (ti.should .empty ()) {
106- internal::MakeAndRegisterTestInfo (ti.type .c_str (), ti.name .c_str (), nullptr , nullptr , {ti. file . c_str (), ti. line } ,
107- internal::GetTestTypeId (), Test::SetUpTestCase, Test::TearDownTestCase ,
108- new internal::TestFactoryImpl<T>{});
113+ internal::MakeAndRegisterTestInfo (( IsDisabled ( ti.disabled ) + ti. type ) .c_str (), ti.name .c_str (), nullptr , nullptr ,
114+ {ti. file . c_str (), ti. line }, internal::GetTestTypeId (), Test::SetUpTestCase,
115+ Test::TearDownTestCase, new internal::TestFactoryImpl<T>{});
109116 } else {
110- internal::MakeAndRegisterTestInfo ((ti.type + ti.name ).c_str (), (std::string{GUNIT_SHOULD_PREFIX} + ti.should ).c_str (),
111- nullptr , nullptr , {ti.file .c_str (), ti.line }, internal::GetTestTypeId (),
112- Test::SetUpTestCase, Test::TearDownTestCase, new internal::TestFactoryImpl<T>{});
117+ internal::MakeAndRegisterTestInfo ((IsDisabled (ti.disabled ) + ti.type + ti.name ).c_str (),
118+ (std::string{GUNIT_SHOULD_PREFIX} + ti.should ).c_str (), nullptr , nullptr ,
119+ {ti.file .c_str (), ti.line }, internal::GetTestTypeId (), Test::SetUpTestCase,
120+ Test::TearDownTestCase, new internal::TestFactoryImpl<T>{});
113121 }
114122 }
115123
@@ -143,7 +151,7 @@ class GTestAutoRegister {
143151 UnitTest::GetInstance ()
144152 ->parameterized_test_registry ()
145153 .GetTestCasePatternHolder <T>(ti.type .c_str (), {ti.file , ti.line })
146- ->AddTestPattern (ti.type .c_str (), std::string{GUNIT_SHOULD_PREFIX + ti.should }.c_str (),
154+ ->AddTestPattern (( IsDisabled ( ti.disabled ) + ti. type ) .c_str (), std::string{GUNIT_SHOULD_PREFIX + ti.should }.c_str (),
147155 new internal::TestMetaFactory<T>());
148156 registered = true ;
149157 }
@@ -154,9 +162,14 @@ class GTestAutoRegister {
154162 public:
155163 GTestAutoRegister () {
156164 if (!RegisterShouldTestCase ()) {
157- MakeAndRegisterTestInfo (
158- {{}, GetTypeName (detail::type<typename T::TEST_TYPE>{}), T::TEST_NAME::c_str (), T::TEST_FILE, T::TEST_LINE, {}},
159- detail::type<decltype (internal::MakeAndRegisterTestInfo)>{});
165+ MakeAndRegisterTestInfo ({DISABLED,
166+ {},
167+ GetTypeName (detail::type<typename T::TEST_TYPE>{}),
168+ T::TEST_NAME::c_str (),
169+ T::TEST_FILE,
170+ T::TEST_LINE,
171+ {}},
172+ detail::type<decltype (internal::MakeAndRegisterTestInfo)>{});
160173 }
161174 }
162175
@@ -173,7 +186,8 @@ class GTestAutoRegister {
173186 UnitTest::GetInstance ()
174187 ->parameterized_test_registry ()
175188 .GetTestCasePatternHolder <T>(GetTypeName (detail::type<typename T::TEST_TYPE>{}), {T::TEST_FILE, T::TEST_LINE})
176- ->AddTestCaseInstantiation (T::TEST_NAME::c_str (), eval, genNames, T::TEST_FILE, T::TEST_LINE);
189+ ->AddTestCaseInstantiation ((std::string{IsDisabled (DISABLED)} + T::TEST_NAME::c_str ()).c_str (), eval, genNames,
190+ T::TEST_FILE, T::TEST_LINE);
177191 }
178192};
179193
@@ -210,7 +224,7 @@ class GTest<T, TParamType, std::false_type, TAny> : public Test {
210224template <class T , class TParamType >
211225class GTest <T, TParamType, std::true_type, std::true_type> : public T {};
212226
213- template <class Name , class File , int Line, class Should , class T >
227+ template <bool Disabled, class Name , class File , int Line, class Should , class T >
214228bool SHOULD_REGISTER_GTEST () {
215229 static auto shouldRegister = true ;
216230 return shouldRegister;
@@ -223,7 +237,7 @@ class GTest : public detail::GTest<T, TParamType> {};
223237} // v1
224238} // testing
225239
226- #define __GTEST_IMPL (TYPE, NAME, PARAMS, ...) \
240+ #define __GTEST_IMPL (DISABLED, TYPE, NAME, PARAMS, ...) \
227241 struct __GUNIT_CAT (GTEST_STRING_, __LINE__) { \
228242 const char * chrs = #TYPE; \
229243 }; \
@@ -244,16 +258,17 @@ class GTest : public detail::GTest<T, TParamType> {};
244258 static constexpr auto TEST_LINE = __LINE__; \
245259 void TestBody (); \
246260 }; \
247- static ::testing::detail::GTestAutoRegister<GTEST<__GUNIT_CAT(GTEST_TYPE_, __LINE__), NAME>> __GUNIT_CAT ( \
261+ static ::testing::detail::GTestAutoRegister<DISABLED, GTEST<__GUNIT_CAT(GTEST_TYPE_, __LINE__), NAME>> __GUNIT_CAT ( \
248262 ar, __LINE__){__VA_ARGS__}; \
249263 void GTEST<__GUNIT_CAT(GTEST_TYPE_, __LINE__), NAME>::TestBody()
250264
251- #define __GTEST_IMPL_1 (TYPE ) __GTEST_IMPL(TYPE, ::testing::detail::string<>, ::testing::detail::type<void >{}, )
252- #define __GTEST_IMPL_2 (TYPE, NAME ) \
265+ #define __GTEST_IMPL_1 (DISABLED, TYPE ) \
266+ __GTEST_IMPL (DISABLED, TYPE, ::testing::detail::string<>, ::testing::detail::type<void >{}, )
267+ #define __GTEST_IMPL_2 (DISABLED, TYPE, NAME ) \
253268 using __GUNIT_CAT (GTEST_TEST_NAME, __LINE__) = decltype(__GUNIT_CAT(NAME, _gtest_string)); \
254- __GTEST_IMPL (TYPE, __GUNIT_CAT(GTEST_TEST_NAME, __LINE__), ::testing::detail::type<void>{}, )
269+ __GTEST_IMPL (DISABLED, TYPE, __GUNIT_CAT(GTEST_TEST_NAME, __LINE__), ::testing::detail::type<void>{}, )
255270
256- #define __GTEST_IMPL_3 (TYPE, NAME, PARAMS ) \
271+ #define __GTEST_IMPL_3 (DISABLED, TYPE, NAME, PARAMS ) \
257272 using __GUNIT_CAT (GTEST_TEST_NAME, __LINE__) = decltype(__GUNIT_CAT(NAME, _gtest_string)); \
258273 static ::testing::internal::ParamGenerator<::testing::detail::apply_t <std::common_type_t , decltype (PARAMS)>> __GUNIT_CAT ( \
259274 GTEST_EVAL, __LINE__)() { \
@@ -263,13 +278,20 @@ class GTest : public detail::GTest<T, TParamType> {};
263278 const ::testing::TestParamInfo<::testing::detail::apply_t <std::common_type_t , decltype (PARAMS)>>& info) { \
264279 return ::testing::internal::GetParamNameGen<::testing::detail::apply_t <std::common_type_t , decltype (PARAMS)>>()(info); \
265280 } \
266- __GTEST_IMPL (TYPE, __GUNIT_CAT(GTEST_TEST_NAME, __LINE__), PARAMS, &__GUNIT_CAT(GTEST_EVAL, __LINE__), \
281+ __GTEST_IMPL (DISABLED, TYPE, __GUNIT_CAT(GTEST_TEST_NAME, __LINE__), PARAMS, &__GUNIT_CAT(GTEST_EVAL, __LINE__), \
267282 &__GUNIT_CAT(GTEST_GENERATE_NAMES, __LINE__))
268283
269- #define GTEST (...) __GUNIT_CAT(__GTEST_IMPL_, __GUNIT_SIZE(__VA_ARGS__))(__VA_ARGS__)
284+ #define GTEST (...) __GUNIT_CAT(__GTEST_IMPL_, __GUNIT_SIZE(__VA_ARGS__))(false , __VA_ARGS__)
285+ #define DISABLED_GTEST (...) __GUNIT_CAT(__GTEST_IMPL_, __GUNIT_SIZE(__VA_ARGS__))(true , __VA_ARGS__)
270286
271287#define SHOULD (NAME ) \
272- if (::testing::detail::SHOULD_REGISTER_GTEST<TEST_NAME, decltype (__GUNIT_CAT(__FILE__, _gtest_string)), __LINE__, \
288+ if (::testing::detail::SHOULD_REGISTER_GTEST<false , TEST_NAME, decltype (__GUNIT_CAT(__FILE__, _gtest_string)), __LINE__, \
289+ decltype (__GUNIT_CAT(NAME, _gtest_string)), TEST_TYPE>() && \
290+ std::string{::testing::UnitTest::GetInstance ()->current_test_info ()->name ()}.find(std::string{GUNIT_SHOULD_PREFIX} + \
291+ NAME) != std::string::npos)
292+
293+ #define DISABLED_SHOULD (NAME ) \
294+ if (::testing::detail::SHOULD_REGISTER_GTEST<true , TEST_NAME, decltype (__GUNIT_CAT(__FILE__, _gtest_string)), __LINE__, \
273295 decltype (__GUNIT_CAT(NAME, _gtest_string)), TEST_TYPE>() && \
274296 std::string{::testing::UnitTest::GetInstance ()->current_test_info ()->name ()}.find(std::string{GUNIT_SHOULD_PREFIX} + \
275297 NAME) != std::string::npos)
0 commit comments