Hello

The attached patch improves the coverage with --check & --strict, especially in the context of errors/warnings.

Cheers
Sylvestre

From 5f132954d3e372c4f0f14806fe2d12272ab25e04 Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <sylves...@debian.org>
Date: Fri, 10 May 2024 22:57:11 +0200
Subject: [PATCH] cksum: tests: add incorrect data to verify --check & --strict

    * tests/cksum/cksum-c.sh: Add test cases.
---
 tests/cksum/cksum-c.sh | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tests/cksum/cksum-c.sh b/tests/cksum/cksum-c.sh
index aad626607..8f8f6dd81 100755
--- a/tests/cksum/cksum-c.sh
+++ b/tests/cksum/cksum-c.sh
@@ -56,4 +56,32 @@ returns_ 1 cksum -a crc -c CHECKSUMS || fail=1
 cksum -a crc 'input' > CHECKSUMS.crc || fail=1
 returns_ 1 cksum -c CHECKSUMS.crc || fail=1
 
+# Check for the error mgmt
+echo "invalid line" >> CHECKSUMS
+# Exit code is 0 in this case
+cksum --check CHECKSUMS &> out || fail=1
+grep -q "1 line is improperly formatted" out || fail=1
+# But not with --strict
+cksum --strict --check CHECKSUMS &> out && fail=1
+grep -q "1 line is improperly formatted" out || fail=1
+echo "invalid line" >> CHECKSUMS
+# plurial checks
+cksum --strict --check CHECKSUMS &> out && fail=1
+grep -q "2 lines are improperly formatted" out || fail=1
+
+# Inject an incorrect checksum
+echo "SM3 (input) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaafdb57c725157cb40b5aee8d937b8351477e" >> CHECKSUMS
+cksum --check CHECKSUMS &> out && fail=1
+# with --strict (won't change the result)
+grep -q "1 computed checksum did NOT match" out || fail=1
+grep -q "input: FAILED" out || fail=1
+cksum --check --strict CHECKSUMS &> out && fail=1
+
+# With a non existing file
+echo "SM3 (input2) = bbbbbbbbbbbaaaaaaaaaaaaaaaaaafdb57c725157cb40b5aee8d937b8351477e" >> CHECKSUMS2
+cksum --check CHECKSUMS2 &> out && fail=1
+grep -q "input2: FAILED open or read" out || fail=1
+grep -q "1 listed file could not be read" out || fail=1
+# with --strict (won't change the result)
+cksum --check --strict CHECKSUMS2 &> out && fail=1
 Exit $fail
-- 
2.43.0

Reply via email to