mirror of
https://github.com/google/googletest.git
synced 2026-07-30 16:26:24 +08:00
Merge ed86686425dfb67d7197f1057a01222e907b051f into 3ff51c3e80f2c2eb105d43ecb9acab9a62e01600
This commit is contained in:
commit
51a4a04ba1
@ -110,6 +110,10 @@ GTEST_DECLARE_bool_(install_failure_signal_handler);
|
|||||||
// are actually run if the flag is provided.
|
// are actually run if the flag is provided.
|
||||||
GTEST_DECLARE_bool_(list_tests);
|
GTEST_DECLARE_bool_(list_tests);
|
||||||
|
|
||||||
|
// This flag suppresses the "# GetParam() = ..." and "# TypeParam = ..."
|
||||||
|
// annotations when listing tests with --gtest_list_tests.
|
||||||
|
GTEST_DECLARE_bool_(list_tests_brief);
|
||||||
|
|
||||||
// This flag controls whether Google Test emits a detailed XML report to a file
|
// This flag controls whether Google Test emits a detailed XML report to a file
|
||||||
// in addition to its normal textual output.
|
// in addition to its normal textual output.
|
||||||
GTEST_DECLARE_string_(output);
|
GTEST_DECLARE_string_(output);
|
||||||
|
|||||||
@ -322,6 +322,12 @@ GTEST_DEFINE_bool_(
|
|||||||
|
|
||||||
GTEST_DEFINE_bool_(list_tests, false, "List all tests without running them.");
|
GTEST_DEFINE_bool_(list_tests, false, "List all tests without running them.");
|
||||||
|
|
||||||
|
GTEST_DEFINE_bool_(
|
||||||
|
list_tests_brief,
|
||||||
|
testing::internal::BoolFromGTestEnv("list_tests_brief", false),
|
||||||
|
"True if --gtest_list_tests should omit the per-test "
|
||||||
|
"\"# GetParam() = ...\" and \"# TypeParam = ...\" annotations.");
|
||||||
|
|
||||||
// The net priority order after flag processing is thus:
|
// The net priority order after flag processing is thus:
|
||||||
// --gtest_output command line flag
|
// --gtest_output command line flag
|
||||||
// GTEST_OUTPUT environment variable
|
// GTEST_OUTPUT environment variable
|
||||||
@ -6390,6 +6396,7 @@ static void PrintOnOneLine(const char* str, int max_length) {
|
|||||||
void UnitTestImpl::ListTestsMatchingFilter() {
|
void UnitTestImpl::ListTestsMatchingFilter() {
|
||||||
// Print at most this many characters for each type/value parameter.
|
// Print at most this many characters for each type/value parameter.
|
||||||
const int kMaxParamLength = 250;
|
const int kMaxParamLength = 250;
|
||||||
|
const bool brief = GTEST_FLAG_GET(list_tests_brief);
|
||||||
|
|
||||||
for (auto* test_suite : test_suites_) {
|
for (auto* test_suite : test_suites_) {
|
||||||
bool printed_test_suite_name = false;
|
bool printed_test_suite_name = false;
|
||||||
@ -6400,7 +6407,7 @@ void UnitTestImpl::ListTestsMatchingFilter() {
|
|||||||
if (!printed_test_suite_name) {
|
if (!printed_test_suite_name) {
|
||||||
printed_test_suite_name = true;
|
printed_test_suite_name = true;
|
||||||
printf("%s.", test_suite->name());
|
printf("%s.", test_suite->name());
|
||||||
if (test_suite->type_param() != nullptr) {
|
if (!brief && test_suite->type_param() != nullptr) {
|
||||||
printf(" # %s = ", kTypeParamLabel);
|
printf(" # %s = ", kTypeParamLabel);
|
||||||
// We print the type parameter on a single line to make
|
// We print the type parameter on a single line to make
|
||||||
// the output easy to parse by a program.
|
// the output easy to parse by a program.
|
||||||
@ -6409,7 +6416,7 @@ void UnitTestImpl::ListTestsMatchingFilter() {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
printf(" %s", test_info->name());
|
printf(" %s", test_info->name());
|
||||||
if (test_info->value_param() != nullptr) {
|
if (!brief && test_info->value_param() != nullptr) {
|
||||||
printf(" # %s = ", kValueParamLabel);
|
printf(" # %s = ", kValueParamLabel);
|
||||||
// We print the value parameter on a single line to make the
|
// We print the value parameter on a single line to make the
|
||||||
// output easy to parse by a program.
|
// output easy to parse by a program.
|
||||||
@ -6708,6 +6715,10 @@ static const char kColorEncodedHelpMessage[] =
|
|||||||
" List the names of all tests instead of running them. The name of\n"
|
" List the names of all tests instead of running them. The name of\n"
|
||||||
" TEST(Foo, Bar) is \"Foo.Bar\".\n"
|
" TEST(Foo, Bar) is \"Foo.Bar\".\n"
|
||||||
" @G--" GTEST_FLAG_PREFIX_
|
" @G--" GTEST_FLAG_PREFIX_
|
||||||
|
"list_tests_brief@D\n"
|
||||||
|
" When listing tests, omit the \"# GetParam() = ...\" and\n"
|
||||||
|
" \"# TypeParam = ...\" annotations.\n"
|
||||||
|
" @G--" GTEST_FLAG_PREFIX_
|
||||||
"filter=@YPOSITIVE_PATTERNS"
|
"filter=@YPOSITIVE_PATTERNS"
|
||||||
"[@G-@YNEGATIVE_PATTERNS]@D\n"
|
"[@G-@YNEGATIVE_PATTERNS]@D\n"
|
||||||
" Run only the tests whose name matches one of the positive patterns "
|
" Run only the tests whose name matches one of the positive patterns "
|
||||||
@ -6830,6 +6841,7 @@ static bool ParseGoogleTestFlag(const char* const arg) {
|
|||||||
GTEST_INTERNAL_PARSE_FLAG(filter);
|
GTEST_INTERNAL_PARSE_FLAG(filter);
|
||||||
GTEST_INTERNAL_PARSE_FLAG(internal_run_death_test);
|
GTEST_INTERNAL_PARSE_FLAG(internal_run_death_test);
|
||||||
GTEST_INTERNAL_PARSE_FLAG(list_tests);
|
GTEST_INTERNAL_PARSE_FLAG(list_tests);
|
||||||
|
GTEST_INTERNAL_PARSE_FLAG(list_tests_brief);
|
||||||
GTEST_INTERNAL_PARSE_FLAG(output);
|
GTEST_INTERNAL_PARSE_FLAG(output);
|
||||||
GTEST_INTERNAL_PARSE_FLAG(brief);
|
GTEST_INTERNAL_PARSE_FLAG(brief);
|
||||||
GTEST_INTERNAL_PARSE_FLAG(print_time);
|
GTEST_INTERNAL_PARSE_FLAG(print_time);
|
||||||
|
|||||||
@ -96,6 +96,53 @@ MyInstantiation/ValueParamTest\.
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# The expected output when running googletest-list-tests-unittest_ with
|
||||||
|
# --gtest_list_tests and --gtest_list_tests_brief. The "# TypeParam = ..."
|
||||||
|
# and "# GetParam() = ..." annotations must be omitted.
|
||||||
|
EXPECTED_OUTPUT_BRIEF_RE = re.compile(
|
||||||
|
r"""FooDeathTest\.
|
||||||
|
Test1
|
||||||
|
Foo\.
|
||||||
|
Bar1
|
||||||
|
Bar2
|
||||||
|
DISABLED_Bar3
|
||||||
|
Abc\.
|
||||||
|
Xyz
|
||||||
|
Def
|
||||||
|
FooBar\.
|
||||||
|
Baz
|
||||||
|
FooTest\.
|
||||||
|
Test1
|
||||||
|
DISABLED_Test2
|
||||||
|
Test3
|
||||||
|
TypedTest/0\.
|
||||||
|
TestA
|
||||||
|
TestB
|
||||||
|
TypedTest/1\.
|
||||||
|
TestA
|
||||||
|
TestB
|
||||||
|
TypedTest/2\.
|
||||||
|
TestA
|
||||||
|
TestB
|
||||||
|
My/TypeParamTest/0\.
|
||||||
|
TestA
|
||||||
|
TestB
|
||||||
|
My/TypeParamTest/1\.
|
||||||
|
TestA
|
||||||
|
TestB
|
||||||
|
My/TypeParamTest/2\.
|
||||||
|
TestA
|
||||||
|
TestB
|
||||||
|
MyInstantiation/ValueParamTest\.
|
||||||
|
TestA/0
|
||||||
|
TestA/1
|
||||||
|
TestA/2
|
||||||
|
TestB/0
|
||||||
|
TestB/1
|
||||||
|
TestB/2
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
# The expected output when running googletest-list-tests-unittest_ with
|
# The expected output when running googletest-list-tests-unittest_ with
|
||||||
# --gtest_list_tests and --gtest_filter=Foo*.
|
# --gtest_list_tests and --gtest_filter=Foo*.
|
||||||
EXPECTED_OUTPUT_FILTER_FOO_RE = re.compile(
|
EXPECTED_OUTPUT_FILTER_FOO_RE = re.compile(
|
||||||
@ -220,6 +267,19 @@ class GTestListTestsUnitTest(gtest_test_utils.TestCase):
|
|||||||
other_flag='--gtest_filter=Foo*',
|
other_flag='--gtest_filter=Foo*',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def testListTestsBriefOmitsParamAnnotations(self):
|
||||||
|
"""--gtest_list_tests_brief omits "# GetParam() =" and "# TypeParam ="."""
|
||||||
|
|
||||||
|
output = Run(['--gtest_list_tests', '--gtest_list_tests_brief'])
|
||||||
|
self.assertTrue(
|
||||||
|
EXPECTED_OUTPUT_BRIEF_RE.match(output),
|
||||||
|
'output of "--gtest_list_tests --gtest_list_tests_brief" is "%s",\n'
|
||||||
|
'which does not match regex "%s"'
|
||||||
|
% (output, EXPECTED_OUTPUT_BRIEF_RE.pattern),
|
||||||
|
)
|
||||||
|
self.assertNotIn('GetParam()', output)
|
||||||
|
self.assertNotIn('TypeParam =', output)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gtest_test_utils.Main()
|
gtest_test_utils.Main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user