Item 3: failed checks keep their evidence lines (verify, gate, unit record). done 3 / next 4 (dead code and seams)
This commit is contained in:
1 parent
23a7cc7aec
commit
ed018a364c
8 files changed
+154
-24
No files matched your search
@@ -528,6 +528,16 @@ class FlowTests(GateBase):
|
||||
self.assertEqual(a, "block")
|
||||
self.assertIn("bad", msg)
|
||||
|
||||
def test_the_send_back_shows_the_failing_test_not_only_the_end_of_the_output(self):
|
||||
"""R-5.6-1, R-5.6-4: the failure printed 300 lines above the end of the output is in the gate's message."""
|
||||
cmd = ("echo 'FAIL: test_needle (mod.T.test_needle)'; echo 'AssertionError: needle missing'; "
|
||||
"for i in $(seq 1 300); do echo \"summary $i\"; done; exit 1")
|
||||
self.write_contract(contract([check("t", cmd)]) | {"risk": {"profile": "isolated"}})
|
||||
a, msg = self.call()
|
||||
self.assertEqual(a, "block")
|
||||
self.assertIn("FAIL: test_needle (mod.T.test_needle)", msg)
|
||||
self.assertIn("AssertionError: needle missing", msg)
|
||||
|
||||
def test_a_check_over_the_budget_is_reported_not_passed(self):
|
||||
"""R-15-5: a check that cannot finish in time is not-run, never passed."""
|
||||
with open(os.path.join(self.tmp, "cfg"), "w"):
|
||||
|
||||
@@ -2,6 +2,64 @@ import json, unittest
|
||||
from support import *
|
||||
|
||||
|
||||
class EvidenceTests(SisiCase):
|
||||
"""R-5.6-1, R-5.6-4: a failed check keeps the lines that identify the failure, not only the tail of its output."""
|
||||
|
||||
NOISE = "for i in $(seq 1 300); do echo \"summary noise $i\"; done"
|
||||
|
||||
def test_a_failure_300_lines_above_the_end_is_in_the_stored_result_and_the_report(self):
|
||||
cmd = "echo 'FAIL: test_alpha (mod.T.test_alpha)'; echo 'AssertionError: 1 != 2'; %s; exit 1" % self.NOISE
|
||||
r = self.sisi("verify") if self.write_contract(contract([check("t", cmd)])) is None else None
|
||||
self.assertEqual(r.returncode, 1)
|
||||
row = [x for x in self.results() if x["check"] == "t"][0]
|
||||
self.assertEqual(row["status"], "failed")
|
||||
self.assertIn("FAIL: test_alpha (mod.T.test_alpha)", row["evidence"])
|
||||
self.assertIn("AssertionError: 1 != 2", row["evidence"])
|
||||
self.assertLess(len(row["evidence"]), 3100)
|
||||
shown = r.stdout[r.stdout.index("FAILED:"):]
|
||||
self.assertIn("test_alpha", shown)
|
||||
self.assertLess(shown.index("test_alpha"), shown.index("summary noise 300"))
|
||||
|
||||
def test_each_known_runner_keeps_its_failing_test_names(self):
|
||||
from sisi import verify as V
|
||||
outputs = {
|
||||
"unittest": ("FAIL: test_a (m.T.test_a)\n----\nTraceback\nAssertionError: x\n" + "ok\n" * 200 + "FAILED (failures=1)", "test_a (m.T.test_a)"),
|
||||
"pytest": ("_____ test_b _____\nE assert 1 == 2\n" + "x\n" * 200 + "FAILED tests/t.py::test_b - assert 1 == 2", "tests/t.py::test_b"),
|
||||
"cargo": ("test tests::c ... FAILED\n---- tests::c stdout ----\nthread 'tests::c' panicked at src/l.rs:1:1:\n" + "x\n" * 200 + "test result: FAILED", "tests::c"),
|
||||
"go": ("--- FAIL: TestD (0.00s)\n d_test.go:9: want 1 got 2\n" + "x\n" * 200 + "FAIL\tpkg", "TestD"),
|
||||
"jest": (" ● suite › case e\n Expected: 1\n Received: 2\n" + "x\n" * 200 + "Tests: 1 failed", "case e"),
|
||||
}
|
||||
for name, (text, want) in outputs.items():
|
||||
with self.subTest(name):
|
||||
ev = V.evidence(text)
|
||||
self.assertIn(want, ev)
|
||||
self.assertNotIn("\nx\nx\nx", ev)
|
||||
|
||||
def test_unknown_output_keeps_the_first_and_last_30_lines_bounded_and_scrubbed(self):
|
||||
from sisi import verify as V
|
||||
text = "\n".join(["line %d" % i for i in range(1, 401)] + ["password=hunter2hunter2"])
|
||||
ev = V.evidence(text)
|
||||
self.assertIn("line 1\n", ev + "\n")
|
||||
self.assertIn("line 30\n", ev + "\n")
|
||||
self.assertNotIn("line 31\n", ev + "\n")
|
||||
self.assertIn("line 400", ev)
|
||||
self.assertNotIn("hunter2", ev)
|
||||
self.assertLessEqual(len(V.evidence("y" * 100000)), V.EVIDENCE_CHARS)
|
||||
|
||||
def test_a_timeout_keeps_what_it_had_printed(self):
|
||||
c = contract([check("slow", "echo 'FAIL: test_slow (m.T.test_slow)'; sleep 5", timeout_s=0.5)])
|
||||
self.write_contract(c)
|
||||
self.sisi("verify")
|
||||
row = [x for x in self.results() if x["check"] == "slow"][0]
|
||||
self.assertEqual(row["status"], "not-run")
|
||||
self.assertIn("test_slow", row["evidence"])
|
||||
|
||||
def test_a_passing_check_stores_no_evidence(self):
|
||||
self.write_contract(contract([check("ok", "echo fine; test -d .")]))
|
||||
self.sisi("verify")
|
||||
self.assertEqual([x["evidence"] for x in self.results() if x["check"] == "ok"], [""])
|
||||
|
||||
|
||||
class VerifyTests(SisiCase):
|
||||
def run_verify(self, c, *extra):
|
||||
self.write_contract(c)
|
||||
|
||||
Reference in new issue
Block a user