diff options
Diffstat (limited to 'googlemock')
-rw-r--r-- | googlemock/cmake/gmock.pc.in | 2 | ||||
-rw-r--r-- | googlemock/cmake/gmock_main.pc.in | 2 | ||||
-rw-r--r-- | googlemock/docs/pump_manual.md | 21 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-function-mocker.h | 42 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 2 | ||||
-rwxr-xr-x | googlemock/scripts/pump.py | 13 | ||||
-rw-r--r-- | googlemock/test/gmock-function-mocker_test.cc | 29 |
7 files changed, 41 insertions, 70 deletions
diff --git a/googlemock/cmake/gmock.pc.in b/googlemock/cmake/gmock.pc.in index 5780fca..2ef0fbc 100644 --- a/googlemock/cmake/gmock.pc.in +++ b/googlemock/cmake/gmock.pc.in @@ -7,4 +7,4 @@ Version: @PROJECT_VERSION@ URL: https://github.com/google/googletest Requires: gtest Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ +Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ diff --git a/googlemock/cmake/gmock_main.pc.in b/googlemock/cmake/gmock_main.pc.in index f2dfe69..04658fe 100644 --- a/googlemock/cmake/gmock_main.pc.in +++ b/googlemock/cmake/gmock_main.pc.in @@ -7,4 +7,4 @@ Version: @PROJECT_VERSION@ URL: https://github.com/google/googletest Requires: gmock Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ +Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ diff --git a/googlemock/docs/pump_manual.md b/googlemock/docs/pump_manual.md index cdf7c57..10b3c5f 100644 --- a/googlemock/docs/pump_manual.md +++ b/googlemock/docs/pump_manual.md @@ -6,15 +6,18 @@ Template and macro libraries often need to define many classes, functions, or macros that vary only (or almost only) in the number of arguments they take. It's a lot of repetitive, mechanical, and error-prone work. -Our experience is that it's tedious to write custom scripts, which tend to -reflect the structure of the generated code poorly and are often hard to read -and edit. For example, a small change needed in the generated code may require -some non-intuitive, non-trivial changes in the script. This is especially -painful when experimenting with the code. - -This script may be useful for generating meta code, for example a series of -macros of FOO1, FOO2, etc. Nevertheless, please make it your last resort -technique by favouring C++ template metaprogramming or variadic macros. +Variadic templates and variadic macros can alleviate the problem. However, while +both are being considered by the C++ committee, neither is in the standard yet +or widely supported by compilers. Thus they are often not a good choice, +especially when your code needs to be portable. And their capabilities are still +limited. + +As a result, authors of such libraries often have to write scripts to generate +their implementation. However, our experience is that it's tedious to write such +scripts, which tend to reflect the structure of the generated code poorly and +are often hard to read and edit. For example, a small change needed in the +generated code may require some non-intuitive, non-trivial changes in the +script. This is especially painful when experimenting with the code. # Our Solution diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index c529141..684db13 100644 --- a/googlemock/include/gmock/gmock-function-mocker.h +++ b/googlemock/include/gmock/gmock-function-mocker.h @@ -58,17 +58,16 @@ using identity_t = T; #define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \ GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ - GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ - GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ - GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ - GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ - GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ - GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ - GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ - GMOCK_INTERNAL_GET_CALLTYPE(_Spec), \ +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ + GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ + GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ + GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ + GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ + GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ + GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ + GMOCK_INTERNAL_HAS_NOEXCEPT(_Spec), GMOCK_INTERNAL_GET_CALLTYPE(_Spec), \ (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) #define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \ @@ -108,14 +107,15 @@ using identity_t = T; GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec) #define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \ - _Override, _Final, _NoexceptSpec, \ + _Override, _Final, _Noexcept, \ _CallType, _Signature) \ typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \ _Signature)>::Result \ GMOCK_INTERNAL_EXPAND(_CallType) \ _MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \ - GMOCK_PP_IF(_Constness, const, ) _NoexceptSpec \ - GMOCK_PP_IF(_Override, override, ) GMOCK_PP_IF(_Final, final, ) { \ + GMOCK_PP_IF(_Constness, const, ) GMOCK_PP_IF(_Noexcept, noexcept, ) \ + GMOCK_PP_IF(_Override, override, ) \ + GMOCK_PP_IF(_Final, final, ) { \ GMOCK_MOCKER_(_N, _Constness, _MethodName) \ .SetOwnerAndName(this, #_MethodName); \ return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ @@ -131,7 +131,8 @@ using identity_t = T; ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \ const ::testing::internal::WithoutMatchers&, \ GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \ - GMOCK_PP_REMOVE_PARENS(_Signature)>*) const _NoexceptSpec { \ + GMOCK_PP_REMOVE_PARENS(_Signature)>*) \ + const GMOCK_PP_IF(_Noexcept, noexcept, ) { \ return GMOCK_PP_CAT(::testing::internal::AdjustConstness_, \ GMOCK_PP_IF(_Constness, const, ))(this) \ ->gmock_##_MethodName(GMOCK_PP_REPEAT( \ @@ -153,13 +154,9 @@ using identity_t = T; #define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \ GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple)) -#define GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Tuple) \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT, ~, _Tuple) - -#define GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT(_i, _, _elem) \ - GMOCK_PP_IF( \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \ - _elem, ) +#define GMOCK_INTERNAL_HAS_NOEXCEPT(_Tuple) \ + GMOCK_PP_HAS_COMMA( \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_NOEXCEPT, ~, _Tuple)) #define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) @@ -190,6 +187,7 @@ using identity_t = T; #define GMOCK_INTERNAL_DETECT_FINAL_I_final , +// TODO(iserna): Maybe noexcept should accept an argument here as well. #define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \ GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index e71570b..b8ec24d 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1323,7 +1323,7 @@ class PredicateFormatterFromMatcher { << "Expected: "; matcher.DescribeTo(&ss); - // Rerun the matcher to "PrintAndExplain" the failure. + // Rerun the matcher to "PrintAndExain" the failure. StringMatchResultListener listener; if (MatchPrintAndExplain(x, matcher, &listener)) { ss << "\n The matcher failed on the initial attempt; but passed when " diff --git a/googlemock/scripts/pump.py b/googlemock/scripts/pump.py index 5523a19..66e3217 100755 --- a/googlemock/scripts/pump.py +++ b/googlemock/scripts/pump.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.7 # # Copyright 2008, Google Inc. # All rights reserved. @@ -64,7 +64,6 @@ GRAMMAR: from __future__ import print_function -import io import os import re import sys @@ -835,7 +834,7 @@ def main(argv): sys.exit(1) file_path = argv[-1] - output_str = ConvertFromPumpSource(io.open(file_path, 'r').read()) + output_str = ConvertFromPumpSource(file(file_path, 'r').read()) if file_path.endswith('.pump'): output_file_path = file_path[:-5] else: @@ -843,11 +842,11 @@ def main(argv): if output_file_path == '-': print(output_str,) else: - output_file = io.open(output_file_path, 'w') - output_file.write(u'// This file was GENERATED by command:\n') - output_file.write(u'// %s %s\n' % + output_file = file(output_file_path, 'w') + output_file.write('// This file was GENERATED by command:\n') + output_file.write('// %s %s\n' % (os.path.basename(__file__), os.path.basename(file_path))) - output_file.write(u'// DO NOT EDIT BY HAND!!!\n\n') + output_file.write('// DO NOT EDIT BY HAND!!!\n\n') output_file.write(output_str) output_file.close() diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index 90d6b5f..55be70a 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -42,8 +42,6 @@ #include <map> #include <string> -#include <type_traits> - #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -665,32 +663,5 @@ TEST(MockMethodMockFunctionTest, MockMethodSizeOverhead) { EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4)); } -void hasTwoParams(int, int); -void MaybeThrows(); -void DoesntThrow() noexcept; -struct MockMethodNoexceptSpecifier { - MOCK_METHOD(void, func1, (), (noexcept)); - MOCK_METHOD(void, func2, (), (noexcept(true))); - MOCK_METHOD(void, func3, (), (noexcept(false))); - MOCK_METHOD(void, func4, (), (noexcept(noexcept(MaybeThrows())))); - MOCK_METHOD(void, func5, (), (noexcept(noexcept(DoesntThrow())))); - MOCK_METHOD(void, func6, (), (noexcept(noexcept(DoesntThrow())), const)); - MOCK_METHOD(void, func7, (), (const, noexcept(noexcept(DoesntThrow())))); - // Put commas in the noexcept expression - MOCK_METHOD(void, func8, (), (noexcept(noexcept(hasTwoParams(1, 2))), const)); -}; - -TEST(MockMethodMockFunctionTest, NoexceptSpecifierPreserved) { - EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func1())); - EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func2())); - EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func3())); - EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func4())); - EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func5())); - EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func6())); - EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func7())); - EXPECT_EQ(noexcept(std::declval<MockMethodNoexceptSpecifier>().func8()), - noexcept(hasTwoParams(1, 2))); -} - } // namespace gmock_function_mocker_test } // namespace testing |