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 | |
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
-rwxr-xr-x | check | 24 | ||||
-rw-r--r-- | reference.md | 21 |
2 files changed, 40 insertions, 5 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") diff --git a/reference.md b/reference.md index 09ac659..48e2295 100644 --- a/reference.md +++ b/reference.md @@ -1,3 +1,4 @@ + # Introduction This document describes how we guard against accidental breaking @@ -40,7 +41,25 @@ then command is successful #!/bin/bash set -euo pipefail -python3 src/test-inner.py --log test-inner.log --env "PATH=$PATH" --env SUBPLOT_DIR=/ + +N=100 + +if python3 src/test-inner.py --log test-inner.log --env "PATH=$PATH" --env SUBPLOT_DIR=/ +then + exit=0 +else + exit="$?" +fi + +if [ "$exit" != 0 ] +then + # Failure. Show end of inner log file. + + echo "last $N lines of test-inner.log:" + tail "-n$N" test-inner.log | sed 's/^/ /' +fi + +exit "$exit" ~~~ |