0
0
mirror of https://github.com/google/googletest.git synced 2025-03-19 10:23:48 +00:00

Merge pull request #2751 from calumr:quiet-flag

PiperOrigin-RevId: 309958629
This commit is contained in:
vslashg 2020-05-05 17:07:14 -04:00
commit e589a33717
8 changed files with 260 additions and 57 deletions

View File

@ -2261,6 +2261,12 @@ disable colors, or let googletest decide. When the value is `auto`, googletest
will use colors if and only if the output goes to a terminal and (on non-Windows will use colors if and only if the output goes to a terminal and (on non-Windows
platforms) the `TERM` environment variable is set to `xterm` or `xterm-color`. platforms) the `TERM` environment variable is set to `xterm` or `xterm-color`.
#### Suppressing test passes
By default, googletest prints 1 line of output for each test, indicating if it
passed or failed. To show only test failures, run the test program with
`--gtest_brief=1`, or set the GTEST_BRIEF environment variable to `1`.
#### Suppressing the Elapsed Time #### Suppressing the Elapsed Time
By default, googletest prints the time it takes to run each test. To disable By default, googletest prints the time it takes to run each test. To disable

View File

@ -121,6 +121,9 @@ GTEST_DECLARE_bool_(list_tests);
// in addition to its normal textual output. // in addition to its normal textual output.
GTEST_DECLARE_string_(output); GTEST_DECLARE_string_(output);
// This flags control whether Google Test prints only test failures.
GTEST_DECLARE_bool_(brief);
// This flags control whether Google Test prints the elapsed time for each // This flags control whether Google Test prints the elapsed time for each
// test. // test.
GTEST_DECLARE_bool_(print_time); GTEST_DECLARE_bool_(print_time);

View File

@ -88,6 +88,7 @@ const char kFailFast[] = "fail_fast";
const char kFilterFlag[] = "filter"; const char kFilterFlag[] = "filter";
const char kListTestsFlag[] = "list_tests"; const char kListTestsFlag[] = "list_tests";
const char kOutputFlag[] = "output"; const char kOutputFlag[] = "output";
const char kBriefFlag[] = "brief";
const char kPrintTimeFlag[] = "print_time"; const char kPrintTimeFlag[] = "print_time";
const char kPrintUTF8Flag[] = "print_utf8"; const char kPrintUTF8Flag[] = "print_utf8";
const char kRandomSeedFlag[] = "random_seed"; const char kRandomSeedFlag[] = "random_seed";
@ -170,6 +171,7 @@ class GTestFlagSaver {
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test); internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
list_tests_ = GTEST_FLAG(list_tests); list_tests_ = GTEST_FLAG(list_tests);
output_ = GTEST_FLAG(output); output_ = GTEST_FLAG(output);
brief_ = GTEST_FLAG(brief);
print_time_ = GTEST_FLAG(print_time); print_time_ = GTEST_FLAG(print_time);
print_utf8_ = GTEST_FLAG(print_utf8); print_utf8_ = GTEST_FLAG(print_utf8);
random_seed_ = GTEST_FLAG(random_seed); random_seed_ = GTEST_FLAG(random_seed);
@ -193,6 +195,7 @@ class GTestFlagSaver {
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_; GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
GTEST_FLAG(list_tests) = list_tests_; GTEST_FLAG(list_tests) = list_tests_;
GTEST_FLAG(output) = output_; GTEST_FLAG(output) = output_;
GTEST_FLAG(brief) = brief_;
GTEST_FLAG(print_time) = print_time_; GTEST_FLAG(print_time) = print_time_;
GTEST_FLAG(print_utf8) = print_utf8_; GTEST_FLAG(print_utf8) = print_utf8_;
GTEST_FLAG(random_seed) = random_seed_; GTEST_FLAG(random_seed) = random_seed_;
@ -216,6 +219,7 @@ class GTestFlagSaver {
std::string internal_run_death_test_; std::string internal_run_death_test_;
bool list_tests_; bool list_tests_;
std::string output_; std::string output_;
bool brief_;
bool print_time_; bool print_time_;
bool print_utf8_; bool print_utf8_;
int32_t random_seed_; int32_t random_seed_;

View File

@ -289,6 +289,10 @@ GTEST_DEFINE_string_(
"executable's name and, if necessary, made unique by adding " "executable's name and, if necessary, made unique by adding "
"digits."); "digits.");
GTEST_DEFINE_bool_(
brief, internal::BoolFromGTestEnv("brief", false),
"True if only test failures should be displayed in text output.");
GTEST_DEFINE_bool_(print_time, internal::BoolFromGTestEnv("print_time", true), GTEST_DEFINE_bool_(print_time, internal::BoolFromGTestEnv("print_time", true),
"True if and only if " GTEST_NAME_ "True if and only if " GTEST_NAME_
" should display elapsed time in text output."); " should display elapsed time in text output.");
@ -3640,6 +3644,110 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
// End PrettyUnitTestResultPrinter // End PrettyUnitTestResultPrinter
// This class implements the TestEventListener interface.
//
// Class BriefUnitTestResultPrinter is copyable.
class BriefUnitTestResultPrinter : public TestEventListener {
public:
BriefUnitTestResultPrinter() {}
static void PrintTestName(const char* test_suite, const char* test) {
printf("%s.%s", test_suite, test);
}
// The following methods override what's in the TestEventListener class.
void OnTestProgramStart(const UnitTest& /*unit_test*/) override {}
void OnTestIterationStart(const UnitTest& /*unit_test*/,
int /*iteration*/) override {}
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {}
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestCaseStart(const TestCase& /*test_case*/) override {}
#else
void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {}
#endif // OnTestCaseStart
void OnTestStart(const TestInfo& /*test_info*/) override {}
void OnTestPartResult(const TestPartResult& result) override;
void OnTestEnd(const TestInfo& test_info) override;
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestCaseEnd(const TestCase& /*test_case*/) override {}
#else
void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {}
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
};
// Called after an assertion failure.
void BriefUnitTestResultPrinter::OnTestPartResult(
const TestPartResult& result) {
switch (result.type()) {
// If the test part succeeded, we don't need to do anything.
case TestPartResult::kSuccess:
return;
default:
// Print failure message from the assertion
// (e.g. expected this and got that).
PrintTestPartResult(result);
fflush(stdout);
}
}
void BriefUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
if (test_info.result()->Failed()) {
ColoredPrintf(GTestColor::kRed, "[ FAILED ] ");
PrintTestName(test_info.test_suite_name(), test_info.name());
PrintFullTestCommentIfPresent(test_info);
if (GTEST_FLAG(print_time)) {
printf(" (%s ms)\n",
internal::StreamableToString(test_info.result()->elapsed_time())
.c_str());
} else {
printf("\n");
}
fflush(stdout);
}
}
void BriefUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
int /*iteration*/) {
ColoredPrintf(GTestColor::kGreen, "[==========] ");
printf("%s from %s ran.",
FormatTestCount(unit_test.test_to_run_count()).c_str(),
FormatTestSuiteCount(unit_test.test_suite_to_run_count()).c_str());
if (GTEST_FLAG(print_time)) {
printf(" (%s ms total)",
internal::StreamableToString(unit_test.elapsed_time()).c_str());
}
printf("\n");
ColoredPrintf(GTestColor::kGreen, "[ PASSED ] ");
printf("%s.\n", FormatTestCount(unit_test.successful_test_count()).c_str());
const int skipped_test_count = unit_test.skipped_test_count();
if (skipped_test_count > 0) {
ColoredPrintf(GTestColor::kGreen, "[ SKIPPED ] ");
printf("%s.\n", FormatTestCount(skipped_test_count).c_str());
}
int num_disabled = unit_test.reportable_disabled_test_count();
if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) {
if (unit_test.Passed()) {
printf("\n"); // Add a spacer if no FAILURE banner is displayed.
}
ColoredPrintf(GTestColor::kYellow, " YOU HAVE %d DISABLED %s\n\n",
num_disabled, num_disabled == 1 ? "TEST" : "TESTS");
}
// Ensure that Google Test output is printed before, e.g., heapchecker output.
fflush(stdout);
}
// End BriefUnitTestResultPrinter
// class TestEventRepeater // class TestEventRepeater
// //
// This class forwards events to other event listeners. // This class forwards events to other event listeners.
@ -5390,6 +5498,10 @@ void UnitTestImpl::PostFlagParsingInit() {
// to shut down the default XML output before invoking RUN_ALL_TESTS. // to shut down the default XML output before invoking RUN_ALL_TESTS.
ConfigureXmlOutput(); ConfigureXmlOutput();
if (GTEST_FLAG(brief)) {
listeners()->SetDefaultResultPrinter(new BriefUnitTestResultPrinter);
}
#if GTEST_CAN_STREAM_RESULTS_ #if GTEST_CAN_STREAM_RESULTS_
// Configures listeners for streaming test results to the specified server. // Configures listeners for streaming test results to the specified server.
ConfigureStreamingOutput(); ConfigureStreamingOutput();
@ -6141,69 +6253,96 @@ static void PrintColorEncoded(const char* str) {
} }
static const char kColorEncodedHelpMessage[] = static const char kColorEncodedHelpMessage[] =
"This program contains tests written using " GTEST_NAME_ ". You can use the\n" "This program contains tests written using " GTEST_NAME_
"following command line flags to control its behavior:\n" ". You can use the\n"
"\n" "following command line flags to control its behavior:\n"
"Test Selection:\n" "\n"
" @G--" GTEST_FLAG_PREFIX_ "list_tests@D\n" "Test Selection:\n"
" List the names of all tests instead of running them. The name of\n" " @G--" GTEST_FLAG_PREFIX_
" TEST(Foo, Bar) is \"Foo.Bar\".\n" "list_tests@D\n"
" @G--" GTEST_FLAG_PREFIX_ "filter=@YPOSTIVE_PATTERNS" " List the names of all tests instead of running them. The name of\n"
" TEST(Foo, Bar) is \"Foo.Bar\".\n"
" @G--" GTEST_FLAG_PREFIX_
"filter=@YPOSTIVE_PATTERNS"
"[@G-@YNEGATIVE_PATTERNS]@D\n" "[@G-@YNEGATIVE_PATTERNS]@D\n"
" Run only the tests whose name matches one of the positive patterns but\n" " Run only the tests whose name matches one of the positive patterns "
" none of the negative patterns. '?' matches any single character; '*'\n" "but\n"
" matches any substring; ':' separates two patterns.\n" " none of the negative patterns. '?' matches any single character; "
" @G--" GTEST_FLAG_PREFIX_ "also_run_disabled_tests@D\n" "'*'\n"
" Run all disabled tests too.\n" " matches any substring; ':' separates two patterns.\n"
"\n" " @G--" GTEST_FLAG_PREFIX_
"Test Execution:\n" "also_run_disabled_tests@D\n"
" @G--" GTEST_FLAG_PREFIX_ "repeat=@Y[COUNT]@D\n" " Run all disabled tests too.\n"
" Run the tests repeatedly; use a negative count to repeat forever.\n" "\n"
" @G--" GTEST_FLAG_PREFIX_ "shuffle@D\n" "Test Execution:\n"
" Randomize tests' orders on every iteration.\n" " @G--" GTEST_FLAG_PREFIX_
" @G--" GTEST_FLAG_PREFIX_ "random_seed=@Y[NUMBER]@D\n" "repeat=@Y[COUNT]@D\n"
" Random number seed to use for shuffling test orders (between 1 and\n" " Run the tests repeatedly; use a negative count to repeat forever.\n"
" 99999, or 0 to use a seed based on the current time).\n" " @G--" GTEST_FLAG_PREFIX_
"\n" "shuffle@D\n"
"Test Output:\n" " Randomize tests' orders on every iteration.\n"
" @G--" GTEST_FLAG_PREFIX_ "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n" " @G--" GTEST_FLAG_PREFIX_
" Enable/disable colored output. The default is @Gauto@D.\n" "random_seed=@Y[NUMBER]@D\n"
" -@G-" GTEST_FLAG_PREFIX_ "print_time=0@D\n" " Random number seed to use for shuffling test orders (between 1 and\n"
" Don't print the elapsed time of each test.\n" " 99999, or 0 to use a seed based on the current time).\n"
" @G--" GTEST_FLAG_PREFIX_ "output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G" "\n"
GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n" "Test Output:\n"
" Generate a JSON or XML report in the given directory or with the given\n" " @G--" GTEST_FLAG_PREFIX_
" file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n" "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n"
" Enable/disable colored output. The default is @Gauto@D.\n"
" -@G-" GTEST_FLAG_PREFIX_
"brief=1@D\n"
" Only print test failures.\n"
" -@G-" GTEST_FLAG_PREFIX_
"print_time=0@D\n"
" Don't print the elapsed time of each test.\n"
" @G--" GTEST_FLAG_PREFIX_
"output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G" GTEST_PATH_SEP_
"@Y|@G:@YFILE_PATH]@D\n"
" Generate a JSON or XML report in the given directory or with the "
"given\n"
" file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n"
# if GTEST_CAN_STREAM_RESULTS_ # if GTEST_CAN_STREAM_RESULTS_
" @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n" " @G--" GTEST_FLAG_PREFIX_
" Stream test results to the given server.\n" "stream_result_to=@YHOST@G:@YPORT@D\n"
" Stream test results to the given server.\n"
# endif // GTEST_CAN_STREAM_RESULTS_ # endif // GTEST_CAN_STREAM_RESULTS_
"\n" "\n"
"Assertion Behavior:\n" "Assertion Behavior:\n"
# if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS # if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
" @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n" " @G--" GTEST_FLAG_PREFIX_
" Set the default death test style.\n" "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
" Set the default death test style.\n"
# endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS # endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
" @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n" " @G--" GTEST_FLAG_PREFIX_
" Turn assertion failures into debugger break-points.\n" "break_on_failure@D\n"
" @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n" " Turn assertion failures into debugger break-points.\n"
" Turn assertion failures into C++ exceptions for use by an external\n" " @G--" GTEST_FLAG_PREFIX_
" test framework.\n" "throw_on_failure@D\n"
" @G--" GTEST_FLAG_PREFIX_ "catch_exceptions=0@D\n" " Turn assertion failures into C++ exceptions for use by an external\n"
" Do not report exceptions as test failures. Instead, allow them\n" " test framework.\n"
" to crash the program or throw a pop-up (on Windows).\n" " @G--" GTEST_FLAG_PREFIX_
"\n" "catch_exceptions=0@D\n"
"Except for @G--" GTEST_FLAG_PREFIX_ "list_tests@D, you can alternatively set " " Do not report exceptions as test failures. Instead, allow them\n"
" to crash the program or throw a pop-up (on Windows).\n"
"\n"
"Except for @G--" GTEST_FLAG_PREFIX_
"list_tests@D, you can alternatively set "
"the corresponding\n" "the corresponding\n"
"environment variable of a flag (all letters in upper-case). For example, to\n" "environment variable of a flag (all letters in upper-case). For example, "
"disable colored text output, you can either specify @G--" GTEST_FLAG_PREFIX_ "to\n"
"disable colored text output, you can either specify "
"@G--" GTEST_FLAG_PREFIX_
"color=no@D or set\n" "color=no@D or set\n"
"the @G" GTEST_FLAG_PREFIX_UPPER_ "COLOR@D environment variable to @Gno@D.\n" "the @G" GTEST_FLAG_PREFIX_UPPER_
"\n" "COLOR@D environment variable to @Gno@D.\n"
"For more information, please read the " GTEST_NAME_ " documentation at\n" "\n"
"@G" GTEST_PROJECT_URL_ "@D. If you find a bug in " GTEST_NAME_ "\n" "For more information, please read the " GTEST_NAME_
"(not one in your own code or tests), please report it to\n" " documentation at\n"
"@G<" GTEST_DEV_EMAIL_ ">@D.\n"; "@G" GTEST_PROJECT_URL_ "@D. If you find a bug in " GTEST_NAME_
"\n"
"(not one in your own code or tests), please report it to\n"
"@G<" GTEST_DEV_EMAIL_ ">@D.\n";
static bool ParseGoogleTestFlag(const char* const arg) { static bool ParseGoogleTestFlag(const char* const arg) {
return ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag, return ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag,
@ -6223,6 +6362,7 @@ static bool ParseGoogleTestFlag(const char* const arg) {
&GTEST_FLAG(internal_run_death_test)) || &GTEST_FLAG(internal_run_death_test)) ||
ParseBoolFlag(arg, kListTestsFlag, &GTEST_FLAG(list_tests)) || ParseBoolFlag(arg, kListTestsFlag, &GTEST_FLAG(list_tests)) ||
ParseStringFlag(arg, kOutputFlag, &GTEST_FLAG(output)) || ParseStringFlag(arg, kOutputFlag, &GTEST_FLAG(output)) ||
ParseBoolFlag(arg, kBriefFlag, &GTEST_FLAG(brief)) ||
ParseBoolFlag(arg, kPrintTimeFlag, &GTEST_FLAG(print_time)) || ParseBoolFlag(arg, kPrintTimeFlag, &GTEST_FLAG(print_time)) ||
ParseBoolFlag(arg, kPrintUTF8Flag, &GTEST_FLAG(print_utf8)) || ParseBoolFlag(arg, kPrintUTF8Flag, &GTEST_FLAG(print_utf8)) ||
ParseInt32Flag(arg, kRandomSeedFlag, &GTEST_FLAG(random_seed)) || ParseInt32Flag(arg, kRandomSeedFlag, &GTEST_FLAG(random_seed)) ||

View File

@ -90,6 +90,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
TestFlag('filter', 'FooTest.Bar', '*') TestFlag('filter', 'FooTest.Bar', '*')
SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test
TestFlag('output', 'xml:tmp/foo.xml', '') TestFlag('output', 'xml:tmp/foo.xml', '')
TestFlag('brief', '1', '0')
TestFlag('print_time', '0', '1') TestFlag('print_time', '0', '1')
TestFlag('repeat', '999', '1') TestFlag('repeat', '999', '1')
TestFlag('throw_on_failure', '1', '0') TestFlag('throw_on_failure', '1', '0')

View File

@ -87,6 +87,11 @@ void PrintFlag(const char* flag) {
return; return;
} }
if (strcmp(flag, "brief") == 0) {
cout << GTEST_FLAG(brief);
return;
}
if (strcmp(flag, "print_time") == 0) { if (strcmp(flag, "print_time") == 0) {
cout << GTEST_FLAG(print_time); cout << GTEST_FLAG(print_time);
return; return;

View File

@ -68,6 +68,7 @@ HELP_REGEX = re.compile(
FLAG_PREFIX + r'shuffle.*' + FLAG_PREFIX + r'shuffle.*' +
FLAG_PREFIX + r'random_seed=.*' + FLAG_PREFIX + r'random_seed=.*' +
FLAG_PREFIX + r'color=.*' + FLAG_PREFIX + r'color=.*' +
FLAG_PREFIX + r'brief.*' +
FLAG_PREFIX + r'print_time.*' + FLAG_PREFIX + r'print_time.*' +
FLAG_PREFIX + r'output=.*' + FLAG_PREFIX + r'output=.*' +
FLAG_PREFIX + r'break_on_failure.*' + FLAG_PREFIX + r'break_on_failure.*' +

View File

@ -45,7 +45,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
testing::GTEST_FLAG(filter) != "unknown" || testing::GTEST_FLAG(filter) != "unknown" ||
testing::GTEST_FLAG(list_tests) || testing::GTEST_FLAG(list_tests) ||
testing::GTEST_FLAG(output) != "unknown" || testing::GTEST_FLAG(output) != "unknown" ||
testing::GTEST_FLAG(print_time) || testing::GTEST_FLAG(brief) || testing::GTEST_FLAG(print_time) ||
testing::GTEST_FLAG(random_seed) || testing::GTEST_FLAG(random_seed) ||
testing::GTEST_FLAG(repeat) > 0 || testing::GTEST_FLAG(repeat) > 0 ||
testing::GTEST_FLAG(show_internal_stack_frames) || testing::GTEST_FLAG(show_internal_stack_frames) ||
@ -207,6 +207,7 @@ using testing::GTEST_FLAG(fail_fast);
using testing::GTEST_FLAG(filter); using testing::GTEST_FLAG(filter);
using testing::GTEST_FLAG(list_tests); using testing::GTEST_FLAG(list_tests);
using testing::GTEST_FLAG(output); using testing::GTEST_FLAG(output);
using testing::GTEST_FLAG(brief);
using testing::GTEST_FLAG(print_time); using testing::GTEST_FLAG(print_time);
using testing::GTEST_FLAG(random_seed); using testing::GTEST_FLAG(random_seed);
using testing::GTEST_FLAG(repeat); using testing::GTEST_FLAG(repeat);
@ -1604,6 +1605,7 @@ class GTestFlagSaverTest : public Test {
GTEST_FLAG(filter) = ""; GTEST_FLAG(filter) = "";
GTEST_FLAG(list_tests) = false; GTEST_FLAG(list_tests) = false;
GTEST_FLAG(output) = ""; GTEST_FLAG(output) = "";
GTEST_FLAG(brief) = false;
GTEST_FLAG(print_time) = true; GTEST_FLAG(print_time) = true;
GTEST_FLAG(random_seed) = 0; GTEST_FLAG(random_seed) = 0;
GTEST_FLAG(repeat) = 1; GTEST_FLAG(repeat) = 1;
@ -1632,6 +1634,7 @@ class GTestFlagSaverTest : public Test {
EXPECT_STREQ("", GTEST_FLAG(filter).c_str()); EXPECT_STREQ("", GTEST_FLAG(filter).c_str());
EXPECT_FALSE(GTEST_FLAG(list_tests)); EXPECT_FALSE(GTEST_FLAG(list_tests));
EXPECT_STREQ("", GTEST_FLAG(output).c_str()); EXPECT_STREQ("", GTEST_FLAG(output).c_str());
EXPECT_FALSE(GTEST_FLAG(brief));
EXPECT_TRUE(GTEST_FLAG(print_time)); EXPECT_TRUE(GTEST_FLAG(print_time));
EXPECT_EQ(0, GTEST_FLAG(random_seed)); EXPECT_EQ(0, GTEST_FLAG(random_seed));
EXPECT_EQ(1, GTEST_FLAG(repeat)); EXPECT_EQ(1, GTEST_FLAG(repeat));
@ -1649,6 +1652,7 @@ class GTestFlagSaverTest : public Test {
GTEST_FLAG(filter) = "abc"; GTEST_FLAG(filter) = "abc";
GTEST_FLAG(list_tests) = true; GTEST_FLAG(list_tests) = true;
GTEST_FLAG(output) = "xml:foo.xml"; GTEST_FLAG(output) = "xml:foo.xml";
GTEST_FLAG(brief) = true;
GTEST_FLAG(print_time) = false; GTEST_FLAG(print_time) = false;
GTEST_FLAG(random_seed) = 1; GTEST_FLAG(random_seed) = 1;
GTEST_FLAG(repeat) = 100; GTEST_FLAG(repeat) = 100;
@ -5509,6 +5513,7 @@ struct Flags {
filter(""), filter(""),
list_tests(false), list_tests(false),
output(""), output(""),
brief(false),
print_time(true), print_time(true),
random_seed(0), random_seed(0),
repeat(1), repeat(1),
@ -5583,6 +5588,14 @@ struct Flags {
return flags; return flags;
} }
// Creates a Flags struct where the gtest_brief flag has the given
// value.
static Flags Brief(bool brief) {
Flags flags;
flags.brief = brief;
return flags;
}
// Creates a Flags struct where the gtest_print_time flag has the given // Creates a Flags struct where the gtest_print_time flag has the given
// value. // value.
static Flags PrintTime(bool print_time) { static Flags PrintTime(bool print_time) {
@ -5648,6 +5661,7 @@ struct Flags {
const char* filter; const char* filter;
bool list_tests; bool list_tests;
const char* output; const char* output;
bool brief;
bool print_time; bool print_time;
int32_t random_seed; int32_t random_seed;
int32_t repeat; int32_t repeat;
@ -5670,6 +5684,7 @@ class ParseFlagsTest : public Test {
GTEST_FLAG(filter) = ""; GTEST_FLAG(filter) = "";
GTEST_FLAG(list_tests) = false; GTEST_FLAG(list_tests) = false;
GTEST_FLAG(output) = ""; GTEST_FLAG(output) = "";
GTEST_FLAG(brief) = false;
GTEST_FLAG(print_time) = true; GTEST_FLAG(print_time) = true;
GTEST_FLAG(random_seed) = 0; GTEST_FLAG(random_seed) = 0;
GTEST_FLAG(repeat) = 1; GTEST_FLAG(repeat) = 1;
@ -5701,6 +5716,7 @@ class ParseFlagsTest : public Test {
EXPECT_STREQ(expected.filter, GTEST_FLAG(filter).c_str()); EXPECT_STREQ(expected.filter, GTEST_FLAG(filter).c_str());
EXPECT_EQ(expected.list_tests, GTEST_FLAG(list_tests)); EXPECT_EQ(expected.list_tests, GTEST_FLAG(list_tests));
EXPECT_STREQ(expected.output, GTEST_FLAG(output).c_str()); EXPECT_STREQ(expected.output, GTEST_FLAG(output).c_str());
EXPECT_EQ(expected.brief, GTEST_FLAG(brief));
EXPECT_EQ(expected.print_time, GTEST_FLAG(print_time)); EXPECT_EQ(expected.print_time, GTEST_FLAG(print_time));
EXPECT_EQ(expected.random_seed, GTEST_FLAG(random_seed)); EXPECT_EQ(expected.random_seed, GTEST_FLAG(random_seed));
EXPECT_EQ(expected.repeat, GTEST_FLAG(repeat)); EXPECT_EQ(expected.repeat, GTEST_FLAG(repeat));
@ -5992,6 +6008,33 @@ TEST_F(ParseFlagsTest, OutputXmlDirectory) {
Flags::Output("xml:directory/path/"), false); Flags::Output("xml:directory/path/"), false);
} }
// Tests having a --gtest_brief flag
TEST_F(ParseFlagsTest, BriefFlag) {
const char* argv[] = {"foo.exe", "--gtest_brief", nullptr};
const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Brief(true), false);
}
// Tests having a --gtest_brief flag with a "true" value
TEST_F(ParseFlagsTest, BriefFlagTrue) {
const char* argv[] = {"foo.exe", "--gtest_brief=1", nullptr};
const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Brief(true), false);
}
// Tests having a --gtest_brief flag with a "false" value
TEST_F(ParseFlagsTest, BriefFlagFalse) {
const char* argv[] = {"foo.exe", "--gtest_brief=0", nullptr};
const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Brief(false), false);
}
// Tests having a --gtest_print_time flag // Tests having a --gtest_print_time flag
TEST_F(ParseFlagsTest, PrintTimeFlag) { TEST_F(ParseFlagsTest, PrintTimeFlag) {
const char* argv[] = {"foo.exe", "--gtest_print_time", nullptr}; const char* argv[] = {"foo.exe", "--gtest_print_time", nullptr};