Skip to content

Commit 48545fe

Browse files
committed
sharness: add t0030-sha2.sh
1 parent a902fa0 commit 48545fe

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

tests/sharness/lib/test-lib.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@ SHARNESS_LIB="lib/sharness/sharness.sh"
3333

3434
# Please put multihash specific shell functions below
3535

36-
for hashbin in sha1sum shasum; do
37-
if type "$hashbin" >/dev/null; then
38-
export SHA1SUMBIN="$hashbin" &&
36+
if type shasum >/dev/null; then
37+
export SHA1SUMBIN="shasum" &&
3938
test_set_prereq SHA1SUM &&
40-
break
39+
export SHA256SUMBIN="shasum -a 256" &&
40+
test_set_prereq SHA256SUM &&
41+
export SHA512SUMBIN="shasum -a 512" &&
42+
test_set_prereq SHA512SUM
43+
else
44+
if type sha1sum >/dev/null; then
45+
export SHA1SUMBIN="sha1sum" &&
46+
test_set_prereq SHA1SUM
4147
fi
42-
done
43-
48+
if type sha256sum >/dev/null; then
49+
export SHA256SUMBIN="sha256sum" &&
50+
test_set_prereq SHA256SUM
51+
fi
52+
if type sha512sum >/dev/null; then
53+
export SHA512SUMBIN="sha512sum" &&
54+
test_set_prereq SHA512SUM
55+
fi
56+
fi

tests/sharness/t0030-sha2.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2016 Christian Couder
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
7+
test_description="sha2 tests"
8+
9+
. lib/test-lib.sh
10+
11+
test_expect_success "setup sha2 tests" '
12+
echo "Hash me!" >hash_me.txt &&
13+
SHA256=c16bdce7e126ff8e241a9893ccd908c292cd0e54c403145326eb0c567071a613 &&
14+
SHA512=4c4a59a7d958cff035eb7d752b319b90337037e352b89d58aa5be29ef051ea0a565133781aa3279384654274c4786893287ea8037f0a1a15d9b40ea0bc4be73c &&
15+
echo "1220$SHA256" >expected256 &&
16+
echo "1340$SHA512" >expected512
17+
'
18+
19+
test_expect_success "'multihash -a=sha2-256 -e=hex' works" '
20+
multihash -a=sha2-256 -e=hex hash_me.txt >actual256
21+
'
22+
23+
test_expect_success "'multihash -a=sha2-256 -e=hex' output looks good" '
24+
test_cmp expected256 actual256
25+
'
26+
27+
test_expect_success "'multihash -a=sha2-512 -e=hex' works" '
28+
multihash -a=sha2-512 -e=hex hash_me.txt >actual512
29+
'
30+
31+
test_expect_success "'multihash -a=sha2-512 -e=hex' output looks good" '
32+
test_cmp expected512 actual512
33+
'
34+
35+
test_expect_success SHA256SUM "check sha2-256 hash using '$SHA256SUMBIN'" '
36+
echo "$SHA256 hash_me.txt" >expected &&
37+
$SHA256SUMBIN hash_me.txt >actual &&
38+
test_cmp expected actual
39+
'
40+
41+
test_expect_success SHA512SUM "check sha2-512 hash using '$SHA512SUMBIN'" '
42+
echo "$SHA512 hash_me.txt" >expected &&
43+
$SHA512SUMBIN hash_me.txt >actual &&
44+
test_cmp expected actual
45+
'
46+
47+
test_done

0 commit comments

Comments
 (0)