Answer stability round 1: 1 🔴, 2 🟡; end the command at a glued &< and pin each redirect form

This commit is contained in:
2026-10-22 02:40:13 +02:00
parent 18c284c1fe
commit 6b23808127
3 changed files with 14 additions and 6 deletions
+8 -2
View File
@@ -77,12 +77,18 @@ class Commits(unittest.TestCase):
def test_a_redirect_keeps_its_command_s_words_together(self):
self.assertEqual(segments("echo hi > f arg"), [["echo", "hi", "arg"]])
self.assertEqual(committed("git > /tmp/x commit -m hi"), [Commit("/r", ["hi"], False)])
for redirect in [">", ">>", "<", "<<<", "<>", ">&", "<&", ">|", "&>", "&>>"]:
with self.subTest(redirect):
self.assertEqual(committed(f"git {redirect} /tmp/x commit -m hi"), [Commit("/r", ["hi"], False)])
self.assertEqual(committed("git commit >&2 -m hi 2>&1"), [Commit("/r", ["hi"], False)])
self.assertEqual(committed("> out git commit -m hi"), [Commit("/r", ["hi"], False)])
def test_a_command_after_a_redirect_and_a_separator_is_still_apart(self):
def test_a_separator_glued_to_a_redirect_still_ends_the_command(self):
self.assertEqual(segments("echo a > f; echo b | cat &> g\nls"), [["echo", "a"], ["echo", "b"], ["cat"], ["ls"]])
for command in ["echo a &</dev/null git commit -m hi", "echo a;>f git commit -m hi", "tee >(true) git commit -m hi"]:
with self.subTest(command):
self.assertEqual(committed(command), [Commit("/r", ["hi"], False)])
self.assertEqual(segments("diff <(a) b"), [["diff"], ["b"]])
class CommandBreaches(unittest.TestCase):