diff options
Diffstat (limited to 'googletest/test')
27 files changed, 258 insertions, 238 deletions
diff --git a/googletest/test/googletest-break-on-failure-unittest_.cc b/googletest/test/googletest-break-on-failure-unittest_.cc index 324294f3..337e34c3 100644 --- a/googletest/test/googletest-break-on-failure-unittest_.cc +++ b/googletest/test/googletest-break-on-failure-unittest_.cc @@ -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 diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index 515b5998..4cc81b72 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -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"); diff --git a/googletest/test/googletest-death-test_ex_test.cc b/googletest/test/googletest-death-test_ex_test.cc index f2515e37..34d55013 100644 --- a/googletest/test/googletest-death-test_ex_test.cc +++ b/googletest/test/googletest-death-test_ex_test.cc @@ -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(). diff --git a/googletest/test/googletest-filepath-test.cc b/googletest/test/googletest-filepath-test.cc index 5f0c9c2f..3e9c79f0 100644 --- a/googletest/test/googletest-filepath-test.cc +++ b/googletest/test/googletest-filepath-test.cc @@ -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()); diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py index 83a56de1..5626004e 100644 --- a/googletest/test/googletest-json-outfiles-test.py +++ b/googletest/test/googletest-json-outfiles-test.py @@ -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', diff --git a/googletest/test/googletest-json-output-unittest.py b/googletest/test/googletest-json-output-unittest.py index b3a08deb..cb976945 100644 --- a/googletest/test/googletest-json-output-unittest.py +++ b/googletest/test/googletest-json-output-unittest.py @@ -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': '*', diff --git a/googletest/test/googletest-list-tests-unittest_.cc b/googletest/test/googletest-list-tests-unittest_.cc index 5577e896..a1ea6cf4 100644 --- a/googletest/test/googletest-list-tests-unittest_.cc +++ b/googletest/test/googletest-list-tests-unittest_.cc @@ -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. diff --git a/googletest/test/googletest-listener-test.cc b/googletest/test/googletest-listener-test.cc index 89d01b37..d7c47c21 100644 --- a/googletest/test/googletest-listener-test.cc +++ b/googletest/test/googletest-listener-test.cc @@ -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); diff --git a/googletest/test/googletest-options-test.cc b/googletest/test/googletest-options-test.cc index 87463209..b712c06f 100644 --- a/googletest/test/googletest-options-test.cc +++ b/googletest/test/googletest-options-test.cc @@ -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()); diff --git a/googletest/test/googletest-output-test.py b/googletest/test/googletest-output-test.py index 347b8546..6d80d532 100755 --- a/googletest/test/googletest-output-test.py +++ b/googletest/test/googletest-output-test.py @@ -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): diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index 1bace982..f1facf57 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -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); diff --git a/googletest/test/googletest-param-test-invalid-name2-test_.cc b/googletest/test/googletest-param-test-invalid-name2-test_.cc index d0c44da5..6d88a9ce 100644 --- a/googletest/test/googletest-param-test-invalid-name2-test_.cc +++ b/googletest/test/googletest-param-test-invalid-name2-test_.cc @@ -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 { diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index 63db2860..c9c5e78e 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -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_; } diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index bb536ac5..32a2a7b4 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -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>(); } diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index 34aa9245..f44f29a5 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -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[]>())); diff --git a/googletest/test/googletest-shuffle-test_.cc b/googletest/test/googletest-shuffle-test_.cc index a14e22f9..b570c488 100644 --- a/googletest/test/googletest-shuffle-test_.cc +++ b/googletest/test/googletest-shuffle-test_.cc @@ -35,7 +35,6 @@ namespace { using ::testing::EmptyTestEventListener; using ::testing::InitGoogleTest; -using ::testing::Message; using ::testing::Test; using ::testing::TestEventListeners; using ::testing::TestInfo; diff --git a/googletest/test/gtest_dirs_test.cc b/googletest/test/gtest_dirs_test.cc index c0da9ac4..1a5b63d3 100644 --- a/googletest/test/gtest_dirs_test.cc +++ b/googletest/test/gtest_dirs_test.cc @@ -7,6 +7,8 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-port.h" +#if GTEST_HAS_FILE_SYSTEM + namespace { class SetEnv { @@ -94,4 +96,6 @@ TEST(SrcDirTest, NotInEnvironment) { EXPECT_NE(testing::SrcDir(), ""); } +#endif // GTEST_HAS_FILE_SYSTEM + } // namespace diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index fda40bff..85a0c33c 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -43,6 +43,7 @@ import sys from googletest.test import gtest_test_utils +IS_DARWIN = os.name == 'posix' and os.uname()[0] == 'Darwin' IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' IS_GNUHURD = os.name == 'posix' and os.uname()[0] == 'GNU' IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD' @@ -53,7 +54,6 @@ PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') FLAG_PREFIX = '--gtest_' DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style' STREAM_RESULT_TO_FLAG = FLAG_PREFIX + 'stream_result_to' -UNKNOWN_GTEST_PREFIXED_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing' LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests' INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing' @@ -136,7 +136,7 @@ class GTestHelpTest(gtest_test_utils.TestCase): self.assertTrue(HELP_REGEX.search(output), output) - if IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD or IS_OPENBSD: + if IS_DARWIN or IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD or IS_OPENBSD: self.assertIn(STREAM_RESULT_TO_FLAG, output) else: self.assertNotIn(STREAM_RESULT_TO_FLAG, output) @@ -176,16 +176,6 @@ class GTestHelpTest(gtest_test_utils.TestCase): def testPrintsHelpWithFullFlag(self): self.TestHelpFlag('--help') - def testPrintsHelpWithUnrecognizedGoogleTestFlag(self): - # The behavior is slightly different when Abseil flags is - # used. Abseil flags rejects all unknown flags, while the builtin - # GTest flags implementation interprets an unknown flag with a - # '--gtest_' prefix as a request for help. - if HAS_ABSL_FLAGS: - self.TestUnknownFlagWithAbseil(UNKNOWN_GTEST_PREFIXED_FLAG) - else: - self.TestHelpFlag(UNKNOWN_GTEST_PREFIXED_FLAG) - def testRunsTestsWithoutHelpFlag(self): """Verifies correct behavior when no help flag is specified. diff --git a/googletest/test/gtest_help_test_.cc b/googletest/test/gtest_help_test_.cc index da289f05..18b5f3cd 100644 --- a/googletest/test/gtest_help_test_.cc +++ b/googletest/test/gtest_help_test_.cc @@ -39,6 +39,6 @@ TEST(HelpFlagTest, ShouldNotBeRun) { ASSERT_TRUE(false) << "Tests shouldn't be run when --help is specified."; } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST TEST(DeathTest, UsedByPythonScriptToDetectSupportForDeathTestsInThisBinary) {} #endif diff --git a/googletest/test/gtest_repeat_test.cc b/googletest/test/gtest_repeat_test.cc index 73fb8dc9..f67b7886 100644 --- a/googletest/test/gtest_repeat_test.cc +++ b/googletest/test/gtest_repeat_test.cc @@ -61,7 +61,7 @@ int g_environment_tear_down_count = 0; class MyEnvironment : public testing::Environment { public: - MyEnvironment() {} + MyEnvironment() = default; void SetUp() override { g_environment_set_up_count++; } void TearDown() override { g_environment_tear_down_count++; } }; diff --git a/googletest/test/gtest_stress_test.cc b/googletest/test/gtest_stress_test.cc index 24b173ff..af8e757d 100644 --- a/googletest/test/gtest_stress_test.cc +++ b/googletest/test/gtest_stress_test.cc @@ -30,12 +30,15 @@ // Tests that SCOPED_TRACE() and various Google Test assertions can be // used in a large number of threads concurrently. +#include <algorithm> +#include <memory> +#include <string> #include <vector> #include "gtest/gtest.h" #include "src/gtest-internal-inl.h" -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE namespace testing { namespace { @@ -118,8 +121,8 @@ TEST(StressTest, CanUseScopedTraceAndAssertionsInManyThreads) { std::unique_ptr<ThreadWithParam<int> > threads[kThreadCount]; Notification threads_can_start; for (int i = 0; i != kThreadCount; i++) - threads[i].reset( - new ThreadWithParam<int>(&ManyAsserts, i, &threads_can_start)); + threads[i] = std::make_unique<ThreadWithParam<int>>(&ManyAsserts, i, + &threads_can_start); threads_can_start.Notify(); diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 180c3abe..eac35407 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -60,8 +60,10 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include <cstdint> #include <map> +#include <memory> #include <ostream> #include <set> +#include <stdexcept> #include <string> #include <type_traits> #include <unordered_set> @@ -210,7 +212,6 @@ using testing::TestPartResult; using testing::TestPartResultArray; using testing::TestProperty; using testing::TestResult; -using testing::TestSuite; using testing::TimeInMillis; using testing::UnitTest; using testing::internal::AlwaysFalse; @@ -226,7 +227,6 @@ using testing::internal::FloatingPoint; using testing::internal::ForEach; using testing::internal::FormatEpochTimeInMillisAsIso8601; using testing::internal::FormatTimeInMillisAsSeconds; -using testing::internal::GetCurrentOsStackTraceExceptTop; using testing::internal::GetElementOr; using testing::internal::GetNextRandomSeed; using testing::internal::GetRandomSeedFromFlag; @@ -243,8 +243,6 @@ using testing::internal::IsNotContainer; using testing::internal::kMaxRandomSeed; using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::NativeArray; -using testing::internal::OsStackTraceGetter; -using testing::internal::OsStackTraceGetterInterface; using testing::internal::ParseFlag; using testing::internal::RelationToSourceCopy; using testing::internal::RelationToSourceReference; @@ -258,7 +256,6 @@ using testing::internal::StreamableToString; using testing::internal::String; using testing::internal::TestEventListenersAccessor; using testing::internal::TestResultAccessor; -using testing::internal::UnitTestImpl; using testing::internal::WideStringToUtf8; using testing::internal::edit_distance::CalculateOptimalEdits; using testing::internal::edit_distance::CreateUnifiedDiff; @@ -269,7 +266,7 @@ using testing::internal::CaptureStdout; using testing::internal::GetCapturedStdout; #endif -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE using testing::internal::ThreadWithParam; #endif @@ -424,10 +421,12 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { private: void SetUp() override { - saved_tz_ = nullptr; + saved_tz_.reset(); - GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */) - if (getenv("TZ")) saved_tz_ = strdup(getenv("TZ")); + GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv: deprecated */) + if (const char* tz = getenv("TZ")) { + saved_tz_ = std::make_unique<std::string>(tz); + } GTEST_DISABLE_MSC_DEPRECATED_POP_() // Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We @@ -437,16 +436,15 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { } void TearDown() override { - SetTimeZone(saved_tz_); - free(const_cast<char*>(saved_tz_)); - saved_tz_ = nullptr; + SetTimeZone(saved_tz_ != nullptr ? saved_tz_->c_str() : nullptr); + saved_tz_.reset(); } static void SetTimeZone(const char* time_zone) { // tzset() distinguishes between the TZ variable being present and empty // and not being present, so we have to consider the case of time_zone // being NULL. -#if defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW +#if defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW) // ...Unless it's MSVC, whose standard library's _putenv doesn't // distinguish between an empty and a missing variable. const std::string env_var = @@ -456,7 +454,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { tzset(); GTEST_DISABLE_MSC_WARNINGS_POP_() #else -#if GTEST_OS_LINUX_ANDROID && __ANDROID_API__ < 21 +#if defined(GTEST_OS_LINUX_ANDROID) && __ANDROID_API__ < 21 // Work around KitKat bug in tzset by setting "UTC" before setting "UTC+00". // See https://github.com/android/ndk/issues/1604. setenv("TZ", "UTC", 1); @@ -471,7 +469,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { #endif } - const char* saved_tz_; + std::unique_ptr<std::string> saved_tz_; // Empty and null are different here }; const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec; @@ -1088,7 +1086,7 @@ TEST(StringTest, CaseInsensitiveWideCStringEquals) { EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"FOOBAR", L"foobar")); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests String::ShowWideCString(). TEST(StringTest, ShowWideCString) { @@ -1097,7 +1095,7 @@ TEST(StringTest, ShowWideCString) { EXPECT_STREQ("foo", String::ShowWideCString(L"foo").c_str()); } -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE TEST(StringTest, AnsiAndUtf16Null) { EXPECT_EQ(NULL, String::AnsiToUtf16(NULL)); EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL)); @@ -1187,7 +1185,7 @@ TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) { EXPECT_EQ(1, results.size()); } -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE class ScopedFakeTestPartResultReporterWithThreadsTest : public ScopedFakeTestPartResultReporterTest { @@ -1345,7 +1343,7 @@ TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) { ""); } -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE typedef ScopedFakeTestPartResultReporterWithThreadsTest ExpectFailureWithThreadsTest; @@ -1674,7 +1672,7 @@ TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { VerifyAndModifyFlags(); } // value. If the value argument is "", unsets the environment // variable. The caller must ensure that both arguments are not NULL. static void SetEnv(const char* name, const char* value) { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Environment variables are not supported on Windows CE. return; #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) @@ -1697,7 +1695,7 @@ static void SetEnv(const char* name, const char* value) { // We cast away the 'const' since that would work for both variants. putenv(const_cast<char*>(added_env[name]->c_str())); delete prev_env; -#elif GTEST_OS_WINDOWS // If we are on Windows proper. +#elif defined(GTEST_OS_WINDOWS) // If we are on Windows proper. _putenv((Message() << name << "=" << value).GetString().c_str()); #else if (*value == '\0') { @@ -1708,7 +1706,7 @@ static void SetEnv(const char* name, const char* value) { #endif // GTEST_OS_WINDOWS_MOBILE } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Environment variables are not supported on Windows CE. using testing::internal::Int32FromGTestEnv; @@ -1817,7 +1815,7 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) { // Tests that Int32FromEnvOrDie() parses the value of the var or // returns the correct default. // Environment variables are not supported on Windows CE. -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123"); @@ -1890,7 +1888,7 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) { // Tests that sharding is enabled if total_shards > 1 and // we are not in a death test subprocess. // Environment variables are not supported on Windows CE. -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { SetEnv(index_var_, "4"); SetEnv(total_var_, "22"); @@ -3920,7 +3918,7 @@ TEST(AssertionTest, NamedEnum) { enum { kCaseA = -1, -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX // We want to test the case where the size of the anonymous enum is // larger than sizeof(int), to make sure our implementation of the @@ -3943,7 +3941,7 @@ enum { }; TEST(AssertionTest, AnonymousEnum) { -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB)); @@ -3977,7 +3975,7 @@ TEST(AssertionTest, AnonymousEnum) { #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS static HRESULT UnexpectedHRESULTFailure() { return E_UNEXPECTED; } @@ -4337,7 +4335,7 @@ TEST(AssertionWithMessageTest, ASSERT_TRUE) { "(null)(null)"); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests using wide strings in assertion messages. TEST(AssertionWithMessageTest, WideStringMessage) { EXPECT_NONFATAL_FAILURE( @@ -4949,7 +4947,7 @@ TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) { // both in a TEST and in a TEST_F. class Foo { public: - Foo() {} + Foo() = default; private: int Bar() const { return 1; } @@ -6172,12 +6170,12 @@ TEST_F(ParseFlagsTest, FilterBad) { const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr}; -#if GTEST_HAS_ABSL && GTEST_HAS_DEATH_TEST +#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST) // Invalid flag arguments are a fatal error when using the Abseil Flags. EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true), testing::ExitedWithCode(1), "ERROR: Missing the value for the flag 'gtest_filter'"); -#elif !GTEST_HAS_ABSL +#elif !defined(GTEST_HAS_ABSL) GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true); #else static_cast<void>(argv); @@ -6191,12 +6189,12 @@ TEST_F(ParseFlagsTest, OutputEmpty) { const char* argv2[] = {"foo.exe", "--gtest_output", nullptr}; -#if GTEST_HAS_ABSL && GTEST_HAS_DEATH_TEST +#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST) // Invalid flag arguments are a fatal error when using the Abseil Flags. EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true), testing::ExitedWithCode(1), "ERROR: Missing the value for the flag 'gtest_output'"); -#elif !GTEST_HAS_ABSL +#elif !defined(GTEST_HAS_ABSL) GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true); #else static_cast<void>(argv); @@ -6204,7 +6202,7 @@ TEST_F(ParseFlagsTest, OutputEmpty) { #endif } -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL TEST_F(ParseFlagsTest, AbseilPositionalFlags) { const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=1", "--", "--other_flag", nullptr}; @@ -6218,7 +6216,16 @@ TEST_F(ParseFlagsTest, AbseilPositionalFlags) { } #endif -#if GTEST_OS_WINDOWS +TEST_F(ParseFlagsTest, UnrecognizedFlags) { + const char* argv[] = {"foo.exe", "--gtest_filter=abcd", "--other_flag", + nullptr}; + + const char* argv2[] = {"foo.exe", "--other_flag", nullptr}; + + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abcd"), false); +} + +#ifdef GTEST_OS_WINDOWS // Tests parsing wide strings. TEST_F(ParseFlagsTest, WideStrings) { const wchar_t* argv[] = {L"foo.exe", @@ -6608,7 +6615,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { GTEST_FLAG_SET(color, "auto"); -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) // On Windows, we ignore the TERM variable as it's usually not set. SetEnv("TERM", "dumb"); @@ -6974,7 +6981,7 @@ TEST(EventListenerTest, SuppressEventForwarding) { // Tests that events generated by Google Test are not forwarded in // death test subprocesses. -TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) { +TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprocesses) { EXPECT_DEATH_IF_SUPPORTED( { GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled( diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc index 5ee216df..4a76429c 100644 --- a/googletest/test/gtest_xml_outfile2_test_.cc +++ b/googletest/test/gtest_xml_outfile2_test_.cc @@ -30,6 +30,8 @@ // gtest_xml_outfile2_test_ writes some xml via TestProperty used by // gtest_xml_outfiles_test.py +#include <atomic> + #include "gtest/gtest.h" class PropertyTwo : public testing::Test { @@ -38,9 +40,7 @@ class PropertyTwo : public testing::Test { void TearDown() override { RecordProperty("TearDownProp", 2); } }; -TEST_F(PropertyTwo, TestInt64Properties) { - // Floats and doubles are written as int64_t, so we test that the values - // written are truncated to int64_t. +TEST_F(PropertyTwo, TestInt64ConvertibleProperties) { float float_prop = 3.25; RecordProperty("TestFloatProperty", float_prop); diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index 7ee0f3c8..d17cc0c9 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -57,14 +57,14 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?> EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?> <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests"> <testsuite name="PropertyTwo" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*"> - <testcase name="TestInt64Properties" file="gtest_xml_outfile2_test_.cc" line="41" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo"> + <testcase name="TestInt64ConvertibleProperties" file="gtest_xml_outfile2_test_.cc" line="43" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo"> <properties> <property name="SetUpProp" value="2"/> - <property name="TestFloatProperty" value="3"/> - <property name="TestDoubleProperty" value="4"/> + <property name="TestFloatProperty" value="3.25"/> + <property name="TestDoubleProperty" value="4.75"/> <property name="TestSizetProperty" value="5"/> - <property name="TestBoolProperty" value="1"/> - <property name="TestCharProperty" value="65"/> + <property name="TestBoolProperty" value="true"/> + <property name="TestCharProperty" value="A"/> <property name="TestInt16Property" value="6"/> <property name="TestInt32Property" value="7"/> <property name="TestInt64Property" value="8"/> diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 5ca11cb6..422569e4 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -59,135 +59,138 @@ SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv if SUPPORTS_STACK_TRACES: STACK_TRACE_TEMPLATE = '\nStack trace:\n*' + STACK_TRACE_ENTITY_TEMPLATE = '' else: - STACK_TRACE_TEMPLATE = '' + STACK_TRACE_TEMPLATE = '\n' + STACK_TRACE_ENTITY_TEMPLATE = '
' # unittest.main() can't handle unknown flags sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG) EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?> <testsuites tests="26" failures="5" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42"> <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="51" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/> + <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="53" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/> </testsuite> <testsuite name="FailedTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="Fails" file="gtest_xml_output_unittest_.cc" line="59" status="run" result="completed" time="*" timestamp="*" classname="FailedTest"> - <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:* + <testcase name="Fails" file="gtest_xml_output_unittest_.cc" line="61" status="run" result="completed" time="*" timestamp="*" classname="FailedTest"> + <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:* Expected equality of these values: 1 2%(stack)s]]></failure> </testcase> </testsuite> <testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="86" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest"/> - <testcase name="Fails" file="gtest_xml_output_unittest_.cc" line="91" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest"> - <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:* + <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="88" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest"/> + <testcase name="Fails" file="gtest_xml_output_unittest_.cc" line="93" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest"> + <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:* Expected equality of these values: 1 2%(stack)s]]></failure> - <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 2
 3" type=""><![CDATA[gtest_xml_output_unittest_.cc:* + <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 2
 3%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:* Expected equality of these values: 2 3%(stack)s]]></failure> </testcase> - <testcase name="DISABLED_test" file="gtest_xml_output_unittest_.cc" line="96" status="notrun" result="suppressed" time="*" timestamp="*" classname="MixedResultTest"/> + <testcase name="DISABLED_test" file="gtest_xml_output_unittest_.cc" line="98" status="notrun" result="suppressed" time="*" timestamp="*" classname="MixedResultTest"/> </testsuite> <testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="OutputsCData" file="gtest_xml_output_unittest_.cc" line="100" status="run" result="completed" time="*" timestamp="*" classname="XmlQuotingTest"> - <failure message="gtest_xml_output_unittest_.cc:*
Failed
XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]></top>" type=""><![CDATA[gtest_xml_output_unittest_.cc:* + <testcase name="OutputsCData" file="gtest_xml_output_unittest_.cc" line="102" status="run" result="completed" time="*" timestamp="*" classname="XmlQuotingTest"> + <failure message="gtest_xml_output_unittest_.cc:*
Failed
XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]></top>%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:* Failed XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]>]]><![CDATA[</top>%(stack)s]]></failure> </testcase> </testsuite> <testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="InvalidCharactersInMessage" file="gtest_xml_output_unittest_.cc" line="107" status="run" result="completed" time="*" timestamp="*" classname="InvalidCharactersTest"> - <failure message="gtest_xml_output_unittest_.cc:*
Failed
Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:* + <testcase name="InvalidCharactersInMessage" file="gtest_xml_output_unittest_.cc" line="109" status="run" result="completed" time="*" timestamp="*" classname="InvalidCharactersTest"> + <failure message="gtest_xml_output_unittest_.cc:*
Failed
Invalid characters in brackets []%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:* Failed Invalid characters in brackets []%(stack)s]]></failure> </testcase> </testsuite> <testsuite name="DisabledTest" tests="1" failures="0" disabled="1" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="DISABLED_test_not_run" file="gtest_xml_output_unittest_.cc" line="66" status="notrun" result="suppressed" time="*" timestamp="*" classname="DisabledTest"/> + <testcase name="DISABLED_test_not_run" file="gtest_xml_output_unittest_.cc" line="68" status="notrun" result="suppressed" time="*" timestamp="*" classname="DisabledTest"/> </testsuite> <testsuite name="SkippedTest" tests="3" failures="1" disabled="0" skipped="2" errors="0" time="*" timestamp="*"> - <testcase name="Skipped" status="run" file="gtest_xml_output_unittest_.cc" line="73" result="skipped" time="*" timestamp="*" classname="SkippedTest"> - <skipped message="gtest_xml_output_unittest_.cc:*
"><![CDATA[gtest_xml_output_unittest_.cc:* + <testcase name="Skipped" status="run" file="gtest_xml_output_unittest_.cc" line="75" result="skipped" time="*" timestamp="*" classname="SkippedTest"> + <skipped message="gtest_xml_output_unittest_.cc:*
%(stack_entity)s"><![CDATA[gtest_xml_output_unittest_.cc:* %(stack)s]]></skipped> </testcase> - <testcase name="SkippedWithMessage" file="gtest_xml_output_unittest_.cc" line="77" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest"> - <skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:* + <testcase name="SkippedWithMessage" file="gtest_xml_output_unittest_.cc" line="79" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest"> + <skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test.%(stack_entity)s"><![CDATA[gtest_xml_output_unittest_.cc:* It is good practice to tell why you skip a test.%(stack)s]]></skipped> </testcase> - <testcase name="SkippedAfterFailure" file="gtest_xml_output_unittest_.cc" line="81" status="run" result="completed" time="*" timestamp="*" classname="SkippedTest"> - <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:* + <testcase name="SkippedAfterFailure" file="gtest_xml_output_unittest_.cc" line="83" status="run" result="completed" time="*" timestamp="*" classname="SkippedTest"> + <failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:* Expected equality of these values: 1 2%(stack)s]]></failure> - <skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:* + <skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test.%(stack_entity)s"><![CDATA[gtest_xml_output_unittest_.cc:* It is good practice to tell why you skip a test.%(stack)s]]></skipped> </testcase> </testsuite> <testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye"> - <testcase name="OneProperty" file="gtest_xml_output_unittest_.cc" line="119" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> + <testcase name="OneProperty" file="gtest_xml_output_unittest_.cc" line="121" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> <properties> <property name="key_1" value="1"/> </properties> </testcase> - <testcase name="IntValuedProperty" file="gtest_xml_output_unittest_.cc" line="123" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> + <testcase name="IntValuedProperty" file="gtest_xml_output_unittest_.cc" line="125" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> <properties> <property name="key_int" value="1"/> </properties> </testcase> - <testcase name="ThreeProperties" file="gtest_xml_output_unittest_.cc" line="127" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> + <testcase name="ThreeProperties" file="gtest_xml_output_unittest_.cc" line="129" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> <properties> <property name="key_1" value="1"/> <property name="key_2" value="2"/> <property name="key_3" value="3"/> </properties> </testcase> - <testcase name="TwoValuesForOneKeyUsesLastValue" file="gtest_xml_output_unittest_.cc" line="133" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> + <testcase name="TwoValuesForOneKeyUsesLastValue" file="gtest_xml_output_unittest_.cc" line="135" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> <properties> <property name="key_1" value="2"/> </properties> </testcase> </testsuite> <testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="RecordProperty" file="gtest_xml_output_unittest_.cc" line="138" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest"> + <testcase name="RecordProperty" file="gtest_xml_output_unittest_.cc" line="140" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest"> <properties> <property name="key" value="1"/> </properties> </testcase> - <testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" file="gtest_xml_output_unittest_.cc" line="151" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest"> + <testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" file="gtest_xml_output_unittest_.cc" line="153" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest"> <properties> <property name="key_for_utility_int" value="1"/> </properties> </testcase> - <testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" file="gtest_xml_output_unittest_.cc" line="155" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest"> + <testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" file="gtest_xml_output_unittest_.cc" line="157" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest"> <properties> <property name="key_for_utility_string" value="1"/> </properties> </testcase> </testsuite> <testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="HasValueParamAttribute/0" file="gtest_xml_output_unittest_.cc" line="162" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> - <testcase name="HasValueParamAttribute/1" file="gtest_xml_output_unittest_.cc" line="162" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> - <testcase name="AnotherTestThatHasValueParamAttribute/0" file="gtest_xml_output_unittest_.cc" line="163" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> - <testcase name="AnotherTestThatHasValueParamAttribute/1" file="gtest_xml_output_unittest_.cc" line="163" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> + <testcase name="HasValueParamAttribute/0" file="gtest_xml_output_unittest_.cc" line="164" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> + <testcase name="HasValueParamAttribute/1" file="gtest_xml_output_unittest_.cc" line="164" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> + <testcase name="AnotherTestThatHasValueParamAttribute/0" file="gtest_xml_output_unittest_.cc" line="165" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> + <testcase name="AnotherTestThatHasValueParamAttribute/1" file="gtest_xml_output_unittest_.cc" line="165" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> </testsuite> <testsuite name="TypedTest/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="171" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/0" /> + <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="173" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/0" /> </testsuite> <testsuite name="TypedTest/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="171" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/1" /> + <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="173" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/1" /> </testsuite> <testsuite name="Single/TypeParameterizedTestSuite/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="178" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/0" /> + <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="180" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/0" /> </testsuite> <testsuite name="Single/TypeParameterizedTestSuite/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="178" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/1" /> + <testcase name="HasTypeParamAttribute" file="gtest_xml_output_unittest_.cc" line="180" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/1" /> </testsuite> </testsuites>""" % { - 'stack': STACK_TRACE_TEMPLATE + 'stack': STACK_TRACE_TEMPLATE, + 'stack_entity': STACK_TRACE_ENTITY_TEMPLATE, } EXPECTED_FILTERED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?> @@ -195,24 +198,24 @@ EXPECTED_FILTERED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?> timestamp="*" name="AllTests" ad_hoc_property="42"> <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="51" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/> + <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="53" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/> </testsuite> </testsuites>""" EXPECTED_SHARDED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?> <testsuites tests="3" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42"> <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="51" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/> + <testcase name="Succeeds" file="gtest_xml_output_unittest_.cc" line="53" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/> </testsuite> <testsuite name="PropertyRecordingTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye"> - <testcase name="IntValuedProperty" file="gtest_xml_output_unittest_.cc" line="123" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> + <testcase name="IntValuedProperty" file="gtest_xml_output_unittest_.cc" line="125" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest"> <properties> <property name="key_int" value="1"/> </properties> </testcase> </testsuite> <testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> - <testcase name="HasValueParamAttribute/0" file="gtest_xml_output_unittest_.cc" line="162" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> + <testcase name="HasValueParamAttribute/0" file="gtest_xml_output_unittest_.cc" line="164" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" /> </testsuite> </testsuites>""" @@ -221,14 +224,15 @@ EXPECTED_NO_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?> timestamp="*" name="AllTests"> <testsuite name="NonTestSuiteFailure" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*"> <testcase name="" status="run" result="completed" time="*" timestamp="*" classname=""> - <failure message="gtest_no_test_unittest.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_no_test_unittest.cc:* + <failure message="gtest_no_test_unittest.cc:*
Expected equality of these values:
 1
 2%(stack_entity)s" type=""><![CDATA[gtest_no_test_unittest.cc:* Expected equality of these values: 1 2%(stack)s]]></failure> </testcase> </testsuite> </testsuites>""" % { - 'stack': STACK_TRACE_TEMPLATE + 'stack': STACK_TRACE_TEMPLATE, + 'stack_entity': STACK_TRACE_ENTITY_TEMPLATE, } GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) diff --git a/googletest/test/gtest_xml_output_unittest_.cc b/googletest/test/gtest_xml_output_unittest_.cc index 4bdb0c7e..0ab33022 100644 --- a/googletest/test/gtest_xml_output_unittest_.cc +++ b/googletest/test/gtest_xml_output_unittest_.cc @@ -37,6 +37,8 @@ // directly. // clang-format off +#include <string> + #include "gtest/gtest.h" using ::testing::InitGoogleTest; diff --git a/googletest/test/gtest_xml_test_utils.py b/googletest/test/gtest_xml_test_utils.py index 8fcb6933..74e0f4a0 100755 --- a/googletest/test/gtest_xml_test_utils.py +++ b/googletest/test/gtest_xml_test_utils.py @@ -218,7 +218,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): ) if element.tagName in ('testsuites', 'testsuite', 'testcase'): time = element.getAttributeNode('time') - # The value for exact N seconds has a traling decimal point (e.g., "10." + # The value for exact N seconds has a trailing decimal point (e.g., "10." # instead of "10") time.value = re.sub(r'^\d+\.(\d+)?$', '*', time.value) type_param = element.getAttributeNode('type_param') |