Skip to content

Commit a8b1a66

Browse files
committed
Merge pull request #2388 from kuzkry:remove-gtest-type-util.pump
PiperOrigin-RevId: 276944601
2 parents 540835f + 1a49b67 commit a8b1a66

File tree

10 files changed

+251
-3523
lines changed

10 files changed

+251
-3523
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ All tests should pass.
133133

134134
Some of Google Test's source files are generated from templates (not in the C++
135135
sense) using a script. For example, the file
136-
include/gtest/internal/gtest-type-util.h.pump is used to generate
137-
gtest-type-util.h in the same directory.
136+
*googlemock/include/gmock/gmock-generated-actions.h.pump* is used to generate
137+
*gmock-generated-actions.h* in the same directory.
138138

139139
You don't need to worry about regenerating the source files unless you need to
140140
modify them. You would then modify the corresponding `.pump` files and run the
141-
'[pump.py](googletest/scripts/pump.py)' generator script. See the
142-
[Pump Manual](googletest/docs/pump_manual.md).
141+
'[pump.py](googlemock/scripts/pump.py)' generator script. See the
142+
[Pump Manual](googlemock/docs/pump_manual.md).
File renamed without changes.
File renamed without changes.

googlemock/test/pump_test.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2010, Google Inc.
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are
8+
# met:
9+
#
10+
# * Redistributions of source code must retain the above copyright
11+
# notice, this list of conditions and the following disclaimer.
12+
# * Redistributions in binary form must reproduce the above
13+
# copyright notice, this list of conditions and the following disclaimer
14+
# in the documentation and/or other materials provided with the
15+
# distribution.
16+
# * Neither the name of Google Inc. nor the names of its
17+
# contributors may be used to endorse or promote products derived from
18+
# this software without specific prior written permission.
19+
#
20+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
"""Tests for the Pump meta-programming tool."""
33+
34+
from google3.testing.pybase import googletest
35+
import google3.third_party.googletest.googlemock.scripts.pump
36+
37+
pump = google3.third_party.googletest.googlemock.scripts.pump
38+
Convert = pump.ConvertFromPumpSource
39+
StripMetaComments = pump.StripMetaComments
40+
41+
42+
class PumpTest(googletest.TestCase):
43+
44+
def testConvertsEmptyToEmpty(self):
45+
self.assertEquals('', Convert('').strip())
46+
47+
def testConvertsPlainCodeToSame(self):
48+
self.assertEquals('#include <stdio.h>\n',
49+
Convert('#include <stdio.h>\n'))
50+
51+
def testConvertsLongIWYUPragmaToSame(self):
52+
long_line = '// IWYU pragma: private, include "' + (80*'a') + '.h"\n'
53+
self.assertEquals(long_line, Convert(long_line))
54+
55+
def testConvertsIWYUPragmaWithLeadingSpaceToSame(self):
56+
long_line = ' // IWYU pragma: private, include "' + (80*'a') + '.h"\n'
57+
self.assertEquals(long_line, Convert(long_line))
58+
59+
def testConvertsIWYUPragmaWithSlashStarLeaderToSame(self):
60+
long_line = '/* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
61+
self.assertEquals(long_line, Convert(long_line))
62+
63+
def testConvertsIWYUPragmaWithSlashStarAndSpacesToSame(self):
64+
long_line = ' /* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
65+
self.assertEquals(long_line, Convert(long_line))
66+
67+
def testIgnoresMetaComment(self):
68+
self.assertEquals('',
69+
Convert('$$ This is a Pump meta comment.\n').strip())
70+
71+
def testSimpleVarDeclarationWorks(self):
72+
self.assertEquals('3\n',
73+
Convert('$var m = 3\n'
74+
'$m\n'))
75+
76+
def testVarDeclarationCanReferenceEarlierVar(self):
77+
self.assertEquals('43 != 3;\n',
78+
Convert('$var a = 42\n'
79+
'$var b = a + 1\n'
80+
'$var c = (b - a)*3\n'
81+
'$b != $c;\n'))
82+
83+
def testSimpleLoopWorks(self):
84+
self.assertEquals('1, 2, 3, 4, 5\n',
85+
Convert('$var n = 5\n'
86+
'$range i 1..n\n'
87+
'$for i, [[$i]]\n'))
88+
89+
def testSimpleLoopWithCommentWorks(self):
90+
self.assertEquals('1, 2, 3, 4, 5\n',
91+
Convert('$var n = 5 $$ This is comment 1.\n'
92+
'$range i 1..n $$ This is comment 2.\n'
93+
'$for i, [[$i]]\n'))
94+
95+
def testNonTrivialRangeExpressionsWork(self):
96+
self.assertEquals('1, 2, 3, 4\n',
97+
Convert('$var n = 5\n'
98+
'$range i (n/n)..(n - 1)\n'
99+
'$for i, [[$i]]\n'))
100+
101+
def testLoopWithoutSeparatorWorks(self):
102+
self.assertEquals('a + 1 + 2 + 3;\n',
103+
Convert('$range i 1..3\n'
104+
'a$for i [[ + $i]];\n'))
105+
106+
def testCanGenerateDollarSign(self):
107+
self.assertEquals('$\n', Convert('$($)\n'))
108+
109+
def testCanIterpolateExpressions(self):
110+
self.assertEquals('a[2] = 3;\n',
111+
Convert('$var i = 1\n'
112+
'a[$(i + 1)] = $(i*4 - 1);\n'))
113+
114+
def testConditionalWithoutElseBranchWorks(self):
115+
self.assertEquals('true\n',
116+
Convert('$var n = 5\n'
117+
'$if n > 0 [[true]]\n'))
118+
119+
def testConditionalWithElseBranchWorks(self):
120+
self.assertEquals('true -- really false\n',
121+
Convert('$var n = 5\n'
122+
'$if n > 0 [[true]]\n'
123+
'$else [[false]] -- \n'
124+
'$if n > 10 [[really true]]\n'
125+
'$else [[really false]]\n'))
126+
127+
def testConditionalWithCascadingElseBranchWorks(self):
128+
self.assertEquals('a\n',
129+
Convert('$var n = 5\n'
130+
'$if n > 0 [[a]]\n'
131+
'$elif n > 10 [[b]]\n'
132+
'$else [[c]]\n'))
133+
self.assertEquals('b\n',
134+
Convert('$var n = 5\n'
135+
'$if n > 10 [[a]]\n'
136+
'$elif n > 0 [[b]]\n'
137+
'$else [[c]]\n'))
138+
self.assertEquals('c\n',
139+
Convert('$var n = 5\n'
140+
'$if n > 10 [[a]]\n'
141+
'$elif n > 8 [[b]]\n'
142+
'$else [[c]]\n'))
143+
144+
def testNestedLexicalBlocksWork(self):
145+
self.assertEquals('a = 5;\n',
146+
Convert('$var n = 5\n'
147+
'a = [[$if n > 0 [[$n]]]];\n'))
148+
149+
150+
class StripMetaCommentsTest(googletest.TestCase):
151+
152+
def testReturnsSameStringIfItContainsNoComment(self):
153+
self.assertEquals('', StripMetaComments(''))
154+
self.assertEquals(' blah ', StripMetaComments(' blah '))
155+
self.assertEquals('A single $ is fine.',
156+
StripMetaComments('A single $ is fine.'))
157+
self.assertEquals('multiple\nlines',
158+
StripMetaComments('multiple\nlines'))
159+
160+
def testStripsSimpleComment(self):
161+
self.assertEquals('yes\n', StripMetaComments('yes $$ or no?\n'))
162+
163+
def testStripsSimpleCommentWithMissingNewline(self):
164+
self.assertEquals('yes', StripMetaComments('yes $$ or no?'))
165+
166+
def testStripsPureCommentLinesEntirely(self):
167+
self.assertEquals('yes\n',
168+
StripMetaComments('$$ a pure comment line.\n'
169+
'yes $$ or no?\n'
170+
' $$ another comment line.\n'))
171+
172+
def testStripsCommentsFromMultiLineText(self):
173+
self.assertEquals('multi-\n'
174+
'line\n'
175+
'text is fine.',
176+
StripMetaComments('multi- $$ comment 1\n'
177+
'line\n'
178+
'text is fine. $$ comment 2'))
179+
180+
181+
if __name__ == '__main__':
182+
googletest.main()

googletest/CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Jói Sigurðsson <[email protected]>
1717
Keir Mierle <[email protected]>
1818
Keith Ray <[email protected]>
1919
Kenton Varda <[email protected]>
20+
Krystian Kuzniarek <[email protected]>
2021
Manuel Klimek <[email protected]>
2122
Markus Heule <[email protected]>
2223
Mika Raento <[email protected]>

googletest/include/gtest/gtest-typed-test.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
3130
// GOOGLETEST_CM0001 DO NOT DELETE
3231

3332
#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
@@ -188,13 +187,13 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
188187
#define GTEST_NAME_GENERATOR_(TestSuiteName) \
189188
gtest_type_params_##TestSuiteName##_NameGenerator
190189

191-
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
192-
typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
193-
CaseName); \
194-
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
190+
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
191+
typedef ::testing::internal::GenerateTypeList<Types>::type \
192+
GTEST_TYPE_PARAMS_(CaseName); \
193+
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
195194
GTEST_NAME_GENERATOR_(CaseName)
196195

197-
# define TYPED_TEST(CaseName, TestName) \
196+
#define TYPED_TEST(CaseName, TestName) \
198197
template <typename gtest_TypeParam_> \
199198
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
200199
: public CaseName<gtest_TypeParam_> { \
@@ -204,8 +203,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
204203
void TestBody() override; \
205204
}; \
206205
static bool gtest_##CaseName##_##TestName##_registered_ \
207-
GTEST_ATTRIBUTE_UNUSED_ = \
208-
::testing::internal::TypeParameterizedTest< \
206+
GTEST_ATTRIBUTE_UNUSED_ = ::testing::internal::TypeParameterizedTest< \
209207
CaseName, \
210208
::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
211209
TestName)>, \
@@ -286,13 +284,13 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
286284
void GTEST_SUITE_NAMESPACE_( \
287285
SuiteName)::TestName<gtest_TypeParam_>::TestBody()
288286

289-
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
290-
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
291-
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
292-
} \
293-
static const char* const GTEST_REGISTERED_TEST_NAMES_( \
294-
SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
295-
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
287+
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
288+
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
289+
typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \
290+
} \
291+
static const char* const GTEST_REGISTERED_TEST_NAMES_( \
292+
SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
293+
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
296294
__FILE__, __LINE__, #__VA_ARGS__)
297295

298296
// Legacy API is deprecated but still available
@@ -307,15 +305,15 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
307305
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
308306
::testing::internal::TypeParameterizedTestSuite< \
309307
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
310-
::testing::internal::TypeList<Types>::type>:: \
308+
::testing::internal::GenerateTypeList<Types>::type>:: \
311309
Register(#Prefix, \
312310
::testing::internal::CodeLocation(__FILE__, __LINE__), \
313311
&GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
314312
GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
315313
::testing::internal::GenerateNames< \
316314
::testing::internal::NameGeneratorSelector< \
317315
__VA_ARGS__>::type, \
318-
::testing::internal::TypeList<Types>::type>())
316+
::testing::internal::GenerateTypeList<Types>::type>())
319317

320318
// Legacy API is deprecated but still available
321319
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_

googletest/include/gtest/internal/gtest-internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ struct NameGeneratorSelector {
662662
};
663663

664664
template <typename NameGenerator>
665-
void GenerateNamesRecursively(Types0, std::vector<std::string>*, int) {}
665+
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
666666

667667
template <typename NameGenerator, typename Types>
668668
void GenerateNamesRecursively(Types, std::vector<std::string>* result, int i) {
@@ -729,7 +729,7 @@ class TypeParameterizedTest {
729729

730730
// The base case for the compile time recursion.
731731
template <GTEST_TEMPLATE_ Fixture, class TestSel>
732-
class TypeParameterizedTest<Fixture, TestSel, Types0> {
732+
class TypeParameterizedTest<Fixture, TestSel, internal::None> {
733733
public:
734734
static bool Register(const char* /*prefix*/, const CodeLocation&,
735735
const char* /*case_name*/, const char* /*test_names*/,
@@ -781,7 +781,7 @@ class TypeParameterizedTestSuite {
781781

782782
// The base case for the compile time recursion.
783783
template <GTEST_TEMPLATE_ Fixture, typename Types>
784-
class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
784+
class TypeParameterizedTestSuite<Fixture, internal::None, Types> {
785785
public:
786786
static bool Register(const char* /*prefix*/, const CodeLocation&,
787787
const TypedTestSuitePState* /*state*/,

0 commit comments

Comments
 (0)