Merge pull request #4333 from ngie-eign:gtest_help_test-fix-FreeBSD
PiperOrigin-RevId: 557197748
Change-Id: I55b86353f5351bbcbdf8e6bca70e82d7383a5080
diff --git a/docs/advanced.md b/docs/advanced.md
index 3871db1..344d541 100644
--- a/docs/advanced.md
+++ b/docs/advanced.md
@@ -899,10 +899,10 @@
variables to hold the shared resources.
2. Outside your test fixture class (typically just below it), define those
member variables, optionally giving them initial values.
-3. In the same test fixture class, define a `static void SetUpTestSuite()`
- function (remember not to spell it as **`SetupTestSuite`** with a small
- `u`!) to set up the shared resources and a `static void TearDownTestSuite()`
- function to tear them down.
+3. In the same test fixture class, define a public member function `static void
+ SetUpTestSuite()` (remember not to spell it as **`SetupTestSuite`** with a
+ small `u`!) to set up the shared resources and a `static void
+ TearDownTestSuite()` function to tear them down.
That's it! GoogleTest automatically calls `SetUpTestSuite()` before running the
*first test* in the `FooTest` test suite (i.e. before creating the first
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index bd9ba73..f20258b 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -175,9 +175,15 @@
static T Get() {
Assert(false, __FILE__, __LINE__,
"Default action undefined for the function return type.");
- return internal::Invalid<T>();
+#if defined(__GNUC__) || defined(__clang__)
+ __builtin_unreachable();
+#elif defined(_MSC_VER)
+ __assume(0);
+#else
+ return Invalid<T>();
// The above statement will never be reached, but is required in
// order for this function to compile.
+#endif
}
};
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h
index de7d528..a932e68 100644
--- a/googletest/include/gtest/gtest.h
+++ b/googletest/include/gtest/gtest.h
@@ -51,7 +51,6 @@
#include <cstddef>
#include <cstdint>
-#include <iomanip>
#include <limits>
#include <memory>
#include <ostream>
@@ -1574,12 +1573,12 @@
}
::std::stringstream lhs_ss;
- lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
- << lhs_value;
+ lhs_ss.precision(std::numeric_limits<RawType>::digits10 + 2);
+ lhs_ss << lhs_value;
::std::stringstream rhs_ss;
- rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
- << rhs_value;
+ rhs_ss.precision(std::numeric_limits<RawType>::digits10 + 2);
+ rhs_ss << rhs_value;
return EqFailure(lhs_expression, rhs_expression,
StringStreamToString(&lhs_ss), StringStreamToString(&rhs_ss),
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index a04a920..97a9833 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -58,7 +58,6 @@
#include <cstdint>
#include <functional>
-#include <iomanip>
#include <limits>
#include <map>
#include <set>
diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc
index 32a2a7b..e0793ba 100644
--- a/googletest/test/googletest-port-test.cc
+++ b/googletest/test/googletest-port-test.cc
@@ -418,8 +418,8 @@
const RE simple(TypeParam("hello"));
EXPECT_STREQ("hello", simple.pattern());
- const RE normal(TypeParam(".*(\\w+)"));
- EXPECT_STREQ(".*(\\w+)", normal.pattern());
+ const RE normal(TypeParam(".*([[:alnum:]_]+)"));
+ EXPECT_STREQ(".*([[:alnum:]_]+)", normal.pattern());
}
// Tests that RE's constructors reject invalid regular expressions.
diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py
index a4c7991..38fc90f 100755
--- a/googletest/test/gtest_help_test.py
+++ b/googletest/test/gtest_help_test.py
@@ -44,13 +44,14 @@
FREEBSD = ('FreeBSD', 'GNU/kFreeBSD')
-NETBSD = ('NetBSD', )
-OPENBSD = ('OpenBSD', )
+NETBSD = ('NetBSD',)
+OPENBSD = ('OpenBSD',)
+
def is_bsd_based_os() -> bool:
"""Determine whether or not the OS is BSD-based."""
if os.name != 'posix':
- return False
+ return False
return os.uname()[0] in (FREEBSD + NETBSD + OPENBSD)
@@ -106,7 +107,7 @@
)
-def RunWithFlag(flag):
+def run_with_flag(flag):
"""Runs gtest_help_test_ with the given flag.
Returns:
@@ -126,17 +127,14 @@
class GTestHelpTest(gtest_test_utils.TestCase):
"""Tests the --help flag and its equivalent forms."""
- def TestHelpFlag(self, flag):
+ def test_prints_help_with_full_flag(self):
"""Verifies correct behavior when help flag is specified.
The right message must be printed and the tests must
skipped when the given flag is specified.
-
- Args:
- flag: A flag to pass to the binary or None.
"""
- exit_code, output = RunWithFlag(flag)
+ exit_code, output = run_with_flag('--help')
if HAS_ABSL_FLAGS:
# The Abseil flags library prints the ProgramUsageMessage() with
# --help and returns 1.
@@ -156,53 +154,27 @@
else:
self.assertNotIn(DEATH_TEST_STYLE_FLAG, output)
- def TestUnknownFlagWithAbseil(self, flag):
- """Verifies correct behavior when an unknown flag is specified.
-
- The right message must be printed and the tests must
- skipped when the given flag is specified.
-
- Args:
- flag: A flag to pass to the binary or None.
- """
- exit_code, output = RunWithFlag(flag)
- self.assertEqual(1, exit_code)
- self.assertIn('ERROR: Unknown command line flag', output)
-
- def TestNonHelpFlag(self, flag):
+ def test_runs_tests_without_help_flag(self):
"""Verifies correct behavior when no help flag is specified.
Verifies that when no help flag is specified, the tests are run
and the help message is not printed.
-
- Args:
- flag: A flag to pass to the binary or None.
"""
- exit_code, output = RunWithFlag(flag)
+ exit_code, output = run_with_flag(None)
self.assertNotEqual(exit_code, 0)
self.assertFalse(HELP_REGEX.search(output), output)
- def testPrintsHelpWithFullFlag(self):
- self.TestHelpFlag('--help')
-
- def testRunsTestsWithoutHelpFlag(self):
- """Verifies correct behavior when no help flag is specified.
-
- Verifies that when no help flag is specified, the tests are run
- and the help message is not printed.
- """
-
- self.TestNonHelpFlag(None)
-
- def testRunsTestsWithGtestInternalFlag(self):
+ def test_runs_tests_with_gtest_internal_flag(self):
"""Verifies correct behavior when internal testing flag is specified.
Verifies that the tests are run and no help message is printed when
a flag starting with Google Test prefix and 'internal_' is supplied.
"""
- self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING)
+ exit_code, output = run_with_flag(INTERNAL_FLAG_FOR_TESTING)
+ self.assertNotEqual(exit_code, 0)
+ self.assertFalse(HELP_REGEX.search(output), output)
if __name__ == '__main__':