Skip to content

Commit c6748a0

Browse files
vladimirolteankuba-moo
authored andcommitted
ingest_mdir: reject invalid --test and --disable-test values
Currently, if we specify an invalid test name such as "checkpatch" instead of "patch/checkpatch", the script falls through with no test run, and no indication as to what was wrong. That is admittedly not very friendly. We'd need to call list_tests regardless of whether the --list-tests argument was specified, and validate against its output. However, this makes it redundant to have that function, we can just move it into main(). Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
1 parent cc1af1d commit c6748a0

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

ingest_mdir.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,16 @@ def load_patches(args):
264264
return series
265265

266266

267-
def list_tests(args, config):
268-
""" List all available tests and exit """
267+
def validate_test_list(test_list, all_test_names, parser_instance, error_description):
268+
"""Check a list of test names against the set of all available tests."""
269+
if test_list:
270+
invalid_tests = [name for name in test_list if name not in all_test_names]
269271

270-
tester = Tester(args.result_dir, None, None, None, config=config)
271-
print(' ', '\n '.join(tester.get_test_names()))
272+
if invalid_tests:
273+
invalid_str = ', '.join(invalid_tests)
274+
msg = f"the following {error_description} are invalid: {invalid_str}\n" \
275+
f"Run with --list-tests to see available tests."
276+
parser_instance.error(msg)
272277

273278

274279
def main():
@@ -286,15 +291,28 @@ def main():
286291
YELLOW = ''
287292
RESET = ''
288293

289-
if args.test:
290-
config.set('tests', 'include', ','.join(args.test))
294+
# Get all available test names for validation and --list-tests
295+
# We can instantiate a temporary Tester just for this purpose.
296+
tester_for_names = Tester(None, None, None, None, config=config)
297+
all_test_names = set(tester_for_names.get_test_names())
291298

292-
# Handle --list-tests first, as it needs no other arguments
299+
# Handle --list-tests first (using the list we just fetched)
293300
if args.list_tests:
294-
list_tests(args, config)
301+
print(' ', '\n '.join(sorted(all_test_names)))
295302
return
296303

297-
# If not listing tests, manually validate the required arguments
304+
# Validate --test and --disable-test
305+
validate_test_list(args.test, all_test_names, parser, "tests")
306+
validate_test_list(args.disable_test, all_test_names, parser, "disabled tests")
307+
308+
# Set configs after validation
309+
if args.test:
310+
config.set('tests', 'include', ','.join(args.test))
311+
312+
if args.disable_test:
313+
config.set('tests', 'exclude', ','.join(args.disable_test))
314+
315+
# If not listing tests, manually validate the other required arguments
298316
if not args.tree:
299317
parser.error("the following arguments are required: --tree")
300318

0 commit comments

Comments
 (0)