diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-06-16 09:56:26 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-06-16 10:42:17 +0300 |
commit | 4ce46e7ace32b521b3f503ca9b533964d2ad57a2 (patch) | |
tree | 575a00ec08079bde5411c79debb92ae4ab6d09f8 /check | |
parent | 6aeacebbf5f5e03257deb87b63048e27906dbe64 (diff) | |
download | subplot-4ce46e7ace32b521b3f503ca9b533964d2ad57a2.tar.gz |
test: have ./check tail the test.py log file on failure
For each subplot, if running the test program fails, the last 100
lines of the log file is output. For the reference.md subplot, the
last 100 lines of the log file for the test program from the
referenced subplot is output.
This makes it easier to debug failures in CI.
Sponsored-by: author
Diffstat (limited to 'check')
-rwxr-xr-x | check | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -36,7 +36,7 @@ class Runcmd: elif self._progress: self._write_msg(title) - def _runcmd_unchecked(self, argv, **kwargs): + def runcmd_unchecked(self, argv, **kwargs): """Run a command (generic version) Return a subcommand.CompletedProcess. It's the caller's duty @@ -70,7 +70,7 @@ class Runcmd: a subprocess.CompletedProcess. """ - p = self._runcmd_unchecked(argv, **kwargs) + p = self.runcmd_unchecked(argv, **kwargs) if p.returncode != 0: sys.stdout.write((p.stdout or b"").decode("UTF-8")) sys.stderr.write((p.stderr or b"").decode("UTF-8")) @@ -85,7 +85,7 @@ class Runcmd: def got_command(self, name): """Is a command of a given name available?""" - p = self._runcmd_unchecked(["which", name], stdout=DEVNULL) + p = self.runcmd_unchecked(["which", name], stdout=DEVNULL) return p.returncode == 0 def cargo(self, args, **kwargs): @@ -222,7 +222,11 @@ def check_subplots(r): os.remove(test_log) r.codegen(md, test_py, cwd=dirname) - r.runcmd(["python3", test_py, "--log", test_log], cwd=dirname) + p = r.runcmd_unchecked(["python3", test_py, "--log", test_log], cwd=dirname) + if p.returncode != 0: + if os.path.exists(test_log): + tail(test_log) + sys.exit(1) elif template == "bash": test_sh = os.path.join(output, f"test-{base}.sh") r.codegen(md, test_sh, cwd=dirname) @@ -237,6 +241,18 @@ def check_subplots(r): r.docgen(md, base + ".html", cwd=dirname) +def tail(filename, numlines=100): + lines = [] + with open(filename) as f: + for line in f.readlines(): + lines.append(line) + lines = lines[-numlines:] + + print(f"last {len(lines)} of {filename}:") + for line in lines: + print(f" {line.rstrip()}") + + def check_subplotlib(r): """Run all checks for subplotlib""" r.title("checking subplotlib code") |