Skip to content

Commit eb5ca29

Browse files
author
Julian Lettner
committed
[lit] Cleanup printing of discovered suites and tests
1 parent 5be42f3 commit eb5ca29

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

llvm/utils/lit/lit/cl_arguments.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,10 @@ def parse_args():
152152
help="Enable debugging (for 'lit' development)",
153153
action="store_true")
154154
debug_group.add_argument("--show-suites",
155-
dest="showSuites",
156-
help="Show discovered test suites",
155+
help="Show discovered test suites and exit",
157156
action="store_true")
158157
debug_group.add_argument("--show-tests",
159-
dest="showTests",
160-
help="Show all discovered tests",
158+
help="Show all discovered tests and exit",
161159
action="store_true")
162160

163161
# LIT is special: environment variables override command line arguments.

llvm/utils/lit/lit/main.py

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def main(builtin_params={}):
4242
sys.stderr.write('error: did not discover any tests for provided path(s)\n')
4343
sys.exit(2)
4444

45+
if opts.show_suites or opts.show_tests:
46+
print_discovered(discovered_tests, opts.show_suites, opts.show_tests)
47+
sys.exit(0)
48+
4549
# Command line overrides configuration for maxIndividualTestTime.
4650
if opts.maxIndividualTestTime is not None: # `not None` is important (default: 0)
4751
if opts.maxIndividualTestTime != lit_config.maxIndividualTestTime:
@@ -53,10 +57,6 @@ def main(builtin_params={}):
5357
opts.maxIndividualTestTime))
5458
lit_config.maxIndividualTestTime = opts.maxIndividualTestTime
5559

56-
if opts.showSuites or opts.showTests:
57-
print_suites_or_tests(discovered_tests, opts)
58-
return
59-
6060
filtered_tests = [t for t in discovered_tests if
6161
opts.filter.search(t.getFullName())]
6262
if not filtered_tests:
@@ -119,34 +119,29 @@ def parse(p):
119119
params.update([parse(p) for p in user_params])
120120
return params
121121

122-
def print_suites_or_tests(tests, opts):
123-
# Aggregate the tests by suite.
124-
suitesAndTests = {}
125-
for result_test in tests:
126-
if result_test.suite not in suitesAndTests:
127-
suitesAndTests[result_test.suite] = []
128-
suitesAndTests[result_test.suite].append(result_test)
129-
suitesAndTests = list(suitesAndTests.items())
130-
suitesAndTests.sort(key = lambda item: item[0].name)
131-
132-
# Show the suites, if requested.
133-
if opts.showSuites:
122+
123+
def print_discovered(tests, show_suites, show_tests):
124+
# Suite names are not necessarily unique. Include object identity in sort
125+
# key to avoid mixing tests of different suites.
126+
tests.sort(key=lambda t: (t.suite.name, t.suite, t.path_in_suite))
127+
128+
if show_suites:
129+
import itertools
130+
tests_by_suite = itertools.groupby(tests, lambda t: t.suite)
134131
print('-- Test Suites --')
135-
for ts,ts_tests in suitesAndTests:
136-
print(' %s - %d tests' %(ts.name, len(ts_tests)))
137-
print(' Source Root: %s' % ts.source_root)
138-
print(' Exec Root : %s' % ts.exec_root)
139-
if ts.config.available_features:
140-
print(' Available Features : %s' % ' '.join(
141-
sorted(ts.config.available_features)))
142-
143-
# Show the tests, if requested.
144-
if opts.showTests:
132+
for suite, suite_iter in tests_by_suite:
133+
test_count = sum(1 for _ in suite_iter)
134+
print(' %s - %d tests' % (suite.name, test_count))
135+
print(' Source Root: %s' % suite.source_root)
136+
print(' Exec Root : %s' % suite.exec_root)
137+
if suite.config.available_features:
138+
features = ' '.join(sorted(suite.config.available_features))
139+
print(' Available Features : %s' % features)
140+
141+
if show_tests:
145142
print('-- Available Tests --')
146-
for ts,ts_tests in suitesAndTests:
147-
ts_tests.sort(key = lambda test: test.path_in_suite)
148-
for test in ts_tests:
149-
print(' %s' % (test.getFullName(),))
143+
for t in tests:
144+
print(' %s' % t.getFullName())
150145

151146

152147
def determine_order(tests, order):

0 commit comments

Comments
 (0)