mirror of
https://github.com/google/googletest.git
synced 2026-07-30 16:26:24 +08:00
Compare commits
8 Commits
85687129b9
...
06582db7c2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06582db7c2 | ||
|
|
a0f06a70e3 | ||
|
|
3ff51c3e80 | ||
|
|
c6f04243ed | ||
|
|
af4c3cfcb3 | ||
|
|
ecb18f0b03 | ||
|
|
1269db9643 | ||
|
|
9d0754ba6b |
@ -6008,7 +6008,7 @@ PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage(
|
||||
} \
|
||||
template <typename arg_type> \
|
||||
bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain( \
|
||||
const arg_type& arg, \
|
||||
[[maybe_unused]] const arg_type& arg, \
|
||||
[[maybe_unused]] ::testing::MatchResultListener* result_listener) const
|
||||
|
||||
#define MATCHER_P(name, p0, description) \
|
||||
@ -6093,7 +6093,7 @@ PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage(
|
||||
template <typename arg_type> \
|
||||
bool full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>:: \
|
||||
gmock_Impl<arg_type>::MatchAndExplain( \
|
||||
const arg_type& arg, \
|
||||
[[maybe_unused]] const arg_type& arg, \
|
||||
[[maybe_unused]] ::testing::MatchResultListener* result_listener) \
|
||||
const
|
||||
|
||||
|
||||
@ -301,6 +301,8 @@ void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
|
||||
case UnorderedMatcherRequire::Subset:
|
||||
*os << "an injection from elements to requirements exists such that:\n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const char* sep = "";
|
||||
@ -343,6 +345,8 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
|
||||
case UnorderedMatcherRequire::Subset:
|
||||
*os << "no injection from elements to requirements exists such that:\n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const char* sep = "";
|
||||
for (size_t i = 0; i != matcher_describers_.size(); ++i) {
|
||||
|
||||
@ -301,6 +301,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
|
||||
"knowing-when-to-expect-useoncall for details.\n",
|
||||
stack_frames_to_skip);
|
||||
break;
|
||||
case kFail:
|
||||
default: // FAIL
|
||||
Expect(false, nullptr, -1, msg);
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ class TemplatedCopyable {
|
||||
TemplatedCopyable() = default;
|
||||
|
||||
template <typename U>
|
||||
TemplatedCopyable(const U& other) {} // NOLINT
|
||||
TemplatedCopyable(const U&) {} // NOLINT
|
||||
};
|
||||
|
||||
class FooInterface {
|
||||
|
||||
@ -2829,6 +2829,8 @@ class PredicateFormatterFromMatcherTest : public ::testing::Test {
|
||||
// an "interested" listener; so this will return |true|, thus
|
||||
// simulating a flaky matcher.
|
||||
return listener->IsInterested();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
GTEST_LOG_(FATAL) << "This should never be reached";
|
||||
|
||||
@ -30,6 +30,8 @@
|
||||
// Tests that Google Mock constructs can be used in a large number of
|
||||
// threads concurrently.
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -188,7 +190,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
|
||||
&TestPartiallyOrderedExpectationsWithThreads,
|
||||
};
|
||||
|
||||
const int kRoutines = sizeof(test_routines) / sizeof(test_routines[0]);
|
||||
const int kRoutines = std::size(test_routines);
|
||||
const int kCopiesOfEachRoutine = kMaxTestThreads / kRoutines;
|
||||
const int kTestThreads = kCopiesOfEachRoutine * kRoutines;
|
||||
ThreadWithParam<Dummy>* threads[kTestThreads] = {};
|
||||
|
||||
@ -95,7 +95,17 @@ macro(config_compiler_and_linker)
|
||||
endif()
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
|
||||
CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
|
||||
set(cxx_base_flags "-Wall -Wshadow -Wconversion -Wundef")
|
||||
set(cxx_base_flags "-Wall \
|
||||
-Wshadow \
|
||||
-Wconversion \
|
||||
-Wundef \
|
||||
-Wswitch-default \
|
||||
-Wswitch-enum \
|
||||
-Wextra \
|
||||
-Wcast-align \
|
||||
-Wunused \
|
||||
-Wunreachable-code \
|
||||
")
|
||||
set(cxx_exception_flags "-fexceptions")
|
||||
set(cxx_no_exception_flags "-fno-exceptions")
|
||||
set(cxx_strict_flags "-W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Winline -Wredundant-decls")
|
||||
|
||||
@ -945,13 +945,13 @@ template <typename T>
|
||||
class [[nodiscard]] UniversalPrinter<std::optional<T>> {
|
||||
public:
|
||||
static void Print(const std::optional<T>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
if (!value) {
|
||||
*os << "nullopt";
|
||||
UniversalPrint(std::nullopt, os);
|
||||
} else {
|
||||
*os << '(';
|
||||
UniversalPrint(*value, os);
|
||||
*os << ')';
|
||||
}
|
||||
*os << ')';
|
||||
}
|
||||
};
|
||||
|
||||
@ -961,27 +961,38 @@ class [[nodiscard]] UniversalPrinter<std::nullopt_t> {
|
||||
static void Print(std::nullopt_t, ::std::ostream* os) { *os << "(nullopt)"; }
|
||||
};
|
||||
|
||||
struct UniversalPrinterVisitor {
|
||||
template <typename T>
|
||||
void operator()(const T& arg) const {
|
||||
*os << "'" << GetTypeName<T>() << "(index = " << index << ")' with value ";
|
||||
UniversalPrint(arg, os);
|
||||
}
|
||||
::std::ostream* os;
|
||||
std::size_t index;
|
||||
};
|
||||
|
||||
// Printer for std::variant
|
||||
template <typename... T>
|
||||
class [[nodiscard]] UniversalPrinter<std::variant<T...>> {
|
||||
public:
|
||||
static void Print(const std::variant<T...>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
std::visit(Visitor{os, value.index()}, value);
|
||||
*os << ')';
|
||||
}
|
||||
|
||||
private:
|
||||
struct Visitor {
|
||||
template <typename U>
|
||||
void operator()(const U& u) const {
|
||||
*os << "'" << GetTypeName<U>() << "(index = " << index
|
||||
<< ")' with value ";
|
||||
UniversalPrint(u, os);
|
||||
if (value.valueless_by_exception()) {
|
||||
*os << "(valueless)";
|
||||
} else {
|
||||
*os << '(';
|
||||
std::visit(UniversalPrinterVisitor{os, value.index()}, value);
|
||||
*os << ')';
|
||||
}
|
||||
::std::ostream* os;
|
||||
std::size_t index;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Printer for std::monostate
|
||||
template <>
|
||||
class [[nodiscard]] UniversalPrinter<std::monostate> {
|
||||
public:
|
||||
static void Print(std::monostate, ::std::ostream* os) {
|
||||
*os << "(monostate)";
|
||||
}
|
||||
};
|
||||
|
||||
// UniversalPrintArray(begin, len, os) prints an array of 'len'
|
||||
|
||||
@ -244,6 +244,8 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
|
||||
break; \
|
||||
} \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} else \
|
||||
|
||||
@ -39,6 +39,8 @@
|
||||
|
||||
#include "sample2.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
namespace {
|
||||
// In this example, we test the MyString class (a simple string).
|
||||
@ -78,7 +80,7 @@ const char kHelloString[] = "Hello, world!";
|
||||
TEST(MyString, ConstructorFromCString) {
|
||||
const MyString s(kHelloString);
|
||||
EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
|
||||
EXPECT_EQ(sizeof(kHelloString) / sizeof(kHelloString[0]) - 1, s.Length());
|
||||
EXPECT_EQ(std::size(kHelloString) - 1, s.Length());
|
||||
}
|
||||
|
||||
// Tests the copy c'tor.
|
||||
|
||||
@ -587,7 +587,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||
const TestSuite* GetTestSuite(int i) const {
|
||||
const int index = GetElementOr(test_suite_indices_, i, -1);
|
||||
return index < 0 ? nullptr : test_suites_[static_cast<size_t>(i)];
|
||||
return index < 0 ? nullptr : test_suites_[static_cast<size_t>(index)];
|
||||
}
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
|
||||
@ -1497,6 +1497,8 @@ class Hunk {
|
||||
++adds_;
|
||||
hunk_adds_.push_back(std::make_pair('+', line));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3308,6 +3310,7 @@ static const char* GetAnsiColorCode(GTestColor color) {
|
||||
return "2";
|
||||
case GTestColor::kYellow:
|
||||
return "3";
|
||||
case GTestColor::kDefault:
|
||||
default:
|
||||
assert(false);
|
||||
return "9";
|
||||
@ -3564,6 +3567,9 @@ void PrettyUnitTestResultPrinter::OnTestPartResult(
|
||||
// If the test part succeeded, we don't need to do anything.
|
||||
case TestPartResult::kSuccess:
|
||||
return;
|
||||
case TestPartResult::kNonFatalFailure:
|
||||
case TestPartResult::kFatalFailure:
|
||||
case TestPartResult::kSkip:
|
||||
default:
|
||||
// Print failure message from the assertion
|
||||
// (e.g. expected this and got that).
|
||||
@ -3782,6 +3788,9 @@ void BriefUnitTestResultPrinter::OnTestPartResult(
|
||||
// If the test part succeeded, we don't need to do anything.
|
||||
case TestPartResult::kSuccess:
|
||||
return;
|
||||
case TestPartResult::kNonFatalFailure:
|
||||
case TestPartResult::kFatalFailure:
|
||||
case TestPartResult::kSkip:
|
||||
default:
|
||||
// Print failure message from the assertion
|
||||
// (e.g. expected this and got that).
|
||||
|
||||
@ -348,7 +348,7 @@ TEST_F(TestForDeathTest, SwitchStatement) {
|
||||
ASSERT_DEATH(_Exit(1), "") << "exit in default switch handler";
|
||||
|
||||
switch (0)
|
||||
case 0:
|
||||
default:
|
||||
EXPECT_DEATH(_Exit(1), "") << "exit in switch case";
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
@ -1501,7 +1501,7 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
|
||||
ASSERT_DEATH_IF_SUPPORTED(_Exit(1), "") << "exit in default switch handler";
|
||||
|
||||
switch (0)
|
||||
case 0:
|
||||
default:
|
||||
EXPECT_DEATH_IF_SUPPORTED(_Exit(1), "") << "exit in switch case";
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
// This file verifies Google Test event listeners receive events at the
|
||||
// right times.
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -498,8 +499,7 @@ int main(int argc, char** argv) {
|
||||
"1st.OnTestProgramEnd"};
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
VerifyResults(events, expected_events,
|
||||
sizeof(expected_events) / sizeof(expected_events[0]));
|
||||
VerifyResults(events, expected_events, std::size(expected_events));
|
||||
|
||||
// We need to check manually for ad hoc test failures that happen after
|
||||
// RUN_ALL_TESTS finishes.
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
@ -149,7 +150,7 @@ TEST(LoggingTest, InterleavingLoggingAndAssertions) {
|
||||
static const int a[4] = {3, 9, 2, 6};
|
||||
|
||||
printf("(expecting 2 failures on (3) >= (a[i]))\n");
|
||||
for (int i = 0; i < static_cast<int>(sizeof(a) / sizeof(*a)); i++) {
|
||||
for (int i = 0; i < static_cast<int>(std::size(a)); i++) {
|
||||
printf("i == %d\n", i);
|
||||
EXPECT_GE(3, a[i]);
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
@ -737,10 +738,7 @@ const int test_generation_params[] = {36, 42, 72};
|
||||
|
||||
class TestGenerationTest : public TestWithParam<int> {
|
||||
public:
|
||||
enum {
|
||||
PARAMETER_COUNT =
|
||||
sizeof(test_generation_params) / sizeof(test_generation_params[0])
|
||||
};
|
||||
enum { PARAMETER_COUNT = std::size(test_generation_params) };
|
||||
|
||||
typedef TestGenerationEnvironment<PARAMETER_COUNT> Environment;
|
||||
|
||||
|
||||
@ -239,7 +239,7 @@ TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
|
||||
}
|
||||
|
||||
switch (0)
|
||||
case 0:
|
||||
default:
|
||||
GTEST_CHECK_(true) << "Check failed in switch case";
|
||||
}
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
@ -1784,7 +1785,7 @@ TEST(IsValidUTF8Test, IllFormedUTF8) {
|
||||
// too.
|
||||
{"\xEE\x80\x80", "\"\\xEE\\x80\\x80\"\n As Text: \"\""}};
|
||||
|
||||
for (int i = 0; i < int(sizeof(kTestdata) / sizeof(kTestdata[0])); ++i) {
|
||||
for (int i = 0; i < int(std::size(kTestdata)); ++i) {
|
||||
EXPECT_PRINT_TO_STRING_(kTestdata[i][0], kTestdata[i][1]);
|
||||
}
|
||||
}
|
||||
@ -2029,6 +2030,26 @@ TEST(PrintOneofTest, Basic) {
|
||||
PrintToString(Type(NonPrintable{})));
|
||||
}
|
||||
|
||||
TEST(PrintVariantTest, Monostate) {
|
||||
EXPECT_EQ("(monostate)", PrintToString(std::monostate()));
|
||||
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
struct ThrowOnMove {
|
||||
ThrowOnMove() = default;
|
||||
ThrowOnMove(ThrowOnMove&& other) { *this = std::move(other); }
|
||||
ThrowOnMove& operator=(ThrowOnMove&&) {
|
||||
(void)std::vector<bool>().at(0);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
std::variant<std::monostate, ThrowOnMove> v = std::monostate();
|
||||
EXPECT_EQ("('std::monostate(index = 0)' with value (monostate))",
|
||||
PrintToString(v));
|
||||
EXPECT_THROW(v = ThrowOnMove(), std::out_of_range);
|
||||
EXPECT_EQ("(valueless)", PrintToString(v));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if GTEST_INTERNAL_HAS_COMPARE_LIB
|
||||
TEST(PrintOrderingTest, Basic) {
|
||||
EXPECT_EQ("(less)", PrintToString(std::strong_ordering::less));
|
||||
|
||||
@ -63,6 +63,7 @@ class MyEnvironment : public testing::Environment {
|
||||
case FATAL_FAILURE:
|
||||
FAIL() << "Expected fatal failure in global set-up.";
|
||||
break;
|
||||
case NO_FAILURE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -33,6 +33,8 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
// Verifies that the command line flag variables can be accessed in
|
||||
// code once "gtest.h" has been #included.
|
||||
// Do not move it after other gtest #includes.
|
||||
@ -4280,7 +4282,7 @@ TEST(AssertionSyntaxTest, WorksWithSwitch) {
|
||||
}
|
||||
|
||||
switch (0)
|
||||
case 0:
|
||||
default:
|
||||
EXPECT_FALSE(false) << "EXPECT_FALSE failed in switch case";
|
||||
|
||||
// Binary assertions are implemented using a different code path
|
||||
@ -4292,7 +4294,7 @@ TEST(AssertionSyntaxTest, WorksWithSwitch) {
|
||||
}
|
||||
|
||||
switch (0)
|
||||
case 0:
|
||||
default:
|
||||
EXPECT_NE(1, 2);
|
||||
}
|
||||
|
||||
@ -5853,9 +5855,8 @@ class ParseFlagsTest : public Test {
|
||||
// to specify the array sizes.
|
||||
|
||||
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
|
||||
TestParsingFlags(sizeof(argv1) / sizeof(*argv1) - 1, argv1, \
|
||||
sizeof(argv2) / sizeof(*argv2) - 1, argv2, expected, \
|
||||
should_print_help)
|
||||
TestParsingFlags(std::size(argv1) - 1, argv1, std::size(argv2) - 1, argv2, \
|
||||
expected, should_print_help)
|
||||
};
|
||||
|
||||
// Tests parsing an empty command line.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user