install.sh: expand @cfg_name@ in processed scripts
[girocco.git] / src / ltsha1-test.sh
blobf7585aa607b5d334aa3980cc808a6def29a2d55c
1 #!/bin/sh
3 # License: public domain -or- http://www.wtfpl.net/txt/copying/
5 die() { >&2 printf 'Bail out! %s\n' "$*"; exit 1; }
7 testnum=0
9 # $1 => value to hash (may contain escapes) '-' reads stdin
10 # $2 => lowercase sha256 hash expected
11 # $3... => test name
12 test_sha1() {
13 _val="$1"; shift
14 _hash="$1"; shift
15 _test="$*"
16 if [ "$_val" = "-" ]; then
17 _check="$(./ltsha1)"
18 else
19 _check="$(printf '%b' "$_val" | ./ltsha1)"
20 fi ||
21 die "could not run ltsha1 utility"
22 _result="ok"
23 [ "$_check" = "$_hash" ] || _result="not ok"
24 testnum="$(( $testnum + 1 ))"
25 printf '%s %u - %s\n' "$_result" "$testnum" "$_test"
28 echo '1..6'
30 test_sha1 \
31 "abc" \
32 a9993e364706816aba3e25717850c26c9cd0d89d \
33 abc
35 test_sha1 \
36 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" \
37 84983e441c3bd26ebaae4aa1f95129e5e54670f1 \
38 abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
40 test_sha1 \
41 "123456789" \
42 f7c3bc1d808e04732adf679965ccc34ca7ae3441 \
43 123456789
45 test_sha1 \
46 "The quick brown fox jumped over the lazy dog.\n" \
47 bae5ed658ab3546aee12f23f36392f35dba1ebdd \
48 "quick brown fox"
50 test_sha1 \
51 - <gitblob.bin \
52 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 \
53 "git sha1 empty blob"
55 test_sha1 \
56 - <gittree.bin \
57 4b825dc642cb6eb9a060e54bf8d69288fbee4904 \
58 "git sha1 empty tree"
60 exit 0