diff options
Diffstat (limited to 'googletest/test')
-rwxr-xr-x | googletest/test/googletest-color-test.py | 1 | ||||
-rw-r--r-- | googletest/test/googletest-death-test-test.cc | 2 | ||||
-rwxr-xr-x | googletest/test/googletest-fail-if-no-test-linked-test.py | 6 | ||||
-rw-r--r-- | googletest/test/googletest-fail-if-no-test-selected-test.py | 91 | ||||
-rw-r--r-- | googletest/test/googletest-output-test-golden-lin.txt | 2 | ||||
-rw-r--r-- | googletest/test/googletest-param-test-test.cc | 2 | ||||
-rw-r--r-- | googletest/test/googletest-printers-test.cc | 84 | ||||
-rw-r--r-- | googletest/test/gtest_unittest.cc | 13 |
8 files changed, 170 insertions, 31 deletions
diff --git a/googletest/test/googletest-color-test.py b/googletest/test/googletest-color-test.py index 8968cf1..76ca8e0 100755 --- a/googletest/test/googletest-color-test.py +++ b/googletest/test/googletest-color-test.py @@ -79,6 +79,7 @@ class GTestColorTest(gtest_test_utils.TestCase): self.assertTrue(UsesColor('cygwin', None, None)) self.assertTrue(UsesColor('xterm', None, None)) self.assertTrue(UsesColor('xterm-color', None, None)) + self.assertTrue(UsesColor('xterm-ghostty', None, None)) self.assertTrue(UsesColor('xterm-kitty', None, None)) self.assertTrue(UsesColor('alacritty', None, None)) self.assertTrue(UsesColor('xterm-256color', None, None)) diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index 44b8046..8770315 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -291,7 +291,7 @@ TEST(ExitStatusPredicateTest, KilledBySignal) { const int status_kill = KilledExitStatus(SIGKILL); const testing::KilledBySignal pred_segv(SIGSEGV); const testing::KilledBySignal pred_kill(SIGKILL); -#if !(defined(GTEST_OS_LINUX_ANDROID) && __ANDROID_API__ <= 21) +#if !(defined(GTEST_OS_LINUX_ANDROID) && __ANDROID_API__ <= 23) EXPECT_PRED1(pred_segv, status_segv); #endif EXPECT_PRED1(pred_kill, status_kill); diff --git a/googletest/test/googletest-fail-if-no-test-linked-test.py b/googletest/test/googletest-fail-if-no-test-linked-test.py index f5854ba..e62bfb2 100755 --- a/googletest/test/googletest-fail-if-no-test-linked-test.py +++ b/googletest/test/googletest-fail-if-no-test-linked-test.py @@ -80,11 +80,7 @@ class GTestFailIfNoTestLinkedTest(gtest_test_utils.TestCase): ) ) warning_file_contents = open(warning_file, "r").read() - self.assertEqual( - warning_file_contents, - "This test program does NOT link in any test case. Please make sure" - " this is intended.\n", - ) + self.assertIn("does NOT link", warning_file_contents) def testFailsIfNoTestLinkedAndFlagSpecified(self): """Tests the behavior of no test linked and flag specified.""" diff --git a/googletest/test/googletest-fail-if-no-test-selected-test.py b/googletest/test/googletest-fail-if-no-test-selected-test.py new file mode 100644 index 0000000..03a324c --- /dev/null +++ b/googletest/test/googletest-fail-if-no-test-selected-test.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 # pylint: disable=g-interpreter-mismatch +# +# Copyright 2025, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""Tests for Google Test's --gtest_fail_if_no_test_selected flag.""" + +from googletest.test import gtest_test_utils + + +# The command line flag for enabling the fail-if-no-test-selected behavior. +FAIL_IF_NO_TEST_SELECTED_FLAG = "gtest_fail_if_no_test_selected" + +# The environment variable for the test output warnings file. +TEST_WARNINGS_OUTPUT_FILE = "TEST_WARNINGS_OUTPUT_FILE" + + +class GTestFailIfNoTestSelectedTest(gtest_test_utils.TestCase): + """Tests the --gtest_fail_if_no_test_selected flag.""" + + def Run(self, program_name, flags=None, env=None): + """Run the given program with the given flag. + + Args: + program_name: Name of the program to run. + flags: The command line flags to pass to the program, or None. + env: Dictionary with environment to pass to the subprocess. + + Returns: + True if the program exits with code 0, false otherwise. + """ + + exe_path = gtest_test_utils.GetTestExecutablePath(program_name) + args = [exe_path] + if flags is not None: + args.extend(flags) + process = gtest_test_utils.Subprocess(args, capture_stderr=False, env=env) + return process.exited and process.exit_code == 0 + + def testSucceedsWhenFlagIsNotSetAndOnlyDisabledTestsPresent(self): + """Tests that no test selected results in success without the flag set.""" + self.assertTrue( + self.Run("googletest-fail-if-no-test-linked-test-with-disabled-test_"), + ) + + def testFailsWhenFlagIsSetAndOnlyDisabledTestsPresent(self): + """Tests that no test selected results in failure with the flag set.""" + self.assertFalse( + self.Run( + "googletest-fail-if-no-test-linked-test-with-disabled-test_", + flags=[f"--{FAIL_IF_NO_TEST_SELECTED_FLAG}"], + ), + ) + + def testSucceedsWhenFlagIsSetAndEnabledTestsPresent(self): + """Tests that a test running still succeeds when the flag is set.""" + self.assertTrue( + self.Run( + "googletest-fail-if-no-test-linked-test-with-enabled-test_", + flags=[f"--{FAIL_IF_NO_TEST_SELECTED_FLAG}"], + ), + ) + + +if __name__ == "__main__": + gtest_test_utils.Main() diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 533eb8c..57f7d1a 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -62,7 +62,7 @@ Expected equality of these values: Which is: "\"Line\0 1\"\nLine 2" "Line 2" With diff: -@@ -1,2 @@ +@@ -1,2 +1 @@ -\"Line\0 1\" Line 2 diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index bc13060..fab977e 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -1174,7 +1174,7 @@ TEST_P(ParameterizedDerivedTest, SeesSequence) { class ParameterizedDeathTest : public ::testing::TestWithParam<int> {}; TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) { - EXPECT_DEATH_IF_SUPPORTED(GetParam(), ".* value-parameterized test .*"); + EXPECT_DEATH_IF_SUPPORTED((void)GetParam(), ".* value-parameterized test .*"); } INSTANTIATE_TEST_SUITE_P(RangeZeroToFive, ParameterizedDerivedTest, diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index 52b2c49..c5d9756 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -32,6 +32,7 @@ // This file tests the universal value printer. #include <algorithm> +#include <any> #include <cctype> #include <cstdint> #include <cstring> @@ -42,14 +43,17 @@ #include <list> #include <map> #include <memory> +#include <optional> #include <ostream> #include <set> #include <sstream> #include <string> +#include <string_view> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> +#include <variant> #include <vector> #include "gtest/gtest-printers.h" @@ -62,7 +66,7 @@ #if GTEST_INTERNAL_HAS_STD_SPAN #include <span> // NOLINT -#endif // GTEST_INTERNAL_HAS_STD_SPAN +#endif // GTEST_INTERNAL_HAS_STD_SPAN #if GTEST_INTERNAL_HAS_COMPARE_LIB #include <compare> // NOLINT @@ -796,7 +800,7 @@ struct Foo { TEST(PrintPointerTest, MemberVariablePointer) { EXPECT_TRUE(HasPrefix(Print(&Foo::value), Print(sizeof(&Foo::value)) + "-byte object ")); - int Foo::*p = NULL; // NOLINT + int Foo::* p = NULL; // NOLINT EXPECT_TRUE(HasPrefix(Print(p), Print(sizeof(p)) + "-byte object ")); } @@ -923,7 +927,7 @@ TEST(PrintArrayTest, BigArray) { PrintArrayHelper(a)); } -// Tests printing ::string and ::std::string. +// Tests printing ::std::string and ::string_view. // ::std::string. TEST(PrintStringTest, StringInStdNamespace) { @@ -933,6 +937,13 @@ TEST(PrintStringTest, StringInStdNamespace) { Print(str)); } +TEST(PrintStringTest, StringViewInStdNamespace) { + const char s[] = "'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a"; + const ::std::string_view str(s, sizeof(s)); + EXPECT_EQ("\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"", + Print(str)); +} + TEST(PrintStringTest, StringAmbiguousHex) { // "\x6BANANA" is ambiguous, it can be interpreted as starting with either of: // '\x6', '\x6B', or '\x6BA'. @@ -950,7 +961,7 @@ TEST(PrintStringTest, StringAmbiguousHex) { EXPECT_EQ("\"!\\x5-!\"", Print(::std::string("!\x5-!"))); } -// Tests printing ::std::wstring. +// Tests printing ::std::wstring and ::std::wstring_view. #if GTEST_HAS_STD_WSTRING // ::std::wstring. TEST(PrintWideStringTest, StringInStdNamespace) { @@ -962,6 +973,15 @@ TEST(PrintWideStringTest, StringInStdNamespace) { Print(str)); } +TEST(PrintWideStringTest, StringViewInStdNamespace) { + const wchar_t s[] = L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a"; + const ::std::wstring_view str(s, sizeof(s) / sizeof(wchar_t)); + EXPECT_EQ( + "L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v" + "\\xD3\\x576\\x8D3\\xC74D a\\0\"", + Print(str)); +} + TEST(PrintWideStringTest, StringAmbiguousHex) { // same for wide strings. EXPECT_EQ("L\"0\\x12\" L\"3\"", Print(::std::wstring(L"0\x12" @@ -980,6 +1000,12 @@ TEST(PrintStringTest, U8String) { EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type. EXPECT_EQ("u8\"Hello, \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"", Print(str)); } + +TEST(PrintStringTest, U8StringView) { + std::u8string_view str = u8"Hello, 世界"; + EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type. + EXPECT_EQ("u8\"Hello, \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"", Print(str)); +} #endif TEST(PrintStringTest, U16String) { @@ -988,12 +1014,24 @@ TEST(PrintStringTest, U16String) { EXPECT_EQ("u\"Hello, \\x4E16\\x754C\"", Print(str)); } +TEST(PrintStringTest, U16StringView) { + std::u16string_view str = u"Hello, 世界"; + EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type. + EXPECT_EQ("u\"Hello, \\x4E16\\x754C\"", Print(str)); +} + TEST(PrintStringTest, U32String) { std::u32string str = U"Hello, 🗺️"; EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type EXPECT_EQ("U\"Hello, \\x1F5FA\\xFE0F\"", Print(str)); } +TEST(PrintStringTest, U32StringView) { + std::u32string_view str = U"Hello, 🗺️"; + EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type + EXPECT_EQ("U\"Hello, \\x1F5FA\\xFE0F\"", Print(str)); +} + // Tests printing types that support generic streaming (i.e. streaming // to std::basic_ostream<Char, CharTraits> for any valid Char and // CharTraits types). @@ -1453,7 +1491,7 @@ TEST(PrintReferenceTest, HandlesMemberFunctionPointer) { // Tests that the universal printer prints a member variable pointer // passed by reference. TEST(PrintReferenceTest, HandlesMemberVariablePointer) { - int Foo::*p = &Foo::value; // NOLINT + int Foo::* p = &Foo::value; // NOLINT EXPECT_TRUE(HasPrefix(PrintByRef(p), "@" + PrintPointer(&p) + " " + Print(sizeof(p)) + "-byte object ")); } @@ -1891,6 +1929,22 @@ TEST(UniversalPrintTest, SmartPointers) { PrintToString(std::shared_ptr<void>(p.get(), [](void*) {}))); } +TEST(UniversalPrintTest, StringViewNonZeroTerminated) { + // Craft a non-ASCII UTF-8 input (to trigger a special path in + // `ConditionalPrintAsText`). Use array notation instead of the string + // literal syntax, to avoid placing a terminating 0 at the end of the input. + const char s[] = {'\357', '\243', '\242', 'X'}; + // Only include the first 3 bytes in the `string_view` and leave the last one + // ('X') outside. This way, if the code tries to use `str.data()` with + // `strlen` instead of `str.size()`, it will include 'X' and cause a visible + // difference (in addition to ASAN tests detecting a buffer overflow due to + // the missing 0 at the end). + const ::std::string_view str(s, 3); + ::std::stringstream ss; + UniversalPrint(str, &ss); + EXPECT_EQ("\"\\xEF\\xA3\\xA2\"\n As Text: \"\xEF\xA3\xA2\"", ss.str()); +} + TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) { Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple()); EXPECT_EQ(0u, result.size()); @@ -1920,7 +1974,6 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) { EXPECT_EQ("\"a\"", result[1]); } -#if GTEST_INTERNAL_HAS_ANY class PrintAnyTest : public ::testing::Test { protected: template <typename T> @@ -1934,12 +1987,12 @@ class PrintAnyTest : public ::testing::Test { }; TEST_F(PrintAnyTest, Empty) { - internal::Any any; + std::any any; EXPECT_EQ("no value", PrintToString(any)); } TEST_F(PrintAnyTest, NonEmpty) { - internal::Any any; + std::any any; constexpr int val1 = 10; const std::string val2 = "content"; @@ -1950,27 +2003,23 @@ TEST_F(PrintAnyTest, NonEmpty) { EXPECT_EQ("value of type " + ExpectedTypeName<std::string>(), PrintToString(any)); } -#endif // GTEST_INTERNAL_HAS_ANY -#if GTEST_INTERNAL_HAS_OPTIONAL TEST(PrintOptionalTest, Basic) { - EXPECT_EQ("(nullopt)", PrintToString(internal::Nullopt())); - internal::Optional<int> value; + EXPECT_EQ("(nullopt)", PrintToString(std::nullopt)); + std::optional<int> value; EXPECT_EQ("(nullopt)", PrintToString(value)); value = {7}; EXPECT_EQ("(7)", PrintToString(value)); - EXPECT_EQ("(1.1)", PrintToString(internal::Optional<double>{1.1})); - EXPECT_EQ("(\"A\")", PrintToString(internal::Optional<std::string>{"A"})); + EXPECT_EQ("(1.1)", PrintToString(std::optional<double>{1.1})); + EXPECT_EQ("(\"A\")", PrintToString(std::optional<std::string>{"A"})); } -#endif // GTEST_INTERNAL_HAS_OPTIONAL -#if GTEST_INTERNAL_HAS_VARIANT struct NonPrintable { unsigned char contents = 17; }; TEST(PrintOneofTest, Basic) { - using Type = internal::Variant<int, StreamableInGlobal, NonPrintable>; + using Type = std::variant<int, StreamableInGlobal, NonPrintable>; EXPECT_EQ("('int(index = 0)' with value 7)", PrintToString(Type(7))); EXPECT_EQ("('StreamableInGlobal(index = 1)' with value StreamableInGlobal)", PrintToString(Type(StreamableInGlobal{}))); @@ -1979,7 +2028,6 @@ TEST(PrintOneofTest, Basic) { "1-byte object <11>)", PrintToString(Type(NonPrintable{}))); } -#endif // GTEST_INTERNAL_HAS_VARIANT #if GTEST_INTERNAL_HAS_COMPARE_LIB TEST(PrintOrderingTest, Basic) { diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 559d34c..a31b7ba 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3579,13 +3579,13 @@ TEST(EditDistance, TestSuites) { {__LINE__, "A", "A", " ", ""}, {__LINE__, "ABCDE", "ABCDE", " ", ""}, // Simple adds. - {__LINE__, "X", "XA", " +", "@@ +1,2 @@\n X\n+A\n"}, - {__LINE__, "X", "XABCD", " ++++", "@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"}, + {__LINE__, "X", "XA", " +", "@@ -1 +1,2 @@\n X\n+A\n"}, + {__LINE__, "X", "XABCD", " ++++", "@@ -1 +1,5 @@\n X\n+A\n+B\n+C\n+D\n"}, // Simple removes. - {__LINE__, "XA", "X", " -", "@@ -1,2 @@\n X\n-A\n"}, - {__LINE__, "XABCD", "X", " ----", "@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"}, + {__LINE__, "XA", "X", " -", "@@ -1,2 +1 @@\n X\n-A\n"}, + {__LINE__, "XABCD", "X", " ----", "@@ -1,5 +1 @@\n X\n-A\n-B\n-C\n-D\n"}, // Simple replaces. - {__LINE__, "A", "a", "/", "@@ -1,1 +1,1 @@\n-A\n+a\n"}, + {__LINE__, "A", "a", "/", "@@ -1 +1 @@\n-A\n+a\n"}, {__LINE__, "ABCD", "abcd", "////", "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"}, // Path finding. @@ -6717,6 +6717,9 @@ TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { SetEnv("TERM", "xterm-color"); // TERM supports colors. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. + SetEnv("TERM", "xterm-ghostty"); // TERM supports colors. + EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. + SetEnv("TERM", "xterm-kitty"); // TERM supports colors. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. |