Skip to content

Commit

Permalink
9pm: add graceful check for missing suites and tests
Browse files Browse the repository at this point in the history
Avoid python internal error messages for missing tests or suites.
These messages should be much clearer to the user, also they are
executed earlier, which makes cleanup nicer.

Signed-off-by: Richard Alpe <[email protected]>
  • Loading branch information
rical committed Sep 12, 2023
1 parent baf7ab9 commit 83dc352
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions 9pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def parse_yaml(path):
return -1
return data

def parse(fpath, options, name=None):
def parse_suite(fpath, pname, options, name=None):
suite = {}
suite['fpath'] = fpath
suite['suite'] = []
Expand All @@ -182,19 +182,24 @@ def parse(fpath, options, name=None):
else:
suite['name'] = gen_name(fpath)

if not os.path.isfile(fpath):
print("error, test suite not found {}" . format(fpath))
print("(referenced from {})" . format(pname))
sys.exit(1)

data = parse_yaml(fpath)
pname = fpath
for entry in data:
if 'suite' in entry:
fpath = os.path.join(cur, entry['suite'])
if 'opts' in entry:
opts = lmerge(entry['opts'], options)
else:
opts = options.copy()

if 'name' in entry:
suite['suite'].append(parse(fpath, opts, prefix_name(entry['name'])))
suite['suite'].append(parse_suite(fpath, pname, opts, prefix_name(entry['name'])))
else:
suite['suite'].append(parse(fpath, opts))
suite['suite'].append(parse_suite(fpath, pname, opts))

elif 'case' in entry:
case = {}
Expand All @@ -219,6 +224,13 @@ def parse(fpath, options, name=None):
case['case'] = os.path.join(cur, entry['case'])
case['path'] = cur
case['name'] = prefix_name(name)
if not os.path.isfile(case['case']):
print("error, test case not found {}" . format(case['case']))
print("(referenced from {})" . format(fpath))
sys.exit(1)
if not os.access(case['case'], os.X_OK):
print("error, test case not executable {}".format(case['case']))
sys.exit(1)
suite['suite'].append(case)
else:
print("error, missing suite/case in suite {}".format(suite['name']))
Expand Down Expand Up @@ -454,7 +466,7 @@ def main():
for filename in args.suites:
fpath = os.path.join(os.getcwd(), filename)
if filename.endswith('.yaml'):
cmdl['suite'].append(parse(fpath, args.option))
cmdl['suite'].append(parse_suite(fpath, "command line", args.option))
else:
test = {"case": fpath, "name": gen_name(filename)}

Expand Down

0 comments on commit 83dc352

Please sign in to comment.