test/problems: Report when tests do not run properly

When some of the individual tests fail to run, the `make test` target would
still pass since test/problems would not return an error which could hide the
fact that there are problems in the test.

With this change, if you do not have the python dateutil package, you will now
get output like:

  'test_totals.t' failed to run any tests.
  Passed:                           975
  Failed:                             1
  Unexpected successes:               0
  Skipped:                            0
  Expected failures:                  0
  Runtime:                         4.83 seconds

Or, if you do not have UTF-8 encoding set in your language you will get
something like:

  'track.t' failed to run all tests.
  'stop.t' failed to run all tests.
  'start.t' failed to run all tests.
  'test_totals.t' failed to run all tests.
  Passed:                           941
  Failed:                            50
  Unexpected successes:               0
  Skipped:                            0
  Expected failures:                  0
  Runtime:                         4.55 seconds
This commit is contained in:
Shaun Ruffell 2020-01-02 21:40:11 -06:00 committed by lauft
parent d62fc02649
commit 6852fd2924

View file

@ -60,10 +60,13 @@ if __name__ == "__main__":
ok = re.compile(r"^ok ", re.I)
not_ok = re.compile(r"^not ok", re.I)
comment = re.compile(r"^#")
plan = re.compile(r"^1..\d+\s*(?:#.*)?$")
plan = re.compile(r"^1..(\d+)\s*(?:#.*)?$")
start = None
stop = None
filename = None
expected_test_count = 0
need_plan = False
with open(cmd_args.tapfile) as fh:
for line in fh:
@ -74,22 +77,39 @@ if __name__ == "__main__":
match = file.match(line)
if match:
if filename:
if expected_test_count > 0:
print(color("'{}' failed to run all tests.".format(filename), "red"), file=sys.stderr)
errors[filename] += expected_test_count
elif need_plan:
print(color("'{}' failed to run any tests.".format(filename), "red"), file=sys.stderr)
errors[filename] += 1
filename = match.group(1)
need_plan = True
continue
match = plan.match(line)
if match:
expected_test_count = int(match.group(1))
need_plan = False
continue
match = expected_fail.match(line)
if match:
expected[filename] += 1
expected_test_count -= 1
continue
match = unexpected_pass.match(line)
if match:
unexpected[filename] += 1
expected_test_count -= 1
continue
match = skip.match(line)
if match:
skipped[filename] += 1
expected_test_count -= 1
continue
# It's important these come last, since they're subpatterns of the above
@ -97,15 +117,13 @@ if __name__ == "__main__":
match = ok.match(line)
if match:
passed[filename] += 1
expected_test_count -= 1
continue
match = not_ok.match(line)
if match:
errors[filename] += 1
continue
match = plan.match(line)
if match:
expected_test_count -= 1
continue
match = comment.match(line)