aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock')
-rw-r--r--googlemock/docs/cheat_sheet.md35
-rw-r--r--googlemock/docs/pump_manual.md190
-rw-r--r--googlemock/include/gmock/gmock-actions.h49
-rw-r--r--googlemock/include/gmock/gmock-matchers.h28
-rw-r--r--googlemock/include/gmock/internal/gmock-internal-utils.h92
-rw-r--r--googlemock/include/gmock/internal/gmock-pp.h108
-rw-r--r--googlemock/scripts/README.md5
-rwxr-xr-xgooglemock/scripts/generator/cpp/ast.py46
-rwxr-xr-xgooglemock/scripts/generator/cpp/gmock_class.py114
-rwxr-xr-xgooglemock/scripts/generator/cpp/gmock_class_test.py93
-rwxr-xr-xgooglemock/scripts/generator/cpp/keywords.py39
-rwxr-xr-xgooglemock/scripts/generator/cpp/tokenize.py39
-rwxr-xr-xgooglemock/scripts/generator/cpp/utils.py40
-rwxr-xr-xgooglemock/scripts/generator/gmock_gen.py36
-rwxr-xr-xgooglemock/scripts/gmock-config.in303
-rwxr-xr-xgooglemock/scripts/gmock_doctor.py640
-rwxr-xr-xgooglemock/scripts/pump.py855
-rwxr-xr-xgooglemock/scripts/upload.py35
-rw-r--r--googlemock/src/gmock_main.cc9
-rw-r--r--googlemock/test/gmock-actions_test.cc26
-rw-r--r--googlemock/test/gmock-generated-matchers_test.cc53
-rw-r--r--googlemock/test/gmock-matchers_test.cc146
-rw-r--r--googlemock/test/gmock-pp_test.cc10
-rwxr-xr-xgooglemock/test/pump_test.py182
24 files changed, 1884 insertions, 1289 deletions
diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md
index 8ec5ea08..975362bf 100644
--- a/googlemock/docs/cheat_sheet.md
+++ b/googlemock/docs/cheat_sheet.md
@@ -287,6 +287,7 @@ is not changed afterwards, or the meaning of your matcher will be changed.
| `FloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as unequal. |
| `NanSensitiveDoubleEq(a_double)` | `argument` is a `double` value approximately equal to `a_double`, treating two NaNs as equal. |
| `NanSensitiveFloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as equal. |
+| `IsNan()` | `argument` is any floating-point type with a NaN value. |
<!-- mdformat on -->
The above matchers use ULP-based comparison (the same as used in googletest).
@@ -502,16 +503,17 @@ which must be a permanent callback.
#### Returning a Value
<!-- mdformat off(no multiline tables) -->
-| | |
-| :-------------------------- | :-------------------------------------------- |
-| `Return()` | Return from a `void` mock function. |
-| `Return(value)` | Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type <i>at the time the expectation is set</i>, not when the action is executed. |
-| `ReturnArg<N>()` | Return the `N`-th (0-based) argument. |
-| `ReturnNew<T>(a1, ..., ak)` | Return `new T(a1, ..., ak)`; a different object is created each time. |
-| `ReturnNull()` | Return a null pointer. |
-| `ReturnPointee(ptr)` | Return the value pointed to by `ptr`. |
-| `ReturnRef(variable)` | Return a reference to `variable`. |
-| `ReturnRefOfCopy(value)` | Return a reference to a copy of `value`; the copy lives as long as the action. |
+| | |
+| :-------------------------------- | :-------------------------------------------- |
+| `Return()` | Return from a `void` mock function. |
+| `Return(value)` | Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type <i>at the time the expectation is set</i>, not when the action is executed. |
+| `ReturnArg<N>()` | Return the `N`-th (0-based) argument. |
+| `ReturnNew<T>(a1, ..., ak)` | Return `new T(a1, ..., ak)`; a different object is created each time. |
+| `ReturnNull()` | Return a null pointer. |
+| `ReturnPointee(ptr)` | Return the value pointed to by `ptr`. |
+| `ReturnRef(variable)` | Return a reference to `variable`. |
+| `ReturnRefOfCopy(value)` | Return a reference to a copy of `value`; the copy lives as long as the action. |
+| `ReturnRoundRobin({a1, ..., ak})` | Each call will return the next `ai` in the list, starting at the beginning when the end of the list is reached. |
<!-- mdformat on -->
#### Side Effects
@@ -612,19 +614,6 @@ composite action - trying to do so will result in a run-time error.
#### Defining Actions
-<table border="1" cellspacing="0" cellpadding="1">
- <tr>
- <td>`struct SumAction {` <br>
- &emsp;`template <typename T>` <br>
- &emsp;`T operator()(T x, Ty) { return x + y; }` <br>
- `};`
- </td>
- <td> Defines a generic functor that can be used as an action summing its
- arguments. </td> </tr>
- <tr>
- </tr>
-</table>
-
<!-- mdformat off(no multiline tables) -->
| | |
| :--------------------------------- | :-------------------------------------- |
diff --git a/googlemock/docs/pump_manual.md b/googlemock/docs/pump_manual.md
new file mode 100644
index 00000000..10b3c5ff
--- /dev/null
+++ b/googlemock/docs/pump_manual.md
@@ -0,0 +1,190 @@
+<b>P</b>ump is <b>U</b>seful for <b>M</b>eta <b>P</b>rogramming.
+
+# The Problem
+
+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.
+
+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
+
+Pump (for Pump is Useful for Meta Programming, Pretty Useful for Meta
+Programming, or Practical Utility for Meta Programming, whichever you prefer) is
+a simple meta-programming tool for C++. The idea is that a programmer writes a
+`foo.pump` file which contains C++ code plus meta code that manipulates the C++
+code. The meta code can handle iterations over a range, nested iterations, local
+meta variable definitions, simple arithmetic, and conditional expressions. You
+can view it as a small Domain-Specific Language. The meta language is designed
+to be non-intrusive (s.t. it won't confuse Emacs' C++ mode, for example) and
+concise, making Pump code intuitive and easy to maintain.
+
+## Highlights
+
+* The implementation is in a single Python script and thus ultra portable: no
+ build or installation is needed and it works cross platforms.
+* Pump tries to be smart with respect to
+ [Google's style guide](https://github.com/google/styleguide): it breaks long
+ lines (easy to have when they are generated) at acceptable places to fit
+ within 80 columns and indent the continuation lines correctly.
+* The format is human-readable and more concise than XML.
+* The format works relatively well with Emacs' C++ mode.
+
+## Examples
+
+The following Pump code (where meta keywords start with `$`, `[[` and `]]` are
+meta brackets, and `$$` starts a meta comment that ends with the line):
+
+```
+$var n = 3 $$ Defines a meta variable n.
+$range i 0..n $$ Declares the range of meta iterator i (inclusive).
+$for i [[
+ $$ Meta loop.
+// Foo$i does blah for $i-ary predicates.
+$range j 1..i
+template <size_t N $for j [[, typename A$j]]>
+class Foo$i {
+$if i == 0 [[
+ blah a;
+]] $elif i <= 2 [[
+ blah b;
+]] $else [[
+ blah c;
+]]
+};
+
+]]
+```
+
+will be translated by the Pump compiler to:
+
+```cpp
+// Foo0 does blah for 0-ary predicates.
+template <size_t N>
+class Foo0 {
+ blah a;
+};
+
+// Foo1 does blah for 1-ary predicates.
+template <size_t N, typename A1>
+class Foo1 {
+ blah b;
+};
+
+// Foo2 does blah for 2-ary predicates.
+template <size_t N, typename A1, typename A2>
+class Foo2 {
+ blah b;
+};
+
+// Foo3 does blah for 3-ary predicates.
+template <size_t N, typename A1, typename A2, typename A3>
+class Foo3 {
+ blah c;
+};
+```
+
+In another example,
+
+```
+$range i 1..n
+Func($for i + [[a$i]]);
+$$ The text between i and [[ is the separator between iterations.
+```
+
+will generate one of the following lines (without the comments), depending on
+the value of `n`:
+
+```cpp
+Func(); // If n is 0.
+Func(a1); // If n is 1.
+Func(a1 + a2); // If n is 2.
+Func(a1 + a2 + a3); // If n is 3.
+// And so on...
+```
+
+## Constructs
+
+We support the following meta programming constructs:
+
+| `$var id = exp` | Defines a named constant value. `$id` is |
+: : valid util the end of the current meta :
+: : lexical block. :
+| :------------------------------- | :--------------------------------------- |
+| `$range id exp..exp` | Sets the range of an iteration variable, |
+: : which can be reused in multiple loops :
+: : later. :
+| `$for id sep [[ code ]]` | Iteration. The range of `id` must have |
+: : been defined earlier. `$id` is valid in :
+: : `code`. :
+| `$($)` | Generates a single `$` character. |
+| `$id` | Value of the named constant or iteration |
+: : variable. :
+| `$(exp)` | Value of the expression. |
+| `$if exp [[ code ]] else_branch` | Conditional. |
+| `[[ code ]]` | Meta lexical block. |
+| `cpp_code` | Raw C++ code. |
+| `$$ comment` | Meta comment. |
+
+**Note:** To give the user some freedom in formatting the Pump source code, Pump
+ignores a new-line character if it's right after `$for foo` or next to `[[` or
+`]]`. Without this rule you'll often be forced to write very long lines to get
+the desired output. Therefore sometimes you may need to insert an extra new-line
+in such places for a new-line to show up in your output.
+
+## Grammar
+
+```ebnf
+code ::= atomic_code*
+atomic_code ::= $var id = exp
+ | $var id = [[ code ]]
+ | $range id exp..exp
+ | $for id sep [[ code ]]
+ | $($)
+ | $id
+ | $(exp)
+ | $if exp [[ code ]] else_branch
+ | [[ code ]]
+ | cpp_code
+sep ::= cpp_code | empty_string
+else_branch ::= $else [[ code ]]
+ | $elif exp [[ code ]] else_branch
+ | empty_string
+exp ::= simple_expression_in_Python_syntax
+```
+
+## Code
+
+You can find the source code of Pump in [scripts/pump.py](../scripts/pump.py).
+It is still very unpolished and lacks automated tests, although it has been
+successfully used many times. If you find a chance to use it in your project,
+please let us know what you think! We also welcome help on improving Pump.
+
+## Real Examples
+
+You can find real-world applications of Pump in
+[Google Test](https://github.com/google/googletest/tree/master/googletest) and
+[Google Mock](https://github.com/google/googletest/tree/master/googlemock). The
+source file `foo.h.pump` generates `foo.h`.
+
+## Tips
+
+* If a meta variable is followed by a letter or digit, you can separate them
+ using `[[]]`, which inserts an empty string. For example `Foo$j[[]]Helper`
+ generate `Foo1Helper` when `j` is 1.
+* To avoid extra-long Pump source lines, you can break a line anywhere you
+ want by inserting `[[]]` followed by a new line. Since any new-line
+ character next to `[[` or `]]` is ignored, the generated code won't contain
+ this new line.
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index 931e69a7..2fe7574a 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -716,6 +716,36 @@ class ReturnRefOfCopyAction {
GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
};
+// Implements the polymorphic ReturnRoundRobin(v) action, which can be
+// used in any function that returns the element_type of v.
+template <typename T>
+class ReturnRoundRobinAction {
+ public:
+ explicit ReturnRoundRobinAction(std::vector<T> values) {
+ GTEST_CHECK_(!values.empty())
+ << "ReturnRoundRobin requires at least one element.";
+ state_->values = std::move(values);
+ }
+
+ template <typename... Args>
+ T operator()(Args&&...) const {
+ return state_->Next();
+ }
+
+ private:
+ struct State {
+ T Next() {
+ T ret_val = values[i++];
+ if (i == values.size()) i = 0;
+ return ret_val;
+ }
+
+ std::vector<T> values;
+ size_t i = 0;
+ };
+ std::shared_ptr<State> state_ = std::make_shared<State>();
+};
+
// Implements the polymorphic DoDefault() action.
class DoDefaultAction {
public:
@@ -1023,7 +1053,7 @@ inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
}
// Prevent using ReturnRef on reference to temporary.
-template <typename R>
+template <typename R, R* = nullptr>
internal::ReturnRefAction<R> ReturnRef(R&&) = delete;
// Creates an action that returns the reference to a copy of the
@@ -1043,6 +1073,23 @@ internal::ByMoveWrapper<R> ByMove(R x) {
return internal::ByMoveWrapper<R>(std::move(x));
}
+// Creates an action that returns an element of `vals`. Calling this action will
+// repeatedly return the next value from `vals` until it reaches the end and
+// will restart from the beginning.
+template <typename T>
+internal::ReturnRoundRobinAction<T> ReturnRoundRobin(std::vector<T> vals) {
+ return internal::ReturnRoundRobinAction<T>(std::move(vals));
+}
+
+// Creates an action that returns an element of `vals`. Calling this action will
+// repeatedly return the next value from `vals` until it reaches the end and
+// will restart from the beginning.
+template <typename T>
+internal::ReturnRoundRobinAction<T> ReturnRoundRobin(
+ std::initializer_list<T> vals) {
+ return internal::ReturnRoundRobinAction<T>(std::vector<T>(vals));
+}
+
// Creates an action that does the default action for the give mock function.
inline internal::DoDefaultAction DoDefault() {
return internal::DoDefaultAction();
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 4428ec14..bb047da9 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -42,8 +42,8 @@
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
-#include <math.h>
#include <algorithm>
+#include <cmath>
#include <initializer_list>
#include <iterator>
#include <limits>
@@ -54,6 +54,7 @@
#include <type_traits>
#include <utility>
#include <vector>
+
#include "gmock/internal/gmock-internal-utils.h"
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
@@ -141,7 +142,7 @@ class MatcherCastImpl {
template <bool Ignore>
static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
std::true_type /* convertible_to_matcher */,
- bool_constant<Ignore>) {
+ std::integral_constant<bool, Ignore>) {
// M is implicitly convertible to Matcher<T>, which means that either
// M is a polymorphic matcher or Matcher<T> has an implicit constructor
// from M. In both cases using the implicit conversion will produce a
@@ -1349,6 +1350,22 @@ MakePredicateFormatterFromMatcher(M matcher) {
return PredicateFormatterFromMatcher<M>(std::move(matcher));
}
+// Implements the polymorphic IsNan() matcher, which matches any floating type
+// value that is Nan.
+class IsNanMatcher {
+ public:
+ template <typename FloatType>
+ bool MatchAndExplain(const FloatType& f,
+ MatchResultListener* /* listener */) const {
+ return (::std::isnan)(f);
+ }
+
+ void DescribeTo(::std::ostream* os) const { *os << "is NaN"; }
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "isn't NaN";
+ }
+};
+
// Implements the polymorphic floating point equality matcher, which matches
// two float values using ULP-based approximation or, optionally, a
// user-specified epsilon. The template is meant to be instantiated with
@@ -1409,7 +1426,7 @@ class FloatingEqMatcher {
}
const FloatType diff = value - expected_;
- if (fabs(diff) <= max_abs_error_) {
+ if (::std::fabs(diff) <= max_abs_error_) {
return true;
}
@@ -3626,6 +3643,11 @@ inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
return internal::RefMatcher<T&>(x);
}
+// Creates a polymorphic matcher that matches any NaN floating point.
+inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() {
+ return MakePolymorphicMatcher(internal::IsNanMatcher());
+}
+
// Creates a matcher that matches any double argument approximately
// equal to rhs, where two NANs are considered unequal.
inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h
index 584afa98..5fd169e9 100644
--- a/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ b/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -157,9 +157,6 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
static_cast< ::testing::internal::TypeKind>( \
::testing::internal::KindOf<type>::value)
-// Evaluates to true if and only if integer type T is signed.
-#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
-
// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
// is true if and only if arithmetic type From can be losslessly converted to
// arithmetic type To.
@@ -170,65 +167,30 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
// From, and kToKind is the kind of To; the value is
// implementation-defined when the above pre-condition is violated.
template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
-struct LosslessArithmeticConvertibleImpl : public std::false_type {};
-
-// Converting bool to bool is lossless.
-template <>
-struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
- : public std::true_type {};
-
-// Converting bool to any integer type is lossless.
-template <typename To>
-struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
- : public std::true_type {};
-
-// Converting bool to any floating-point type is lossless.
-template <typename To>
-struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
- : public std::true_type {};
-
-// Converting an integer to bool is lossy.
-template <typename From>
-struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
- : public std::false_type {};
-
-// Converting an integer to another non-bool integer is lossless
-// if and only if the target type's range encloses the source type's range.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
- : public bool_constant<
- // When converting from a smaller size to a larger size, we are
- // fine as long as we are not converting from signed to unsigned.
- ((sizeof(From) < sizeof(To)) &&
- (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
- // When converting between the same size, the signedness must match.
- ((sizeof(From) == sizeof(To)) &&
- (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
-
-#undef GMOCK_IS_SIGNED_
-
-// Converting an integer to a floating-point type may be lossy, since
-// the format of a floating-point number is implementation-defined.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
- : public std::false_type {};
-
-// Converting a floating-point to bool is lossy.
-template <typename From>
-struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
- : public std::false_type {};
-
-// Converting a floating-point to an integer is lossy.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
- : public std::false_type {};
-
-// Converting a floating-point to another floating-point is lossless
-// if and only if the target type is at least as big as the source type.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<
- kFloatingPoint, From, kFloatingPoint, To>
- : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
+using LosslessArithmeticConvertibleImpl = std::integral_constant<
+ bool,
+ // clang-format off
+ // Converting from bool is always lossless
+ (kFromKind == kBool) ? true
+ // Converting between any other type kinds will be lossy if the type
+ // kinds are not the same.
+ : (kFromKind != kToKind) ? false
+ : (kFromKind == kInteger &&
+ // Converting between integers of different widths is allowed so long
+ // as the conversion does not go from signed to unsigned.
+ (((sizeof(From) < sizeof(To)) &&
+ !(std::is_signed<From>::value && !std::is_signed<To>::value)) ||
+ // Converting between integers of the same width only requires the
+ // two types to have the same signedness.
+ ((sizeof(From) == sizeof(To)) &&
+ (std::is_signed<From>::value == std::is_signed<To>::value)))
+ ) ? true
+ // Floating point conversions are lossless if and only if `To` is at least
+ // as wide as `From`.
+ : (kFromKind == kFloatingPoint && (sizeof(From) <= sizeof(To))) ? true
+ : false
+ // clang-format on
+ >;
// LosslessArithmeticConvertible<From, To>::value is true if and only if
// arithmetic type From can be losslessly converted to arithmetic type To.
@@ -238,9 +200,9 @@ struct LosslessArithmeticConvertibleImpl<
// reference) built-in arithmetic types; the value is
// implementation-defined when the above pre-condition is violated.
template <typename From, typename To>
-struct LosslessArithmeticConvertible
- : public LosslessArithmeticConvertibleImpl<
- GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
+using LosslessArithmeticConvertible =
+ LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
+ GMOCK_KIND_OF_(To), To>;
// This interface knows how to report a Google Mock failure (either
// non-fatal or fatal).
diff --git a/googlemock/include/gmock/internal/gmock-pp.h b/googlemock/include/gmock/internal/gmock-pp.h
index 1ab80e1c..c3759f66 100644
--- a/googlemock/include/gmock/internal/gmock-pp.h
+++ b/googlemock/include/gmock/internal/gmock-pp.h
@@ -1,19 +1,6 @@
#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
-#undef GMOCK_PP_INTERNAL_USE_MSVC
-#if defined(__clang__)
-#define GMOCK_PP_INTERNAL_USE_MSVC 0
-#elif defined(_MSC_VER)
-// TODO(iserna): Also verify tradional versus comformant preprocessor.
-static_assert(
- _MSC_VER >= 1900,
- "MSVC version not supported. There is support for MSVC 14.0 and above.");
-#define GMOCK_PP_INTERNAL_USE_MSVC 1
-#else
-#define GMOCK_PP_INTERNAL_USE_MSVC 0
-#endif
-
// Expands and concatenates the arguments. Constructed macros reevaluate.
#define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2)
@@ -29,10 +16,6 @@ static_assert(
// Returns the only argument.
#define GMOCK_PP_IDENTITY(_1) _1
-// MSVC preprocessor collapses __VA_ARGS__ in a single argument, we use a
-// CAT-like directive to force correct evaluation. Each macro has its own.
-#if GMOCK_PP_INTERNAL_USE_MSVC
-
// Evaluates to the number of arguments after expansion.
//
// #define PAIR x, y
@@ -43,45 +26,27 @@ static_assert(
// GMOCK_PP_NARG(PAIR) => 2
//
// Requires: the number of arguments after expansion is at most 15.
-#define GMOCK_PP_NARG(...) \
- GMOCK_PP_INTERNAL_NARG_CAT( \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, \
- 8, 7, 6, 5, 4, 3, 2, 1), )
+#define GMOCK_PP_NARG(...) \
+ GMOCK_PP_INTERNAL_16TH( \
+ (__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
// Returns 1 if the expansion of arguments has an unprotected comma. Otherwise
// returns 0. Requires no more than 15 unprotected commas.
-#define GMOCK_PP_HAS_COMMA(...) \
- GMOCK_PP_INTERNAL_HAS_COMMA_CAT( \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
- 1, 1, 1, 1, 1, 0), )
+#define GMOCK_PP_HAS_COMMA(...) \
+ GMOCK_PP_INTERNAL_16TH( \
+ (__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0))
+
// Returns the first argument.
-#define GMOCK_PP_HEAD(...) \
- GMOCK_PP_INTERNAL_HEAD_CAT(GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__), )
+#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD((__VA_ARGS__))
// Returns the tail. A variadic list of all arguments minus the first. Requires
// at least one argument.
-#define GMOCK_PP_TAIL(...) \
- GMOCK_PP_INTERNAL_TAIL_CAT(GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__), )
+#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL((__VA_ARGS__))
// Calls CAT(_Macro, NARG(__VA_ARGS__))(__VA_ARGS__)
#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
- GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT( \
- GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__), )
-
-#else // GMOCK_PP_INTERNAL_USE_MSVC
-
-#define GMOCK_PP_NARG(...) \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, \
- 7, 6, 5, 4, 3, 2, 1)
-#define GMOCK_PP_HAS_COMMA(...) \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
- 1, 1, 1, 1, 0)
-#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__)
-#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__)
-#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
- GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__)
-
-#endif // GMOCK_PP_INTERNAL_USE_MSVC
+ GMOCK_PP_IDENTITY( \
+ GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__))
// If the arguments after expansion have no tokens, evaluates to `1`. Otherwise
// evaluates to `0`.
@@ -139,10 +104,9 @@ static_assert(
// Expands to 1 if the first argument starts with something in parentheses,
// otherwise to 0.
-#define GMOCK_PP_IS_BEGIN_PARENS(...) \
- GMOCK_PP_INTERNAL_ALTERNATE_HEAD( \
- GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \
- GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__))
+#define GMOCK_PP_IS_BEGIN_PARENS(...) \
+ GMOCK_PP_HEAD(GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \
+ GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__))
// Expands to 1 is there is only one argument and it is enclosed in parentheses.
#define GMOCK_PP_IS_ENCLOSED_PARENS(...) \
@@ -179,10 +143,6 @@ static_assert(
#define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , )
#define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2
#define GMOCK_PP_INTERNAL_STRINGIZE(...) #__VA_ARGS__
-#define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \
- _10, _11, _12, _13, _14, _15, _16, \
- ...) \
- _16
#define GMOCK_PP_INTERNAL_CAT_5(_1, _2, _3, _4, _5) _1##_2##_3##_4##_5
#define GMOCK_PP_INTERNAL_IS_EMPTY(_1, _2, _3, _4) \
GMOCK_PP_HAS_COMMA(GMOCK_PP_INTERNAL_CAT_5(GMOCK_PP_INTERNAL_IS_EMPTY_CASE_, \
@@ -190,30 +150,24 @@ static_assert(
#define GMOCK_PP_INTERNAL_IS_EMPTY_CASE_0001 ,
#define GMOCK_PP_INTERNAL_IF_1(_Then, _Else) _Then
#define GMOCK_PP_INTERNAL_IF_0(_Then, _Else) _Else
-#define GMOCK_PP_INTERNAL_HEAD(_1, ...) _1
-#define GMOCK_PP_INTERNAL_TAIL(_1, ...) __VA_ARGS__
-#if GMOCK_PP_INTERNAL_USE_MSVC
-#define GMOCK_PP_INTERNAL_NARG_CAT(_1, _2) GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_HEAD_CAT(_1, _2) GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT(_1, _2) \
- GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_TAIL_CAT(_1, _2) GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT(_1, _2) \
- GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) \
- GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(GMOCK_PP_HEAD(__VA_ARGS__), )
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(_1, _2) \
- GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2) _1##_2
-#else // GMOCK_PP_INTERNAL_USE_MSVC
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) GMOCK_PP_HEAD(__VA_ARGS__)
-#endif // GMOCK_PP_INTERNAL_USE_MSVC
+// Because of MSVC treating a token with a comma in it as a single token when
+// passed to another macro, we need to force it to evaluate it as multiple
+// tokens. We do that by using a "IDENTITY(MACRO PARENTHESIZED_ARGS)" macro. We
+// define one per possible macro that relies on this behavior. Note "_Args" must
+// be parenthesized.
+#define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \
+ _10, _11, _12, _13, _14, _15, _16, \
+ ...) \
+ _16
+#define GMOCK_PP_INTERNAL_16TH(_Args) \
+ GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_16TH _Args)
+#define GMOCK_PP_INTERNAL_INTERNAL_HEAD(_1, ...) _1
+#define GMOCK_PP_INTERNAL_HEAD(_Args) \
+ GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_HEAD _Args)
+#define GMOCK_PP_INTERNAL_INTERNAL_TAIL(_1, ...) __VA_ARGS__
+#define GMOCK_PP_INTERNAL_TAIL(_Args) \
+ GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_TAIL _Args)
#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C(...) 1 _
#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_1 1,
diff --git a/googlemock/scripts/README.md b/googlemock/scripts/README.md
new file mode 100644
index 00000000..fa359fed
--- /dev/null
+++ b/googlemock/scripts/README.md
@@ -0,0 +1,5 @@
+# Please Note:
+
+Files in this directory are no longer supported by the maintainers. They
+represent mosty historical artifacts and supported by the community only. There
+is no guarantee whatsoever that these scripts still work.
diff --git a/googlemock/scripts/generator/cpp/ast.py b/googlemock/scripts/generator/cpp/ast.py
index f14728b4..77bbec99 100755
--- a/googlemock/scripts/generator/cpp/ast.py
+++ b/googlemock/scripts/generator/cpp/ast.py
@@ -17,10 +17,7 @@
"""Generate an Abstract Syntax Tree (AST) for C++."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
-# TODO:
+# FIXME:
# * Tokens should never be exported, need to convert to Nodes
# (return types, parameters, etc.)
# * Handle static class data for templatized classes
@@ -338,7 +335,7 @@ class Class(_GenericDeclaration):
# TODO(nnorwitz): handle namespaces, etc.
if self.bases:
for token_list in self.bases:
- # TODO(nnorwitz): bases are tokens, do name comparison.
+ # TODO(nnorwitz): bases are tokens, do name comparision.
for token in token_list:
if token.name == node.name:
return True
@@ -381,7 +378,7 @@ class Function(_GenericDeclaration):
def Requires(self, node):
if self.parameters:
- # TODO(nnorwitz): parameters are tokens, do name comparison.
+ # TODO(nnorwitz): parameters are tokens, do name comparision.
for p in self.parameters:
if p.name == node.name:
return True
@@ -739,6 +736,14 @@ class AstBuilder(object):
if token.token_type == tokenize.NAME:
if (keywords.IsKeyword(token.name) and
not keywords.IsBuiltinType(token.name)):
+ if token.name == 'enum':
+ # Pop the next token and only put it back if it's not
+ # 'class'. This allows us to support the two-token
+ # 'enum class' keyword as if it were simply 'enum'.
+ next = self._GetNextToken()
+ if next.name != 'class':
+ self._AddBackToken(next)
+
method = getattr(self, 'handle_' + token.name)
return method()
elif token.name == self.in_class_name_only:
@@ -754,7 +759,8 @@ class AstBuilder(object):
# Handle data or function declaration/definition.
syntax = tokenize.SYNTAX
temp_tokens, last_token = \
- self._GetVarTokensUpTo(syntax, '(', ';', '{', '[')
+ self._GetVarTokensUpToIgnoringTemplates(syntax,
+ '(', ';', '{', '[')
temp_tokens.insert(0, token)
if last_token.name == '(':
# If there is an assignment before the paren,
@@ -858,7 +864,25 @@ class AstBuilder(object):
last_token = self._GetNextToken()
return tokens, last_token
- # TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be necessary.
+ # Same as _GetVarTokensUpTo, but skips over '<...>' which could contain an
+ # expected token.
+ def _GetVarTokensUpToIgnoringTemplates(self, expected_token_type,
+ *expected_tokens):
+ last_token = self._GetNextToken()
+ tokens = []
+ nesting = 0
+ while (nesting > 0 or
+ last_token.token_type != expected_token_type or
+ last_token.name not in expected_tokens):
+ tokens.append(last_token)
+ last_token = self._GetNextToken()
+ if last_token.name == '<':
+ nesting += 1
+ elif last_token.name == '>':
+ nesting -= 1
+ return tokens, last_token
+
+ # TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be necesary.
def _IgnoreUpTo(self, token_type, token):
unused_tokens = self._GetTokensUpTo(token_type, token)
@@ -1264,9 +1288,6 @@ class AstBuilder(object):
return self._GetNestedType(Union)
def handle_enum(self):
- token = self._GetNextToken()
- if not (token.token_type == tokenize.NAME and token.name == 'class'):
- self._AddBackToken(token)
return self._GetNestedType(Enum)
def handle_auto(self):
@@ -1298,7 +1319,8 @@ class AstBuilder(object):
if token2.token_type == tokenize.SYNTAX and token2.name == '~':
return self.GetMethod(FUNCTION_VIRTUAL + FUNCTION_DTOR, None)
assert token.token_type == tokenize.NAME or token.name == '::', token
- return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(') # )
+ return_type_and_name, _ = self._GetVarTokensUpToIgnoringTemplates(
+ tokenize.SYNTAX, '(') # )
return_type_and_name.insert(0, token)
if token2 is not token:
return_type_and_name.insert(1, token2)
diff --git a/googlemock/scripts/generator/cpp/gmock_class.py b/googlemock/scripts/generator/cpp/gmock_class.py
index f9966cbb..86dcedbf 100755
--- a/googlemock/scripts/generator/cpp/gmock_class.py
+++ b/googlemock/scripts/generator/cpp/gmock_class.py
@@ -1,18 +1,33 @@
#!/usr/bin/env python
#
-# Copyright 2008 Google Inc. All Rights Reserved.
+# Copyright 2008, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * 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.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# 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.
"""Generate Google Mock classes from base classes.
@@ -26,9 +41,6 @@ Usage:
Output is sent to stdout.
"""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
import os
import re
import sys
@@ -48,6 +60,50 @@ _VERSION = (1, 0, 1) # The version of this script.
_INDENT = 2
+def _RenderType(ast_type):
+ """Renders the potentially recursively templated type into a string.
+
+ Args:
+ ast_type: The AST of the type.
+
+ Returns:
+ Rendered string and a boolean to indicate whether we have multiple args
+ (which is not handled correctly).
+ """
+ has_multiarg_error = False
+ # Add modifiers like 'const'.
+ modifiers = ''
+ if ast_type.modifiers:
+ modifiers = ' '.join(ast_type.modifiers) + ' '
+ return_type = modifiers + ast_type.name
+ if ast_type.templated_types:
+ # Collect template args.
+ template_args = []
+ for arg in ast_type.templated_types:
+ rendered_arg, e = _RenderType(arg)
+ if e: has_multiarg_error = True
+ template_args.append(rendered_arg)
+ return_type += '<' + ', '.join(template_args) + '>'
+ # We are actually not handling multi-template-args correctly. So mark it.
+ if len(template_args) > 1:
+ has_multiarg_error = True
+ if ast_type.pointer:
+ return_type += '*'
+ if ast_type.reference:
+ return_type += '&'
+ return return_type, has_multiarg_error
+
+
+def _GetNumParameters(parameters, source):
+ num_parameters = len(parameters)
+ if num_parameters == 1:
+ first_param = parameters[0]
+ if source[first_param.start:first_param.end].strip() == 'void':
+ # We must treat T(void) as a function with no parameters.
+ return 0
+ return num_parameters
+
+
def _GenerateMethods(output_lines, source, class_node):
function_type = (ast.FUNCTION_VIRTUAL | ast.FUNCTION_PURE_VIRTUAL |
ast.FUNCTION_OVERRIDE)
@@ -63,32 +119,16 @@ def _GenerateMethods(output_lines, source, class_node):
const = ''
if node.modifiers & ast.FUNCTION_CONST:
const = 'CONST_'
+ num_parameters = _GetNumParameters(node.parameters, source)
return_type = 'void'
if node.return_type:
- # Add modifiers like 'const'.
- modifiers = ''
- if node.return_type.modifiers:
- modifiers = ' '.join(node.return_type.modifiers) + ' '
- return_type = modifiers + node.return_type.name
- template_args = [arg.name for arg in node.return_type.templated_types]
- if template_args:
- return_type += '<' + ', '.join(template_args) + '>'
- if len(template_args) > 1:
- for line in [
- '// The following line won\'t really compile, as the return',
- '// type has multiple template arguments. To fix it, use a',
- '// typedef for the return type.']:
- output_lines.append(indent + line)
- if node.return_type.pointer:
- return_type += '*'
- if node.return_type.reference:
- return_type += '&'
- num_parameters = len(node.parameters)
- if len(node.parameters) == 1:
- first_param = node.parameters[0]
- if source[first_param.start:first_param.end].strip() == 'void':
- # We must treat T(void) as a function with no parameters.
- num_parameters = 0
+ return_type, has_multiarg_error = _RenderType(node.return_type)
+ if has_multiarg_error:
+ for line in [
+ '// The following line won\'t really compile, as the return',
+ '// type has multiple template arguments. To fix it, use a',
+ '// typedef for the return type.']:
+ output_lines.append(indent + line)
tmpl = ''
if class_node.templated_types:
tmpl = '_T'
diff --git a/googlemock/scripts/generator/cpp/gmock_class_test.py b/googlemock/scripts/generator/cpp/gmock_class_test.py
index c53e6000..05051626 100755
--- a/googlemock/scripts/generator/cpp/gmock_class_test.py
+++ b/googlemock/scripts/generator/cpp/gmock_class_test.py
@@ -1,25 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2009 Neal Norwitz All Rights Reserved.
-# Portions Copyright 2009 Google Inc. All Rights Reserved.
+# Copyright 2009, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * 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.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# 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 gmock.scripts.generator.cpp.gmock_class."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
import os
import sys
import unittest
@@ -444,19 +455,63 @@ void(const FooType& test_arg));
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
- def testEnumClass(self):
+ def testEnumType(self):
source = """
class Test {
public:
- enum class Baz { BAZINGA };
- virtual void Bar(const FooType& test_arg);
+ enum Bar {
+ BAZ, QUX, QUUX, QUUUX
+ };
+ virtual void Foo();
};
"""
expected = """\
class MockTest : public Test {
public:
-MOCK_METHOD1(Bar,
-void(const FooType& test_arg));
+MOCK_METHOD0(Foo,
+void());
+};
+"""
+ self.assertEqualIgnoreLeadingWhitespace(
+ expected, self.GenerateMocks(source))
+
+ def testEnumClassType(self):
+ source = """
+class Test {
+ public:
+ enum class Bar {
+ BAZ, QUX, QUUX, QUUUX
+ };
+ virtual void Foo();
+};
+"""
+ expected = """\
+class MockTest : public Test {
+public:
+MOCK_METHOD0(Foo,
+void());
+};
+"""
+ self.assertEqualIgnoreLeadingWhitespace(
+ expected, self.GenerateMocks(source))
+
+ def testStdFunction(self):
+ source = """
+class Test {
+ public:
+ Test(std::function<int(std::string)> foo) : foo_(foo) {}
+
+ virtual std::function<int(std::string)> foo();
+
+ private:
+ std::function<int(std::string)> foo_;
+};
+"""
+ expected = """\
+class MockTest : public Test {
+public:
+MOCK_METHOD0(foo,
+std::function<int (std::string)>());
};
"""
self.assertEqualIgnoreLeadingWhitespace(
diff --git a/googlemock/scripts/generator/cpp/keywords.py b/googlemock/scripts/generator/cpp/keywords.py
index f694450e..8b75c2b4 100755
--- a/googlemock/scripts/generator/cpp/keywords.py
+++ b/googlemock/scripts/generator/cpp/keywords.py
@@ -1,25 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2007 Neal Norwitz
-# Portions Copyright 2007 Google Inc.
+# Copyright 2007, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * 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.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# 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.
"""C++ keywords and helper utilities for determining keywords."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
try:
# Python 3.x
import builtins
diff --git a/googlemock/scripts/generator/cpp/tokenize.py b/googlemock/scripts/generator/cpp/tokenize.py
index 359d5562..c64dcdee 100755
--- a/googlemock/scripts/generator/cpp/tokenize.py
+++ b/googlemock/scripts/generator/cpp/tokenize.py
@@ -1,25 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2007 Neal Norwitz
-# Portions Copyright 2007 Google Inc.
+# Copyright 2007, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * 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.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# 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.
"""Tokenize C++ source code."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
try:
# Python 3.x
import builtins
diff --git a/googlemock/scripts/generator/cpp/utils.py b/googlemock/scripts/generator/cpp/utils.py
index eab36eec..6945a78c 100755
--- a/googlemock/scripts/generator/cpp/utils.py
+++ b/googlemock/scripts/generator/cpp/utils.py
@@ -1,28 +1,38 @@
#!/usr/bin/env python
#
-# Copyright 2007 Neal Norwitz
-# Portions Copyright 2007 Google Inc.
+# Copyright 2007, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * 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.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# 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.
"""Generic utilities for C++ parsing."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
import sys
-
# Set to True to see the start/end token indices.
DEBUG = True
diff --git a/googlemock/scripts/generator/gmock_gen.py b/googlemock/scripts/generator/gmock_gen.py
index 8cc0d135..34a7f887 100755
--- a/googlemock/scripts/generator/gmock_gen.py
+++ b/googlemock/scripts/generator/gmock_gen.py
@@ -1,22 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2008 Google Inc. All Rights Reserved.
+# Copyright 2008, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * 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.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# 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.
"""Driver for starting up Google Mock class generator."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
import os
import sys
diff --git a/googlemock/scripts/gmock-config.in b/googlemock/scripts/gmock-config.in
deleted file mode 100755
index 2baefe94..00000000
--- a/googlemock/scripts/gmock-config.in
+++ /dev/null
@@ -1,303 +0,0 @@
-#!/bin/sh
-
-# These variables are automatically filled in by the configure script.
-name="@PACKAGE_TARNAME@"
-version="@PACKAGE_VERSION@"
-
-show_usage()
-{
- echo "Usage: gmock-config [OPTIONS...]"
-}
-
-show_help()
-{
- show_usage
- cat <<\EOF
-
-The `gmock-config' script provides access to the necessary compile and linking
-flags to connect with Google C++ Mocking Framework, both in a build prior to
-installation, and on the system proper after installation. The installation
-overrides may be issued in combination with any other queries, but will only
-affect installation queries if called on a built but not installed gmock. The
-installation queries may not be issued with any other types of queries, and
-only one installation query may be made at a time. The version queries and
-compiler flag queries may be combined as desired but not mixed. Different
-version queries are always combined with logical "and" semantics, and only the
-last of any particular query is used while all previous ones ignored. All
-versions must be specified as a sequence of numbers separated by periods.
-Compiler flag queries output the union of the sets of flags when combined.
-
- Examples:
- gmock-config --min-version=1.0 || echo "Insufficient Google Mock version."
-
- g++ $(gmock-config --cppflags --cxxflags) -o foo.o -c foo.cpp
- g++ $(gmock-config --ldflags --libs) -o foo foo.o
-
- # When using a built but not installed Google Mock:
- g++ $(../../my_gmock_build/scripts/gmock-config ...) ...
-
- # When using an installed Google Mock, but with installation overrides:
- export GMOCK_PREFIX="/opt"
- g++ $(gmock-config --libdir="/opt/lib64" ...) ...
-
- Help:
- --usage brief usage information
- --help display this help message
-
- Installation Overrides:
- --prefix=<dir> overrides the installation prefix
- --exec-prefix=<dir> overrides the executable installation prefix
- --libdir=<dir> overrides the library installation prefix
- --includedir=<dir> overrides the header file installation prefix
-
- Installation Queries:
- --prefix installation prefix
- --exec-prefix executable installation prefix
- --libdir library installation directory
- --includedir header file installation directory
- --version the version of the Google Mock installation
-
- Version Queries:
- --min-version=VERSION return 0 if the version is at least VERSION
- --exact-version=VERSION return 0 if the version is exactly VERSION
- --max-version=VERSION return 0 if the version is at most VERSION
-
- Compilation Flag Queries:
- --cppflags compile flags specific to the C-like preprocessors
- --cxxflags compile flags appropriate for C++ programs
- --ldflags linker flags
- --libs libraries for linking
-
-EOF
-}
-
-# This function bounds our version with a min and a max. It uses some clever
-# POSIX-compliant variable expansion to portably do all the work in the shell
-# and avoid any dependency on a particular "sed" or "awk" implementation.
-# Notable is that it will only ever compare the first 3 components of versions.
-# Further components will be cleanly stripped off. All versions must be
-# unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and
-# the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should
-# investigate expanding this via autom4te from AS_VERSION_COMPARE rather than
-# continuing to maintain our own shell version.
-check_versions()
-{
- major_version=${version%%.*}
- minor_version="0"
- point_version="0"
- if test "${version#*.}" != "${version}"; then
- minor_version=${version#*.}
- minor_version=${minor_version%%.*}
- fi
- if test "${version#*.*.}" != "${version}"; then
- point_version=${version#*.*.}
- point_version=${point_version%%.*}
- fi
-
- min_version="$1"
- min_major_version=${min_version%%.*}
- min_minor_version="0"
- min_point_version="0"
- if test "${min_version#*.}" != "${min_version}"; then
- min_minor_version=${min_version#*.}
- min_minor_version=${min_minor_version%%.*}
- fi
- if test "${min_version#*.*.}" != "${min_version}"; then
- min_point_version=${min_version#*.*.}
- min_point_version=${min_point_version%%.*}
- fi
-
- max_version="$2"
- max_major_version=${max_version%%.*}
- max_minor_version="0"
- max_point_version="0"
- if test "${max_version#*.}" != "${max_version}"; then
- max_minor_version=${max_version#*.}
- max_minor_version=${max_minor_version%%.*}
- fi
- if test "${max_version#*.*.}" != "${max_version}"; then
- max_point_version=${max_version#*.*.}
- max_point_version=${max_point_version%%.*}
- fi
-
- test $(($major_version)) -lt $(($min_major_version)) && exit 1
- if test $(($major_version)) -eq $(($min_major_version)); then
- test $(($minor_version)) -lt $(($min_minor_version)) && exit 1
- if test $(($minor_version)) -eq $(($min_minor_version)); then
- test $(($point_version)) -lt $(($min_point_version)) && exit 1
- fi
- fi
-
- test $(($major_version)) -gt $(($max_major_version)) && exit 1
- if test $(($major_version)) -eq $(($max_major_version)); then
- test $(($minor_version)) -gt $(($max_minor_version)) && exit 1
- if test $(($minor_version)) -eq $(($max_minor_version)); then
- test $(($point_version)) -gt $(($max_point_version)) && exit 1
- fi
- fi
-
- exit 0
-}
-
-# Show the usage line when no arguments are specified.
-if test $# -eq 0; then
- show_usage
- exit 1
-fi
-
-while test $# -gt 0; do
- case $1 in
- --usage) show_usage; exit 0;;
- --help) show_help; exit 0;;
-
- # Installation overrides
- --prefix=*) GMOCK_PREFIX=${1#--prefix=};;
- --exec-prefix=*) GMOCK_EXEC_PREFIX=${1#--exec-prefix=};;
- --libdir=*) GMOCK_LIBDIR=${1#--libdir=};;
- --includedir=*) GMOCK_INCLUDEDIR=${1#--includedir=};;
-
- # Installation queries
- --prefix|--exec-prefix|--libdir|--includedir|--version)
- if test -n "${do_query}"; then
- show_usage
- exit 1
- fi
- do_query=${1#--}
- ;;
-
- # Version checking
- --min-version=*)
- do_check_versions=yes
- min_version=${1#--min-version=}
- ;;
- --max-version=*)
- do_check_versions=yes
- max_version=${1#--max-version=}
- ;;
- --exact-version=*)
- do_check_versions=yes
- exact_version=${1#--exact-version=}
- ;;
-
- # Compiler flag output
- --cppflags) echo_cppflags=yes;;
- --cxxflags) echo_cxxflags=yes;;
- --ldflags) echo_ldflags=yes;;
- --libs) echo_libs=yes;;
-
- # Everything else is an error
- *) show_usage; exit 1;;
- esac
- shift
-done
-
-# These have defaults filled in by the configure script but can also be
-# overridden by environment variables or command line parameters.
-prefix="${GMOCK_PREFIX:-@prefix@}"
-exec_prefix="${GMOCK_EXEC_PREFIX:-@exec_prefix@}"
-libdir="${GMOCK_LIBDIR:-@libdir@}"
-includedir="${GMOCK_INCLUDEDIR:-@includedir@}"
-
-# We try and detect if our binary is not located at its installed location. If
-# it's not, we provide variables pointing to the source and build tree rather
-# than to the install tree. We also locate Google Test using the configured
-# gtest-config script rather than searching the PATH and our bindir for one.
-# This allows building against a just-built gmock rather than an installed
-# gmock.
-bindir="@bindir@"
-this_relative_bindir=`dirname $0`
-this_bindir=`cd ${this_relative_bindir}; pwd -P`
-if test "${this_bindir}" = "${this_bindir%${bindir}}"; then
- # The path to the script doesn't end in the bindir sequence from Autoconf,
- # assume that we are in a build tree.
- build_dir=`dirname ${this_bindir}`
- src_dir=`cd ${this_bindir}/@top_srcdir@; pwd -P`
-
- # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we
- # should work to remove it, and/or remove libtool altogether, replacing it
- # with direct references to the library and a link path.
- gmock_libs="${build_dir}/lib/libgmock.la"
- gmock_ldflags=""
-
- # We provide hooks to include from either the source or build dir, where the
- # build dir is always preferred. This will potentially allow us to write
- # build rules for generated headers and have them automatically be preferred
- # over provided versions.
- gmock_cppflags="-I${build_dir}/include -I${src_dir}/include"
- gmock_cxxflags=""
-
- # Directly invoke the gtest-config script used during the build process.
- gtest_config="@GTEST_CONFIG@"
-else
- # We're using an installed gmock, although it may be staged under some
- # prefix. Assume (as our own libraries do) that we can resolve the prefix,
- # and are present in the dynamic link paths.
- gmock_ldflags="-L${libdir}"
- gmock_libs="-l${name}"
- gmock_cppflags="-I${includedir}"
- gmock_cxxflags=""
-
- # We also prefer any gtest-config script installed in our prefix. Lacking
- # one, we look in the PATH for one.
- gtest_config="${bindir}/gtest-config"
- if test ! -x "${gtest_config}"; then
- gtest_config=`which gtest-config`
- fi
-fi
-
-# Ensure that we have located a Google Test to link against.
-if ! test -x "${gtest_config}"; then
- echo "Unable to locate Google Test, check your Google Mock configuration" \
- "and installation" >&2
- exit 1
-elif ! "${gtest_config}" "--exact-version=@GTEST_VERSION@"; then
- echo "The Google Test found is not the same version as Google Mock was " \
- "built against" >&2
- exit 1
-fi
-
-# Add the necessary Google Test bits into the various flag variables
-gmock_cppflags="${gmock_cppflags} `${gtest_config} --cppflags`"
-gmock_cxxflags="${gmock_cxxflags} `${gtest_config} --cxxflags`"
-gmock_ldflags="${gmock_ldflags} `${gtest_config} --ldflags`"
-gmock_libs="${gmock_libs} `${gtest_config} --libs`"
-
-# Do an installation query if requested.
-if test -n "$do_query"; then
- case $do_query in
- prefix) echo $prefix; exit 0;;
- exec-prefix) echo $exec_prefix; exit 0;;
- libdir) echo $libdir; exit 0;;
- includedir) echo $includedir; exit 0;;
- version) echo $version; exit 0;;
- *) show_usage; exit 1;;
- esac
-fi
-
-# Do a version check if requested.
-if test "$do_check_versions" = "yes"; then
- # Make sure we didn't receive a bad combination of parameters.
- test "$echo_cppflags" = "yes" && show_usage && exit 1
- test "$echo_cxxflags" = "yes" && show_usage && exit 1
- test "$echo_ldflags" = "yes" && show_usage && exit 1
- test "$echo_libs" = "yes" && show_usage && exit 1
-
- if test "$exact_version" != ""; then
- check_versions $exact_version $exact_version
- # unreachable
- else
- check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999}
- # unreachable
- fi
-fi
-
-# Do the output in the correct order so that these can be used in-line of
-# a compiler invocation.
-output=""
-test "$echo_cppflags" = "yes" && output="$output $gmock_cppflags"
-test "$echo_cxxflags" = "yes" && output="$output $gmock_cxxflags"
-test "$echo_ldflags" = "yes" && output="$output $gmock_ldflags"
-test "$echo_libs" = "yes" && output="$output $gmock_libs"
-echo $output
-
-exit 0
diff --git a/googlemock/scripts/gmock_doctor.py b/googlemock/scripts/gmock_doctor.py
deleted file mode 100755
index 74992bc7..00000000
--- a/googlemock/scripts/gmock_doctor.py
+++ /dev/null
@@ -1,640 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008, 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.
-
-"""Converts compiler's errors in code using Google Mock to plain English."""
-
-__author__ = 'wan@google.com (Zhanyong Wan)'
-
-import re
-import sys
-
-_VERSION = '1.0.3'
-
-_EMAIL = 'googlemock@googlegroups.com'
-
-_COMMON_GMOCK_SYMBOLS = [
- # Matchers
- '_',
- 'A',
- 'AddressSatisfies',
- 'AllOf',
- 'An',
- 'AnyOf',
- 'ContainerEq',
- 'Contains',
- 'ContainsRegex',
- 'DoubleEq',
- 'ElementsAre',
- 'ElementsAreArray',
- 'EndsWith',
- 'Eq',
- 'Field',
- 'FloatEq',
- 'Ge',
- 'Gt',
- 'HasSubstr',
- 'IsInitializedProto',
- 'Le',
- 'Lt',
- 'MatcherCast',
- 'Matches',
- 'MatchesRegex',
- 'NanSensitiveDoubleEq',
- 'NanSensitiveFloatEq',
- 'Ne',
- 'Not',
- 'NotNull',
- 'Pointee',
- 'Property',
- 'Ref',
- 'ResultOf',
- 'SafeMatcherCast',
- 'StartsWith',
- 'StrCaseEq',
- 'StrCaseNe',
- 'StrEq',
- 'StrNe',
- 'Truly',
- 'TypedEq',
- 'Value',
-
- # Actions
- 'Assign',
- 'ByRef',
- 'DeleteArg',
- 'DoAll',
- 'DoDefault',
- 'IgnoreResult',
- 'Invoke',
- 'InvokeArgument',
- 'InvokeWithoutArgs',
- 'Return',
- 'ReturnNew',
- 'ReturnNull',
- 'ReturnRef',
- 'SaveArg',
- 'SetArgReferee',
- 'SetArgPointee',
- 'SetArgumentPointee',
- 'SetArrayArgument',
- 'SetErrnoAndReturn',
- 'Throw',
- 'WithArg',
- 'WithArgs',
- 'WithoutArgs',
-
- # Cardinalities
- 'AnyNumber',
- 'AtLeast',
- 'AtMost',
- 'Between',
- 'Exactly',
-
- # Sequences
- 'InSequence',
- 'Sequence',
-
- # Misc
- 'DefaultValue',
- 'Mock',
- ]
-
-# Regex for matching source file path and line number in the compiler's errors.
-_GCC_FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):(\d+:)?\s+'
-_CLANG_FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):(?P<column>\d+):\s+'
-_CLANG_NON_GMOCK_FILE_LINE_RE = (
- r'(?P<file>.*[/\\^](?!gmock-)[^/\\]+):(?P<line>\d+):(?P<column>\d+):\s+')
-
-
-def _FindAllMatches(regex, s):
- """Generates all matches of regex in string s."""
-
- r = re.compile(regex)
- return r.finditer(s)
-
-
-def _GenericDiagnoser(short_name, long_name, diagnoses, msg):
- """Diagnoses the given disease by pattern matching.
-
- Can provide different diagnoses for different patterns.
-
- Args:
- short_name: Short name of the disease.
- long_name: Long name of the disease.
- diagnoses: A list of pairs (regex, pattern for formatting the diagnosis
- for matching regex).
- msg: Compiler's error messages.
- Yields:
- Tuples of the form
- (short name of disease, long name of disease, diagnosis).
- """
- for regex, diagnosis in diagnoses:
- if re.search(regex, msg):
- diagnosis = '%(file)s:%(line)s:' + diagnosis
- for m in _FindAllMatches(regex, msg):
- yield (short_name, long_name, diagnosis % m.groupdict())
-
-
-def _NeedToReturnReferenceDiagnoser(msg):
- """Diagnoses the NRR disease, given the error messages by the compiler."""
-
- gcc_regex = (r'In member function \'testing::internal::ReturnAction<R>.*\n'
- + _GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*gmock-actions\.h.*error: creating array with negative size')
- clang_regex = (r'error:.*array.*negative.*\r?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE +
- r'note: in instantiation of function template specialization '
- r'\'testing::internal::ReturnAction<(?P<type>.*)>'
- r'::operator Action<.*>\' requested here')
- clang11_re = (r'use_ReturnRef_instead_of_Return_to_return_a_reference.*'
- r'(.*\n)*?' + _CLANG_NON_GMOCK_FILE_LINE_RE)
-
- diagnosis = """
-You are using a Return() action in a function that returns a reference to
-%(type)s. Please use ReturnRef() instead."""
- return _GenericDiagnoser('NRR', 'Need to Return Reference',
- [(clang_regex, diagnosis),
- (clang11_re, diagnosis % {'type': 'a type'}),
- (gcc_regex, diagnosis % {'type': 'a type'})],
- msg)
-
-
-def _NeedToReturnSomethingDiagnoser(msg):
- """Diagnoses the NRS disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'(instantiated from here\n.'
- r'*gmock.*actions\.h.*error: void value not ignored)'
- r'|(error: control reaches end of non-void function)')
- clang_regex1 = (_CLANG_FILE_LINE_RE +
- r'error: cannot initialize return object '
- r'of type \'Result\' \(aka \'(?P<return_type>.*)\'\) '
- r'with an rvalue of type \'void\'')
- clang_regex2 = (_CLANG_FILE_LINE_RE +
- r'error: cannot initialize return object '
- r'of type \'(?P<return_type>.*)\' '
- r'with an rvalue of type \'void\'')
- diagnosis = """
-You are using an action that returns void, but it needs to return
-%(return_type)s. Please tell it *what* to return. Perhaps you can use
-the pattern DoAll(some_action, Return(some_value))?"""
- return _GenericDiagnoser(
- 'NRS',
- 'Need to Return Something',
- [(gcc_regex, diagnosis % {'return_type': '*something*'}),
- (clang_regex1, diagnosis),
- (clang_regex2, diagnosis)],
- msg)
-
-
-def _NeedToReturnNothingDiagnoser(msg):
- """Diagnoses the NRN disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*gmock-actions\.h.*error: instantiation of '
- r'\'testing::internal::ReturnAction<R>::Impl<F>::value_\' '
- r'as type \'void\'')
- clang_regex1 = (r'error: field has incomplete type '
- r'\'Result\' \(aka \'void\'\)(\r)?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE + r'note: in instantiation '
- r'of function template specialization '
- r'\'testing::internal::ReturnAction<(?P<return_type>.*)>'
- r'::operator Action<void \(.*\)>\' requested here')
- clang_regex2 = (r'error: field has incomplete type '
- r'\'Result\' \(aka \'void\'\)(\r)?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE + r'note: in instantiation '
- r'of function template specialization '
- r'\'testing::internal::DoBothAction<.*>'
- r'::operator Action<(?P<return_type>.*) \(.*\)>\' '
- r'requested here')
- diagnosis = """
-You are using an action that returns %(return_type)s, but it needs to return
-void. Please use a void-returning action instead.
-
-All actions but the last in DoAll(...) must return void. Perhaps you need
-to re-arrange the order of actions in a DoAll(), if you are using one?"""
- return _GenericDiagnoser(
- 'NRN',
- 'Need to Return Nothing',
- [(gcc_regex, diagnosis % {'return_type': '*something*'}),
- (clang_regex1, diagnosis),
- (clang_regex2, diagnosis)],
- msg)
-
-
-def _IncompleteByReferenceArgumentDiagnoser(msg):
- """Diagnoses the IBRA disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*gtest-printers\.h.*error: invalid application of '
- r'\'sizeof\' to incomplete type \'(?P<type>.*)\'')
-
- clang_regex = (r'.*gtest-printers\.h.*error: invalid application of '
- r'\'sizeof\' to an incomplete type '
- r'\'(?P<type>.*)( const)?\'\r?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE +
- r'note: in instantiation of member function '
- r'\'testing::internal2::TypeWithoutFormatter<.*>::'
- r'PrintValue\' requested here')
- diagnosis = """
-In order to mock this function, Google Mock needs to see the definition
-of type "%(type)s" - declaration alone is not enough. Either #include
-the header that defines it, or change the argument to be passed
-by pointer."""
-
- return _GenericDiagnoser('IBRA', 'Incomplete By-Reference Argument Type',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _OverloadedFunctionMatcherDiagnoser(msg):
- """Diagnoses the OFM disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: no matching function for '
- r'call to \'Truly\(<unresolved overloaded function type>\)')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: no matching function for '
- r'call to \'Truly')
- diagnosis = """
-The argument you gave to Truly() is an overloaded function. Please tell
-your compiler which overloaded version you want to use.
-
-For example, if you want to use the version whose signature is
- bool Foo(int n);
-you should write
- Truly(static_cast<bool (*)(int n)>(Foo))"""
- return _GenericDiagnoser('OFM', 'Overloaded Function Matcher',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _OverloadedFunctionActionDiagnoser(msg):
- """Diagnoses the OFA disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: no matching function for call to '
- r'\'Invoke\(<unresolved overloaded function type>')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: no matching '
- r'function for call to \'Invoke\'\r?\n'
- r'(.*\n)*?'
- r'.*\bgmock-generated-actions\.h:\d+:\d+:\s+'
- r'note: candidate template ignored:\s+'
- r'couldn\'t infer template argument \'FunctionImpl\'')
- diagnosis = """
-Function you are passing to Invoke is overloaded. Please tell your compiler
-which overloaded version you want to use.
-
-For example, if you want to use the version whose signature is
- bool MyFunction(int n, double x);
-you should write something like
- Invoke(static_cast<bool (*)(int n, double x)>(MyFunction))"""
- return _GenericDiagnoser('OFA', 'Overloaded Function Action',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _OverloadedMethodActionDiagnoser(msg):
- """Diagnoses the OMA disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: no matching function for '
- r'call to \'Invoke\(.+, <unresolved overloaded function '
- r'type>\)')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: no matching function '
- r'for call to \'Invoke\'\r?\n'
- r'(.*\n)*?'
- r'.*\bgmock-generated-actions\.h:\d+:\d+: '
- r'note: candidate function template not viable: '
- r'requires .*, but 2 (arguments )?were provided')
- diagnosis = """
-The second argument you gave to Invoke() is an overloaded method. Please
-tell your compiler which overloaded version you want to use.
-
-For example, if you want to use the version whose signature is
- class Foo {
- ...
- bool Bar(int n, double x);
- };
-you should write something like
- Invoke(foo, static_cast<bool (Foo::*)(int n, double x)>(&Foo::Bar))"""
- return _GenericDiagnoser('OMA', 'Overloaded Method Action',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _MockObjectPointerDiagnoser(msg):
- """Diagnoses the MOP disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: request for member '
- r'\'gmock_(?P<method>.+)\' in \'(?P<mock_object>.+)\', '
- r'which is of non-class type \'(.*::)*(?P<class_name>.+)\*\'')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: member reference type '
- r'\'(?P<class_name>.*?) *\' is a pointer; '
- r'(did you mean|maybe you meant) to use \'->\'\?')
- diagnosis = """
-The first argument to ON_CALL() and EXPECT_CALL() must be a mock *object*,
-not a *pointer* to it. Please write '*(%(mock_object)s)' instead of
-'%(mock_object)s' as your first argument.
-
-For example, given the mock class:
-
- class %(class_name)s : public ... {
- ...
- MOCK_METHOD0(%(method)s, ...);
- };
-
-and the following mock instance:
-
- %(class_name)s* mock_ptr = ...
-
-you should use the EXPECT_CALL like this:
-
- EXPECT_CALL(*mock_ptr, %(method)s(...));"""
-
- return _GenericDiagnoser(
- 'MOP',
- 'Mock Object Pointer',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis % {'mock_object': 'mock_object',
- 'method': 'method',
- 'class_name': '%(class_name)s'})],
- msg)
-
-
-def _NeedToUseSymbolDiagnoser(msg):
- """Diagnoses the NUS disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: \'(?P<symbol>.+)\' '
- r'(was not declared in this scope|has not been declared)')
- clang_regex = (_CLANG_FILE_LINE_RE +
- r'error: (use of undeclared identifier|unknown type name|'
- r'no template named) \'(?P<symbol>[^\']+)\'')
- diagnosis = """
-'%(symbol)s' is defined by Google Mock in the testing namespace.
-Did you forget to write
- using testing::%(symbol)s;
-?"""
- for m in (list(_FindAllMatches(gcc_regex, msg)) +
- list(_FindAllMatches(clang_regex, msg))):
- symbol = m.groupdict()['symbol']
- if symbol in _COMMON_GMOCK_SYMBOLS:
- yield ('NUS', 'Need to Use Symbol', diagnosis % m.groupdict())
-
-
-def _NeedToUseReturnNullDiagnoser(msg):
- """Diagnoses the NRNULL disease, given the error messages by the compiler."""
-
- gcc_regex = ('instantiated from \'testing::internal::ReturnAction<R>'
- '::operator testing::Action<Func>\(\) const.*\n' +
- _GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*error: no matching function for call to \'ImplicitCast_\('
- r'(:?long )?int&\)')
- clang_regex = (r'\bgmock-actions.h:.* error: no matching function for '
- r'call to \'ImplicitCast_\'\r?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE + r'note: in instantiation '
- r'of function template specialization '
- r'\'testing::internal::ReturnAction<(int|long)>::operator '
- r'Action<(?P<type>.*)\(\)>\' requested here')
- diagnosis = """
-You are probably calling Return(NULL) and the compiler isn't sure how to turn
-NULL into %(type)s. Use ReturnNull() instead.
-Note: the line number may be off; please fix all instances of Return(NULL)."""
- return _GenericDiagnoser(
- 'NRNULL', 'Need to use ReturnNull',
- [(clang_regex, diagnosis),
- (gcc_regex, diagnosis % {'type': 'the right type'})],
- msg)
-
-
-def _TypeInTemplatedBaseDiagnoser(msg):
- """Diagnoses the TTB disease, given the error messages by the compiler."""
-
- # This version works when the type is used as the mock function's return
- # type.
- gcc_4_3_1_regex_type_in_retval = (
- r'In member function \'int .*\n' + _GCC_FILE_LINE_RE +
- r'error: a function call cannot appear in a constant-expression')
- gcc_4_4_0_regex_type_in_retval = (
- r'error: a function call cannot appear in a constant-expression'
- + _GCC_FILE_LINE_RE + r'error: template argument 1 is invalid\n')
- # This version works when the type is used as the mock function's sole
- # parameter type.
- gcc_regex_type_of_sole_param = (
- _GCC_FILE_LINE_RE +
- r'error: \'(?P<type>.+)\' was not declared in this scope\n'
- r'.*error: template argument 1 is invalid\n')
- # This version works when the type is used as a parameter of a mock
- # function that has multiple parameters.
- gcc_regex_type_of_a_param = (
- r'error: expected `;\' before \'::\' token\n'
- + _GCC_FILE_LINE_RE +
- r'error: \'(?P<type>.+)\' was not declared in this scope\n'
- r'.*error: template argument 1 is invalid\n'
- r'.*error: \'.+\' was not declared in this scope')
- clang_regex_type_of_retval_or_sole_param = (
- _CLANG_FILE_LINE_RE +
- r'error: use of undeclared identifier \'(?P<type>.*)\'\n'
- r'(.*\n)*?'
- r'(?P=file):(?P=line):\d+: error: '
- r'non-friend class member \'Result\' cannot have a qualified name'
- )
- clang_regex_type_of_a_param = (
- _CLANG_FILE_LINE_RE +
- r'error: C\+\+ requires a type specifier for all declarations\n'
- r'(.*\n)*?'
- r'(?P=file):(?P=line):(?P=column): error: '
- r'C\+\+ requires a type specifier for all declarations'
- )
- clang_regex_unknown_type = (
- _CLANG_FILE_LINE_RE +
- r'error: unknown type name \'(?P<type>[^\']+)\''
- )
-
- diagnosis = """
-In a mock class template, types or typedefs defined in the base class
-template are *not* automatically visible. This is how C++ works. Before
-you can use a type or typedef named %(type)s defined in base class Base<T>, you
-need to make it visible. One way to do it is:
-
- typedef typename Base<T>::%(type)s %(type)s;"""
-
- for diag in _GenericDiagnoser(
- 'TTB', 'Type in Template Base',
- [(gcc_4_3_1_regex_type_in_retval, diagnosis % {'type': 'Foo'}),
- (gcc_4_4_0_regex_type_in_retval, diagnosis % {'type': 'Foo'}),
- (gcc_regex_type_of_sole_param, diagnosis),
- (gcc_regex_type_of_a_param, diagnosis),
- (clang_regex_type_of_retval_or_sole_param, diagnosis),
- (clang_regex_type_of_a_param, diagnosis % {'type': 'Foo'})],
- msg):
- yield diag
- # Avoid overlap with the NUS pattern.
- for m in _FindAllMatches(clang_regex_unknown_type, msg):
- type_ = m.groupdict()['type']
- if type_ not in _COMMON_GMOCK_SYMBOLS:
- yield ('TTB', 'Type in Template Base', diagnosis % m.groupdict())
-
-
-def _WrongMockMethodMacroDiagnoser(msg):
- """Diagnoses the WMM disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE +
- r'.*this_method_does_not_take_(?P<wrong_args>\d+)_argument.*\n'
- r'.*\n'
- r'.*candidates are.*FunctionMocker<[^>]+A(?P<args>\d+)\)>')
- clang_regex = (_CLANG_NON_GMOCK_FILE_LINE_RE +
- r'error:.*array.*negative.*r?\n'
- r'(.*\n)*?'
- r'(?P=file):(?P=line):(?P=column): error: too few arguments '
- r'to function call, expected (?P<args>\d+), '
- r'have (?P<wrong_args>\d+)')
- clang11_re = (_CLANG_NON_GMOCK_FILE_LINE_RE +
- r'.*this_method_does_not_take_'
- r'(?P<wrong_args>\d+)_argument.*')
- diagnosis = """
-You are using MOCK_METHOD%(wrong_args)s to define a mock method that has
-%(args)s arguments. Use MOCK_METHOD%(args)s (or MOCK_CONST_METHOD%(args)s,
-MOCK_METHOD%(args)s_T, MOCK_CONST_METHOD%(args)s_T as appropriate) instead."""
- return _GenericDiagnoser('WMM', 'Wrong MOCK_METHODn Macro',
- [(gcc_regex, diagnosis),
- (clang11_re, diagnosis % {'wrong_args': 'm',
- 'args': 'n'}),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _WrongParenPositionDiagnoser(msg):
- """Diagnoses the WPP disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE +
- r'error:.*testing::internal::MockSpec<.* has no member named \''
- r'(?P<method>\w+)\'')
- clang_regex = (_CLANG_NON_GMOCK_FILE_LINE_RE +
- r'error: no member named \'(?P<method>\w+)\' in '
- r'\'testing::internal::MockSpec<.*>\'')
- diagnosis = """
-The closing parenthesis of ON_CALL or EXPECT_CALL should be *before*
-".%(method)s". For example, you should write:
- EXPECT_CALL(my_mock, Foo(_)).%(method)s(...);
-instead of:
- EXPECT_CALL(my_mock, Foo(_).%(method)s(...));"""
- return _GenericDiagnoser('WPP', 'Wrong Parenthesis Position',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-_DIAGNOSERS = [
- _IncompleteByReferenceArgumentDiagnoser,
- _MockObjectPointerDiagnoser,
- _NeedToReturnNothingDiagnoser,
- _NeedToReturnReferenceDiagnoser,
- _NeedToReturnSomethingDiagnoser,
- _NeedToUseReturnNullDiagnoser,
- _NeedToUseSymbolDiagnoser,
- _OverloadedFunctionActionDiagnoser,
- _OverloadedFunctionMatcherDiagnoser,
- _OverloadedMethodActionDiagnoser,
- _TypeInTemplatedBaseDiagnoser,
- _WrongMockMethodMacroDiagnoser,
- _WrongParenPositionDiagnoser,
- ]
-
-
-def Diagnose(msg):
- """Generates all possible diagnoses given the compiler error message."""
-
- msg = re.sub(r'\x1b\[[^m]*m', '', msg) # Strips all color formatting.
- # Assuming the string is using the UTF-8 encoding, replaces the left and
- # the right single quote characters with apostrophes.
- msg = re.sub(r'(\xe2\x80\x98|\xe2\x80\x99)', "'", msg)
-
- diagnoses = []
- for diagnoser in _DIAGNOSERS:
- for diag in diagnoser(msg):
- diagnosis = '[%s - %s]\n%s' % diag
- if not diagnosis in diagnoses:
- diagnoses.append(diagnosis)
- return diagnoses
-
-
-def main():
- print ('Google Mock Doctor v%s - '
- 'diagnoses problems in code using Google Mock.' % _VERSION)
-
- if sys.stdin.isatty():
- print ('Please copy and paste the compiler errors here. Press c-D when '
- 'you are done:')
- else:
- print ('Waiting for compiler errors on stdin . . .')
-
- msg = sys.stdin.read().strip()
- diagnoses = Diagnose(msg)
- count = len(diagnoses)
- if not count:
- print ("""
-Your compiler complained:
-8<------------------------------------------------------------
-%s
------------------------------------------------------------->8
-
-Uh-oh, I'm not smart enough to figure out what the problem is. :-(
-However...
-If you send your source code and the compiler's error messages to
-%s, you can be helped and I can get smarter --
-win-win for us!""" % (msg, _EMAIL))
- else:
- print ('------------------------------------------------------------')
- print ('Your code appears to have the following',)
- if count > 1:
- print ('%s diseases:' % (count,))
- else:
- print ('disease:')
- i = 0
- for d in diagnoses:
- i += 1
- if count > 1:
- print ('\n#%s:' % (i,))
- print (d)
- print ("""
-How did I do? If you think I'm wrong or unhelpful, please send your
-source code and the compiler's error messages to %s.
-Then you can be helped and I can get smarter -- I promise I won't be upset!""" %
- _EMAIL)
-
-
-if __name__ == '__main__':
- main()
diff --git a/googlemock/scripts/pump.py b/googlemock/scripts/pump.py
new file mode 100755
index 00000000..66e32170
--- /dev/null
+++ b/googlemock/scripts/pump.py
@@ -0,0 +1,855 @@
+#!/usr/bin/env python2.7
+#
+# Copyright 2008, 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.
+
+"""pump v0.2.0 - Pretty Useful for Meta Programming.
+
+A tool for preprocessor meta programming. Useful for generating
+repetitive boilerplate code. Especially useful for writing C++
+classes, functions, macros, and templates that need to work with
+various number of arguments.
+
+USAGE:
+ pump.py SOURCE_FILE
+
+EXAMPLES:
+ pump.py foo.cc.pump
+ Converts foo.cc.pump to foo.cc.
+
+GRAMMAR:
+ CODE ::= ATOMIC_CODE*
+ ATOMIC_CODE ::= $var ID = EXPRESSION
+ | $var ID = [[ CODE ]]
+ | $range ID EXPRESSION..EXPRESSION
+ | $for ID SEPARATOR [[ CODE ]]
+ | $($)
+ | $ID
+ | $(EXPRESSION)
+ | $if EXPRESSION [[ CODE ]] ELSE_BRANCH
+ | [[ CODE ]]
+ | RAW_CODE
+ SEPARATOR ::= RAW_CODE | EMPTY
+ ELSE_BRANCH ::= $else [[ CODE ]]
+ | $elif EXPRESSION [[ CODE ]] ELSE_BRANCH
+ | EMPTY
+ EXPRESSION has Python syntax.
+"""
+
+from __future__ import print_function
+
+import os
+import re
+import sys
+
+
+TOKEN_TABLE = [
+ (re.compile(r'\$var\s+'), '$var'),
+ (re.compile(r'\$elif\s+'), '$elif'),
+ (re.compile(r'\$else\s+'), '$else'),
+ (re.compile(r'\$for\s+'), '$for'),
+ (re.compile(r'\$if\s+'), '$if'),
+ (re.compile(r'\$range\s+'), '$range'),
+ (re.compile(r'\$[_A-Za-z]\w*'), '$id'),
+ (re.compile(r'\$\(\$\)'), '$($)'),
+ (re.compile(r'\$'), '$'),
+ (re.compile(r'\[\[\n?'), '[['),
+ (re.compile(r'\]\]\n?'), ']]'),
+ ]
+
+
+class Cursor:
+ """Represents a position (line and column) in a text file."""
+
+ def __init__(self, line=-1, column=-1):
+ self.line = line
+ self.column = column
+
+ def __eq__(self, rhs):
+ return self.line == rhs.line and self.column == rhs.column
+
+ def __ne__(self, rhs):
+ return not self == rhs
+
+ def __lt__(self, rhs):
+ return self.line < rhs.line or (
+ self.line == rhs.line and self.column < rhs.column)
+
+ def __le__(self, rhs):
+ return self < rhs or self == rhs
+
+ def __gt__(self, rhs):
+ return rhs < self
+
+ def __ge__(self, rhs):
+ return rhs <= self
+
+ def __str__(self):
+ if self == Eof():
+ return 'EOF'
+ else:
+ return '%s(%s)' % (self.line + 1, self.column)
+
+ def __add__(self, offset):
+ return Cursor(self.line, self.column + offset)
+
+ def __sub__(self, offset):
+ return Cursor(self.line, self.column - offset)
+
+ def Clone(self):
+ """Returns a copy of self."""
+
+ return Cursor(self.line, self.column)
+
+
+# Special cursor to indicate the end-of-file.
+def Eof():
+ """Returns the special cursor to denote the end-of-file."""
+ return Cursor(-1, -1)
+
+
+class Token:
+ """Represents a token in a Pump source file."""
+
+ def __init__(self, start=None, end=None, value=None, token_type=None):
+ if start is None:
+ self.start = Eof()
+ else:
+ self.start = start
+ if end is None:
+ self.end = Eof()
+ else:
+ self.end = end
+ self.value = value
+ self.token_type = token_type
+
+ def __str__(self):
+ return 'Token @%s: \'%s\' type=%s' % (
+ self.start, self.value, self.token_type)
+
+ def Clone(self):
+ """Returns a copy of self."""
+
+ return Token(self.start.Clone(), self.end.Clone(), self.value,
+ self.token_type)
+
+
+def StartsWith(lines, pos, string):
+ """Returns True iff the given position in lines starts with 'string'."""
+
+ return lines[pos.line][pos.column:].startswith(string)
+
+
+def FindFirstInLine(line, token_table):
+ best_match_start = -1
+ for (regex, token_type) in token_table:
+ m = regex.search(line)
+ if m:
+ # We found regex in lines
+ if best_match_start < 0 or m.start() < best_match_start:
+ best_match_start = m.start()
+ best_match_length = m.end() - m.start()
+ best_match_token_type = token_type
+
+ if best_match_start < 0:
+ return None
+
+ return (best_match_start, best_match_length, best_match_token_type)
+
+
+def FindFirst(lines, token_table, cursor):
+ """Finds the first occurrence of any string in strings in lines."""
+
+ start = cursor.Clone()
+ cur_line_number = cursor.line
+ for line in lines[start.line:]:
+ if cur_line_number == start.line:
+ line = line[start.column:]
+ m = FindFirstInLine(line, token_table)
+ if m:
+ # We found a regex in line.
+ (start_column, length, token_type) = m
+ if cur_line_number == start.line:
+ start_column += start.column
+ found_start = Cursor(cur_line_number, start_column)
+ found_end = found_start + length
+ return MakeToken(lines, found_start, found_end, token_type)
+ cur_line_number += 1
+ # We failed to find str in lines
+ return None
+
+
+def SubString(lines, start, end):
+ """Returns a substring in lines."""
+
+ if end == Eof():
+ end = Cursor(len(lines) - 1, len(lines[-1]))
+
+ if start >= end:
+ return ''
+
+ if start.line == end.line:
+ return lines[start.line][start.column:end.column]
+
+ result_lines = ([lines[start.line][start.column:]] +
+ lines[start.line + 1:end.line] +
+ [lines[end.line][:end.column]])
+ return ''.join(result_lines)
+
+
+def StripMetaComments(str):
+ """Strip meta comments from each line in the given string."""
+
+ # First, completely remove lines containing nothing but a meta
+ # comment, including the trailing \n.
+ str = re.sub(r'^\s*\$\$.*\n', '', str)
+
+ # Then, remove meta comments from contentful lines.
+ return re.sub(r'\s*\$\$.*', '', str)
+
+
+def MakeToken(lines, start, end, token_type):
+ """Creates a new instance of Token."""
+
+ return Token(start, end, SubString(lines, start, end), token_type)
+
+
+def ParseToken(lines, pos, regex, token_type):
+ line = lines[pos.line][pos.column:]
+ m = regex.search(line)
+ if m and not m.start():
+ return MakeToken(lines, pos, pos + m.end(), token_type)
+ else:
+ print('ERROR: %s expected at %s.' % (token_type, pos))
+ sys.exit(1)
+
+
+ID_REGEX = re.compile(r'[_A-Za-z]\w*')
+EQ_REGEX = re.compile(r'=')
+REST_OF_LINE_REGEX = re.compile(r'.*?(?=$|\$\$)')
+OPTIONAL_WHITE_SPACES_REGEX = re.compile(r'\s*')
+WHITE_SPACE_REGEX = re.compile(r'\s')
+DOT_DOT_REGEX = re.compile(r'\.\.')
+
+
+def Skip(lines, pos, regex):
+ line = lines[pos.line][pos.column:]
+ m = re.search(regex, line)
+ if m and not m.start():
+ return pos + m.end()
+ else:
+ return pos
+
+
+def SkipUntil(lines, pos, regex, token_type):
+ line = lines[pos.line][pos.column:]
+ m = re.search(regex, line)
+ if m:
+ return pos + m.start()
+ else:
+ print ('ERROR: %s expected on line %s after column %s.' %
+ (token_type, pos.line + 1, pos.column))
+ sys.exit(1)
+
+
+def ParseExpTokenInParens(lines, pos):
+ def ParseInParens(pos):
+ pos = Skip(lines, pos, OPTIONAL_WHITE_SPACES_REGEX)
+ pos = Skip(lines, pos, r'\(')
+ pos = Parse(pos)
+ pos = Skip(lines, pos, r'\)')
+ return pos
+
+ def Parse(pos):
+ pos = SkipUntil(lines, pos, r'\(|\)', ')')
+ if SubString(lines, pos, pos + 1) == '(':
+ pos = Parse(pos + 1)
+ pos = Skip(lines, pos, r'\)')
+ return Parse(pos)
+ else:
+ return pos
+
+ start = pos.Clone()
+ pos = ParseInParens(pos)
+ return MakeToken(lines, start, pos, 'exp')
+
+
+def RStripNewLineFromToken(token):
+ if token.value.endswith('\n'):
+ return Token(token.start, token.end, token.value[:-1], token.token_type)
+ else:
+ return token
+
+
+def TokenizeLines(lines, pos):
+ while True:
+ found = FindFirst(lines, TOKEN_TABLE, pos)
+ if not found:
+ yield MakeToken(lines, pos, Eof(), 'code')
+ return
+
+ if found.start == pos:
+ prev_token = None
+ prev_token_rstripped = None
+ else:
+ prev_token = MakeToken(lines, pos, found.start, 'code')
+ prev_token_rstripped = RStripNewLineFromToken(prev_token)
+
+ if found.token_type == '$var':
+ if prev_token_rstripped:
+ yield prev_token_rstripped
+ yield found
+ id_token = ParseToken(lines, found.end, ID_REGEX, 'id')
+ yield id_token
+ pos = Skip(lines, id_token.end, OPTIONAL_WHITE_SPACES_REGEX)
+
+ eq_token = ParseToken(lines, pos, EQ_REGEX, '=')
+ yield eq_token
+ pos = Skip(lines, eq_token.end, r'\s*')
+
+ if SubString(lines, pos, pos + 2) != '[[':
+ exp_token = ParseToken(lines, pos, REST_OF_LINE_REGEX, 'exp')
+ yield exp_token
+ pos = Cursor(exp_token.end.line + 1, 0)
+ elif found.token_type == '$for':
+ if prev_token_rstripped:
+ yield prev_token_rstripped
+ yield found
+ id_token = ParseToken(lines, found.end, ID_REGEX, 'id')
+ yield id_token
+ pos = Skip(lines, id_token.end, WHITE_SPACE_REGEX)
+ elif found.token_type == '$range':
+ if prev_token_rstripped:
+ yield prev_token_rstripped
+ yield found
+ id_token = ParseToken(lines, found.end, ID_REGEX, 'id')
+ yield id_token
+ pos = Skip(lines, id_token.end, OPTIONAL_WHITE_SPACES_REGEX)
+
+ dots_pos = SkipUntil(lines, pos, DOT_DOT_REGEX, '..')
+ yield MakeToken(lines, pos, dots_pos, 'exp')
+ yield MakeToken(lines, dots_pos, dots_pos + 2, '..')
+ pos = dots_pos + 2
+ new_pos = Cursor(pos.line + 1, 0)
+ yield MakeToken(lines, pos, new_pos, 'exp')
+ pos = new_pos
+ elif found.token_type == '$':
+ if prev_token:
+ yield prev_token
+ yield found
+ exp_token = ParseExpTokenInParens(lines, found.end)
+ yield exp_token
+ pos = exp_token.end
+ elif (found.token_type == ']]' or found.token_type == '$if' or
+ found.token_type == '$elif' or found.token_type == '$else'):
+ if prev_token_rstripped:
+ yield prev_token_rstripped
+ yield found
+ pos = found.end
+ else:
+ if prev_token:
+ yield prev_token
+ yield found
+ pos = found.end
+
+
+def Tokenize(s):
+ """A generator that yields the tokens in the given string."""
+ if s != '':
+ lines = s.splitlines(True)
+ for token in TokenizeLines(lines, Cursor(0, 0)):
+ yield token
+
+
+class CodeNode:
+ def __init__(self, atomic_code_list=None):
+ self.atomic_code = atomic_code_list
+
+
+class VarNode:
+ def __init__(self, identifier=None, atomic_code=None):
+ self.identifier = identifier
+ self.atomic_code = atomic_code
+
+
+class RangeNode:
+ def __init__(self, identifier=None, exp1=None, exp2=None):
+ self.identifier = identifier
+ self.exp1 = exp1
+ self.exp2 = exp2
+
+
+class ForNode:
+ def __init__(self, identifier=None, sep=None, code=None):
+ self.identifier = identifier
+ self.sep = sep
+ self.code = code
+
+
+class ElseNode:
+ def __init__(self, else_branch=None):
+ self.else_branch = else_branch
+
+
+class IfNode:
+ def __init__(self, exp=None, then_branch=None, else_branch=None):
+ self.exp = exp
+ self.then_branch = then_branch
+ self.else_branch = else_branch
+
+
+class RawCodeNode:
+ def __init__(self, token=None):
+ self.raw_code = token
+
+
+class LiteralDollarNode:
+ def __init__(self, token):
+ self.token = token
+
+
+class ExpNode:
+ def __init__(self, token, python_exp):
+ self.token = token
+ self.python_exp = python_exp
+
+
+def PopFront(a_list):
+ head = a_list[0]
+ a_list[:1] = []
+ return head
+
+
+def PushFront(a_list, elem):
+ a_list[:0] = [elem]
+
+
+def PopToken(a_list, token_type=None):
+ token = PopFront(a_list)
+ if token_type is not None and token.token_type != token_type:
+ print('ERROR: %s expected at %s' % (token_type, token.start))
+ print('ERROR: %s found instead' % (token,))
+ sys.exit(1)
+
+ return token
+
+
+def PeekToken(a_list):
+ if not a_list:
+ return None
+
+ return a_list[0]
+
+
+def ParseExpNode(token):
+ python_exp = re.sub(r'([_A-Za-z]\w*)', r'self.GetValue("\1")', token.value)
+ return ExpNode(token, python_exp)
+
+
+def ParseElseNode(tokens):
+ def Pop(token_type=None):
+ return PopToken(tokens, token_type)
+
+ next = PeekToken(tokens)
+ if not next:
+ return None
+ if next.token_type == '$else':
+ Pop('$else')
+ Pop('[[')
+ code_node = ParseCodeNode(tokens)
+ Pop(']]')
+ return code_node
+ elif next.token_type == '$elif':
+ Pop('$elif')
+ exp = Pop('code')
+ Pop('[[')
+ code_node = ParseCodeNode(tokens)
+ Pop(']]')
+ inner_else_node = ParseElseNode(tokens)
+ return CodeNode([IfNode(ParseExpNode(exp), code_node, inner_else_node)])
+ elif not next.value.strip():
+ Pop('code')
+ return ParseElseNode(tokens)
+ else:
+ return None
+
+
+def ParseAtomicCodeNode(tokens):
+ def Pop(token_type=None):
+ return PopToken(tokens, token_type)
+
+ head = PopFront(tokens)
+ t = head.token_type
+ if t == 'code':
+ return RawCodeNode(head)
+ elif t == '$var':
+ id_token = Pop('id')
+ Pop('=')
+ next = PeekToken(tokens)
+ if next.token_type == 'exp':
+ exp_token = Pop()
+ return VarNode(id_token, ParseExpNode(exp_token))
+ Pop('[[')
+ code_node = ParseCodeNode(tokens)
+ Pop(']]')
+ return VarNode(id_token, code_node)
+ elif t == '$for':
+ id_token = Pop('id')
+ next_token = PeekToken(tokens)
+ if next_token.token_type == 'code':
+ sep_token = next_token
+ Pop('code')
+ else:
+ sep_token = None
+ Pop('[[')
+ code_node = ParseCodeNode(tokens)
+ Pop(']]')
+ return ForNode(id_token, sep_token, code_node)
+ elif t == '$if':
+ exp_token = Pop('code')
+ Pop('[[')
+ code_node = ParseCodeNode(tokens)
+ Pop(']]')
+ else_node = ParseElseNode(tokens)
+ return IfNode(ParseExpNode(exp_token), code_node, else_node)
+ elif t == '$range':
+ id_token = Pop('id')
+ exp1_token = Pop('exp')
+ Pop('..')
+ exp2_token = Pop('exp')
+ return RangeNode(id_token, ParseExpNode(exp1_token),
+ ParseExpNode(exp2_token))
+ elif t == '$id':
+ return ParseExpNode(Token(head.start + 1, head.end, head.value[1:], 'id'))
+ elif t == '$($)':
+ return LiteralDollarNode(head)
+ elif t == '$':
+ exp_token = Pop('exp')
+ return ParseExpNode(exp_token)
+ elif t == '[[':
+ code_node = ParseCodeNode(tokens)
+ Pop(']]')
+ return code_node
+ else:
+ PushFront(tokens, head)
+ return None
+
+
+def ParseCodeNode(tokens):
+ atomic_code_list = []
+ while True:
+ if not tokens:
+ break
+ atomic_code_node = ParseAtomicCodeNode(tokens)
+ if atomic_code_node:
+ atomic_code_list.append(atomic_code_node)
+ else:
+ break
+ return CodeNode(atomic_code_list)
+
+
+def ParseToAST(pump_src_text):
+ """Convert the given Pump source text into an AST."""
+ tokens = list(Tokenize(pump_src_text))
+ code_node = ParseCodeNode(tokens)
+ return code_node
+
+
+class Env:
+ def __init__(self):
+ self.variables = []
+ self.ranges = []
+
+ def Clone(self):
+ clone = Env()
+ clone.variables = self.variables[:]
+ clone.ranges = self.ranges[:]
+ return clone
+
+ def PushVariable(self, var, value):
+ # If value looks like an int, store it as an int.
+ try:
+ int_value = int(value)
+ if ('%s' % int_value) == value:
+ value = int_value
+ except Exception:
+ pass
+ self.variables[:0] = [(var, value)]
+
+ def PopVariable(self):
+ self.variables[:1] = []
+
+ def PushRange(self, var, lower, upper):
+ self.ranges[:0] = [(var, lower, upper)]
+
+ def PopRange(self):
+ self.ranges[:1] = []
+
+ def GetValue(self, identifier):
+ for (var, value) in self.variables:
+ if identifier == var:
+ return value
+
+ print('ERROR: meta variable %s is undefined.' % (identifier,))
+ sys.exit(1)
+
+ def EvalExp(self, exp):
+ try:
+ result = eval(exp.python_exp)
+ except Exception as e: # pylint: disable=broad-except
+ print('ERROR: caught exception %s: %s' % (e.__class__.__name__, e))
+ print('ERROR: failed to evaluate meta expression %s at %s' %
+ (exp.python_exp, exp.token.start))
+ sys.exit(1)
+ return result
+
+ def GetRange(self, identifier):
+ for (var, lower, upper) in self.ranges:
+ if identifier == var:
+ return (lower, upper)
+
+ print('ERROR: range %s is undefined.' % (identifier,))
+ sys.exit(1)
+
+
+class Output:
+ def __init__(self):
+ self.string = ''
+
+ def GetLastLine(self):
+ index = self.string.rfind('\n')
+ if index < 0:
+ return ''
+
+ return self.string[index + 1:]
+
+ def Append(self, s):
+ self.string += s
+
+
+def RunAtomicCode(env, node, output):
+ if isinstance(node, VarNode):
+ identifier = node.identifier.value.strip()
+ result = Output()
+ RunAtomicCode(env.Clone(), node.atomic_code, result)
+ value = result.string
+ env.PushVariable(identifier, value)
+ elif isinstance(node, RangeNode):
+ identifier = node.identifier.value.strip()
+ lower = int(env.EvalExp(node.exp1))
+ upper = int(env.EvalExp(node.exp2))
+ env.PushRange(identifier, lower, upper)
+ elif isinstance(node, ForNode):
+ identifier = node.identifier.value.strip()
+ if node.sep is None:
+ sep = ''
+ else:
+ sep = node.sep.value
+ (lower, upper) = env.GetRange(identifier)
+ for i in range(lower, upper + 1):
+ new_env = env.Clone()
+ new_env.PushVariable(identifier, i)
+ RunCode(new_env, node.code, output)
+ if i != upper:
+ output.Append(sep)
+ elif isinstance(node, RawCodeNode):
+ output.Append(node.raw_code.value)
+ elif isinstance(node, IfNode):
+ cond = env.EvalExp(node.exp)
+ if cond:
+ RunCode(env.Clone(), node.then_branch, output)
+ elif node.else_branch is not None:
+ RunCode(env.Clone(), node.else_branch, output)
+ elif isinstance(node, ExpNode):
+ value = env.EvalExp(node)
+ output.Append('%s' % (value,))
+ elif isinstance(node, LiteralDollarNode):
+ output.Append('$')
+ elif isinstance(node, CodeNode):
+ RunCode(env.Clone(), node, output)
+ else:
+ print('BAD')
+ print(node)
+ sys.exit(1)
+
+
+def RunCode(env, code_node, output):
+ for atomic_code in code_node.atomic_code:
+ RunAtomicCode(env, atomic_code, output)
+
+
+def IsSingleLineComment(cur_line):
+ return '//' in cur_line
+
+
+def IsInPreprocessorDirective(prev_lines, cur_line):
+ if cur_line.lstrip().startswith('#'):
+ return True
+ return prev_lines and prev_lines[-1].endswith('\\')
+
+
+def WrapComment(line, output):
+ loc = line.find('//')
+ before_comment = line[:loc].rstrip()
+ if before_comment == '':
+ indent = loc
+ else:
+ output.append(before_comment)
+ indent = len(before_comment) - len(before_comment.lstrip())
+ prefix = indent*' ' + '// '
+ max_len = 80 - len(prefix)
+ comment = line[loc + 2:].strip()
+ segs = [seg for seg in re.split(r'(\w+\W*)', comment) if seg != '']
+ cur_line = ''
+ for seg in segs:
+ if len((cur_line + seg).rstrip()) < max_len:
+ cur_line += seg
+ else:
+ if cur_line.strip() != '':
+ output.append(prefix + cur_line.rstrip())
+ cur_line = seg.lstrip()
+ if cur_line.strip() != '':
+ output.append(prefix + cur_line.strip())
+
+
+def WrapCode(line, line_concat, output):
+ indent = len(line) - len(line.lstrip())
+ prefix = indent*' ' # Prefix of the current line
+ max_len = 80 - indent - len(line_concat) # Maximum length of the current line
+ new_prefix = prefix + 4*' ' # Prefix of a continuation line
+ new_max_len = max_len - 4 # Maximum length of a continuation line
+ # Prefers to wrap a line after a ',' or ';'.
+ segs = [seg for seg in re.split(r'([^,;]+[,;]?)', line.strip()) if seg != '']
+ cur_line = '' # The current line without leading spaces.
+ for seg in segs:
+ # If the line is still too long, wrap at a space.
+ while cur_line == '' and len(seg.strip()) > max_len:
+ seg = seg.lstrip()
+ split_at = seg.rfind(' ', 0, max_len)
+ output.append(prefix + seg[:split_at].strip() + line_concat)
+ seg = seg[split_at + 1:]
+ prefix = new_prefix
+ max_len = new_max_len
+
+ if len((cur_line + seg).rstrip()) < max_len:
+ cur_line = (cur_line + seg).lstrip()
+ else:
+ output.append(prefix + cur_line.rstrip() + line_concat)
+ prefix = new_prefix
+ max_len = new_max_len
+ cur_line = seg.lstrip()
+ if cur_line.strip() != '':
+ output.append(prefix + cur_line.strip())
+
+
+def WrapPreprocessorDirective(line, output):
+ WrapCode(line, ' \\', output)
+
+
+def WrapPlainCode(line, output):
+ WrapCode(line, '', output)
+
+
+def IsMultiLineIWYUPragma(line):
+ return re.search(r'/\* IWYU pragma: ', line)
+
+
+def IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
+ return (re.match(r'^#(ifndef|define|endif\s*//)\s*[\w_]+\s*$', line) or
+ re.match(r'^#include\s', line) or
+ # Don't break IWYU pragmas, either; that causes iwyu.py problems.
+ re.search(r'// IWYU pragma: ', line))
+
+
+def WrapLongLine(line, output):
+ line = line.rstrip()
+ if len(line) <= 80:
+ output.append(line)
+ elif IsSingleLineComment(line):
+ if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
+ # The style guide made an exception to allow long header guard lines,
+ # includes and IWYU pragmas.
+ output.append(line)
+ else:
+ WrapComment(line, output)
+ elif IsInPreprocessorDirective(output, line):
+ if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
+ # The style guide made an exception to allow long header guard lines,
+ # includes and IWYU pragmas.
+ output.append(line)
+ else:
+ WrapPreprocessorDirective(line, output)
+ elif IsMultiLineIWYUPragma(line):
+ output.append(line)
+ else:
+ WrapPlainCode(line, output)
+
+
+def BeautifyCode(string):
+ lines = string.splitlines()
+ output = []
+ for line in lines:
+ WrapLongLine(line, output)
+ output2 = [line.rstrip() for line in output]
+ return '\n'.join(output2) + '\n'
+
+
+def ConvertFromPumpSource(src_text):
+ """Return the text generated from the given Pump source text."""
+ ast = ParseToAST(StripMetaComments(src_text))
+ output = Output()
+ RunCode(Env(), ast, output)
+ return BeautifyCode(output.string)
+
+
+def main(argv):
+ if len(argv) == 1:
+ print(__doc__)
+ sys.exit(1)
+
+ file_path = argv[-1]
+ output_str = ConvertFromPumpSource(file(file_path, 'r').read())
+ if file_path.endswith('.pump'):
+ output_file_path = file_path[:-5]
+ else:
+ output_file_path = '-'
+ if output_file_path == '-':
+ print(output_str,)
+ else:
+ 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('// DO NOT EDIT BY HAND!!!\n\n')
+ output_file.write(output_str)
+ output_file.close()
+
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/googlemock/scripts/upload.py b/googlemock/scripts/upload.py
index 95239dc2..129f53ef 100755
--- a/googlemock/scripts/upload.py
+++ b/googlemock/scripts/upload.py
@@ -1,18 +1,33 @@
#!/usr/bin/env python
#
-# Copyright 2007 Google Inc.
+# Copyright 2009, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * 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.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# 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.
"""Tool for uploading diffs from a version control system to the codereview app.
diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc
index 98611b93..18c500f6 100644
--- a/googlemock/src/gmock_main.cc
+++ b/googlemock/src/gmock_main.cc
@@ -32,7 +32,10 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#ifdef ARDUINO
+#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
+#if GTEST_OS_ESP8266
+extern "C" {
+#endif
void setup() {
// Since Google Mock depends on Google Test, InitGoogleMock() is
// also responsible for initializing Google Test. Therefore there's
@@ -40,6 +43,10 @@ void setup() {
testing::InitGoogleMock();
}
void loop() { RUN_ALL_TESTS(); }
+#if GTEST_OS_ESP8266
+}
+#endif
+
#else
// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index a1b6f113..ae4fa20e 100644
--- a/googlemock/test/gmock-actions_test.cc
+++ b/googlemock/test/gmock-actions_test.cc
@@ -74,6 +74,7 @@ using testing::Return;
using testing::ReturnNull;
using testing::ReturnRef;
using testing::ReturnRefOfCopy;
+using testing::ReturnRoundRobin;
using testing::SetArgPointee;
using testing::SetArgumentPointee;
using testing::Unused;
@@ -706,6 +707,31 @@ TEST(ReturnRefOfCopyTest, IsCovariant) {
EXPECT_NE(&derived, &a.Perform(std::make_tuple()));
}
+// Tests that ReturnRoundRobin(v) works with initializer lists
+TEST(ReturnRoundRobinTest, WorksForInitList) {
+ Action<int()> ret = ReturnRoundRobin({1, 2, 3});
+
+ EXPECT_EQ(1, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(2, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(3, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(1, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(2, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(3, ret.Perform(std::make_tuple()));
+}
+
+// Tests that ReturnRoundRobin(v) works with vectors
+TEST(ReturnRoundRobinTest, WorksForVector) {
+ std::vector<double> v = {4.4, 5.5, 6.6};
+ Action<double()> ret = ReturnRoundRobin(v);
+
+ EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
+}
+
// Tests that DoDefault() does the default action for the mock method.
class MockClass {
diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc
index 6c4b3000..f3f49a68 100644
--- a/googlemock/test/gmock-generated-matchers_test.cc
+++ b/googlemock/test/gmock-generated-matchers_test.cc
@@ -41,6 +41,8 @@
#include "gmock/gmock-generated-matchers.h"
+#include <array>
+#include <iterator>
#include <list>
#include <map>
#include <memory>
@@ -51,8 +53,8 @@
#include <vector>
#include "gmock/gmock.h"
-#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
+#include "gtest/gtest.h"
namespace {
@@ -195,7 +197,7 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
ElementsAre(GreaterThan(1), 0, GreaterThan(2));
const int a[] = { 10, 0, 100 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_EQ("whose element #0 matches, which is 9 more than 1,\n"
"and whose element #2 matches, which is 98 more than 2",
Explain(m, test_vector));
@@ -280,7 +282,7 @@ TEST(ElementsAreTest, MatchesThreeElementsMixedMatchers) {
TEST(ElementsAreTest, MatchesTenElementVector) {
const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector,
// The element list can contain values and/or matchers
@@ -317,13 +319,10 @@ TEST(ElementsAreTest, DoesNotMatchWrongOrder) {
}
TEST(ElementsAreTest, WorksForNestedContainer) {
- const char* strings[] = {
- "Hi",
- "world"
- };
+ constexpr std::array<const char*, 2> strings = {{"Hi", "world"}};
vector<list<char> > nested;
- for (size_t i = 0; i < GTEST_ARRAY_SIZE_(strings); i++) {
+ for (size_t i = 0; i < strings.size(); i++) {
nested.push_back(list<char>(strings[i], strings[i] + strlen(strings[i])));
}
@@ -335,7 +334,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) {
TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
int a[] = { 0, 1, 2 };
- vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> v(std::begin(a), std::end(a));
EXPECT_THAT(v, ElementsAre(Ref(v[0]), Ref(v[1]), Ref(v[2])));
EXPECT_THAT(v, Not(ElementsAre(Ref(v[0]), Ref(v[1]), Ref(a[2]))));
@@ -343,7 +342,7 @@ TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
TEST(ElementsAreTest, WorksWithContainerPointerUsingPointee) {
int a[] = { 0, 1, 2 };
- vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> v(std::begin(a), std::end(a));
EXPECT_THAT(&v, Pointee(ElementsAre(0, 1, _)));
EXPECT_THAT(&v, Not(Pointee(ElementsAre(0, _, 3))));
@@ -440,7 +439,7 @@ TEST(ElementsAreTest, MakesCopyOfArguments) {
TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[2] = 0;
@@ -448,20 +447,20 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
}
TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
- const char* a[] = { "one", "two", "three" };
+ std::array<const char*, 3> a = {{"one", "two", "three"}};
- vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- EXPECT_THAT(test_vector, ElementsAreArray(a, GTEST_ARRAY_SIZE_(a)));
+ vector<std::string> test_vector(std::begin(a), std::end(a));
+ EXPECT_THAT(test_vector, ElementsAreArray(a.data(), a.size()));
- const char** p = a;
+ const char** p = a.data();
test_vector[0] = "1";
- EXPECT_THAT(test_vector, Not(ElementsAreArray(p, GTEST_ARRAY_SIZE_(a))));
+ EXPECT_THAT(test_vector, Not(ElementsAreArray(p, a.size())));
}
TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
const char* a[] = { "one", "two", "three" };
- vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<std::string> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[0] = "1";
@@ -484,8 +483,8 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) {
TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<int> expected(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@@ -530,9 +529,9 @@ TEST(ElementsAreArrayTest,
TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
const int a[] = { 1, 2, 3 };
const Matcher<int> kMatchers[] = { Eq(1), Eq(2), Eq(3) };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<Matcher<int> > expected(
- kMatchers, kMatchers + GTEST_ARRAY_SIZE_(kMatchers));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<Matcher<int>> expected(std::begin(kMatchers),
+ std::end(kMatchers));
EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@@ -540,11 +539,11 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) {
const int a[] = { 1, 2, 3 };
- const vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
+ const vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<int> expected(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected.begin(), expected.end()));
// Pointers are iterators, too.
- EXPECT_THAT(test_vector, ElementsAreArray(a, a + GTEST_ARRAY_SIZE_(a)));
+ EXPECT_THAT(test_vector, ElementsAreArray(std::begin(a), std::end(a)));
// The empty range of NULL pointers should also be okay.
int* const null_int = nullptr;
EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int)));
@@ -564,8 +563,8 @@ TEST(ElementsAreArrayTest, WorksWithNativeArray) {
TEST(ElementsAreArrayTest, SourceLifeSpan) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- vector<int> expect(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ vector<int> expect(std::begin(a), std::end(a));
ElementsAreArrayMatcher<int> matcher_maker =
ElementsAreArray(expect.begin(), expect.end());
EXPECT_THAT(test_vector, matcher_maker);
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc
index 03735267..bc49cb62 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -41,10 +41,11 @@
#endif
#include "gmock/gmock-matchers.h"
-#include "gmock/gmock-more-matchers.h"
#include <string.h>
#include <time.h>
+
+#include <array>
#include <deque>
#include <forward_list>
#include <functional>
@@ -60,9 +61,11 @@
#include <type_traits>
#include <utility>
#include <vector>
+
+#include "gmock/gmock-more-matchers.h"
#include "gmock/gmock.h"
-#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
+#include "gtest/gtest.h"
namespace testing {
namespace gmock_matchers_test {
@@ -2054,6 +2057,114 @@ TEST(PairMatchBaseTest, WorksWithMoveOnly) {
EXPECT_TRUE(matcher.Matches(pointers));
}
+// Tests that IsNan() matches a NaN, with float.
+TEST(IsNan, FloatMatchesNan) {
+ float quiet_nan = std::numeric_limits<float>::quiet_NaN();
+ float other_nan = std::nanf("1");
+ float real_value = 1.0f;
+
+ Matcher<float> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<float&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const float&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with double.
+TEST(IsNan, DoubleMatchesNan) {
+ double quiet_nan = std::numeric_limits<double>::quiet_NaN();
+ double other_nan = std::nan("1");
+ double real_value = 1.0;
+
+ Matcher<double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with long double.
+TEST(IsNan, LongDoubleMatchesNan) {
+ long double quiet_nan = std::numeric_limits<long double>::quiet_NaN();
+ long double other_nan = std::nan("1");
+ long double real_value = 1.0;
+
+ Matcher<long double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<long double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const long double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() works with Not.
+TEST(IsNan, NotMatchesNan) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_FALSE(mf.Matches(std::numeric_limits<float>::quiet_NaN()));
+ EXPECT_FALSE(mf.Matches(std::nanf("1")));
+ EXPECT_TRUE(mf.Matches(1.0));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_FALSE(md.Matches(std::numeric_limits<double>::quiet_NaN()));
+ EXPECT_FALSE(md.Matches(std::nan("1")));
+ EXPECT_TRUE(md.Matches(1.0));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_FALSE(mld.Matches(std::numeric_limits<long double>::quiet_NaN()));
+ EXPECT_FALSE(mld.Matches(std::nanl("1")));
+ EXPECT_TRUE(mld.Matches(1.0));
+}
+
+// Tests that IsNan() can describe itself.
+TEST(IsNan, CanDescribeSelf) {
+ Matcher<float> mf = IsNan();
+ EXPECT_EQ("is NaN", Describe(mf));
+
+ Matcher<double> md = IsNan();
+ EXPECT_EQ("is NaN", Describe(md));
+
+ Matcher<long double> mld = IsNan();
+ EXPECT_EQ("is NaN", Describe(mld));
+}
+
+// Tests that IsNan() can describe itself with Not.
+TEST(IsNan, CanDescribeSelfWithNot) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mf));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(md));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mld));
+}
+
// Tests that FloatEq() matches a 2-tuple where
// FloatEq(first field) matches the second field.
TEST(FloatEq2Test, MatchesEqualArguments) {
@@ -5093,14 +5204,14 @@ TEST(WhenSortedTest, WorksForStreamlike) {
// Streamlike 'container' provides only minimal iterator support.
// Its iterators are tagged with input_iterator_tag.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, WhenSorted(ElementsAre(1, 2, 3, 4, 5)));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
}
TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
const int a[] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
Matcher<const std::vector<int>&> vector_match = ElementsAre(1, 2, 3, 4, 5);
EXPECT_THAT(s, WhenSorted(vector_match));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
@@ -5145,7 +5256,7 @@ TEST(IsSupersetOfTest, WorksForEmpty) {
TEST(IsSupersetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5273,7 +5384,7 @@ TEST(IsSubsetOfTest, WorksForEmpty) {
TEST(IsSubsetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5367,14 +5478,14 @@ TEST(IsSubsetOfTest, WorksWithMoveOnly) {
TEST(ElemensAreStreamTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, ElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(ElementsAre(2, 1, 4, 5, 3)));
}
TEST(ElemensAreArrayStreamTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5421,7 +5532,7 @@ TEST(ElementsAreTest, TakesStlContainer) {
TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
const int a[] = {0, 1, 2, 3, 4};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
do {
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(a),
@@ -5432,8 +5543,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
TEST(UnorderedElementsAreArrayTest, VectorBool) {
const bool a[] = {0, 1, 0, 1, 1};
const bool b[] = {1, 0, 1, 1, 0};
- std::vector<bool> expected(a, a + GTEST_ARRAY_SIZE_(a));
- std::vector<bool> actual(b, b + GTEST_ARRAY_SIZE_(b));
+ std::vector<bool> expected(std::begin(a), std::end(a));
+ std::vector<bool> actual(std::begin(b), std::end(b));
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(expected),
actual, &listener)) << listener.str();
@@ -5444,7 +5555,7 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
::std::vector<int> expected;
expected.push_back(1);
@@ -5527,7 +5638,7 @@ TEST_F(UnorderedElementsAreTest, WorksWithUncopyable) {
TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
const int a[] = {1, 2, 3};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
do {
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3),
@@ -5537,7 +5648,7 @@ TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
TEST_F(UnorderedElementsAreTest, FailsWhenAnElementMatchesNoMatcher) {
const int a[] = {1, 2, 3};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
std::vector<Matcher<int> > mv;
mv.push_back(1);
mv.push_back(2);
@@ -5553,7 +5664,7 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, UnorderedElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(UnorderedElementsAre(2, 2, 3, 4, 5)));
@@ -5869,8 +5980,9 @@ TEST_F(BipartiteNonSquareTest, SimpleBacktracking) {
// :.......:
// 0 1 2
MatchMatrix g(4, 3);
- static const size_t kEdges[][2] = {{0, 2}, {1, 1}, {2, 1}, {3, 0}};
- for (size_t i = 0; i < GTEST_ARRAY_SIZE_(kEdges); ++i) {
+ constexpr std::array<std::array<size_t, 2>, 4> kEdges = {
+ {{{0, 2}}, {{1, 1}}, {{2, 1}}, {{3, 0}}}};
+ for (size_t i = 0; i < kEdges.size(); ++i) {
g.SetEdge(kEdges[i][0], kEdges[i][1], true);
}
EXPECT_THAT(FindBacktrackingMaxBPM(g),
diff --git a/googlemock/test/gmock-pp_test.cc b/googlemock/test/gmock-pp_test.cc
index 7387d398..5d1566e3 100644
--- a/googlemock/test/gmock-pp_test.cc
+++ b/googlemock/test/gmock-pp_test.cc
@@ -1,5 +1,10 @@
#include "gmock/internal/gmock-pp.h"
+// Used to test MSVC treating __VA_ARGS__ with a comma in it as one value
+#define GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_comma ,
+#define GMOCK_TEST_REPLACE_comma_WITH_COMMA(x) \
+ GMOCK_PP_CAT(GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_, x)
+
// Static assertions.
namespace testing {
namespace internal {
@@ -17,6 +22,11 @@ static_assert(GMOCK_PP_NARG(x, y, z, w) == 4, "");
static_assert(!GMOCK_PP_HAS_COMMA(), "");
static_assert(GMOCK_PP_HAS_COMMA(b, ), "");
static_assert(!GMOCK_PP_HAS_COMMA((, )), "");
+static_assert(GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma)),
+ "");
+static_assert(
+ GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma(unrelated))),
+ "");
static_assert(!GMOCK_PP_IS_EMPTY(, ), "");
static_assert(!GMOCK_PP_IS_EMPTY(a), "");
static_assert(!GMOCK_PP_IS_EMPTY(()), "");
diff --git a/googlemock/test/pump_test.py b/googlemock/test/pump_test.py
new file mode 100755
index 00000000..eb5a1313
--- /dev/null
+++ b/googlemock/test/pump_test.py
@@ -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()