From bbd5c3a4b8c34fbba44a784c47ac8366be80c65d Mon Sep 17 00:00:00 2001 From: Alecto Irene Perez Date: Mon, 24 Jun 2024 13:52:15 -0400 Subject: [PATCH] Add support for all help flag variants mentioned in the documentation The documentation specifies that '-h', '-?', and '/?' may be used, but the code failed to check for these flags. This commit fixes the behavior of the executable to match what is specified in the docs. --- googletest/src/gtest.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 9a17180b3..1a998a5d7 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -6672,6 +6672,12 @@ static void LoadFlagsFromFile(const std::string& path) { } #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM +// Checks if the given flag is a help flag. +// Support all help flag variants mentioned in the documentation. +static bool IsHelpFlag(const std::string& flag) { + return flag == "--help" || flag == "-h" || flag == "-?" || flag == "/?"; +} + // Parses the command line for Google Test flags, without initializing // other parts of Google Test. The type parameter CharType can be // instantiated to either char or wchar_t. @@ -6693,7 +6699,7 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { LoadFlagsFromFile(flagfile_value); remove_flag = true; #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM - } else if (arg_string == "--help" || HasGoogleTestFlagPrefix(arg)) { + } else if (IsHelpFlag(arg_string) || HasGoogleTestFlagPrefix(arg)) { // Both help flag and unrecognized Google Test flags (excluding // internal ones) trigger help display. g_help_flag = true;