summaryrefslogtreecommitdiff
path: root/tests/misc/cksum-a.sh
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2021-09-06 15:17:12 +0100
committerPádraig Brady <P@draigBrady.com>2021-09-15 20:44:16 +0100
commitad6c8e1181a3966e35d68c1c354deb1c73f3e974 (patch)
tree43ec3b95effbbaa70ae782b79e6c2f26883590ea /tests/misc/cksum-a.sh
parent6a5c561b4fb3018d284d03747c612527e0c89571 (diff)
downloadcoreutils-ad6c8e1181a3966e35d68c1c354deb1c73f3e974.tar.gz
cksum: add --algorithm option to select digest mode
* src/digest.c: Organize HASH_ALGO_CKSUM to be table driven, and amalgamate all digest algorithms. (main): Parse all options if HASH_ALGO_CKSUM, and disallow --tag, --zero, and --check with the traditional bsd, sysv, and crc checksums for now. * src/local.mk: Reorganize to include all digest modules in cksum. * tests/misc/cksum-a.sh: Add a new test. * tests/misc/b2sum.sh: Update to default to checking with cksum, as b2sum's implementation diverges a bit from the others. * tests/local.mk: Reference the new test. * doc/coreutils.texi (cksum invocation): Adjust the summary to identify the new mode, and document the new --algorithm option. * man/cksum.x: Adjust description to be more general. * man/*sum.x: Add [See Also] section referencing cksum(1). * NEWS: Mention the new feature.
Diffstat (limited to 'tests/misc/cksum-a.sh')
-rwxr-xr-xtests/misc/cksum-a.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh
new file mode 100755
index 000000000..7d95b69a4
--- /dev/null
+++ b/tests/misc/cksum-a.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# Validate cksum --algorithm operation
+
+# Copyright (C) 2021 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cksum
+
+printf "
+bsd sum -r
+sysv sum -s
+crc cksum
+md5 md5um -t
+sha1 sha1sum -t
+sha224 sha224sum -t
+sha256 sha256sum -t
+sha384 sha384sum -t
+sha512 sha512sum -t
+blake2b b2sum -t
+" | while read algo prog; do
+ $prog < /dev/null >> out || continue
+ cksum --algorithm=$algo < /dev/null >> out-a || fail=1
+done
+compare out out-a || fail=1
+
+returns_ 1 cksum -a bsd --tag </dev/null
+returns_ 1 cksum -a bsd --zero </dev/null
+returns_ 1 cksum -a bsd --check </dev/null
+
+Exit $fail