Merge branch 'master' into hethi/unused-import
This commit is contained in:
commit
d6562b5a57
|
@ -36,11 +36,8 @@ compiler:
|
||||||
script: ./travis.sh
|
script: ./travis.sh
|
||||||
env:
|
env:
|
||||||
matrix:
|
matrix:
|
||||||
- GTEST_TARGET=googletest SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
|
- SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE=1
|
||||||
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
|
- SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE=1 CXX_FLAGS=-std=c++11
|
||||||
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug CXX_FLAGS=-std=c++11 VERBOSE_MAKE=true VERBOSE
|
|
||||||
# - GTEST_TARGET=googletest SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
|
|
||||||
# - GTEST_TARGET=googlemock SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
|
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
|
@ -26,7 +26,7 @@ in its interior [googletest/README.md](googletest/README.md) file.
|
||||||
|
|
||||||
## Features ##
|
## Features ##
|
||||||
|
|
||||||
* An [XUnit](https://en.wikipedia.org/wiki/XUnit) test framework.
|
* An [xUnit](https://en.wikipedia.org/wiki/XUnit) test framework.
|
||||||
* Test discovery.
|
* Test discovery.
|
||||||
* A rich set of assertions.
|
* A rich set of assertions.
|
||||||
* User-defined assertions.
|
* User-defined assertions.
|
||||||
|
|
|
@ -148,7 +148,7 @@ Note that the mock class doesn't define `AppendPacket()`, unlike the
|
||||||
real class. That's fine as long as the test doesn't need to call it.
|
real class. That's fine as long as the test doesn't need to call it.
|
||||||
|
|
||||||
Next, you need a way to say that you want to use
|
Next, you need a way to say that you want to use
|
||||||
`ConcretePacketStream` in production code, and use `MockPacketStream`
|
`ConcretePacketStream` in production code and to use `MockPacketStream`
|
||||||
in tests. Since the functions are not virtual and the two classes are
|
in tests. Since the functions are not virtual and the two classes are
|
||||||
unrelated, you must specify your choice at _compile time_ (as opposed
|
unrelated, you must specify your choice at _compile time_ (as opposed
|
||||||
to run time).
|
to run time).
|
||||||
|
@ -706,7 +706,7 @@ type `m` accepts):
|
||||||
1. When both `T` and `U` are built-in arithmetic types (`bool`, integers, and floating-point numbers), the conversion from `T` to `U` is not lossy (in other words, any value representable by `T` can also be represented by `U`); and
|
1. When both `T` and `U` are built-in arithmetic types (`bool`, integers, and floating-point numbers), the conversion from `T` to `U` is not lossy (in other words, any value representable by `T` can also be represented by `U`); and
|
||||||
1. When `U` is a reference, `T` must also be a reference (as the underlying matcher may be interested in the address of the `U` value).
|
1. When `U` is a reference, `T` must also be a reference (as the underlying matcher may be interested in the address of the `U` value).
|
||||||
|
|
||||||
The code won't compile if any of these conditions isn't met.
|
The code won't compile if any of these conditions aren't met.
|
||||||
|
|
||||||
Here's one example:
|
Here's one example:
|
||||||
|
|
||||||
|
|
|
@ -363,7 +363,6 @@ enum CallReaction {
|
||||||
kAllow,
|
kAllow,
|
||||||
kWarn,
|
kWarn,
|
||||||
kFail,
|
kFail,
|
||||||
kDefault = kWarn // By default, warn about uninteresting calls.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
|
@ -71,6 +71,7 @@ namespace testing {
|
||||||
// Declares Google Mock flags that we want a user to use programmatically.
|
// Declares Google Mock flags that we want a user to use programmatically.
|
||||||
GMOCK_DECLARE_bool_(catch_leaked_mocks);
|
GMOCK_DECLARE_bool_(catch_leaked_mocks);
|
||||||
GMOCK_DECLARE_string_(verbose);
|
GMOCK_DECLARE_string_(verbose);
|
||||||
|
GMOCK_DECLARE_int32_(default_mock_behavior);
|
||||||
|
|
||||||
// Initializes Google Mock. This must be called before running the
|
// Initializes Google Mock. This must be called before running the
|
||||||
// tests. In particular, it parses the command line for the flags
|
// tests. In particular, it parses the command line for the flags
|
||||||
|
|
|
@ -508,6 +508,13 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
|
||||||
return expectations_met;
|
return expectations_met;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CallReaction intToCallReaction(int mock_behavior) {
|
||||||
|
if (mock_behavior >= kAllow && mock_behavior <= kFail) {
|
||||||
|
return static_cast<internal::CallReaction>(mock_behavior);
|
||||||
|
}
|
||||||
|
return kWarn;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
// Class Mock.
|
// Class Mock.
|
||||||
|
@ -648,7 +655,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
|
||||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
|
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
|
||||||
internal::kDefault : g_uninteresting_call_reaction[mock_obj];
|
internal::intToCallReaction(GMOCK_FLAG(default_mock_behavior)) :
|
||||||
|
g_uninteresting_call_reaction[mock_obj];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tells Google Mock to ignore mock_obj when checking for leaked mock
|
// Tells Google Mock to ignore mock_obj when checking for leaked mock
|
||||||
|
|
|
@ -48,6 +48,13 @@ GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
|
||||||
" warning - prints warnings and errors.\n"
|
" warning - prints warnings and errors.\n"
|
||||||
" error - prints errors only.");
|
" error - prints errors only.");
|
||||||
|
|
||||||
|
GMOCK_DEFINE_int32_(default_mock_behavior, 1,
|
||||||
|
"Controls the default behavior of mocks."
|
||||||
|
" Valid values:\n"
|
||||||
|
" 0 - by default, mocks act as NiceMocks.\n"
|
||||||
|
" 1 - by default, mocks act as NaggyMocks.\n"
|
||||||
|
" 2 - by default, mocks act as StrictMocks.");
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// Parses a string as a command line flag. The string should have the
|
// Parses a string as a command line flag. The string should have the
|
||||||
|
@ -120,6 +127,19 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ParseGoogleMockIntFlag(const char* str, const char* flag,
|
||||||
|
int* value) {
|
||||||
|
// Gets the value of the flag as a string.
|
||||||
|
const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
|
||||||
|
|
||||||
|
// Aborts if the parsing failed.
|
||||||
|
if (value_str == NULL) return false;
|
||||||
|
|
||||||
|
// Sets *value to the value of the flag.
|
||||||
|
*value = atoi(value_str);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// The internal implementation of InitGoogleMock().
|
// The internal implementation of InitGoogleMock().
|
||||||
//
|
//
|
||||||
// The type parameter CharType can be instantiated to either char or
|
// The type parameter CharType can be instantiated to either char or
|
||||||
|
@ -138,7 +158,9 @@ void InitGoogleMockImpl(int* argc, CharType** argv) {
|
||||||
// Do we see a Google Mock flag?
|
// Do we see a Google Mock flag?
|
||||||
if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks",
|
if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks",
|
||||||
&GMOCK_FLAG(catch_leaked_mocks)) ||
|
&GMOCK_FLAG(catch_leaked_mocks)) ||
|
||||||
ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose))) {
|
ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose)) ||
|
||||||
|
ParseGoogleMockIntFlag(arg, "default_mock_behavior",
|
||||||
|
&GMOCK_FLAG(default_mock_behavior))) {
|
||||||
// Yes. Shift the remainder of the argv list left by one. Note
|
// Yes. Shift the remainder of the argv list left by one. Note
|
||||||
// that argv has (*argc + 1) elements, the last one always being
|
// that argv has (*argc + 1) elements, the last one always being
|
||||||
// NULL. The following loop moves the trailing NULL element as
|
// NULL. The following loop moves the trailing NULL element as
|
||||||
|
|
|
@ -93,8 +93,11 @@ using testing::Sequence;
|
||||||
using testing::SetArgPointee;
|
using testing::SetArgPointee;
|
||||||
using testing::internal::ExpectationTester;
|
using testing::internal::ExpectationTester;
|
||||||
using testing::internal::FormatFileLocation;
|
using testing::internal::FormatFileLocation;
|
||||||
|
using testing::internal::kAllow;
|
||||||
using testing::internal::kErrorVerbosity;
|
using testing::internal::kErrorVerbosity;
|
||||||
|
using testing::internal::kFail;
|
||||||
using testing::internal::kInfoVerbosity;
|
using testing::internal::kInfoVerbosity;
|
||||||
|
using testing::internal::kWarn;
|
||||||
using testing::internal::kWarningVerbosity;
|
using testing::internal::kWarningVerbosity;
|
||||||
using testing::internal::linked_ptr;
|
using testing::internal::linked_ptr;
|
||||||
|
|
||||||
|
@ -691,6 +694,61 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
|
||||||
b.DoB();
|
b.DoB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
|
||||||
|
int original_behavior = testing::GMOCK_FLAG(default_mock_behavior);
|
||||||
|
|
||||||
|
testing::GMOCK_FLAG(default_mock_behavior) = kAllow;
|
||||||
|
CaptureStdout();
|
||||||
|
{
|
||||||
|
MockA a;
|
||||||
|
a.DoA(0);
|
||||||
|
}
|
||||||
|
std::string output = GetCapturedStdout();
|
||||||
|
EXPECT_TRUE(output.empty()) << output;
|
||||||
|
|
||||||
|
testing::GMOCK_FLAG(default_mock_behavior) = kWarn;
|
||||||
|
CaptureStdout();
|
||||||
|
{
|
||||||
|
MockA a;
|
||||||
|
a.DoA(0);
|
||||||
|
}
|
||||||
|
std::string warning_output = GetCapturedStdout();
|
||||||
|
EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output);
|
||||||
|
EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call",
|
||||||
|
warning_output);
|
||||||
|
|
||||||
|
testing::GMOCK_FLAG(default_mock_behavior) = kFail;
|
||||||
|
EXPECT_NONFATAL_FAILURE({
|
||||||
|
MockA a;
|
||||||
|
a.DoA(0);
|
||||||
|
}, "Uninteresting mock function call");
|
||||||
|
|
||||||
|
// Out of bounds values are converted to kWarn
|
||||||
|
testing::GMOCK_FLAG(default_mock_behavior) = -1;
|
||||||
|
CaptureStdout();
|
||||||
|
{
|
||||||
|
MockA a;
|
||||||
|
a.DoA(0);
|
||||||
|
}
|
||||||
|
warning_output = GetCapturedStdout();
|
||||||
|
EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output);
|
||||||
|
EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call",
|
||||||
|
warning_output);
|
||||||
|
testing::GMOCK_FLAG(default_mock_behavior) = 3;
|
||||||
|
CaptureStdout();
|
||||||
|
{
|
||||||
|
MockA a;
|
||||||
|
a.DoA(0);
|
||||||
|
}
|
||||||
|
warning_output = GetCapturedStdout();
|
||||||
|
EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output);
|
||||||
|
EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call",
|
||||||
|
warning_output);
|
||||||
|
|
||||||
|
testing::GMOCK_FLAG(default_mock_behavior) = original_behavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||||
|
|
||||||
// Tests the semantics of ON_CALL().
|
// Tests the semantics of ON_CALL().
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
|
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
|
||||||
|
|
||||||
|
using testing::GMOCK_FLAG(default_mock_behavior);
|
||||||
using testing::GMOCK_FLAG(verbose);
|
using testing::GMOCK_FLAG(verbose);
|
||||||
using testing::InitGoogleMock;
|
using testing::InitGoogleMock;
|
||||||
|
|
||||||
|
@ -103,6 +104,26 @@ TEST(InitGoogleMockTest, ParsesSingleFlag) {
|
||||||
TestInitGoogleMock(argv, new_argv, "info");
|
TestInitGoogleMock(argv, new_argv, "info");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(InitGoogleMockTest, ParsesMultipleFlags) {
|
||||||
|
int old_default_behavior = GMOCK_FLAG(default_mock_behavior);
|
||||||
|
const wchar_t* argv[] = {
|
||||||
|
L"foo.exe",
|
||||||
|
L"--gmock_verbose=info",
|
||||||
|
L"--gmock_default_mock_behavior=2",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
const wchar_t* new_argv[] = {
|
||||||
|
L"foo.exe",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
TestInitGoogleMock(argv, new_argv, "info");
|
||||||
|
EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior));
|
||||||
|
EXPECT_NE(2, old_default_behavior);
|
||||||
|
GMOCK_FLAG(default_mock_behavior) = old_default_behavior;
|
||||||
|
}
|
||||||
|
|
||||||
TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) {
|
TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) {
|
||||||
const char* argv[] = {
|
const char* argv[] = {
|
||||||
"foo.exe",
|
"foo.exe",
|
||||||
|
@ -177,6 +198,26 @@ TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
|
||||||
TestInitGoogleMock(argv, new_argv, "info");
|
TestInitGoogleMock(argv, new_argv, "info");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(WideInitGoogleMockTest, ParsesMultipleFlags) {
|
||||||
|
int old_default_behavior = GMOCK_FLAG(default_mock_behavior);
|
||||||
|
const wchar_t* argv[] = {
|
||||||
|
L"foo.exe",
|
||||||
|
L"--gmock_verbose=info",
|
||||||
|
L"--gmock_default_mock_behavior=2",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
const wchar_t* new_argv[] = {
|
||||||
|
L"foo.exe",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
TestInitGoogleMock(argv, new_argv, "info");
|
||||||
|
EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior));
|
||||||
|
EXPECT_NE(2, old_default_behavior);
|
||||||
|
GMOCK_FLAG(default_mock_behavior) = old_default_behavior;
|
||||||
|
}
|
||||||
|
|
||||||
TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) {
|
TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) {
|
||||||
const wchar_t* argv[] = {
|
const wchar_t* argv[] = {
|
||||||
L"foo.exe",
|
L"foo.exe",
|
||||||
|
|
|
@ -3115,13 +3115,13 @@ TEST(DISABLED_TestCase, DISABLED_TestShouldNotRun) {
|
||||||
FAIL() << "Unexpected failure: Test in disabled test case should not be run.";
|
FAIL() << "Unexpected failure: Test in disabled test case should not be run.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that when all tests in a test case are disabled, SetupTestCase() and
|
// Check that when all tests in a test case are disabled, SetUpTestCase() and
|
||||||
// TearDownTestCase() are not called.
|
// TearDownTestCase() are not called.
|
||||||
class DisabledTestsTest : public Test {
|
class DisabledTestsTest : public Test {
|
||||||
protected:
|
protected:
|
||||||
static void SetUpTestCase() {
|
static void SetUpTestCase() {
|
||||||
FAIL() << "Unexpected failure: All tests disabled in test case. "
|
FAIL() << "Unexpected failure: All tests disabled in test case. "
|
||||||
"SetupTestCase() should not be called.";
|
"SetUpTestCase() should not be called.";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TearDownTestCase() {
|
static void TearDownTestCase() {
|
||||||
|
|
|
@ -3,13 +3,12 @@ set -evx
|
||||||
env | sort
|
env | sort
|
||||||
|
|
||||||
mkdir build || true
|
mkdir build || true
|
||||||
mkdir build/$GTEST_TARGET || true
|
cd build
|
||||||
cd build/$GTEST_TARGET
|
|
||||||
cmake -Dgtest_build_samples=ON \
|
cmake -Dgtest_build_samples=ON \
|
||||||
-Dgmock_build_samples=ON \
|
-Dgmock_build_samples=ON \
|
||||||
-Dgtest_build_tests=ON \
|
-Dgtest_build_tests=ON \
|
||||||
-Dgmock_build_tests=ON \
|
-Dgmock_build_tests=ON \
|
||||||
-DCMAKE_CXX_FLAGS=$CXX_FLAGS \
|
-DCMAKE_CXX_FLAGS=$CXX_FLAGS \
|
||||||
../../$GTEST_TARGET
|
..
|
||||||
make
|
make
|
||||||
CTEST_OUTPUT_ON_FAILURE=1 make test
|
CTEST_OUTPUT_ON_FAILURE=1 make test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user