aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2013-02-28 22:58:51 +0000
committerzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2013-02-28 22:58:51 +0000
commitedd4ab4945aeacdf9bd5ec3ac1654b940ca72532 (patch)
tree2f79533f5eeeb885491b8b4b707d44096e934f7c /include
parentcf40604cf087eb2a616f104fac587bd889b24e5d (diff)
downloadgoogletest-edd4ab4945aeacdf9bd5ec3ac1654b940ca72532.tar.gz
googletest-edd4ab4945aeacdf9bd5ec3ac1654b940ca72532.tar.bz2
googletest-edd4ab4945aeacdf9bd5ec3ac1654b940ca72532.zip
Makes googlemock throw a runtime_error instead of abort when a mock
method with no default value is invoked (if exceptions are enabled).
Diffstat (limited to 'include')
-rw-r--r--include/gmock/gmock-spec-builders.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/include/gmock/gmock-spec-builders.h b/include/gmock/gmock-spec-builders.h
index c677333c..59f1d71e 100644
--- a/include/gmock/gmock-spec-builders.h
+++ b/include/gmock/gmock-spec-builders.h
@@ -66,6 +66,10 @@
#include <string>
#include <vector>
+#if GTEST_HAS_EXCEPTIONS
+# include <stdexcept> // NOLINT
+#endif
+
#include "gmock/gmock-actions.h"
#include "gmock/gmock-cardinalities.h"
#include "gmock/gmock-matchers.h"
@@ -1425,10 +1429,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
return NULL;
}
- // Performs the default action of this mock function on the given arguments
- // and returns the result. Asserts with a helpful call descrption if there is
- // no valid return value. This method doesn't depend on the mutable state of
- // this object, and thus can be called concurrently without locking.
+ // Performs the default action of this mock function on the given
+ // arguments and returns the result. Asserts (or throws if
+ // exceptions are enabled) with a helpful call descrption if there
+ // is no valid return value. This method doesn't depend on the
+ // mutable state of this object, and thus can be called concurrently
+ // without locking.
// L = *
Result PerformDefaultAction(const ArgumentTuple& args,
const string& call_description) const {
@@ -1437,9 +1443,16 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
if (spec != NULL) {
return spec->GetAction().Perform(args);
}
- Assert(DefaultValue<Result>::Exists(), "", -1,
- call_description + "\n The mock function has no default action "
- "set, and its return type has no default value set.");
+ const string message = call_description +
+ "\n The mock function has no default action "
+ "set, and its return type has no default value set.";
+#if GTEST_HAS_EXCEPTIONS
+ if (!DefaultValue<Result>::Exists()) {
+ throw std::runtime_error(message);
+ }
+#else
+ Assert(DefaultValue<Result>::Exists(), "", -1, message);
+#endif
return DefaultValue<Result>::Get();
}