Use override instead of virtual for destructor
https://google.github.io/styleguide/cppguide.html says: "Explicitly annotate overrides of virtual functions or virtual destructors with exactly one of an override or (less frequently) final specifier. Do not use virtual when declaring an override". The mocked class _should_ have a virtual destructor most of the times.
PiperOrigin-RevId: 342082140
Use environment variable TEST_TMPDIR in Linux environments
for temporary directory if available otherwise use /tmp/.
Bazel sets the environment variable TEST_TMPDIR when launching tests.
PiperOrigin-RevId: 342058921
Use a tagged constructor for FlatTuple instead.
Some versions of MSVC are getting confused with that constructor and generating invalid code.
PiperOrigin-RevId: 342050957
Fix *_THROW tests under MSVC, which produce slightly different type
names from std::type_info (e.g. "class std::runtime_error" instead of
"std::runtime_error")
PiperOrigin-RevId: 341874178
Rollback change from
https://github.com/google/googletest/pull/1836. This change generates
a script on Windows to actually run each test, but the script itself
doesn't correctly report if the test passed.
This change will "break tests" that were already broken on Windows,
but weren't being reported as such.
PiperOrigin-RevId: 341850671
Change ACTION{,_Pn,_TEMPLATE} macros to build functors rather than ActionInterface<> subclasses, thus changing the Action<> wrappers they create to use the modernized (non-const) argument tuple type, allowing these macros to mutate their arguments.
Functor-based Action<>s deep-copy the implementing object, so have the functors use a shared_ptr to the non-trivial state of bound value parameters. No longer specialize that shared state to the particular action signature, encoding that information instead only in the instantiation of the implementation function.
PiperOrigin-RevId: 341116208
GMock: Make Truly explain when it fails
I just wrote a test that had a matcher of the form
Optional(AllOf(
SomeMatcher,
SomeOtherMatcher,
Truly(SomePredicate)))
The predicate failed, the other two matchers succeeded, and I got a hard-to-interpret message saying that the value in the optional "didn't match". Didn't match what?
This change improves situations like that slightly by having Truly explain to its result listener when it fails. When there are multiple Trulys in an AllOf, there will be some ambiguity, but it will at least provide more information than right now.
PiperOrigin-RevId: 341105141
On a diskless system you cannot get the current directory. So if
death tests are disabled anyway, there is no point trying to
get current directory.
Without this fix, running tests on diskless systems will fail,
even when death tests are disabled.
Remove obsolete comment about non-const references.
They used to be banned by the C++ style guide, but positions shifted, and this comment is no longer up to date.
There's another reference (heh) on lines 816-819 to how gmock is a "general framework", with the possible implication that support for non-const references was weird in some way and only there to be "general", but I left it alone because I don't really feel I understand what it's saying.
PiperOrigin-RevId: 339323428
Fix some issues when running fuse_gmock_files.
The module path should be updated before importing `fuse_gtest_files`, since
the script may not run from the googletest repo root. We also need a non-frozen
set in order to track progress.
PiperOrigin-RevId: 337380466
Suggest using generic lambdas for composing macros.
Long chains of macros hurt legibility; generic lambdas are an easy way to abbreviate them, but are not an obvious solution to casual users.
Compare:
EXPECT_THAT(f(), ElementsAre(
Property(&MyClass::foo, Property(&OtherClass::bar, Contains("x"))),
Property(&MyClass::foo, Property(&OtherClass::bar, Contains("y"))));
to:
EXPECT_THAT(f(), ElementsAre(HasFooBar("x"), HasFooBar("y")));
PiperOrigin-RevId: 336870137
Improve lookup of operator<< for user types
Without this fix, trying to use this class with googletest
struct Foo {};
template <typename OutputStream>
OutputStream& operator<<(OutputStream& os, const Foo&) {
os << "TemplatedStreamableInFoo";
return os;
}
results in an ambiguity error between the class' operator<< and the
operator<< in gtest-printers.h removed in this CL.
This fix also enables implicit conversions to happen, so that e.g.
we will find the base class operator<< if a subclass has no
operator<< of its own.
PiperOrigin-RevId: 336261221
Please note that changing the default value for a type can make [you]* test.....
Here "you" word doesn't make sense.. rather "your" seems to make it understandable.
Revision of recent DoubleNearPredFormat change to support more toolchains.
isnan() is a macro in C99, and std::isnan() is a function in C++11. The previous change used `isnan` directly, and broke some tests in open source.
This CL changes it to follow the practice in gmock-matchers.h, and spell uses of isnan as
(std::isnan)(f)
. The parens around `std::isnan` prevent it from being recognized as a macro in the preprocessor.
PiperOrigin-RevId: 333374377
Improve DoubleNearPredFormat output on bad epsilons
DoubleNearPredFormat will happily accept epsilon values (abs_error) that
are so small that they are meaningless. This turns EXPECT_NEAR into a
complicated and non-obvious version of EXPECT_EQ.
This change modifies DoubleNearPredFormat) so that when there is a
failure it calculates the smallest meaningful epsilon value, given the
input values, and then prints a message which explains what happened.
If a true equality test is wanted either pass a literal 0.0 as abs_error
or use EXPECT_EQ. If a check for being almost equal is wanted consider
using EXPECT_DOUBLE_EQ which, contrary to its name, verifies that the
two numbers are *almost* equal (within four ULPs).
With this change the flaky test mentioned in crbug.com/786046 gives this
output:
The difference between 4.2934311416234112e+18 and 4.2934311416234107e+18 is 512, where
4.2934311416234112e+18 evaluates to 4.2934311416234112e+18,
4.2934311416234107e+18 evaluates to 4.2934311416234107e+18.
The abs_error parameter 1.0 evaluates to 1 which is smaller than the minimum distance between doubles for numbers of this magnitude which is 512, thus making this EXPECT_NEAR check equivalent to EXPECT_EQUAL. Consider using EXPECT_DOUBLE_EQ instead.
Tested:
I confirmed that this change detects the bad epsilon value that caused
crbug.com/786046 in Chromium and added a test for the desired output.
PiperOrigin-RevId: 332946880
Mark ACTION_Pn()-generated functions as must-use-result.
This catches when a client creates an action and discards it, thinking that the action has actually been applied to something.
This will help people who make the mistake of defining, for example, both `void Use(Foo*)` and `ACTION(Use) { Use(arg); }` for later application to a Foo. With such an overload, a client may then write `Use();`, forgetting the param and being confused why nothing happens.
This also catches when a client defines their own action in terms of an ACTION()-generated one, invokes the ACTION's builder, and then fails to invoke the resulting action, thinking it's operating on the outer action's parameters.
PiperOrigin-RevId: 330614454
gtest.cc: make ColoredPrintf static
the prototype was removed from gtest.h in cl/301446904; quiets a
-Wmissing-declarations warning
PiperOrigin-RevId: 329569020
Add millisecond precision to start timestamp in XML/JSON output
- Previous timestamp had format YYYY-MM-DDThh:mm:ss, now YYYY-MM-DDThh:mm:ss.sss
- This conforms to the ISO 8601 standard
PiperOrigin-RevId: 329503623
Replace uses of ACTION_TEMPLATE and ACTION_P with manually written functors.
The latter provide better error diagnostics.
This fixes https://github.com/google/googletest/issues/2729.
PiperOrigin-RevId: 328573022
Workaround static assert in early versions libc++
The error is "Attempted to construct a reference element in a tuple with an
rvalue". We can fix this by putting everything into a non temporary tuple_args
and implitly convert to the other tuple types. This avoids binding an rvalue
reference to an lvalue reference inside the tuple.
PiperOrigin-RevId: 327624990
Fix DoAll to work with move-only sink arguments.
This changes types of the first n - 1 actions so that they only get a readonly
view of the arguments. The last action will accept move only objects.
PiperOrigin-RevId: 327031893
Mention matchers as an alternative to assertions in subroutines.
Matchers are often the better choice - they can provide more informative error messages and circumvent all of the complexity described in this section.
PiperOrigin-RevId: 326332149
Fixing exception-safety bug in googletest. Previously, if an exception was
thrown during a call to a mock that would have triggered an error, the error
was discarded.
Fixes#2890
PiperOrigin-RevId: 325017806
Fix DoAll to work with move-only sink arguments.
This changes types of the first n - 1 actions so that they only get a readonly
view of the arguments. The last action will accept move only objects.
PiperOrigin-RevId: 324619666
Fix DoAll to work with move-only sink arguments.
This changes types of the first n - 1 actions so that they only get a readonly
view of the arguments. The last action will accept move only objects.
PiperOrigin-RevId: 324600664