Compare commits
17 Commits
9A681768AA
...
1278977C59
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3482353e53 | ||
|
|
78ebd4a796 | ||
|
|
beb28e4d99 | ||
|
|
deeaeb942e | ||
|
|
2ba222fcc5 | ||
|
|
9a976a74c9 | ||
|
|
c16b7aba31 | ||
|
|
78fdd6c00b | ||
|
|
9ed99c6c83 | ||
|
|
2002f267f0 | ||
|
|
1d563578c8 | ||
|
|
cf75d4b92e | ||
|
|
3957b8898b | ||
|
|
967d8e05c2 | ||
|
|
ecefcbd4aa | ||
|
|
a5136dbdd2 | ||
|
|
e1dd49835e |
@@ -8,6 +8,7 @@ environment:
|
||||
generator: "Visual Studio 15 2017"
|
||||
build_system: cmake
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
enabled_on_pr: yes
|
||||
|
||||
- compiler: msvc-15-seh
|
||||
generator: "Visual Studio 15 2017 Win64"
|
||||
@@ -28,6 +29,7 @@ environment:
|
||||
- compiler: msvc-14-seh
|
||||
build_system: cmake
|
||||
generator: "Visual Studio 14 2015 Win64"
|
||||
enabled_on_pr: yes
|
||||
|
||||
- compiler: gcc-6.3.0-posix
|
||||
build_system: cmake
|
||||
|
||||
@@ -1184,6 +1184,46 @@ inline ::std::reference_wrapper<T> ByRef(T& l_value) { // NOLINT
|
||||
return ::std::reference_wrapper<T>(l_value);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
// A macro from the ACTION* family (defined later in gmock-generated-actions.h)
|
||||
// defines an action that can be used in a mock function. Typically,
|
||||
// these actions only care about a subset of the arguments of the mock
|
||||
// function. For example, if such an action only uses the second
|
||||
// argument, it can be used in any mock function that takes >= 2
|
||||
// arguments where the type of the second argument is compatible.
|
||||
//
|
||||
// Therefore, the action implementation must be prepared to take more
|
||||
// arguments than it needs. The ExcessiveArg type is used to
|
||||
// represent those excessive arguments. In order to keep the compiler
|
||||
// error messages tractable, we define it in the testing namespace
|
||||
// instead of testing::internal. However, this is an INTERNAL TYPE
|
||||
// and subject to change without notice, so a user MUST NOT USE THIS
|
||||
// TYPE DIRECTLY.
|
||||
struct ExcessiveArg {};
|
||||
|
||||
// A helper class needed for implementing the ACTION* macros.
|
||||
template <typename Result, class Impl>
|
||||
class ActionHelper {
|
||||
public:
|
||||
template <typename... Ts>
|
||||
static Result Perform(Impl* impl, const std::tuple<Ts...>& args) {
|
||||
return Apply(impl, args, MakeIndexSequence<sizeof...(Ts)>{},
|
||||
MakeIndexSequence<10 - sizeof...(Ts)>{});
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename... Ts, std::size_t... tuple_ids, std::size_t... rest_ids>
|
||||
static Result Apply(Impl* impl, const std::tuple<Ts...>& args,
|
||||
IndexSequence<tuple_ids...>, IndexSequence<rest_ids...>) {
|
||||
return impl->template gmock_PerformImpl<Ts...>(
|
||||
args, std::get<tuple_ids>(args)...,
|
||||
((void)rest_ids, ExcessiveArg())...);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
@@ -47,133 +47,6 @@
|
||||
#include "gmock/gmock-actions.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// A macro from the ACTION* family (defined later in this file)
|
||||
// defines an action that can be used in a mock function. Typically,
|
||||
// these actions only care about a subset of the arguments of the mock
|
||||
// function. For example, if such an action only uses the second
|
||||
// argument, it can be used in any mock function that takes >= 2
|
||||
// arguments where the type of the second argument is compatible.
|
||||
//
|
||||
// Therefore, the action implementation must be prepared to take more
|
||||
// arguments than it needs. The ExcessiveArg type is used to
|
||||
// represent those excessive arguments. In order to keep the compiler
|
||||
// error messages tractable, we define it in the testing namespace
|
||||
// instead of testing::internal. However, this is an INTERNAL TYPE
|
||||
// and subject to change without notice, so a user MUST NOT USE THIS
|
||||
// TYPE DIRECTLY.
|
||||
struct ExcessiveArg {};
|
||||
|
||||
// A helper class needed for implementing the ACTION* macros.
|
||||
template <typename Result, class Impl>
|
||||
class ActionHelper {
|
||||
public:
|
||||
static Result Perform(Impl* impl, const ::std::tuple<>& args) {
|
||||
return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0>& args) {
|
||||
return impl->template gmock_PerformImpl<A0>(args, std::get<0>(args),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1>(args, std::get<0>(args),
|
||||
std::get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2>(args,
|
||||
std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2, typename A3>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args,
|
||||
std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
std::get<3>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2, typename A3, typename A4>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3,
|
||||
A4>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
|
||||
std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
std::get<3>(args), std::get<4>(args), ExcessiveArg(), ExcessiveArg(),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4,
|
||||
A5>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
|
||||
std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
std::get<3>(args), std::get<4>(args), std::get<5>(args),
|
||||
ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5, typename A6>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
|
||||
A6>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
|
||||
std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
std::get<3>(args), std::get<4>(args), std::get<5>(args),
|
||||
std::get<6>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5, typename A6, typename A7>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
|
||||
A6, A7>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
|
||||
A7>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
std::get<3>(args), std::get<4>(args), std::get<5>(args),
|
||||
std::get<6>(args), std::get<7>(args), ExcessiveArg(), ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5, typename A6, typename A7, typename A8>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
|
||||
A6, A7, A8>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
|
||||
A8>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
std::get<3>(args), std::get<4>(args), std::get<5>(args),
|
||||
std::get<6>(args), std::get<7>(args), std::get<8>(args),
|
||||
ExcessiveArg());
|
||||
}
|
||||
|
||||
template <typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5, typename A6, typename A7, typename A8, typename A9>
|
||||
static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
|
||||
A6, A7, A8, A9>& args) {
|
||||
return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
|
||||
A9>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
|
||||
std::get<3>(args), std::get<4>(args), std::get<5>(args),
|
||||
std::get<6>(args), std::get<7>(args), std::get<8>(args),
|
||||
std::get<9>(args));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
// The ACTION* family of macros can be used in a namespace scope to
|
||||
// define custom actions easily. The syntax:
|
||||
//
|
||||
|
||||
@@ -49,54 +49,6 @@ $$}} This meta comment fixes auto-indentation in editors.
|
||||
#include "gmock/gmock-actions.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// A macro from the ACTION* family (defined later in this file)
|
||||
// defines an action that can be used in a mock function. Typically,
|
||||
// these actions only care about a subset of the arguments of the mock
|
||||
// function. For example, if such an action only uses the second
|
||||
// argument, it can be used in any mock function that takes >= 2
|
||||
// arguments where the type of the second argument is compatible.
|
||||
//
|
||||
// Therefore, the action implementation must be prepared to take more
|
||||
// arguments than it needs. The ExcessiveArg type is used to
|
||||
// represent those excessive arguments. In order to keep the compiler
|
||||
// error messages tractable, we define it in the testing namespace
|
||||
// instead of testing::internal. However, this is an INTERNAL TYPE
|
||||
// and subject to change without notice, so a user MUST NOT USE THIS
|
||||
// TYPE DIRECTLY.
|
||||
struct ExcessiveArg {};
|
||||
|
||||
// A helper class needed for implementing the ACTION* macros.
|
||||
template <typename Result, class Impl>
|
||||
class ActionHelper {
|
||||
public:
|
||||
$range i 0..n
|
||||
$for i
|
||||
|
||||
[[
|
||||
$var template = [[$if i==0 [[]] $else [[
|
||||
$range j 0..i-1
|
||||
template <$for j, [[typename A$j]]>
|
||||
]]]]
|
||||
$range j 0..i-1
|
||||
$var As = [[$for j, [[A$j]]]]
|
||||
$var as = [[$for j, [[std::get<$j>(args)]]]]
|
||||
$range k 1..n-i
|
||||
$var eas = [[$for k, [[ExcessiveArg()]]]]
|
||||
$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
|
||||
$template
|
||||
static Result Perform(Impl* impl, const ::std::tuple<$As>& args) {
|
||||
return impl->template gmock_PerformImpl<$As>(args, $arg_list);
|
||||
}
|
||||
|
||||
]]
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
// The ACTION* family of macros can be used in a namespace scope to
|
||||
// define custom actions easily. The syntax:
|
||||
//
|
||||
|
||||
@@ -1350,12 +1350,6 @@ class ReferenceOrValueWrapper<T&> {
|
||||
T* value_ptr_;
|
||||
};
|
||||
|
||||
// MSVC warns about using 'this' in base member initializer list, so
|
||||
// we need to temporarily disable the warning. We have to do it for
|
||||
// the entire class to suppress the warning, even though it's about
|
||||
// the constructor only.
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355)
|
||||
|
||||
// C++ treats the void type specially. For example, you cannot define
|
||||
// a void-typed variable or pass a void value to a function.
|
||||
// ActionResultHolder<T> holds a value of type T, where T must be a
|
||||
@@ -1786,8 +1780,6 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase {
|
||||
}
|
||||
}; // class FunctionMocker
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4355
|
||||
|
||||
// Reports an uninteresting call (whose description is in msg) in the
|
||||
// manner specified by 'reaction'.
|
||||
void ReportUninterestingCall(CallReaction reaction, const std::string& msg);
|
||||
|
||||
@@ -48,14 +48,21 @@ void loop() { RUN_ALL_TESTS(); }
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if __MSC_VER
|
||||
|
||||
// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which
|
||||
// causes a link error when _tmain is defined in a static library and UNICODE
|
||||
// is enabled. For this reason instead of _tmain, main function is used on
|
||||
// Windows. See the following link to track the current status of this bug:
|
||||
// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
|
||||
// // NOLINT
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
# include <tchar.h> // NOLINT
|
||||
|
||||
GTEST_API_ int _tmain(int argc, TCHAR** argv) {
|
||||
#else
|
||||
GTEST_API_ int main(int argc, char** argv) {
|
||||
#endif // __MSC_VER
|
||||
std::cout << "Running main() from " << __FILE__ << '\n';
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
std::cout << "Running main() from gmock_main.cc\n";
|
||||
// Since Google Mock depends on Google Test, InitGoogleMock() is
|
||||
// also responsible for initializing Google Test. Therefore there's
|
||||
// no need for calling testing::InitGoogleTest() separately.
|
||||
|
||||
@@ -392,13 +392,6 @@ TEST(ElementsAreTest, AcceptsStringLiteral) {
|
||||
EXPECT_THAT(array, Not(ElementsAre("hi", "one", "too")));
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
|
||||
// The following test passes a value of type const char[] to a
|
||||
// function template that expects const T&. Some versions of MSVC
|
||||
// generates a compiler error C2665 for that. We believe it's a bug
|
||||
// in MSVC. Therefore this test is #if-ed out for MSVC.
|
||||
|
||||
// Declared here with the size unknown. Defined AFTER the following test.
|
||||
extern const char kHi[];
|
||||
|
||||
@@ -415,8 +408,6 @@ TEST(ElementsAreTest, AcceptsArrayWithUnknownSize) {
|
||||
|
||||
const char kHi[] = "hi";
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
TEST(ElementsAreTest, MakesCopyOfArguments) {
|
||||
int x = 1;
|
||||
int y = 2;
|
||||
|
||||
@@ -412,8 +412,6 @@ class GTEST_API_ Test {
|
||||
// test in test case Foo. Hence a sub-class can define its own
|
||||
// SetUpTestSuite() method to shadow the one defined in the super
|
||||
// class.
|
||||
// Failures that happen during SetUpTestSuite are logged but otherwise
|
||||
// ignored.
|
||||
static void SetUpTestSuite() {}
|
||||
|
||||
// Tears down the stuff shared by all tests in this test suite.
|
||||
@@ -422,8 +420,6 @@ class GTEST_API_ Test {
|
||||
// test in test case Foo. Hence a sub-class can define its own
|
||||
// TearDownTestSuite() method to shadow the one defined in the super
|
||||
// class.
|
||||
// Failures that happen during TearDownTestSuite are logged but otherwise
|
||||
// ignored.
|
||||
static void TearDownTestSuite() {}
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
@@ -889,7 +885,9 @@ class GTEST_API_ TestSuite {
|
||||
bool Passed() const { return !Failed(); }
|
||||
|
||||
// Returns true if and only if the test suite failed.
|
||||
bool Failed() const { return failed_test_count() > 0; }
|
||||
bool Failed() const {
|
||||
return failed_test_count() > 0 || ad_hoc_test_result().Failed();
|
||||
}
|
||||
|
||||
// Returns the elapsed time, in milliseconds.
|
||||
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
||||
|
||||
@@ -42,12 +42,14 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/gtest-printers.h"
|
||||
#include "gtest/gtest-test-part.h"
|
||||
|
||||
namespace testing {
|
||||
// Input to a parameterized test name generator, describing a test parameter.
|
||||
@@ -472,6 +474,9 @@ class ParameterizedTestSuiteInfoBase {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase);
|
||||
};
|
||||
|
||||
GTEST_API_ void InsertSyntheticTestCase(const std::string& name,
|
||||
CodeLocation location);
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P
|
||||
@@ -522,11 +527,13 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
|
||||
return 0; // Return value used only to run this method in namespace scope.
|
||||
}
|
||||
// UnitTest class invokes this method to register tests in this test suite
|
||||
// test suites right before running tests in RUN_ALL_TESTS macro.
|
||||
// right before running tests in RUN_ALL_TESTS macro.
|
||||
// This method should not be called more than once on any single
|
||||
// instance of a ParameterizedTestSuiteInfoBase derived class.
|
||||
// UnitTest has a guard to prevent from calling this method more than once.
|
||||
void RegisterTests() override {
|
||||
bool generated_instantiations = false;
|
||||
|
||||
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
||||
test_it != tests_.end(); ++test_it) {
|
||||
std::shared_ptr<TestInfo> test_info = *test_it;
|
||||
@@ -549,6 +556,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
|
||||
for (typename ParamGenerator<ParamType>::iterator param_it =
|
||||
generator.begin();
|
||||
param_it != generator.end(); ++param_it, ++i) {
|
||||
generated_instantiations = true;
|
||||
|
||||
Message test_name_stream;
|
||||
|
||||
std::string param_name = name_func(
|
||||
@@ -577,6 +586,11 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
|
||||
} // for param_it
|
||||
} // for gen_it
|
||||
} // for test_it
|
||||
|
||||
if (!generated_instantiations) {
|
||||
// There are no generaotrs, or they all generate nothing ...
|
||||
InsertSyntheticTestCase(GetTestSuiteName(), code_location_);
|
||||
}
|
||||
} // RegisterTests
|
||||
|
||||
private:
|
||||
|
||||
@@ -407,6 +407,66 @@ void AssertHelper::operator=(const Message& message) const {
|
||||
); // NOLINT
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// When TEST_P is found without a matching INSTANTIATE_TEST_SUITE_P
|
||||
// to creates test cases for it, a syntetic test case is
|
||||
// inserted to report ether an error or a log message.
|
||||
//
|
||||
// This configuration bit will likely be removed at some point.
|
||||
constexpr bool kErrorOnUninstantiatedParameterizedTest = false;
|
||||
|
||||
// A test that fails at a given file/line location with a given message.
|
||||
class FailureTest : public Test {
|
||||
public:
|
||||
explicit FailureTest(const CodeLocation& loc, std::string error_message,
|
||||
bool as_error)
|
||||
: loc_(loc),
|
||||
error_message_(std::move(error_message)),
|
||||
as_error_(as_error) {}
|
||||
|
||||
void TestBody() override {
|
||||
if (as_error_) {
|
||||
AssertHelper(TestPartResult::kNonFatalFailure, loc_.file.c_str(),
|
||||
loc_.line, "") = Message() << error_message_;
|
||||
} else {
|
||||
std::cout << error_message_ << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const CodeLocation loc_;
|
||||
const std::string error_message_;
|
||||
const bool as_error_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
// If this parameterized test suite has no instantiations (and that
|
||||
// has not been marked as okay), emit a test case reporting that.
|
||||
void InsertSyntheticTestCase(const std::string &name, CodeLocation location) {
|
||||
std::string message =
|
||||
"Paramaterized test suite " + name +
|
||||
" is defined via TEST_P, but never instantiated. None of the test cases "
|
||||
"will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only "
|
||||
"ones provided expand to nothing."
|
||||
"\n\n"
|
||||
"Ideally, TEST_P definitions should only ever be included as part of "
|
||||
"binaries that intend to use them. (As opposed to, for example, being "
|
||||
"placed in a library that may be linked in to get other utilities.)";
|
||||
|
||||
std::string full_name = "UninstantiatedParamaterizedTestSuite<" + name + ">";
|
||||
RegisterTest( //
|
||||
"GoogleTestVerification", full_name.c_str(),
|
||||
nullptr, // No type parameter.
|
||||
nullptr, // No value parameter.
|
||||
location.file.c_str(), location.line, [message, location] {
|
||||
return new FailureTest(location, message,
|
||||
kErrorOnUninstantiatedParameterizedTest);
|
||||
});
|
||||
}
|
||||
|
||||
// A copy of all command line arguments. Set by InitGoogleTest().
|
||||
static ::std::vector<std::string> g_argvs;
|
||||
|
||||
@@ -3138,6 +3198,7 @@ class PrettyUnitTestResultPrinter : public TestEventListener {
|
||||
|
||||
private:
|
||||
static void PrintFailedTests(const UnitTest& unit_test);
|
||||
static void PrintFailedTestSuites(const UnitTest& unit_test);
|
||||
static void PrintSkippedTests(const UnitTest& unit_test);
|
||||
};
|
||||
|
||||
@@ -3290,9 +3351,8 @@ void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(
|
||||
// Internal helper for printing the list of failed tests.
|
||||
void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
|
||||
const int failed_test_count = unit_test.failed_test_count();
|
||||
if (failed_test_count == 0) {
|
||||
return;
|
||||
}
|
||||
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
|
||||
printf("%s, listed below:\n", FormatTestCount(failed_test_count).c_str());
|
||||
|
||||
for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
|
||||
const TestSuite& test_suite = *unit_test.GetTestSuite(i);
|
||||
@@ -3310,6 +3370,30 @@ void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("\n%2d FAILED %s\n", failed_test_count,
|
||||
failed_test_count == 1 ? "TEST" : "TESTS");
|
||||
}
|
||||
|
||||
// Internal helper for printing the list of test suite failures not covered by
|
||||
// PrintFailedTests.
|
||||
void PrettyUnitTestResultPrinter::PrintFailedTestSuites(
|
||||
const UnitTest& unit_test) {
|
||||
int suite_failure_count = 0;
|
||||
for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
|
||||
const TestSuite& test_suite = *unit_test.GetTestSuite(i);
|
||||
if (!test_suite.should_run()) {
|
||||
continue;
|
||||
}
|
||||
if (test_suite.ad_hoc_test_result().Failed()) {
|
||||
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
|
||||
printf("%s: SetUpTestSuite or TearDownTestSuite\n", test_suite.name());
|
||||
++suite_failure_count;
|
||||
}
|
||||
}
|
||||
if (suite_failure_count > 0) {
|
||||
printf("\n%2d FAILED TEST %s\n", suite_failure_count,
|
||||
suite_failure_count == 1 ? "SUITE" : "SUITES");
|
||||
}
|
||||
}
|
||||
|
||||
// Internal helper for printing the list of skipped tests.
|
||||
@@ -3357,19 +3441,14 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
|
||||
PrintSkippedTests(unit_test);
|
||||
}
|
||||
|
||||
int num_failures = unit_test.failed_test_count();
|
||||
if (!unit_test.Passed()) {
|
||||
const int failed_test_count = unit_test.failed_test_count();
|
||||
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
|
||||
printf("%s, listed below:\n", FormatTestCount(failed_test_count).c_str());
|
||||
PrintFailedTests(unit_test);
|
||||
printf("\n%2d FAILED %s\n", num_failures,
|
||||
num_failures == 1 ? "TEST" : "TESTS");
|
||||
PrintFailedTestSuites(unit_test);
|
||||
}
|
||||
|
||||
int num_disabled = unit_test.reportable_disabled_test_count();
|
||||
if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) {
|
||||
if (!num_failures) {
|
||||
if (unit_test.Passed()) {
|
||||
printf("\n"); // Add a spacer if no FAILURE banner is displayed.
|
||||
}
|
||||
ColoredPrintf(COLOR_YELLOW,
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
|
||||
@@ -45,14 +45,9 @@ void loop() { RUN_ALL_TESTS(); }
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if __MSC_VER
|
||||
# include <tchar.h> // NOLINT
|
||||
|
||||
GTEST_API_ int _tmain(int argc, TCHAR** argv) {
|
||||
#else
|
||||
GTEST_API_ int main(int argc, char** argv) {
|
||||
#endif // __MSC_VER
|
||||
std::cout << "Running main() from " << __FILE__ << '\n';
|
||||
GTEST_API_ int main(int argc, char **argv) {
|
||||
printf("Running main() from %s\n", __FILE__);
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ cc_test(
|
||||
"googletest-output-test_.cc",
|
||||
"googletest-list-tests-unittest_.cc",
|
||||
"googletest-shuffle-test_.cc",
|
||||
"googletest-setuptestsuite-test_.cc",
|
||||
"googletest-uninitialized-test_.cc",
|
||||
"googletest-death-test_ex_test.cc",
|
||||
"googletest-param-test-test",
|
||||
@@ -423,6 +424,21 @@ py_test(
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-setuptestsuite-test_",
|
||||
testonly = 1,
|
||||
srcs = ["googletest-setuptestsuite-test_.cc"],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-setuptestsuite-test",
|
||||
size = "medium",
|
||||
srcs = ["googletest-setuptestsuite-test.py"],
|
||||
data = [":googletest-setuptestsuite-test_"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-uninitialized-test_",
|
||||
testonly = 1,
|
||||
|
||||
@@ -12,7 +12,7 @@ Expected equality of these values:
|
||||
3
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [mRunning 84 tests from 39 test suites.
|
||||
[0;32m[==========] [mRunning 85 tests from 40 test suites.
|
||||
[0;32m[----------] [mGlobal test environment set-up.
|
||||
FooEnvironment::SetUp() called.
|
||||
BarEnvironment::SetUp() called.
|
||||
@@ -979,6 +979,12 @@ Expected failure
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
|
||||
[0;32m[----------] [m1 test from GoogleTestVerification
|
||||
[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest>
|
||||
Paramaterized test suite DetectNotInstantiatedTest is defined via TEST_P, but never instantiated. None of the test cases will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only ones provided expand to nothing.
|
||||
|
||||
Ideally, TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.)
|
||||
[0;32m[ OK ] [mGoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest>
|
||||
[0;32m[----------] [mGlobal test environment tear-down
|
||||
BarEnvironment::TearDown() called.
|
||||
googletest-output-test_.cc:#: Failure
|
||||
@@ -992,8 +998,8 @@ Failed
|
||||
Expected fatal failure.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [m84 tests from 39 test suites ran.
|
||||
[0;32m[ PASSED ] [m30 tests.
|
||||
[0;32m[==========] [m85 tests from 40 test suites ran.
|
||||
[0;32m[ PASSED ] [m31 tests.
|
||||
[0;31m[ FAILED ] [m54 tests, listed below:
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings
|
||||
|
||||
@@ -782,6 +782,13 @@ INSTANTIATE_TEST_SUITE_P(PrintingStrings,
|
||||
testing::Values(std::string("a")),
|
||||
ParamNameFunc);
|
||||
|
||||
// fails under kErrorOnUninstantiatedParameterizedTest=true
|
||||
class DetectNotInstantiatedTest : public testing::TestWithParam<int> {};
|
||||
TEST_P(DetectNotInstantiatedTest, Used) { }
|
||||
|
||||
// This would make the test failure from the above go away.
|
||||
// INSTANTIATE_TEST_SUITE_P(Fix, DetectNotInstantiatedTest, testing::Values(1));
|
||||
|
||||
// This #ifdef block tests the output of typed tests.
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
|
||||
|
||||
@@ -1068,6 +1068,12 @@ TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); }
|
||||
INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest,
|
||||
::testing::Values(ENUM1, ENUM2, 0));
|
||||
|
||||
namespace works_here {
|
||||
// Never used not instantiated, this should work.
|
||||
class NotUsedTest : public testing::TestWithParam<int> {};
|
||||
|
||||
} // namespace works_here
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Used in TestGenerationTest test suite.
|
||||
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
|
||||
|
||||
54
googletest/test/googletest-setuptestsuite-test.py
Executable file
54
googletest/test/googletest-setuptestsuite-test.py
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2019, 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.
|
||||
|
||||
"""Verifies that SetUpTestSuite and TearDownTestSuite errors are noticed."""
|
||||
|
||||
import gtest_test_utils
|
||||
|
||||
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||
'googletest-setuptestsuite-test_')
|
||||
|
||||
|
||||
class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testSetupErrorAndTearDownError(self):
|
||||
p = gtest_test_utils.Subprocess(COMMAND)
|
||||
self.assertNotEqual(p.exit_code, 0, msg=p.output)
|
||||
|
||||
self.assertIn(
|
||||
'[ FAILED ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
||||
'[ FAILED ] TearDownFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
||||
'\n'
|
||||
' 2 FAILED TEST SUITES\n',
|
||||
p.output)
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
49
googletest/test/googletest-setuptestsuite-test_.cc
Normal file
49
googletest/test/googletest-setuptestsuite-test_.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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.
|
||||
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
class SetupFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
ASSERT_EQ("", "SET_UP_FAIL");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SetupFailTest, NoopPassingTest) {}
|
||||
|
||||
class TearDownFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void TearDownTestSuite() {
|
||||
ASSERT_EQ("", "TEAR_DOWN_FAIL");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TearDownFailTest, NoopPassingTest) {}
|
||||
@@ -2923,22 +2923,18 @@ TEST_F(FloatTest, Commutative) {
|
||||
TEST_F(FloatTest, EXPECT_NEAR) {
|
||||
EXPECT_NEAR(-1.0f, -1.1f, 0.2f);
|
||||
EXPECT_NEAR(2.0f, 3.0f, 1.0f);
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0f,1.5f, 0.25f), // NOLINT
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0f, 1.5f, 0.25f), // NOLINT
|
||||
"The difference between 1.0f and 1.5f is 0.5, "
|
||||
"which exceeds 0.25f");
|
||||
// To work around a bug in gcc 2.95.0, there is intentionally no
|
||||
// space after the first comma in the previous line.
|
||||
}
|
||||
|
||||
// Tests ASSERT_NEAR.
|
||||
TEST_F(FloatTest, ASSERT_NEAR) {
|
||||
ASSERT_NEAR(-1.0f, -1.1f, 0.2f);
|
||||
ASSERT_NEAR(2.0f, 3.0f, 1.0f);
|
||||
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0f,1.5f, 0.25f), // NOLINT
|
||||
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0f, 1.5f, 0.25f), // NOLINT
|
||||
"The difference between 1.0f and 1.5f is 0.5, "
|
||||
"which exceeds 0.25f");
|
||||
// To work around a bug in gcc 2.95.0, there is intentionally no
|
||||
// space after the first comma in the previous line.
|
||||
}
|
||||
|
||||
// Tests the cases where FloatLE() should succeed.
|
||||
@@ -4321,10 +4317,8 @@ TEST(AssertionWithMessageTest, ASSERT_STR) {
|
||||
TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
|
||||
ASSERT_FLOAT_EQ(1, 1) << "This should succeed.";
|
||||
ASSERT_DOUBLE_EQ(1, 1) << "This should succeed.";
|
||||
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1,1.2, 0.1) << "Expect failure.", // NOLINT
|
||||
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1, 1.2, 0.1) << "Expect failure.", // NOLINT
|
||||
"Expect failure.");
|
||||
// To work around a bug in gcc 2.95.0, there is intentionally no
|
||||
// space after the first comma in the previous statement.
|
||||
}
|
||||
|
||||
// Tests using ASSERT_FALSE with a streamed message.
|
||||
@@ -7446,22 +7440,7 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
|
||||
}
|
||||
|
||||
// Tests ad_hoc_test_result().
|
||||
|
||||
class AdHocTestResultTest : public testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
FAIL() << "A failure happened inside SetUpTestSuite().";
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(AdHocTestResultTest, AdHocTestResultForTestSuiteShowsFailure) {
|
||||
const testing::TestResult& test_result = testing::UnitTest::GetInstance()
|
||||
->current_test_suite()
|
||||
->ad_hoc_test_result();
|
||||
EXPECT_TRUE(test_result.Failed());
|
||||
}
|
||||
|
||||
TEST_F(AdHocTestResultTest, AdHocTestResultTestForUnitTestDoesNotShowFailure) {
|
||||
TEST(AdHocTestResultTest, AdHocTestResultForUnitTestDoesNotShowFailure) {
|
||||
const testing::TestResult& test_result =
|
||||
testing::UnitTest::GetInstance()->ad_hoc_test_result();
|
||||
EXPECT_FALSE(test_result.Failed());
|
||||
|
||||
Reference in New Issue
Block a user