gitweb/indextext_readonly.html: include sample readonly file
[girocco.git] / src / ltsha256-test.sh
blob200ef834107de44a6995bb3e6d5040206a84d7c6
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_sha256() {
13 _val="$1"; shift
14 _hash="$1"; shift
15 _test="$*"
16 if [ "$_val" = "-" ]; then
17 _check="$(./ltsha256)"
18 else
19 _check="$(printf '%b' "$_val" | ./ltsha256)"
20 fi ||
21 die "could not run ltsha256 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_sha256 \
31 "abc" \
32 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad \
33 abc
35 test_sha256 \
36 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" \
37 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 \
38 abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
40 test_sha256 \
41 "123456789" \
42 15e2b0d3c33891ebb0f1ef609ec419420c20e320ce94c65fbc8c3312448eb225 \
43 123456789
45 test_sha256 \
46 "The quick brown fox jumped over the lazy dog.\n" \
47 40d5c6f7fe5672fb52269f651c2b985867dfcfa4a5c5258e3d4f8736d5095037 \
48 "quick brown fox"
50 test_sha256 \
51 - <gitblob.bin \
52 473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 \
53 "git sha256 empty blob"
55 test_sha256 \
56 - <gittree.bin \
57 6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321 \
58 "git sha256 empty tree"
60 exit 0