test_seed.sh (1211B)
1 #!/bin/sh 2 set -eu 3 HERE=$(cd "$(dirname "$0")" && pwd) 4 ROOT=$(cd "${HERE}/.." && pwd) 5 . "${HERE}/_tap.sh" 6 7 BIN=$(ensure_bin "${ROOT}") 8 TMP=$(mktemp -d) 9 trap 'rm -rf "${TMP}"' EXIT 10 11 tap_begin "cli: seed" 12 13 if [ ! -x "${BIN}" ]; then 14 tap 0 "sfinx binary present" "missing ${BIN}" 15 tap_plan 16 exit 1 17 fi 18 tap 1 "sfinx binary present" "" 19 20 "${BIN}" seed >"${TMP}/default.bin" 21 n=$(wc -c <"${TMP}/default.bin" | tr -d '[:space:]') 22 tap "$([ "${n}" = 32 ] && echo 1 || echo 0)" "default is 32 bytes" "got ${n}" 23 24 "${BIN}" seed 16 >"${TMP}/sixteen.bin" 25 n=$(wc -c <"${TMP}/sixteen.bin" | tr -d '[:space:]') 26 tap "$([ "${n}" = 16 ] && echo 1 || echo 0)" "explicit length is honored" "got ${n}" 27 28 "${BIN}" seed 32 >"${TMP}/a.bin" 29 "${BIN}" seed 32 >"${TMP}/b.bin" 30 if cmp -s "${TMP}/a.bin" "${TMP}/b.bin"; then 31 tap 0 "two seeds differ" "identical" 32 else 33 tap 1 "two seeds differ" "" 34 fi 35 36 "${BIN}" seed -o "${TMP}/out.seed" 37 mode=$(stat -c '%a' "${TMP}/out.seed" 2>/dev/null || stat -f '%Lp' "${TMP}/out.seed") 38 tap "$([ "${mode}" = 600 ] && echo 1 || echo 0)" "-o writes mode 0600" "got ${mode}" 39 40 rc=0 41 "${BIN}" seed 0 >/dev/null 2>&1 || rc=$? 42 tap "$([ "${rc}" != 0 ] && echo 1 || echo 0)" "rejects length 0" "exit ${rc}" 43 44 tap_plan