From 22eb2de1efab758bebf8e0142fb0c4a999925b3b Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 7 Aug 2023 20:17:58 -0700 Subject: Fix GTestHelpTest.TestHelpFlag on FreeBSD The test supported a variety of BSDs, including kFreeBSD, but not FreeBSD. Move the BSD checks to a separate function and support checking for FreeBSD, in addition to kFreeBSD. Signed-off-by: Enji Cooper --- googletest/test/gtest_help_test.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index 85a0c33..a4c7991 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -43,11 +43,21 @@ import sys from googletest.test import gtest_test_utils +FREEBSD = ('FreeBSD', 'GNU/kFreeBSD') +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 os.uname()[0] in (FREEBSD + NETBSD + OPENBSD) + + 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' -IS_OPENBSD = os.name == 'posix' and os.uname()[0] == 'OpenBSD' IS_WINDOWS = os.name == 'nt' PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') @@ -136,7 +146,7 @@ class GTestHelpTest(gtest_test_utils.TestCase): self.assertTrue(HELP_REGEX.search(output), output) - if IS_DARWIN or IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD or IS_OPENBSD: + if IS_DARWIN or IS_LINUX or IS_GNUHURD or is_bsd_based_os(): self.assertIn(STREAM_RESULT_TO_FLAG, output) else: self.assertNotIn(STREAM_RESULT_TO_FLAG, output) -- cgit v0.12 From 77485ff0046136f89f14d5e7a51e98849dc00691 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 7 Aug 2023 21:36:44 -0700 Subject: Fix RETest/1.ImplicitConstructorWorks on non-ABSL platforms The last regular expression specified in the test is not technically POSIX compatible. Use `[[:alnum:]_]` instead of `\w+`; the latter is a Perl-compatible regular expression. Signed-off-by: Enji Cooper --- googletest/test/googletest-port-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 @@ TYPED_TEST(RETest, ImplicitConstructorWorks) { 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. -- cgit v0.12 From d76e9e0dd93a9921e4054c71f23e7c8fa8da864d Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 15 Aug 2023 06:42:01 -0700 Subject: gtest_help_test: Delete obsolete helper `TestUnknownFlagWithAbseil` PiperOrigin-RevId: 557116814 Change-Id: I91e06b0d6001952366c50201b67491475a1f98af --- googletest/test/gtest_help_test.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index 85a0c33..a76f220 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -146,19 +146,6 @@ class GTestHelpTest(gtest_test_utils.TestCase): 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): """Verifies correct behavior when no help flag is specified. -- cgit v0.12 From 6513d0272d8bd2062cf4549fe2b0adb1fc862486 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 15 Aug 2023 07:11:18 -0700 Subject: gtest_help_test: Inline test helper functions `TestNonHelpFlag` is only a few asserts with no logic, which is easier to read in line, and helper `TestHelpFlag` is used in a single test case. PiperOrigin-RevId: 557122793 Change-Id: I7367424abfbb883c10c260fae066a2071e5dfa0e --- googletest/test/gtest_help_test.py | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index a76f220..3f78496 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -116,17 +116,14 @@ def RunWithFlag(flag): class GTestHelpTest(gtest_test_utils.TestCase): """Tests the --help flag and its equivalent forms.""" - def TestHelpFlag(self, flag): + def testPrintsHelpWithFullFlag(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 = RunWithFlag('--help') if HAS_ABSL_FLAGS: # The Abseil flags library prints the ProgramUsageMessage() with # --help and returns 1. @@ -146,32 +143,17 @@ class GTestHelpTest(gtest_test_utils.TestCase): else: self.assertNotIn(DEATH_TEST_STYLE_FLAG, output) - def TestNonHelpFlag(self, flag): + 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. - - Args: - flag: A flag to pass to the binary or None. """ - exit_code, output = RunWithFlag(flag) + exit_code, output = RunWithFlag(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): """Verifies correct behavior when internal testing flag is specified. @@ -179,7 +161,9 @@ class GTestHelpTest(gtest_test_utils.TestCase): a flag starting with Google Test prefix and 'internal_' is supplied. """ - self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING) + exit_code, output = RunWithFlag(INTERNAL_FLAG_FOR_TESTING) + self.assertNotEqual(exit_code, 0) + self.assertFalse(HELP_REGEX.search(output), output) if __name__ == '__main__': -- cgit v0.12 From dd9a9569041c1551613d116ff0d092b356c836b1 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 15 Aug 2023 07:59:51 -0700 Subject: gtest_help_test: Make method names `snake_case`, conforming with [the style guide](https://google.github.io/styleguide/pyguide#316-naming) PiperOrigin-RevId: 557133618 Change-Id: I27202ee91ee81b3d2e4c28102190d2bde8efba05 --- googletest/test/gtest_help_test.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index 3f78496..b3b740d 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -96,7 +96,7 @@ HELP_REGEX = re.compile( ) -def RunWithFlag(flag): +def run_with_flag(flag): """Runs gtest_help_test_ with the given flag. Returns: @@ -116,14 +116,14 @@ def RunWithFlag(flag): class GTestHelpTest(gtest_test_utils.TestCase): """Tests the --help flag and its equivalent forms.""" - def testPrintsHelpWithFullFlag(self): + 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. """ - exit_code, output = RunWithFlag('--help') + exit_code, output = run_with_flag('--help') if HAS_ABSL_FLAGS: # The Abseil flags library prints the ProgramUsageMessage() with # --help and returns 1. @@ -143,25 +143,25 @@ class GTestHelpTest(gtest_test_utils.TestCase): else: self.assertNotIn(DEATH_TEST_STYLE_FLAG, output) - def testRunsTestsWithoutHelpFlag(self): + 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. """ - exit_code, output = RunWithFlag(None) + exit_code, output = run_with_flag(None) self.assertNotEqual(exit_code, 0) self.assertFalse(HELP_REGEX.search(output), output) - 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. """ - exit_code, output = RunWithFlag(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) -- cgit v0.12 From f42da0e4431a14260946323bff4d856f20973b2c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 17 Aug 2023 12:55:43 -0700 Subject: Improve error message for invalid parameterized test names. PiperOrigin-RevId: 557910190 Change-Id: Ia965a6c96e4cc5997d8af2611abc62c42e81653e --- googletest/include/gtest/internal/gtest-param-util.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index 6a81c37..dd39e98 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -584,7 +584,9 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { GTEST_CHECK_(IsValidParamName(param_name)) << "Parameterized test name '" << param_name - << "' is invalid, in " << file << " line " << line << std::endl; + << "' is invalid (contains spaces, dashes, underscores, or " + "non-alphanumeric characters), in " + << file << " line " << line << "" << std::endl; GTEST_CHECK_(test_param_names.count(param_name) == 0) << "Duplicate parameterized test name '" << param_name << "', in " -- cgit v0.12