This commit is contained in:
@@ -56,7 +56,8 @@ def changed(diff: bytes) -> tuple[int, tuple[bytes, ...], tuple[bytes, ...]] | N
|
||||
at = [index for index, line in enumerate(body) if line[:1] in (b"-", b"+")]
|
||||
if not at:
|
||||
return None
|
||||
first = int(hunks[0]) + sum(not line.startswith(b"+") for line in body[:at[0]])
|
||||
# Each line before the first changed one is a line of the tree.
|
||||
first = int(hunks[0]) + at[0]
|
||||
span = body[at[0]:at[-1] + 1]
|
||||
was = tuple(line[1:] for line in span if not line.startswith(b"+"))
|
||||
now = tuple(line[1:].replace(MARK, b"") for line in span if not line.startswith(b"-"))
|
||||
@@ -87,6 +88,6 @@ def task_text(output: str) -> str | None:
|
||||
message.append(line.strip())
|
||||
# A test in a module is named after it, as `tests::adds`; a message may name the whole or the test alone. A Rust test's own
|
||||
# name is often a plain word, such as `big`, so a longer identifier that holds it, such as `is_big`, doesn't name the test.
|
||||
names = [re.compile(rf"(?<!\w){re.escape(name)}(?!\w)") for name in {test, test.rpartition("::")[2]} - {""}]
|
||||
names = [re.compile(rf"(?<!\w){re.escape(name)}(?!\w)") for name in {test, test.rpartition("::")[2]}]
|
||||
kept = [text for text in message if text and not any(name.search(text) for name in names)]
|
||||
return "\n".join(kept) or None
|
||||
|
||||
@@ -181,6 +181,7 @@ class TaskTextTest(unittest.TestCase):
|
||||
output = section("tests::adds", "", "thread 'tests::adds' (7) panicked at src/lib.rs:21:9:", "adds: got 0", "want 3")
|
||||
self.assertEqual(task_text(output), "want 3")
|
||||
self.assertEqual(task_text(output.replace("adds: got 0", "tests::adds broke")), "want 3")
|
||||
self.assertEqual(task_text(output.replace("tests::adds", "pick::tests::adds")), "want 3")
|
||||
|
||||
def test_a_message_may_hold_the_tests_name_inside_a_longer_identifier(self):
|
||||
output = section("tests::big", "", "thread 'tests::big' (7) panicked at src/lib.rs:27:9:", "assertion failed: !is_big(10)")
|
||||
@@ -195,6 +196,8 @@ class TaskTextTest(unittest.TestCase):
|
||||
self.assertIsNone(task_text(""))
|
||||
|
||||
def test_a_panic_outside_a_failed_tests_section_is_no_message(self):
|
||||
after_the_list = section("totals", "summing 3 items") + "thread 'main' (7) panicked at src/main.rs:2:5:\nno arguments\n"
|
||||
self.assertIsNone(task_text(after_the_list))
|
||||
self.assertIsNone(task_text("thread 'main' (7) panicked at src/main.rs:2:5:\nno arguments\n"))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user