Le 11/05/2024 à 12:31, Pádraig Brady a écrit :
On 10/05/2024 22:15, Sylvestre Ledru wrote:
Hello
The attached patch improves the coverage with --check & --strict,
especially in the context of errors/warnings.
Pushed with these changes:
- Started the summary line with "tests", as not changing cksum
- Changed double quotes to single quotes where not interpolating
- Avoided non portable -q option to grep
- Avoided non portable &> shell construct
- Ensured lines less that 80 chars in width
Thanks again!
Here are more tests in this patch :)
This time with --status, --ignore-missing and --warn
Cheers,
Sylvestre
From 904fe015c8241fe8d04ea2a9d375512ecb354733 Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <sylves...@debian.org>
Date: Wed, 22 May 2024 00:52:18 +0200
Subject: [PATCH] tests: cksum: Extends with --status, --ignore-missing and
--warn
* tests/cksum/cksum-c.sh: Add test cases.
---
tests/cksum/cksum-c.sh | 57 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/tests/cksum/cksum-c.sh b/tests/cksum/cksum-c.sh
index 1cb5e645f..83ce01f0f 100755
--- a/tests/cksum/cksum-c.sh
+++ b/tests/cksum/cksum-c.sh
@@ -56,6 +56,11 @@ 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
+# Test --status
+cksum --status --check CHECKSUMS >out 2>&1 || fail=1
+# Should be empty
+test -s out && fail=1
+
# Check for the error mgmt
echo 'invalid line' >> CHECKSUMS
# Exit code is 0 in this case
@@ -85,4 +90,56 @@ grep 'input2: FAILED open or read' out || fail=1
grep '1 listed file could not be read' out || fail=1
# with --strict (won't change the result)
cksum --check --strict CHECKSUMS2 >out 2>&1 && fail=1
+
+# With errors
+cksum --status --check CHECKSUMS >out 2>&1 && fail=1
+test -s out && fail=1
+
+# Test --warn
+echo "BLAKE2b (missing-file) = $invalid_sum" >> CHECKSUMS
+cksum --warn --check CHECKSUMS > out 2>&1
+# check that the incorrect lines are correctly reported with --warn
+grep 'CHECKSUMS: 5: improperly formatted SM3 checksum line' out || fail=1
+grep 'CHECKSUMS: 8: improperly formatted BLAKE2b checksum line' out || fail=1
+
+# Test --ignore-missing
+echo 'SM3 (nonexistent) = eea07d7c0e793567dc07082dec2f9e6e7b6ed5fe58f1473c45fea951c163d8d3' >> CHECKSUMS-missing
+# we have output on both stdout and stderr
+cksum --check CHECKSUMS-missing > stdout 2> stderr && fail=1
+grep 'nonexistent: FAILED open or read' stdout || fail=1
+grep 'nonexistent: No such file or directory' stderr || fail=1
+grep '1 listed file could not be read' stderr || fail=1
+
+cksum --ignore-missing --check CHECKSUMS-missing > stdout 2> stderr && fail=1
+# We should not get these errors
+grep -v 'nonexistent: No such file or directory' stdout && fail=1
+grep -v 'nonexistent: FAILED open or read' stdout && fail=1
+grep 'CHECKSUMS-missing: no file was verified' stderr || fail=1
+
+# Combination of --status and --warn
+cksum --status --warn --check CHECKSUMS > out 2>&1 && fail=1
+
+grep 'CHECKSUMS: 8: improperly formatted BLAKE2b checksum line' out || fail=1
+grep 'WARNING: 3 lines are improperly formatted' out || fail=1
+grep 'WARNING: 1 computed checksum did NOT match' out || fail=1
+
+# The order matters. --status will hide the results
+cksum --warn --status --check CHECKSUMS > out 2>&1 && fail=1
+grep -v 'CHECKSUMS: 8: improperly formatted BLAKE2b checksum line' out && fail=1
+grep -v 'WARNING: 3 lines are improperly formatted' out && fail=1
+grep -v 'WARNING: 1 computed checksum did NOT match' out && fail=1
+
+# Combination of --status and --ignore-missing
+cksum --status --ignore-missing --check CHECKSUMS > out 2>&1 && fail=1
+# should be empty
+test -s out && fail=1
+
+# Combination of all three
+cksum --status --warn --ignore-missing --check \
+ CHECKSUMS-missing > out 2>&1 && fail=1
+# Not empty
+test -s out || fail=1
+grep 'CHECKSUMS-missing: no file was verified' out || fail=1
+grep -v 'nonexistent: No such file or directory' stdout && fail=1
+
Exit $fail
--
2.43.0