]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
test(split): cover closed stdin exit 641/head
authorDarafei Praliaskouski <me@komzpa.net>
Fri, 8 May 2026 14:35:22 +0000 (18:35 +0400)
committerDarafei Praliaskouski <me@komzpa.net>
Mon, 25 May 2026 11:05:48 +0000 (15:05 +0400)
test/cmdparse.py

index f3f72be7ac68bbaee806ba57ce5e01252773bb19..914a4785e32dbf1e804d511c3baabd41564d5311 100755 (executable)
@@ -45,6 +45,16 @@ class TestMtrCommandParse(unittest.TestCase):
             universal_newlines=True,
         )
 
+    def run_mtr_detached(self, *args):
+        return subprocess.run(
+            [MTR] + list(args),
+            stdin=subprocess.DEVNULL,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            timeout=10,
+            universal_newlines=True,
+        )
+
     def test_first_ttl_cannot_exceed_max_ttl(self):
         'Test that conflicting first/max TTL options fail fast.'
 
@@ -88,6 +98,7 @@ class TestMtrCommandParse(unittest.TestCase):
 
         reply = self.run_mtr(
             '--report',
+
             '--report-cycles',
             '1',
             '--no-dns',
@@ -99,6 +110,19 @@ class TestMtrCommandParse(unittest.TestCase):
         self.assertIn('Loss%', reply.stdout)
         self.assertIn('0.00%', reply.stdout)
 
+    def test_split_exits_with_closed_stdin(self):
+        'Test split mode exits when stdin is /dev/null.'
+
+        reply = self.run_mtr_detached(
+            '--split',
+            '--report-cycles',
+            '1',
+            '--no-dns',
+            '127.0.0.1',
+        )
+
+        self.assertEqual(reply.returncode, 0)
+
     def test_mtr_options_preserves_quoted_order_spaces(self):
         'Test that quoted MTR_OPTIONS values can contain order separators.'