From 41612869187b556b696caa3f81672fa0615c87f0 Mon Sep 17 00:00:00 2001 From: Thomas Mieslinger Date: Tue, 13 Oct 2026 14:14:11 +0200 Subject: [PATCH] fix(dim-testsuite): compare shell command output as bytes process_command() gets the output of shell lines and the expected lines as bytes, but stripped and matched them with str arguments. Any shell line with an expected output died with a TypeError, so such a line could not be used in a test at all. Only the drill checks of the pdns-output tests have one, and they need a running pdns-output. Use bytes throughout, including the fill value for missing lines. Co-Authored-By: Claude Opus 5.5 --- dim-testsuite/runtest.py | 9 +++++---- dim-testsuite/t/runtest-shell-output.t | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 dim-testsuite/t/runtest-shell-output.t diff --git a/dim-testsuite/runtest.py b/dim-testsuite/runtest.py index a49f893..8069528 100755 --- a/dim-testsuite/runtest.py +++ b/dim-testsuite/runtest.py @@ -161,11 +161,12 @@ def process_command(actual_output, expected_output, out, sort_before=False): if sort_before: actual_output.sort() expected_output.sort() - for actual, expected in zip_longest(actual_output, expected_output, fillvalue=''): - expected = expected.strip('\n') - if expected.endswith(' re'): + # output and expectation are bytes, like the rest of the file handling here + for actual, expected in zip_longest(actual_output, expected_output, fillvalue=b''): + expected = expected.strip(b'\n') + if expected.endswith(b' re'): if re.match(expected[:-3], actual): - out.write(expected + '\n') + out.write(expected + b'\n') else: out.write(actual + b'\n') passed = False diff --git a/dim-testsuite/t/runtest-shell-output.t b/dim-testsuite/t/runtest-shell-output.t new file mode 100644 index 0000000..33ed599 --- /dev/null +++ b/dim-testsuite/t/runtest-shell-output.t @@ -0,0 +1,10 @@ +# The test runner compares the output of shell lines (everything that does not +# start with "ndcli") with the expected lines, exactly or as a regex when the +# expectation ends with " re". +$ echo hello +hello +$ printf 'one\ntwo\n' +one +two +$ date +%Y +^20[0-9][0-9]$ re