Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

ci(go): show a failed test's own output in the lane

Adeshina Lasisi7d0ca778e55c
diff --git a/laya-go/scripts/check_test_json.py b/laya-go/scripts/check_test_json.py
index e7e873b4..d388cea6 100644
--- a/laya-go/scripts/check_test_json.py
+++ b/laya-go/scripts/check_test_json.py
@@ -28,12 +28,22 @@ def read_events(handle):
yield {"Action": "output", "Output": line + "\n", "Raw": number}
+# How much of a failed test's own output is shown. The lane writes `go test -json` to a file, so
+# without this a failure in CI names the test and says nothing about why.
+OUTPUT_LINES = 40
+
+
def summarise(events):
- """(counts, problems) for a stream of test2json events."""
+ """(counts, problems, output of each failed test) for a stream of test2json events."""
final = {}
problems = []
+ output = {}
for event in events:
action, package, test = event.get("Action"), event.get("Package", ""), event.get("Test")
+ if action == "output" and test is not None:
+ lines = output.setdefault((package, test), [])
+ lines.append(event.get("Output", "").rstrip("\n"))
+ del lines[:-OUTPUT_LINES]
if action in ("build-fail",):
problems.append("build failed: %s" % event.get("ImportPath", package))
if test is None:
@@ -49,7 +59,8 @@ def summarise(events):
problems.append("skipped: %s %s" % (package.rsplit("/", 1)[-1], test))
elif action == "fail":
problems.append("failed: %s %s" % (package.rsplit("/", 1)[-1], test))
- return counts, problems
+ failed = {key: output.get(key, []) for key, action in sorted(final.items()) if action == "fail"}
+ return counts, problems, failed
def main(argv=None):
@@ -65,7 +76,7 @@ def main(argv=None):
return 1
handle = sys.stdin if args.events == "-" else open(args.events, encoding="utf-8")
with handle:
- counts, problems = summarise(read_events(handle))
+ counts, problems, failed = summarise(read_events(handle))
total = sum(counts.values())
print("go tests: %d ran, %d passed, %d skipped, %d failed"
% (total, counts["pass"], counts["skip"], counts["fail"]))
@@ -75,6 +86,11 @@ def main(argv=None):
print(" " + problem, file=sys.stderr)
if len(problems) > 50:
print(" ... and %d more" % (len(problems) - 50), file=sys.stderr)
+ for (package, test), lines in list(failed.items())[:10]:
+ print("--- output of %s %s (last %d lines)" % (package.rsplit("/", 1)[-1], test, len(lines)),
+ file=sys.stderr)
+ for line in lines:
+ print(" " + line, file=sys.stderr)
return 1 if problems else 0
diff --git a/laya-go/scripts/test_check_test_json.py b/laya-go/scripts/test_check_test_json.py
index 674d7f93..8ea75350 100644
--- a/laya-go/scripts/test_check_test_json.py
+++ b/laya-go/scripts/test_check_test_json.py
@@ -34,6 +34,17 @@ PASSING = [event("run", "TestA"), event("pass", "TestA"), event("run", "TestB"),
class CheckerTest(unittest.TestCase):
+ def test_a_failed_test_shows_its_own_output(self):
+ said = json.dumps({"Action": "output", "Package": "example.com/m/pkg", "Test": "TestB",
+ "Output": " b_test.go:7: got 3, want 4\n"})
+ other = json.dumps({"Action": "output", "Package": "example.com/m/pkg", "Test": "TestA",
+ "Output": " a_test.go:1: a passing test's log\n"})
+ code, out = run([event("run", "TestA"), other, event("pass", "TestA"), event("run", "TestB"), said,
+ event("fail", "TestB"), event("fail")], "--min-tests", "2")
+ self.assertEqual(code, 1, out)
+ self.assertIn("b_test.go:7: got 3, want 4", out)
+ self.assertNotIn("a passing test's log", out)
+
def test_all_pass(self):
code, out = run(PASSING, "--min-tests", "2")
self.assertEqual(code, 0, out)