Skip to content

Commit

Permalink
Merge pull request #2388 from kuzkry:remove-gtest-type-util.pump
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 276944601
  • Loading branch information
vslashg committed Oct 29, 2019
2 parents 540835f + 1a49b67 commit a8b1a66
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 3,523 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ All tests should pass.

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

You don't need to worry about regenerating the source files unless you need to
modify them. You would then modify the corresponding `.pump` files and run the
'[pump.py](googletest/scripts/pump.py)' generator script. See the
[Pump Manual](googletest/docs/pump_manual.md).
'[pump.py](googlemock/scripts/pump.py)' generator script. See the
[Pump Manual](googlemock/docs/pump_manual.md).
File renamed without changes.
File renamed without changes.
182 changes: 182 additions & 0 deletions googlemock/test/pump_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/usr/bin/env python
#
# Copyright 2010, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Tests for the Pump meta-programming tool."""

from google3.testing.pybase import googletest
import google3.third_party.googletest.googlemock.scripts.pump

pump = google3.third_party.googletest.googlemock.scripts.pump
Convert = pump.ConvertFromPumpSource
StripMetaComments = pump.StripMetaComments


class PumpTest(googletest.TestCase):

def testConvertsEmptyToEmpty(self):
self.assertEquals('', Convert('').strip())

def testConvertsPlainCodeToSame(self):
self.assertEquals('#include <stdio.h>\n',
Convert('#include <stdio.h>\n'))

def testConvertsLongIWYUPragmaToSame(self):
long_line = '// IWYU pragma: private, include "' + (80*'a') + '.h"\n'
self.assertEquals(long_line, Convert(long_line))

def testConvertsIWYUPragmaWithLeadingSpaceToSame(self):
long_line = ' // IWYU pragma: private, include "' + (80*'a') + '.h"\n'
self.assertEquals(long_line, Convert(long_line))

def testConvertsIWYUPragmaWithSlashStarLeaderToSame(self):
long_line = '/* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
self.assertEquals(long_line, Convert(long_line))

def testConvertsIWYUPragmaWithSlashStarAndSpacesToSame(self):
long_line = ' /* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
self.assertEquals(long_line, Convert(long_line))

def testIgnoresMetaComment(self):
self.assertEquals('',
Convert('$$ This is a Pump meta comment.\n').strip())

def testSimpleVarDeclarationWorks(self):
self.assertEquals('3\n',
Convert('$var m = 3\n'
'$m\n'))

def testVarDeclarationCanReferenceEarlierVar(self):
self.assertEquals('43 != 3;\n',
Convert('$var a = 42\n'
'$var b = a + 1\n'
'$var c = (b - a)*3\n'
'$b != $c;\n'))

def testSimpleLoopWorks(self):
self.assertEquals('1, 2, 3, 4, 5\n',
Convert('$var n = 5\n'
'$range i 1..n\n'
'$for i, [[$i]]\n'))

def testSimpleLoopWithCommentWorks(self):
self.assertEquals('1, 2, 3, 4, 5\n',
Convert('$var n = 5 $$ This is comment 1.\n'
'$range i 1..n $$ This is comment 2.\n'
'$for i, [[$i]]\n'))

def testNonTrivialRangeExpressionsWork(self):
self.assertEquals('1, 2, 3, 4\n',
Convert('$var n = 5\n'
'$range i (n/n)..(n - 1)\n'
'$for i, [[$i]]\n'))

def testLoopWithoutSeparatorWorks(self):
self.assertEquals('a + 1 + 2 + 3;\n',
Convert('$range i 1..3\n'
'a$for i [[ + $i]];\n'))

def testCanGenerateDollarSign(self):
self.assertEquals('$\n', Convert('$($)\n'))

def testCanIterpolateExpressions(self):
self.assertEquals('a[2] = 3;\n',
Convert('$var i = 1\n'
'a[$(i + 1)] = $(i*4 - 1);\n'))

def testConditionalWithoutElseBranchWorks(self):
self.assertEquals('true\n',
Convert('$var n = 5\n'
'$if n > 0 [[true]]\n'))

def testConditionalWithElseBranchWorks(self):
self.assertEquals('true -- really false\n',
Convert('$var n = 5\n'
'$if n > 0 [[true]]\n'
'$else [[false]] -- \n'
'$if n > 10 [[really true]]\n'
'$else [[really false]]\n'))

def testConditionalWithCascadingElseBranchWorks(self):
self.assertEquals('a\n',
Convert('$var n = 5\n'
'$if n > 0 [[a]]\n'
'$elif n > 10 [[b]]\n'
'$else [[c]]\n'))
self.assertEquals('b\n',
Convert('$var n = 5\n'
'$if n > 10 [[a]]\n'
'$elif n > 0 [[b]]\n'
'$else [[c]]\n'))
self.assertEquals('c\n',
Convert('$var n = 5\n'
'$if n > 10 [[a]]\n'
'$elif n > 8 [[b]]\n'
'$else [[c]]\n'))

def testNestedLexicalBlocksWork(self):
self.assertEquals('a = 5;\n',
Convert('$var n = 5\n'
'a = [[$if n > 0 [[$n]]]];\n'))


class StripMetaCommentsTest(googletest.TestCase):

def testReturnsSameStringIfItContainsNoComment(self):
self.assertEquals('', StripMetaComments(''))
self.assertEquals(' blah ', StripMetaComments(' blah '))
self.assertEquals('A single $ is fine.',
StripMetaComments('A single $ is fine.'))
self.assertEquals('multiple\nlines',
StripMetaComments('multiple\nlines'))

def testStripsSimpleComment(self):
self.assertEquals('yes\n', StripMetaComments('yes $$ or no?\n'))

def testStripsSimpleCommentWithMissingNewline(self):
self.assertEquals('yes', StripMetaComments('yes $$ or no?'))

def testStripsPureCommentLinesEntirely(self):
self.assertEquals('yes\n',
StripMetaComments('$$ a pure comment line.\n'
'yes $$ or no?\n'
' $$ another comment line.\n'))

def testStripsCommentsFromMultiLineText(self):
self.assertEquals('multi-\n'
'line\n'
'text is fine.',
StripMetaComments('multi- $$ comment 1\n'
'line\n'
'text is fine. $$ comment 2'))


if __name__ == '__main__':
googletest.main()
1 change: 1 addition & 0 deletions googletest/CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Jói Sigurðsson <[email protected]>
Keir Mierle <[email protected]>
Keith Ray <[email protected]>
Kenton Varda <[email protected]>
Krystian Kuzniarek <[email protected]>
Manuel Klimek <[email protected]>
Markus Heule <[email protected]>
Mika Raento <[email protected]>
Expand Down
32 changes: 15 additions & 17 deletions googletest/include/gtest/gtest-typed-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


// GOOGLETEST_CM0001 DO NOT DELETE

#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
Expand Down Expand Up @@ -188,13 +187,13 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
#define GTEST_NAME_GENERATOR_(TestSuiteName) \
gtest_type_params_##TestSuiteName##_NameGenerator

#define TYPED_TEST_SUITE(CaseName, Types, ...) \
typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
CaseName); \
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
typedef ::testing::internal::GenerateTypeList<Types>::type \
GTEST_TYPE_PARAMS_(CaseName); \
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
GTEST_NAME_GENERATOR_(CaseName)

# define TYPED_TEST(CaseName, TestName) \
#define TYPED_TEST(CaseName, TestName) \
template <typename gtest_TypeParam_> \
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
: public CaseName<gtest_TypeParam_> { \
Expand All @@ -204,8 +203,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
void TestBody() override; \
}; \
static bool gtest_##CaseName##_##TestName##_registered_ \
GTEST_ATTRIBUTE_UNUSED_ = \
::testing::internal::TypeParameterizedTest< \
GTEST_ATTRIBUTE_UNUSED_ = ::testing::internal::TypeParameterizedTest< \
CaseName, \
::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
TestName)>, \
Expand Down Expand Up @@ -286,13 +284,13 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
void GTEST_SUITE_NAMESPACE_( \
SuiteName)::TestName<gtest_TypeParam_>::TestBody()

#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
} \
static const char* const GTEST_REGISTERED_TEST_NAMES_( \
SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \
} \
static const char* const GTEST_REGISTERED_TEST_NAMES_( \
SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
__FILE__, __LINE__, #__VA_ARGS__)

// Legacy API is deprecated but still available
Expand All @@ -307,15 +305,15 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
::testing::internal::TypeParameterizedTestSuite< \
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
::testing::internal::TypeList<Types>::type>:: \
::testing::internal::GenerateTypeList<Types>::type>:: \
Register(#Prefix, \
::testing::internal::CodeLocation(__FILE__, __LINE__), \
&GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
::testing::internal::GenerateNames< \
::testing::internal::NameGeneratorSelector< \
__VA_ARGS__>::type, \
::testing::internal::TypeList<Types>::type>())
::testing::internal::GenerateTypeList<Types>::type>())

// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
Expand Down
6 changes: 3 additions & 3 deletions googletest/include/gtest/internal/gtest-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ struct NameGeneratorSelector {
};

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

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

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

// The base case for the compile time recursion.
template <GTEST_TEMPLATE_ Fixture, typename Types>
class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
class TypeParameterizedTestSuite<Fixture, internal::None, Types> {
public:
static bool Register(const char* /*prefix*/, const CodeLocation&,
const TypedTestSuitePState* /*state*/,
Expand Down
Loading

0 comments on commit a8b1a66

Please sign in to comment.