Skip to content

Commit a902fa0

Browse files
committed
sharness: add lib/test-lib.sh
1 parent 2dbf26a commit a902fa0

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

tests/sharness/lib/test-lib.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Test framework for multihash
2+
#
3+
# Copyright (c) 2016 Christian Couder
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
# We are using sharness (https://github.com/chriscool/sharness)
7+
# which was extracted from the Git test framework.
8+
9+
# Test the first 'multihash' tool available in the PATH.
10+
11+
# Add current bin directory to path, in case multihash tool is there.
12+
PATH=$(pwd)/bin:${PATH}
13+
14+
# Set sharness verbosity. we set the env var directly as
15+
# it's too late to pass in --verbose, and --verbose is harder
16+
# to pass through in some cases.
17+
test "$TEST_VERBOSE" = 1 && verbose=t
18+
19+
# Assert a `multihash` tool is available in the PATH.
20+
type multihash >/dev/null || {
21+
echo >&2 "Cannot find any 'multihash' tool in '$PATH'."
22+
echo >&2 "Please make sure 'multihash' is in your PATH."
23+
exit 1
24+
}
25+
26+
SHARNESS_LIB="lib/sharness/sharness.sh"
27+
28+
. "$SHARNESS_LIB" || {
29+
echo >&2 "Cannot source: $SHARNESS_LIB"
30+
echo >&2 "Please check Sharness installation."
31+
exit 1
32+
}
33+
34+
# Please put multihash specific shell functions below
35+
36+
for hashbin in sha1sum shasum; do
37+
if type "$hashbin" >/dev/null; then
38+
export SHA1SUMBIN="$hashbin" &&
39+
test_set_prereq SHA1SUM &&
40+
break
41+
fi
42+
done
43+

tests/sharness/t0010-multihash-basics.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
test_description="Test multihash basics"
44

5-
. ./lib/sharness/sharness.sh
5+
. lib/test-lib.sh
66

77
test_expect_success "current dir is writable" '
88
echo "It works!" >test.txt
99
'
1010

11-
test_expect_success "multihash is available" '
12-
type multihash
13-
'
14-
1511
test_expect_success "'multihash --help' looks good" '
1612
multihash --help >actual 2>&1 || true &&
1713
egrep -i "usage" actual >/dev/null

tests/sharness/t0020-sha1.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
test_description="sha1 tests"
88

9-
. ./lib/sharness/sharness.sh
9+
. lib/test-lib.sh
1010

1111
test_expect_success "setup sha1 tests" '
1212
echo "Hash me!" >hash_me.txt &&
@@ -22,9 +22,9 @@ test_expect_success "'multihash -a=sha1 -e=hex' output looks good" '
2222
test_cmp expected actual
2323
'
2424

25-
test_expect_success SHASUM "check hash using shasum" '
25+
test_expect_success SHA1SUM "check hash using '$SHA1SUMBIN'" '
2626
echo "$SHA1 hash_me.txt" >expected &&
27-
$SHASUMBIN hash_me.txt >actual &&
27+
$SHA1SUMBIN hash_me.txt >actual &&
2828
test_cmp expected actual
2929
'
3030

0 commit comments

Comments
 (0)