Unverified Commit 76bce79a authored by Andy Soffer's avatar Andy Soffer Committed by GitHub
Browse files

Merge branch 'main' into fixes_std_pair_diff

parents 6f1c4b3d f345b2ca
......@@ -32,13 +32,14 @@
#include "gtest/gtest-test-part.h"
#include <ostream>
#include <string>
#include "gtest/internal/gtest-port.h"
#include "src/gtest-internal-inl.h"
namespace testing {
using internal::GetUnitTestImpl;
// Gets the summary of the failure message by omitting the stack trace
// in it.
std::string TestPartResult::ExtractSummary(const char* message) {
......
......@@ -29,6 +29,10 @@
#include "gtest/gtest-typed-test.h"
#include <set>
#include <string>
#include <vector>
#include "gtest/gtest.h"
namespace testing {
......@@ -90,7 +94,7 @@ const char* TypedTestSuitePState::VerifyRegisteredTestNames(
}
const std::string& errors_str = errors.GetString();
if (errors_str != "") {
if (!errors_str.empty()) {
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
errors_str.c_str());
fflush(stderr);
......
......@@ -44,16 +44,21 @@
#include <chrono> // NOLINT
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <ostream> // NOLINT
#include <set>
#include <sstream>
#include <unordered_set>
#include <utility>
#include <vector>
#include "gtest/gtest-assertion-result.h"
......@@ -61,7 +66,7 @@
#include "gtest/internal/custom/gtest.h"
#include "gtest/internal/gtest-port.h"
#if GTEST_OS_LINUX
#ifdef GTEST_OS_LINUX
#include <fcntl.h> // NOLINT
#include <limits.h> // NOLINT
......@@ -74,18 +79,18 @@
#include <string>
#elif GTEST_OS_ZOS
#elif defined(GTEST_OS_ZOS)
#include <sys/time.h> // NOLINT
// On z/OS we additionally need strings.h for strcasecmp.
#include <strings.h> // NOLINT
#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE.
#elif defined(GTEST_OS_WINDOWS_MOBILE) // We are on Windows CE.
#include <windows.h> // NOLINT
#undef min
#elif GTEST_OS_WINDOWS // We are on Windows proper.
#elif defined(GTEST_OS_WINDOWS) // We are on Windows proper.
#include <windows.h> // NOLINT
#undef min
......@@ -99,7 +104,7 @@
#include <sys/timeb.h> // NOLINT
#include <sys/types.h> // NOLINT
#if GTEST_OS_WINDOWS_MINGW
#ifdef GTEST_OS_WINDOWS_MINGW
#include <sys/time.h> // NOLINT
#endif // GTEST_OS_WINDOWS_MINGW
......@@ -125,17 +130,18 @@
#include "src/gtest-internal-inl.h"
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
#define vsnprintf _vsnprintf
#endif // GTEST_OS_WINDOWS
#if GTEST_OS_MAC
#ifdef GTEST_OS_MAC
#ifndef GTEST_OS_IOS
#include <crt_externs.h>
#endif
#endif
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
#include "absl/container/flat_hash_set.h"
#include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/stacktrace.h"
#include "absl/debugging/symbolize.h"
......@@ -143,6 +149,8 @@
#include "absl/flags/usage.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#endif // GTEST_HAS_ABSL
// Checks builtin compiler feature |x| while avoiding an extra layer of #ifdefs
......@@ -408,7 +416,7 @@ uint32_t Random::Generate(uint32_t range) {
// GTestIsInitialized() returns true if and only if the user has initialized
// Google Test. Useful for catching the user mistake of not initializing
// Google Test before calling RUN_ALL_TESTS().
static bool GTestIsInitialized() { return GetArgvs().size() > 0; }
static bool GTestIsInitialized() { return !GetArgvs().empty(); }
// Iterates over a vector of TestSuites, keeping a running sum of the
// results of calling a given int-returning method on each.
......@@ -630,7 +638,7 @@ static ::std::vector<std::string> g_argvs;
FilePath GetCurrentExecutableName() {
FilePath result;
#if GTEST_OS_WINDOWS || GTEST_OS_OS2
#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2)
result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe"));
#else
result.Set(FilePath(GetArgvs()[0]));
......@@ -1165,7 +1173,7 @@ TimeInMillis GetTimeInMillis() {
// class String.
#if GTEST_OS_WINDOWS_MOBILE
#ifdef GTEST_OS_WINDOWS_MOBILE
// Creates a UTF-16 wide string from the given ANSI string, allocating
// memory using new. The caller is responsible for deleting the return
// value using delete[]. Returns the wide string, or NULL if the
......@@ -1867,14 +1875,14 @@ AssertionResult IsNotSubstring(const char* needle_expr,
namespace internal {
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
namespace {
// Helper function for IsHRESULT{SuccessFailure} predicates
AssertionResult HRESULTFailureHelper(const char* expr, const char* expected,
long hr) { // NOLINT
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_TV_TITLE)
// Windows CE doesn't support FormatMessage.
const char error_text[] = "";
......@@ -2135,9 +2143,9 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
if (rhs == nullptr) return false;
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
return _wcsicmp(lhs, rhs) == 0;
#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
#elif defined(GTEST_OS_LINUX) && !defined(GTEST_OS_LINUX_ANDROID)
return wcscasecmp(lhs, rhs) == 0;
#else
// Android, Mac OS X and Cygwin don't define wcscasecmp.
......@@ -2237,7 +2245,7 @@ TestResult::TestResult()
: death_test_count_(0), start_timestamp_(0), elapsed_time_(0) {}
// D'tor.
TestResult::~TestResult() {}
TestResult::~TestResult() = default;
// Returns the i-th test part result among all the results. i can
// range from 0 to total_part_count() - 1. If i is not in that range,
......@@ -2325,7 +2333,9 @@ static std::vector<std::string> GetReservedAttributesForElement(
return std::vector<std::string>();
}
#if GTEST_HAS_FILE_SYSTEM
// TODO(jdesprez): Merge the two getReserved attributes once skip is improved
// This function is only used when file systems are enabled.
static std::vector<std::string> GetReservedOutputAttributesForElement(
const std::string& xml_element) {
if (xml_element == "testsuites") {
......@@ -2340,6 +2350,7 @@ static std::vector<std::string> GetReservedOutputAttributesForElement(
// This code is unreachable but some compilers may not realizes that.
return std::vector<std::string>();
}
#endif
static std::string FormatWordList(const std::vector<std::string>& words) {
Message word_list;
......@@ -2443,7 +2454,7 @@ Test::Test() : gtest_flag_saver_(new GTEST_FLAG_SAVER_) {}
// The d'tor restores the states of all flags. The actual work is
// done by the d'tor of the gtest_flag_saver_ field, and thus not
// visible here.
Test::~Test() {}
Test::~Test() = default;
// Sets up the test fixture.
//
......@@ -2978,6 +2989,25 @@ void TestSuite::Run() {
TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
// Ensure our tests are in a deterministic order.
//
// We do this by sorting lexicographically on (file, line number), providing
// an order matching what the user can see in the source code.
//
// In the common case the line number comparison shouldn't be necessary,
// because the registrations made by the TEST macro are executed in order
// within a translation unit. But this is not true of the manual registration
// API, and in more exotic scenarios a single file may be part of multiple
// translation units.
std::stable_sort(test_info_list_.begin(), test_info_list_.end(),
[](const TestInfo* const a, const TestInfo* const b) {
if (const int result = std::strcmp(a->file(), b->file())) {
return result < 0;
}
return a->line() < b->line();
});
// Call both legacy and the new API
repeater->OnTestSuiteStart(*this);
// Legacy API is deprecated but still available
......@@ -3141,7 +3171,7 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) {
// following statements add the test part result message to the Output
// window such that the user can double-click on it to jump to the
// corresponding source code location; otherwise they do nothing.
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE)
// We don't call OutputDebugString*() on Windows Mobile, as printing
// to stdout is done by OutputDebugString() there already - we don't
// want the same message printed twice.
......@@ -3151,8 +3181,9 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) {
}
// class PrettyUnitTestResultPrinter
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \
!GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \
!defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \
!defined(GTEST_OS_WINDOWS_MINGW)
// Returns the character attribute for the given color.
static WORD GetColorAttribute(GTestColor color) {
......@@ -3224,7 +3255,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
const char* const gtest_color = c.c_str();
if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
// On Windows the TERM variable is usually not set, but the
// console there does support colors.
return stdout_is_tty;
......@@ -3279,8 +3310,9 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) {
return;
}
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \
!GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \
!defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \
!defined(GTEST_OS_WINDOWS_MINGW)
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// Gets the current text color.
......@@ -3334,7 +3366,7 @@ static void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
// Class PrettyUnitTestResultPrinter is copyable.
class PrettyUnitTestResultPrinter : public TestEventListener {
public:
PrettyUnitTestResultPrinter() {}
PrettyUnitTestResultPrinter() = default;
static void PrintTestName(const char* test_suite, const char* test) {
printf("%s.%s", test_suite, test);
}
......@@ -3642,7 +3674,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
// Class BriefUnitTestResultPrinter is copyable.
class BriefUnitTestResultPrinter : public TestEventListener {
public:
BriefUnitTestResultPrinter() {}
BriefUnitTestResultPrinter() = default;
static void PrintTestName(const char* test_suite, const char* test) {
printf("%s.%s", test_suite, test);
}
......@@ -3757,28 +3789,28 @@ class TestEventRepeater : public TestEventListener {
bool forwarding_enabled() const { return forwarding_enabled_; }
void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
void OnTestProgramStart(const UnitTest& unit_test) override;
void OnTestProgramStart(const UnitTest& parameter) override;
void OnTestIterationStart(const UnitTest& unit_test, int iteration) override;
void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override;
void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override;
void OnEnvironmentsSetUpStart(const UnitTest& parameter) override;
void OnEnvironmentsSetUpEnd(const UnitTest& parameter) override;
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestCaseStart(const TestSuite& parameter) override;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestSuiteStart(const TestSuite& parameter) override;
void OnTestStart(const TestInfo& test_info) override;
void OnTestDisabled(const TestInfo& test_info) override;
void OnTestPartResult(const TestPartResult& result) override;
void OnTestEnd(const TestInfo& test_info) override;
void OnTestStart(const TestInfo& parameter) override;
void OnTestDisabled(const TestInfo& parameter) override;
void OnTestPartResult(const TestPartResult& parameter) override;
void OnTestEnd(const TestInfo& parameter) override;
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestCaseEnd(const TestCase& parameter) override;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestSuiteEnd(const TestSuite& parameter) override;
void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override;
void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override;
void OnEnvironmentsTearDownStart(const UnitTest& parameter) override;
void OnEnvironmentsTearDownEnd(const UnitTest& parameter) override;
void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
void OnTestProgramEnd(const UnitTest& unit_test) override;
void OnTestProgramEnd(const UnitTest& parameter) override;
private:
// Controls whether events will be forwarded to listeners_. Set to false
......@@ -4953,7 +4985,7 @@ const char* const OsStackTraceGetterInterface::kElidedFramesMarker =
std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count)
GTEST_LOCK_EXCLUDED_(mutex_) {
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
std::string result;
if (max_depth <= 0) {
......@@ -5002,7 +5034,7 @@ std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count)
}
void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) {
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
void* caller_frame = nullptr;
if (absl::GetStackTrace(&caller_frame, 1, 3) <= 0) {
caller_frame = nullptr;
......@@ -5013,7 +5045,7 @@ void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) {
#endif // GTEST_HAS_ABSL
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// A helper class that creates the premature-exit file in its
// constructor and deletes the file in its destructor.
class ScopedPrematureExitFile {
......@@ -5033,7 +5065,7 @@ class ScopedPrematureExitFile {
}
~ScopedPrematureExitFile() {
#if !GTEST_OS_ESP8266
#ifndef GTEST_OS_ESP8266
if (!premature_exit_filepath_.empty()) {
int retval = remove(premature_exit_filepath_.c_str());
if (retval) {
......@@ -5301,7 +5333,7 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
msg << message;
internal::MutexLock lock(&mutex_);
if (impl_->gtest_trace_stack().size() > 0) {
if (!impl_->gtest_trace_stack().empty()) {
msg << "\n" << GTEST_NAME_ << " trace:";
for (size_t i = impl_->gtest_trace_stack().size(); i > 0; --i) {
......@@ -5314,6 +5346,8 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
if (os_stack_trace.c_str() != nullptr && !os_stack_trace.empty()) {
msg << internal::kStackTraceMarker << os_stack_trace;
} else {
msg << "\n";
}
const TestPartResult result = TestPartResult(
......@@ -5329,7 +5363,8 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
// with another testing framework) and specify the former on the
// command line for debugging.
if (GTEST_FLAG_GET(break_on_failure)) {
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!defined(GTEST_OS_WINDOWS_RT)
// Using DebugBreak on Windows allows gtest to still break into a debugger
// when a failure happens and both the --gtest_break_on_failure and
// the --gtest_catch_exceptions flags are specified.
......@@ -5377,7 +5412,7 @@ void UnitTest::RecordProperty(const std::string& key,
// We don't protect this under mutex_, as we only support calling it
// from the main thread.
int UnitTest::Run() {
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
const bool in_death_test_child_process =
GTEST_FLAG_GET(internal_run_death_test).length() > 0;
......@@ -5406,32 +5441,36 @@ int UnitTest::Run() {
in_death_test_child_process
? nullptr
: internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE"));
#else
const bool in_death_test_child_process = false;
#endif // GTEST_HAS_DEATH_TEST
// Captures the value of GTEST_FLAG(catch_exceptions). This value will be
// used for the duration of the program.
impl()->set_catch_exceptions(GTEST_FLAG_GET(catch_exceptions));
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
// Either the user wants Google Test to catch exceptions thrown by the
// tests or this is executing in the context of death test child
// process. In either case the user does not want to see pop-up dialogs
// about crashes - they are expected.
if (impl()->catch_exceptions() || in_death_test_child_process) {
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!defined(GTEST_OS_WINDOWS_RT)
// SetErrorMode doesn't exist on CE.
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
#endif // !GTEST_OS_WINDOWS_MOBILE
#if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
#if (defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW)) && \
!defined(GTEST_OS_WINDOWS_MOBILE)
// Death test children can be terminated with _abort(). On Windows,
// _abort() can show a dialog with a warning message. This forces the
// abort message to go to stderr instead.
_set_error_mode(_OUT_TO_STDERR);
#endif
#if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
#if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE)
// In the debug version, Visual Studio pops up a separate dialog
// offering a choice to debug the aborted program. We need to suppress
// this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
......@@ -5453,6 +5492,8 @@ int UnitTest::Run() {
}
#endif
}
#else
(void)in_death_test_child_process; // Needed inside the #if block above
#endif // GTEST_OS_WINDOWS
return internal::HandleExceptionsInMethodIfSupported(
......@@ -5548,7 +5589,7 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
random_(0), // Will be reseeded before first use.
start_timestamp_(0),
elapsed_time_(0),
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
death_test_factory_(new DefaultDeathTestFactory),
#endif
// Will be overridden by the flag before first use.
......@@ -5588,11 +5629,11 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
test_result->RecordProperty(xml_element, test_property);
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// Disables event forwarding if the control is currently in a death test
// subprocess. Must not be called before InitGoogleTest.
void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
if (internal_run_death_test_flag_.get() != nullptr)
if (internal_run_death_test_flag_ != nullptr)
listeners()->SuppressEventForwarding();
}
#endif // GTEST_HAS_DEATH_TEST
......@@ -5608,7 +5649,7 @@ void UnitTestImpl::ConfigureXmlOutput() {
} else if (output_format == "json") {
listeners()->SetDefaultXmlGenerator(new JsonUnitTestResultPrinter(
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
} else if (output_format != "") {
} else if (!output_format.empty()) {
GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \""
<< output_format << "\" ignored.";
}
......@@ -5651,7 +5692,7 @@ void UnitTestImpl::PostFlagParsingInit() {
listeners()->Append(new GTEST_CUSTOM_TEST_EVENT_LISTENER_());
#endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
InitDeathTestSubprocessControlInfo();
SuppressTestEventsIfInSubprocess();
#endif // GTEST_HAS_DEATH_TEST
......@@ -5674,7 +5715,7 @@ void UnitTestImpl::PostFlagParsingInit() {
ConfigureStreamingOutput();
#endif // GTEST_CAN_STREAM_RESULTS_
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
if (GTEST_FLAG_GET(install_failure_signal_handler)) {
absl::FailureSignalHandlerOptions options;
absl::InstallFailureSignalHandler(options);
......@@ -5789,9 +5830,8 @@ bool UnitTestImpl::RunAllTests() {
// death test.
bool in_subprocess_for_death_test = false;
#if GTEST_HAS_DEATH_TEST
in_subprocess_for_death_test =
(internal_run_death_test_flag_.get() != nullptr);
#ifdef GTEST_HAS_DEATH_TEST
in_subprocess_for_death_test = (internal_run_death_test_flag_ != nullptr);
#if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
if (in_subprocess_for_death_test) {
GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
......@@ -5954,10 +5994,6 @@ bool UnitTestImpl::RunAllTests() {
"() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_
" will start to enforce the valid usage. "
"Please fix it ASAP, or IT WILL START TO FAIL.\n"); // NOLINT
#if GTEST_FOR_GOOGLE_
ColoredPrintf(GTestColor::kRed,
"For more details, see http://wiki/Main/ValidGUnitMain.\n");
#endif // GTEST_FOR_GOOGLE_
}
return !failed;
......@@ -6513,7 +6549,7 @@ static const char kColorEncodedHelpMessage[] =
#endif // GTEST_CAN_STREAM_RESULTS_
"\n"
"Assertion Behavior:\n"
#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
#if defined(GTEST_HAS_DEATH_TEST) && !defined(GTEST_OS_WINDOWS)
" @G--" GTEST_FLAG_PREFIX_
"death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
" Set the default death test style.\n"
......@@ -6654,26 +6690,60 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
}
// Parses the command line for Google Test flags, without initializing
// other parts of Google Test.
// other parts of Google Test. This function updates argc and argv by removing
// flags that are known to GoogleTest (including other user flags defined using
// ABSL_FLAG if GoogleTest is built with GTEST_USE_ABSL). Other arguments
// remain in place. Unrecognized flags are not reported and do not cause the
// program to exit.
void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
#if GTEST_HAS_ABSL
if (*argc > 0) {
// absl::ParseCommandLine() requires *argc > 0.
auto positional_args = absl::flags_internal::ParseCommandLineImpl(
*argc, argv, absl::flags_internal::ArgvListAction::kRemoveParsedArgs,
absl::flags_internal::UsageFlagsAction::kHandleUsage,
absl::flags_internal::OnUndefinedFlag::kReportUndefined);
// Any command-line positional arguments not part of any command-line flag
// (or arguments to a flag) are copied back out to argv, with the program
// invocation name at position 0, and argc is resized. This includes
// positional arguments after the flag-terminating delimiter '--'.
// See https://abseil.io/docs/cpp/guides/flags.
std::copy(positional_args.begin(), positional_args.end(), argv);
if (static_cast<int>(positional_args.size()) < *argc) {
argv[positional_args.size()] = nullptr;
*argc = static_cast<int>(positional_args.size());
#ifdef GTEST_HAS_ABSL
if (*argc <= 0) return;
std::vector<char*> positional_args;
std::vector<absl::UnrecognizedFlag> unrecognized_flags;
absl::ParseAbseilFlagsOnly(*argc, argv, positional_args, unrecognized_flags);
absl::flat_hash_set<absl::string_view> unrecognized;
for (const auto& flag : unrecognized_flags) {
unrecognized.insert(flag.flag_name);
}
absl::flat_hash_set<char*> positional;
for (const auto& arg : positional_args) {
positional.insert(arg);
}
int out_pos = 1;
int in_pos = 1;
for (; in_pos < *argc; ++in_pos) {
char* arg = argv[in_pos];
absl::string_view arg_str(arg);
if (absl::ConsumePrefix(&arg_str, "--")) {
// Flag-like argument. If the flag was unrecognized, keep it.
// If it was a GoogleTest flag, remove it.
if (unrecognized.contains(arg_str)) {
argv[out_pos++] = argv[in_pos];
continue;
}
}
if (arg_str.empty()) {
++in_pos;
break; // '--' indicates that the rest of the arguments are positional
}
// Probably a positional argument. If it is in fact positional, keep it.
// If it was a value for the flag argument, remove it.
if (positional.contains(arg)) {
argv[out_pos++] = arg;
}
}
// The rest are positional args for sure.
while (in_pos < *argc) {
argv[out_pos++] = argv[in_pos++];
}
*argc = out_pos;
argv[out_pos] = nullptr;
#else
ParseGoogleTestFlagsOnlyImpl(argc, argv);
#endif
......@@ -6681,7 +6751,7 @@ void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
// Fix the value of *_NSGetArgc() on macOS, but if and only if
// *_NSGetArgv() == argv
// Only applicable to char** version of argv
#if GTEST_OS_MAC
#ifdef GTEST_OS_MAC
#ifndef GTEST_OS_IOS
if (*_NSGetArgv() == argv) {
*_NSGetArgc() = *argc;
......@@ -6709,7 +6779,7 @@ void InitGoogleTestImpl(int* argc, CharType** argv) {
g_argvs.push_back(StreamableToString(argv[i]));
}
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
absl::InitializeSymbolizer(g_argvs[0].c_str());
// When using the Abseil Flags library, set the program usage message to the
......@@ -6793,16 +6863,16 @@ static std::string GetDirFromEnv(
std::string TempDir() {
#if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
#elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE
#elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE)
return GetDirFromEnv({"TEST_TMPDIR", "TEMP"}, "\\temp\\", '\\');
#elif GTEST_OS_LINUX_ANDROID
#elif defined(GTEST_OS_LINUX_ANDROID)
return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/');
#else
return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/');
#endif
}
#if !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_)
#if GTEST_HAS_FILE_SYSTEM && !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_)
// Returns the directory path (including terminating separator) of the current
// executable as derived from argv[0].
static std::string GetCurrentExecutableDirectory() {
......@@ -6811,13 +6881,14 @@ static std::string GetCurrentExecutableDirectory() {
}
#endif
#if GTEST_HAS_FILE_SYSTEM
std::string SrcDir() {
#if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_)
return GTEST_CUSTOM_SRCDIR_FUNCTION_();
#elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE
#elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE)
return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(),
'\\');
#elif GTEST_OS_LINUX_ANDROID
#elif defined(GTEST_OS_LINUX_ANDROID)
return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(),
'/');
#else
......@@ -6825,6 +6896,7 @@ std::string SrcDir() {
'/');
#endif
}
#endif
// Class ScopedTrace
......
......@@ -31,10 +31,10 @@
#include "gtest/gtest.h"
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32)
// Arduino-like platforms: program entry points are setup/loop instead of main.
#if GTEST_OS_ESP8266
#ifdef GTEST_OS_ESP8266
extern "C" {
#endif
......@@ -42,11 +42,11 @@ void setup() { testing::InitGoogleTest(); }
void loop() { RUN_ALL_TESTS(); }
#if GTEST_OS_ESP8266
#ifdef GTEST_OS_ESP8266
}
#endif
#elif GTEST_OS_QURT
#elif defined(GTEST_OS_QURT)
// QuRT: program entry point is main, but argc/argv are unusable.
GTEST_API_ int main() {
......
......@@ -39,7 +39,7 @@
#include "gtest/gtest.h"
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
#include <stdlib.h>
#include <windows.h>
#endif
......@@ -49,7 +49,7 @@ namespace {
// A test that's expected to fail.
TEST(Foo, Bar) { EXPECT_EQ(2, 3); }
#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE
#if GTEST_HAS_SEH && !defined(GTEST_OS_WINDOWS_MOBILE)
// On Windows Mobile global exception handlers are not supported.
LONG WINAPI
ExitWithExceptionCode(struct _EXCEPTION_POINTERS* exception_pointers) {
......@@ -60,12 +60,12 @@ ExitWithExceptionCode(struct _EXCEPTION_POINTERS* exception_pointers) {
} // namespace
int main(int argc, char** argv) {
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
// Suppresses display of the Windows error dialog upon encountering
// a general protection fault (segment violation).
SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE
#if GTEST_HAS_SEH && !defined(GTEST_OS_WINDOWS_MOBILE)
// The default unhandled exception filter does not always exit
// with the exception code as exit code - for example it exits with
......
......@@ -37,9 +37,9 @@
using testing::internal::AlwaysFalse;
using testing::internal::AlwaysTrue;
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
#include <direct.h> // For chdir().
#include <fcntl.h> // For O_BINARY
#include <io.h>
......@@ -52,7 +52,10 @@ using testing::internal::AlwaysTrue;
#include <signal.h>
#include <stdio.h>
#if GTEST_OS_LINUX
#include <string>
#include <vector>
#ifdef GTEST_OS_LINUX
#include <sys/time.h>
#endif // GTEST_OS_LINUX
......@@ -200,7 +203,7 @@ int DieInDebugElse12(int* sideeffect) {
return 12;
}
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
// Death in dbg due to Windows CRT assertion failure, not opt.
int DieInCRTDebugElse12(int* sideeffect) {
......@@ -220,7 +223,7 @@ int DieInCRTDebugElse12(int* sideeffect) {
#endif // GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
// Tests the ExitedWithCode predicate.
TEST(ExitStatusPredicateTest, ExitedWithCode) {
......@@ -374,7 +377,7 @@ TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
ASSERT_DEATH(_exit(1), "");
}
#if GTEST_OS_LINUX
#ifdef GTEST_OS_LINUX
void SigprofAction(int, siginfo_t*, void*) { /* no op */
}
......@@ -641,7 +644,7 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
#endif
}
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode
// In debug mode, the calls to _CrtSetReportMode and _CrtSetReportFile enable
......@@ -693,7 +696,7 @@ void ExpectDebugDeathHelper(bool* aborted) {
*aborted = false;
}
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
printf(
"This test should be considered failing if it shows "
......@@ -805,14 +808,14 @@ static void TestExitMacros() {
EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), "");
ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42), "");
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
// Of all signals effects on the process exit code, only those of SIGABRT
// are documented on Windows.
// See https://msdn.microsoft.com/en-us/query-bi/m/dwwzkt4c.
EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3), "") << "b_ar";
#elif !GTEST_OS_FUCHSIA
#elif !defined(GTEST_OS_FUCHSIA)
// Fuchsia has no unix signals.
EXPECT_EXIT(raise(SIGKILL), testing::KilledBySignal(SIGKILL), "") << "foo";
......@@ -1177,7 +1180,7 @@ TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
EXPECT_STREQ("", GetLastErrnoDescription().c_str());
}
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
TEST(AutoHandleTest, AutoHandleWorks) {
HANDLE handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
......@@ -1204,7 +1207,7 @@ TEST(AutoHandleTest, AutoHandleWorks) {
}
#endif // GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
typedef unsigned __int64 BiggestParsable;
typedef signed __int64 BiggestSignedParsable;
#else
......@@ -1301,7 +1304,7 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
EXPECT_EQ(123, char_result);
}
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
TEST(EnvironmentTest, HandleFitsIntoSizeT) {
ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t));
}
......@@ -1353,7 +1356,7 @@ void DieWithMessage(const char* message) {
TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
// googletest tests this, of course; here we ensure that including googlemock
// has not broken it.
#if GTEST_USES_POSIX_RE
#ifdef GTEST_USES_POSIX_RE
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e");
#else
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I di?e");
......
......@@ -33,7 +33,7 @@
#include "gtest/gtest-death-test.h"
#include "gtest/gtest.h"
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
#if GTEST_HAS_SEH
#include <windows.h> // For RaiseException().
......
......@@ -41,9 +41,9 @@
#include "gtest/internal/gtest-filepath.h"
#include "src/gtest-internal-inl.h"
#if GTEST_OS_WINDOWS_MOBILE
#ifdef GTEST_OS_WINDOWS_MOBILE
#include <windows.h> // NOLINT
#elif GTEST_OS_WINDOWS
#elif defined(GTEST_OS_WINDOWS)
#include <direct.h> // NOLINT
#endif // GTEST_OS_WINDOWS_MOBILE
......@@ -51,7 +51,7 @@ namespace testing {
namespace internal {
namespace {
#if GTEST_OS_WINDOWS_MOBILE
#ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have the remove C function.
int remove(const char* path) {
......@@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
const FilePath cwd = FilePath::GetCurrentDir();
posix::ChDir(original_dir.c_str());
#if GTEST_OS_WINDOWS || GTEST_OS_OS2
#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2)
// Skips the ":".
const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
......@@ -174,7 +174,7 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
// RemoveFileName "" -> "./"
TEST(RemoveFileNameTest, EmptyName) {
#if GTEST_OS_WINDOWS_MOBILE
#ifdef GTEST_OS_WINDOWS_MOBILE
// On Windows CE, we use the root as the current directory.
EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
#else
......@@ -357,7 +357,7 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
}
TEST(DirectoryTest, RootDirectoryExists) {
#if GTEST_OS_WINDOWS // We are on Windows.
#ifdef GTEST_OS_WINDOWS // We are on Windows.
char current_drive[_MAX_PATH]; // NOLINT
current_drive[0] = static_cast<char>(_getdrive() + 'A' - 1);
current_drive[1] = ':';
......@@ -369,7 +369,7 @@ TEST(DirectoryTest, RootDirectoryExists) {
#endif // GTEST_OS_WINDOWS
}
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
const int saved_drive_ = _getdrive();
// Find a drive that doesn't exist. Start with 'Z' to avoid common ones.
......@@ -387,7 +387,7 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
}
#endif // GTEST_OS_WINDOWS
#if !GTEST_OS_WINDOWS_MOBILE
#ifndef GTEST_OS_WINDOWS_MOBILE
// Windows CE _does_ consider an empty directory to exist.
TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
EXPECT_FALSE(FilePath("").DirectoryExists());
......@@ -395,7 +395,7 @@ TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
#endif // !GTEST_OS_WINDOWS_MOBILE
TEST(DirectoryTest, CurrentDirectoryExists) {
#if GTEST_OS_WINDOWS // We are on Windows.
#ifdef GTEST_OS_WINDOWS // We are on Windows.
#ifndef _WIN32_CE // Windows CE doesn't have a current directory.
EXPECT_TRUE(FilePath(".").DirectoryExists());
......@@ -423,7 +423,7 @@ TEST(NormalizeTest, MultipleConsecutiveSeparatorsInMidstring) {
// "/bar" == //bar" == "///bar"
TEST(NormalizeTest, MultipleConsecutiveSeparatorsAtStringStart) {
EXPECT_EQ(GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ "bar").string());
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
EXPECT_EQ(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar",
FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
#else
......@@ -515,7 +515,7 @@ class DirectoryCreationTest : public Test {
}
// Strings representing a directory and a file, with identical paths
// except for the trailing separator character that distinquishes
// except for the trailing separator character that distinguishes
// a directory named 'test' from a file named 'test'. Example names:
FilePath testdata_path_; // "/tmp/directory_creation/test/"
FilePath testdata_file_; // "/tmp/directory_creation/test"
......@@ -620,7 +620,7 @@ TEST(FilePathTest, IsDirectory) {
TEST(FilePathTest, IsAbsolutePath) {
EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath());
EXPECT_FALSE(FilePath("").IsAbsolutePath());
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
EXPECT_TRUE(
FilePath("c:\\" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative")
.IsAbsolutePath());
......@@ -638,7 +638,7 @@ TEST(FilePathTest, IsAbsolutePath) {
}
TEST(FilePathTest, IsRootDirectory) {
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
EXPECT_TRUE(FilePath("a:\\").IsRootDirectory());
EXPECT_TRUE(FilePath("Z:/").IsRootDirectory());
EXPECT_TRUE(FilePath("e://").IsRootDirectory());
......
......@@ -88,20 +88,20 @@ EXPECTED_2 = {
'time': '*',
'timestamp': '*',
'testsuite': [{
'name': 'TestInt64Properties',
'name': 'TestInt64ConvertibleProperties',
'file': 'gtest_xml_outfile2_test_.cc',
'line': 41,
'line': 43,
'status': 'RUN',
'result': 'COMPLETED',
'timestamp': '*',
'time': '*',
'classname': 'PropertyTwo',
'SetUpProp': '2',
'TestFloatProperty': '3',
'TestDoubleProperty': '4',
'TestFloatProperty': '3.25',
'TestDoubleProperty': '4.75',
'TestSizetProperty': '5',
'TestBoolProperty': '1',
'TestCharProperty': '65',
'TestBoolProperty': 'true',
'TestCharProperty': 'A',
'TestInt16Property': '6',
'TestInt32Property': '7',
'TestInt64Property': '8',
......
......@@ -54,7 +54,7 @@ SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv
if SUPPORTS_STACK_TRACES:
STACK_TRACE_TEMPLATE = '\nStack trace:\n*'
else:
STACK_TRACE_TEMPLATE = ''
STACK_TRACE_TEMPLATE = '\n'
EXPECTED_NON_EMPTY = {
'tests': 26,
......@@ -77,7 +77,7 @@ EXPECTED_NON_EMPTY = {
'testsuite': [{
'name': 'Succeeds',
'file': 'gtest_xml_output_unittest_.cc',
'line': 51,
'line': 53,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -96,7 +96,7 @@ EXPECTED_NON_EMPTY = {
'testsuite': [{
'name': 'Fails',
'file': 'gtest_xml_output_unittest_.cc',
'line': 59,
'line': 61,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -124,7 +124,7 @@ EXPECTED_NON_EMPTY = {
'testsuite': [{
'name': 'DISABLED_test_not_run',
'file': 'gtest_xml_output_unittest_.cc',
'line': 66,
'line': 68,
'status': 'NOTRUN',
'result': 'SUPPRESSED',
'time': '*',
......@@ -144,7 +144,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'Skipped',
'file': 'gtest_xml_output_unittest_.cc',
'line': 73,
'line': 75,
'status': 'RUN',
'result': 'SKIPPED',
'time': '*',
......@@ -154,7 +154,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'SkippedWithMessage',
'file': 'gtest_xml_output_unittest_.cc',
'line': 77,
'line': 79,
'status': 'RUN',
'result': 'SKIPPED',
'time': '*',
......@@ -164,7 +164,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'SkippedAfterFailure',
'file': 'gtest_xml_output_unittest_.cc',
'line': 81,
'line': 83,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -194,7 +194,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'Succeeds',
'file': 'gtest_xml_output_unittest_.cc',
'line': 86,
'line': 88,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -204,7 +204,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'Fails',
'file': 'gtest_xml_output_unittest_.cc',
'line': 91,
'line': 93,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -234,7 +234,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'DISABLED_test',
'file': 'gtest_xml_output_unittest_.cc',
'line': 96,
'line': 98,
'status': 'NOTRUN',
'result': 'SUPPRESSED',
'time': '*',
......@@ -254,7 +254,7 @@ EXPECTED_NON_EMPTY = {
'testsuite': [{
'name': 'OutputsCData',
'file': 'gtest_xml_output_unittest_.cc',
'line': 100,
'line': 102,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -282,7 +282,7 @@ EXPECTED_NON_EMPTY = {
'testsuite': [{
'name': 'InvalidCharactersInMessage',
'file': 'gtest_xml_output_unittest_.cc',
'line': 107,
'line': 109,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -313,7 +313,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'OneProperty',
'file': 'gtest_xml_output_unittest_.cc',
'line': 119,
'line': 121,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -324,7 +324,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'IntValuedProperty',
'file': 'gtest_xml_output_unittest_.cc',
'line': 123,
'line': 125,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -335,7 +335,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'ThreeProperties',
'file': 'gtest_xml_output_unittest_.cc',
'line': 127,
'line': 129,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -348,7 +348,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'TwoValuesForOneKeyUsesLastValue',
'file': 'gtest_xml_output_unittest_.cc',
'line': 133,
'line': 135,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -370,7 +370,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'RecordProperty',
'file': 'gtest_xml_output_unittest_.cc',
'line': 138,
'line': 140,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -381,7 +381,7 @@ EXPECTED_NON_EMPTY = {
{
'name': 'ExternalUtilityThatCallsRecordIntValuedProperty',
'file': 'gtest_xml_output_unittest_.cc',
'line': 151,
'line': 153,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -394,7 +394,7 @@ EXPECTED_NON_EMPTY = {
'ExternalUtilityThatCallsRecordStringValuedProperty'
),
'file': 'gtest_xml_output_unittest_.cc',
'line': 155,
'line': 157,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -416,7 +416,7 @@ EXPECTED_NON_EMPTY = {
'name': 'HasTypeParamAttribute',
'type_param': 'int',
'file': 'gtest_xml_output_unittest_.cc',
'line': 171,
'line': 173,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -436,7 +436,7 @@ EXPECTED_NON_EMPTY = {
'name': 'HasTypeParamAttribute',
'type_param': 'long',
'file': 'gtest_xml_output_unittest_.cc',
'line': 171,
'line': 173,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -456,7 +456,7 @@ EXPECTED_NON_EMPTY = {
'name': 'HasTypeParamAttribute',
'type_param': 'int',
'file': 'gtest_xml_output_unittest_.cc',
'line': 178,
'line': 180,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -476,7 +476,7 @@ EXPECTED_NON_EMPTY = {
'name': 'HasTypeParamAttribute',
'type_param': 'long',
'file': 'gtest_xml_output_unittest_.cc',
'line': 178,
'line': 180,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -497,7 +497,7 @@ EXPECTED_NON_EMPTY = {
'name': 'HasValueParamAttribute/0',
'value_param': '33',
'file': 'gtest_xml_output_unittest_.cc',
'line': 162,
'line': 164,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -508,7 +508,7 @@ EXPECTED_NON_EMPTY = {
'name': 'HasValueParamAttribute/1',
'value_param': '42',
'file': 'gtest_xml_output_unittest_.cc',
'line': 162,
'line': 164,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -519,7 +519,7 @@ EXPECTED_NON_EMPTY = {
'name': 'AnotherTestThatHasValueParamAttribute/0',
'value_param': '33',
'file': 'gtest_xml_output_unittest_.cc',
'line': 163,
'line': 165,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -530,7 +530,7 @@ EXPECTED_NON_EMPTY = {
'name': 'AnotherTestThatHasValueParamAttribute/1',
'value_param': '42',
'file': 'gtest_xml_output_unittest_.cc',
'line': 163,
'line': 165,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......@@ -562,7 +562,7 @@ EXPECTED_FILTERED = {
'testsuite': [{
'name': 'Succeeds',
'file': 'gtest_xml_output_unittest_.cc',
'line': 51,
'line': 53,
'status': 'RUN',
'result': 'COMPLETED',
'time': '*',
......
......@@ -36,6 +36,9 @@
// This program will be invoked from a Python unit test.
// Don't run it directly.
#include <ostream>
#include <string>
#include "gtest/gtest.h"
// Several different test cases and tests that will be listed.
......
......@@ -32,19 +32,14 @@
// This file verifies Google Test event listeners receive events at the
// right times.
#include <string>
#include <vector>
#include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h"
using ::testing::AddGlobalTestEnvironment;
using ::testing::Environment;
using ::testing::InitGoogleTest;
using ::testing::Test;
using ::testing::TestEventListener;
using ::testing::TestInfo;
using ::testing::TestPartResult;
using ::testing::TestSuite;
using ::testing::UnitTest;
// Used by tests to register their events.
......@@ -278,7 +273,7 @@ int main(int argc, char** argv) {
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
GTEST_CHECK_(events.size() == 0)
GTEST_CHECK_(events.empty())
<< "AddGlobalTestEnvironment should not generate any events itself.";
GTEST_FLAG_SET(repeat, 2);
......
......@@ -40,11 +40,11 @@
#include "gtest/gtest.h"
#if GTEST_OS_WINDOWS_MOBILE
#ifdef GTEST_OS_WINDOWS_MOBILE
#include <windows.h>
#elif GTEST_OS_WINDOWS
#elif defined(GTEST_OS_WINDOWS)
#include <direct.h>
#elif GTEST_OS_OS2
#elif defined(GTEST_OS_OS2)
// For strcasecmp on OS/2
#include <strings.h>
#endif // GTEST_OS_WINDOWS_MOBILE
......@@ -92,7 +92,7 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
.string();
const std::string& output_file =
UnitTestOptions::GetAbsolutePathToOutputFile();
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
#else
EXPECT_EQ(expected_output_file, output_file.c_str());
......@@ -101,19 +101,19 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
const std::string exe_str = GetCurrentExecutableName().string();
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
const bool success =
_strcmpi("googletest-options-test", exe_str.c_str()) == 0 ||
_strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
_strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
_strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
#elif GTEST_OS_OS2
#elif defined(GTEST_OS_OS2)
const bool success =
strcasecmp("googletest-options-test", exe_str.c_str()) == 0 ||
strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 ||
strcasecmp("gtest_all_test", exe_str.c_str()) == 0 ||
strcasecmp("gtest_dll_test", exe_str.c_str()) == 0;
#elif GTEST_OS_FUCHSIA
#elif defined(GTEST_OS_FUCHSIA)
const bool success = exe_str == "app";
#else
const bool success =
......@@ -123,7 +123,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
if (!success) FAIL() << "GetCurrentExecutableName() returns " << exe_str;
}
#if !GTEST_OS_FUCHSIA
#ifndef GTEST_OS_FUCHSIA
class XmlOutputChangeDirTest : public Test {
protected:
......@@ -176,7 +176,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
.string();
const std::string& output_file =
UnitTestOptions::GetAbsolutePathToOutputFile();
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
#else
EXPECT_EQ(expected_output_file, output_file.c_str());
......@@ -184,7 +184,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
}
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
GTEST_FLAG_SET(output, "xml:c:\\tmp\\filename.abc");
EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
......@@ -196,7 +196,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
}
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
const std::string path = "c:\\tmp\\";
#else
const std::string path = "/tmp/";
......@@ -208,7 +208,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
const std::string& output_file =
UnitTestOptions::GetAbsolutePathToOutputFile();
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
#else
EXPECT_EQ(expected_output_file, output_file.c_str());
......
......@@ -132,7 +132,7 @@ def RemoveStackTraces(output):
"""Removes all traces of stack traces from a Google Test program's output."""
# *? means "find the shortest string that matches".
return re.sub(r'Stack trace:(.|\n)*?\n\n', '', output)
return re.sub(r'Stack trace:(.|\n)*?\n', '', output)
def RemoveTime(output):
......
......@@ -35,13 +35,16 @@
#include <stdlib.h>
#include <algorithm>
#include <string>
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h"
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */)
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
using testing::ScopedFakeTestPartResultReporter;
using testing::TestPartResultArray;
......@@ -247,7 +250,7 @@ TEST(SCOPED_TRACETest, CanBeRepeated) {
<< "contain trace point A, B, and D.";
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
// Tests that SCOPED_TRACE()s can be used concurrently from multiple
// threads. Namely, an assertion should be affected by
// SCOPED_TRACE()s in its own thread only.
......@@ -773,7 +776,7 @@ REGISTER_TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest, Used);
// typedef ::testing::Types<char, int, unsigned int> MyTypes;
// INSTANTIATE_TYPED_TEST_SUITE_P(All, DetectNotInstantiatedTypesTest, MyTypes);
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// We rely on the golden file to verify that tests whose test case
// name ends with DeathTest are run first.
......@@ -851,7 +854,7 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailure) {
"failure.");
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
class ExpectFailureWithThreadsTest : public ExpectFailureTest {
protected:
......@@ -1024,11 +1027,11 @@ int main(int argc, char** argv) {
std::count(argv, argv + argc,
std::string("internal_skip_environment_and_ad_hoc_tests")) > 0;
#if GTEST_HAS_DEATH_TEST
if (GTEST_FLAG_GET(internal_run_death_test) != "") {
#ifdef GTEST_HAS_DEATH_TEST
if (!GTEST_FLAG_GET(internal_run_death_test).empty()) {
// Skip the usual output capturing if we're running as the child
// process of an threadsafe-style death test.
#if GTEST_OS_WINDOWS
#if defined(GTEST_OS_WINDOWS)
posix::FReopen("nul:", "w", stdout);
#else
posix::FReopen("/dev/null", "w", stdout);
......
......@@ -27,6 +27,8 @@
// (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 <string>
#include "gtest/gtest.h"
namespace {
......
......@@ -221,7 +221,7 @@ class DogAdder {
}
DogAdder operator+(const DogAdder& other) const {
Message msg;
msg << value_.c_str() << other.value_.c_str();
msg << value_ << other.value_;
return DogAdder(msg.GetString().c_str());
}
bool operator<(const DogAdder& other) const { return value_ < other.value_; }
......
......@@ -32,7 +32,7 @@
#include "gtest/internal/gtest-port.h"
#if GTEST_OS_MAC
#ifdef GTEST_OS_MAC
#include <time.h>
#endif // GTEST_OS_MAC
......@@ -97,7 +97,7 @@ class Base {
explicit Base(int n) : member_(n) {}
Base(const Base&) = default;
Base& operator=(const Base&) = default;
virtual ~Base() {}
virtual ~Base() = default;
int member() { return member_; }
private:
......@@ -281,9 +281,11 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) {
EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1));
}
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA || \
GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \
GTEST_OS_NETBSD || GTEST_OS_OPENBSD || GTEST_OS_GNU_HURD
#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \
defined(GTEST_OS_QNX) || defined(GTEST_OS_FUCHSIA) || \
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \
defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_GNU_HURD)
void* ThreadFunc(void* data) {
internal::Mutex* mutex = static_cast<internal::Mutex*>(data);
mutex->Lock();
......@@ -359,7 +361,7 @@ TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) {
const char regex[] =
#ifdef _MSC_VER
"googletest-port-test\\.cc\\(\\d+\\):"
#elif GTEST_USES_POSIX_RE
#elif defined(GTEST_USES_POSIX_RE)
"googletest-port-test\\.cc:[0-9]+"
#else
"googletest-port-test\\.cc:\\d+"
......@@ -370,7 +372,7 @@ TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) {
regex);
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) {
EXPECT_EXIT(
......@@ -388,7 +390,7 @@ TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) {
// the platform. The test will produce compiler errors in case of failure.
// For simplicity, we only cover the most important platforms here.
TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
EXPECT_TRUE(GTEST_USES_RE2);
#elif GTEST_HAS_POSIX_RE
EXPECT_TRUE(GTEST_USES_POSIX_RE);
......@@ -397,7 +399,7 @@ TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
#endif
}
#if GTEST_USES_POSIX_RE
#ifdef GTEST_USES_POSIX_RE
template <typename Str>
class RETest : public ::testing::Test {};
......@@ -454,7 +456,7 @@ TYPED_TEST(RETest, PartialMatchWorks) {
EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re));
}
#elif GTEST_USES_SIMPLE_RE
#elif defined(GTEST_USES_SIMPLE_RE)
TEST(IsInSetTest, NulCharIsNotInAnySet) {
EXPECT_FALSE(IsInSet('\0', ""));
......@@ -916,7 +918,7 @@ TEST(RETest, PartialMatchWorks) {
#endif // GTEST_USES_POSIX_RE
#if !GTEST_OS_WINDOWS_MOBILE
#ifndef GTEST_OS_WINDOWS_MOBILE
TEST(CaptureTest, CapturesStdout) {
CaptureStdout();
......@@ -977,14 +979,14 @@ TEST(ThreadLocalTest, SingleParamConstructorInitializesToParam) {
EXPECT_EQ(&i, t2.get());
}
class NoDefaultContructor {
class NoDefaultConstructor {
public:
explicit NoDefaultContructor(const char*) {}
NoDefaultContructor(const NoDefaultContructor&) {}
explicit NoDefaultConstructor(const char*) {}
NoDefaultConstructor(const NoDefaultConstructor&) = default;
};
TEST(ThreadLocalTest, ValueDefaultContructorIsNotRequiredForParamVersion) {
ThreadLocal<NoDefaultContructor> bar(NoDefaultContructor("foo"));
ThreadLocal<NoDefaultConstructor> bar(NoDefaultConstructor("foo"));
bar.pointer();
}
......@@ -1009,7 +1011,7 @@ TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) {
EXPECT_EQ(thread_local_string.pointer(), const_thread_local_string.pointer());
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
void AddTwo(int* param) { *param += 2; }
......@@ -1064,7 +1066,7 @@ class AtomicCounterWithMutex {
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex));
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex));
#elif GTEST_OS_WINDOWS
#elif defined(GTEST_OS_WINDOWS)
// On Windows, performing an interlocked access puts up a memory barrier.
volatile LONG dummy = 0;
::InterlockedIncrement(&dummy);
......@@ -1102,9 +1104,9 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) {
// Creates and runs kThreadCount threads that increment locked_counter
// kCycleCount times each.
for (int i = 0; i < kThreadCount; ++i) {
counting_threads[i].reset(new ThreadType(
counting_threads[i] = std::make_unique<ThreadType>(
&CountingThreadFunc, make_pair(&locked_counter, kCycleCount),
&threads_can_start));
&threads_can_start);
}
threads_can_start.Notify();
for (int i = 0; i < kThreadCount; ++i) counting_threads[i]->Join();
......@@ -1146,14 +1148,14 @@ class DestructorCall {
public:
DestructorCall() {
invoked_ = false;
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
wait_event_.Reset(::CreateEvent(NULL, TRUE, FALSE, NULL));
GTEST_CHECK_(wait_event_.Get() != NULL);
#endif
}
bool CheckDestroyed() const {
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
if (::WaitForSingleObject(wait_event_.Get(), 1000) != WAIT_OBJECT_0)
return false;
#endif
......@@ -1162,7 +1164,7 @@ class DestructorCall {
void ReportDestroyed() {
invoked_ = true;
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
::SetEvent(wait_event_.Get());
#endif
}
......@@ -1178,7 +1180,7 @@ class DestructorCall {
private:
bool invoked_;
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
AutoHandle wait_event_;
#endif
static std::vector<DestructorCall*>* const list_;
......@@ -1278,12 +1280,12 @@ TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) {
#endif // GTEST_IS_THREADSAFE
#if GTEST_OS_WINDOWS
#ifdef GTEST_OS_WINDOWS
TEST(WindowsTypesTest, HANDLEIsVoidStar) {
StaticAssertTypeEq<HANDLE, void*>();
}
#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR)
#if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR)
TEST(WindowsTypesTest, _CRITICAL_SECTIONIs_CRITICAL_SECTION) {
StaticAssertTypeEq<CRITICAL_SECTION, _CRITICAL_SECTION>();
}
......
......@@ -42,9 +42,11 @@
#include <list>
#include <map>
#include <memory>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
......@@ -106,7 +108,7 @@ class UnprintableTemplateInGlobal {
// A user-defined streamable type in the global namespace.
class StreamableInGlobal {
public:
virtual ~StreamableInGlobal() {}
virtual ~StreamableInGlobal() = default;
};
inline void operator<<(::std::ostream& os, const StreamableInGlobal& /* x */) {
......@@ -214,7 +216,7 @@ class PathLike {
using value_type = char;
using const_iterator = iterator;
PathLike() {}
PathLike() = default;
iterator begin() const { return iterator(); }
iterator end() const { return iterator(); }
......@@ -266,7 +268,6 @@ using ::std::set;
using ::std::vector;
using ::testing::PrintToString;
using ::testing::internal::FormatForComparisonFailureMessage;
using ::testing::internal::ImplicitCast_;
using ::testing::internal::NativeArray;
using ::testing::internal::RelationToSourceReference;
using ::testing::internal::Strings;
......@@ -360,7 +361,7 @@ TEST(PrintCharTest, Char16) { EXPECT_EQ("U+0041", Print(u'A')); }
TEST(PrintCharTest, Char32) { EXPECT_EQ("U+0041", Print(U'A')); }
#ifdef __cpp_char8_t
#ifdef __cpp_lib_char8_t
TEST(PrintCharTest, Char8) { EXPECT_EQ("U+0041", Print(u8'A')); }
#endif
......@@ -413,7 +414,7 @@ TEST(PrintBuiltInTypeTest, Integer) {
Print(std::numeric_limits<uint64_t>::max())); // uint64
EXPECT_EQ("-9223372036854775808",
Print(std::numeric_limits<int64_t>::min())); // int64
#ifdef __cpp_char8_t
#ifdef __cpp_lib_char8_t
EXPECT_EQ("U+0000",
Print(std::numeric_limits<char8_t>::min())); // char8_t
EXPECT_EQ("U+00FF",
......@@ -432,7 +433,7 @@ TEST(PrintBuiltInTypeTest, Integer) {
// Size types.
TEST(PrintBuiltInTypeTest, Size_t) {
EXPECT_EQ("1", Print(sizeof('a'))); // size_t.
#if !GTEST_OS_WINDOWS
#ifndef GTEST_OS_WINDOWS
// Windows has no ssize_t type.
EXPECT_EQ("-2", Print(static_cast<ssize_t>(-2))); // ssize_t.
#endif // !GTEST_OS_WINDOWS
......@@ -519,7 +520,7 @@ TEST(PrintCStringTest, EscapesProperly) {
Print(p));
}
#ifdef __cpp_char8_t
#ifdef __cpp_lib_char8_t
// const char8_t*.
TEST(PrintU8StringTest, Const) {
const char8_t* p = u8"界";
......@@ -748,7 +749,7 @@ AssertionResult HasPrefix(const StringType& str, const StringType& prefix) {
struct Foo {
public:
virtual ~Foo() {}
virtual ~Foo() = default;
int MyMethod(char x) { return x + 1; }
virtual char MyVirtualMethod(int /* n */) { return 'a'; }
......@@ -816,7 +817,7 @@ TEST(PrintArrayTest, CharArrayWithTerminatingNul) {
EXPECT_EQ("\"\\0Hi\"", PrintArrayHelper(a));
}
#ifdef __cpp_char8_t
#ifdef __cpp_lib_char8_t
// char_t array without terminating NUL.
TEST(PrintArrayTest, Char8ArrayWithNoTerminatingNul) {
// Array a contains '\0' in the middle and doesn't end with '\0'.
......@@ -936,7 +937,7 @@ TEST(PrintWideStringTest, StringAmbiguousHex) {
}
#endif // GTEST_HAS_STD_WSTRING
#ifdef __cpp_char8_t
#ifdef __cpp_lib_char8_t
TEST(PrintStringTest, U8String) {
std::u8string str = u8"Hello, 世界";
EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type.
......@@ -1796,7 +1797,8 @@ TEST(UniversalPrintTest, SmartPointers) {
std::shared_ptr<int> p3(new int(1979));
EXPECT_EQ("(ptr = " + PrintPointer(p3.get()) + ", value = 1979)",
PrintToString(p3));
#if __cpp_lib_shared_ptr_arrays >= 201611L
#if defined(__cpp_lib_shared_ptr_arrays) && \
(__cpp_lib_shared_ptr_arrays >= 201611L)
std::shared_ptr<int[]> p4(new int[2]);
EXPECT_EQ("(" + PrintPointer(p4.get()) + ")", PrintToString(p4));
#endif
......@@ -1815,7 +1817,8 @@ TEST(UniversalPrintTest, SmartPointers) {
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile const int>()));
#if __cpp_lib_shared_ptr_arrays >= 201611L
#if defined(__cpp_lib_shared_ptr_arrays) && \
(__cpp_lib_shared_ptr_arrays >= 201611L)
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int[]>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int[]>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int[]>()));
......
......@@ -35,7 +35,6 @@ namespace {
using ::testing::EmptyTestEventListener;
using ::testing::InitGoogleTest;
using ::testing::Message;
using ::testing::Test;
using ::testing::TestEventListeners;
using ::testing::TestInfo;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment