Skip to content

Commit f2cb45d

Browse files
committed
Make CLI hash assertion portable across CI envs
1 parent e90d363 commit f2cb45d

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

tests/cli/test_cli.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
sha256_file() {
5+
if command -v sha256sum >/dev/null 2>&1; then
6+
sha256sum "$1" | awk '{print $1}'
7+
return
8+
fi
9+
if command -v shasum >/dev/null 2>&1; then
10+
shasum -a 256 "$1" | awk '{print $1}'
11+
return
12+
fi
13+
if command -v openssl >/dev/null 2>&1; then
14+
openssl dgst -sha256 "$1" | awk '{print $NF}'
15+
return
16+
fi
17+
echo "error: no SHA-256 tool available (need sha256sum, shasum, or openssl)" >&2
18+
exit 1
19+
}
20+
421
zig build -Doptimize=ReleaseFast >/dev/null
522

623
output=$(./zig-out/bin/compact-pro --help)
@@ -196,7 +213,7 @@ mkdir -p "$tmp_dir/out-lzh"
196213
[[ -f "$tmp_dir/out-lzh/._MacEnvy" ]]
197214
[[ "$(wc -c < "$tmp_dir/out-lzh/MacEnvy" | tr -d '[:space:]')" == "0" ]]
198215
[[ "$(wc -c < "$tmp_dir/out-lzh/._MacEnvy" | tr -d '[:space:]')" == "36336" ]]
199-
[[ "$(shasum -a 256 "$tmp_dir/out-lzh/._MacEnvy" | awk '{print $1}')" == "7168936e8b51b8e5eb5ea029cc7ab4b43d126c0a0c6ef811623e7872eae8f7cb" ]]
216+
[[ "$(sha256_file "$tmp_dir/out-lzh/._MacEnvy")" == "7168936e8b51b8e5eb5ea029cc7ab4b43d126c0a0c6ef811623e7872eae8f7cb" ]]
200217

201218
if command -v unar >/dev/null 2>&1; then
202219
awk 'BEGIN{srand(12345); n=6*1024*1024; for(i=0;i<n;i++){c=65+int(rand()*8); printf "%c", c}}' >"$tmp_dir/unar-multiblock.txt"

0 commit comments

Comments
 (0)