@cryptotaxi247 / kubo / commits / be4191d80

sharness: nice verbose ouput

Make sharness tests' output helpful when verbose. This means cating certain files, or running diagnostic commands. I used a construction like: test_expect_success ".go-ipfs/ has been created" ' test -d ".go-ipfs" && test -f ".go-ipfs/config" && test -d ".go-ipfs/datastore" || fsh ls -al .go-ipfs ' The `|| ...` is a diagnostic run when the preceding command fails. `fsh` is a trivial script that echoes the args, runs the cmd, and then also fails, making sure the test case fails. (wouldnt want the diagnostic accidentally returning true and making it _seem_ like the test case succeeded).

Juan Batiz-Benet committed Jan 4, 2015 at 22:12 UTC be4191d800b7a1e30afe64a706f73b31217e003f
8 files changed +74 -40
test/bin/fsh new
+13
@@ -0,0 +1,13 @@
1 +#!/bin/sh
2 +# Author: Juan Batiz-Benet <juan@benet.ai>
3 +# MIT LICENSED
4 +
5 +# verbose eval, and exit with error, so we can avoid writing:
6 +# echo "cat version.txt" && cat version.txt && false
7 +
8 +# echo "# > $@"
9 +# eval $@ | sed -e 's/^/# /'
10 +echo "> $@"
11 +eval $@
12 +echo ""
13 +exit 1
test/lib/test-lib.sh
+29 -17
@@ -39,7 +39,7 @@ test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE
39 test_cmp_repeat_10_sec() {
40 for i in 1 2 3 4 5 6 7 8 9 10
41 do
42 - test_cmp "$1" "$2" && return
42 + test_cmp "$1" "$2" >/dev/null && return
43 sleep 1
44 done
45 test_cmp "$1" "$2"
@@ -57,24 +57,11 @@ test_wait_output_n_lines_60_sec() {
57 test_cmp "expected_waitn" "actual_waitn"
58 }
59
60 -test_launch_ipfs_daemon() {
61 -
62 - test_expect_success FUSE "'ipfs daemon' succeeds" '
63 - ipfs daemon >actual &
64 - '
65 -
66 - test_expect_success FUSE "'ipfs daemon' output looks good" '
67 - IPFS_PID=$! &&
68 - echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >expected &&
69 - test_cmp_repeat_10_sec expected actual
70 - '
71 -}
72 -
73 -test_launch_ipfs_daemon_and_mount() {
60 +test_init_ipfs() {
61
62 test_expect_success "ipfs init succeeds" '
63 export IPFS_DIR="$(pwd)/.go-ipfs" &&
77 - ipfs init -b=1024
64 + ipfs init -b=1024 > /dev/null
65 '
66
67 test_expect_success "prepare config" '
@@ -83,7 +70,23 @@ test_launch_ipfs_daemon_and_mount() {
70 ipfs config Mounts.IPNS "$(pwd)/ipns"
71 '
72
86 - test_launch_ipfs_daemon
73 +}
74 +
75 +test_launch_ipfs_daemon() {
76 +
77 + test_expect_success FUSE "'ipfs daemon' succeeds" '
78 + ipfs daemon >actual 2>daemon_err &
79 + '
80 +
81 + test_expect_success FUSE "'ipfs daemon' output looks good" '
82 + IPFS_PID=$! &&
83 + echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >expected &&
84 + test_cmp_repeat_10_sec expected actual ||
85 + fsh cat daemon_err
86 + '
87 +}
88 +
89 +test_mount_ipfs() {
90
91 test_expect_success FUSE "'ipfs mount' succeeds" '
92 ipfs mount >actual
@@ -94,6 +97,15 @@ test_launch_ipfs_daemon_and_mount() {
97 echo "IPNS mounted at: $(pwd)/ipns" >>expected &&
98 test_cmp expected actual
99 '
100 +
101 +}
102 +
103 +test_launch_ipfs_daemon_and_mount() {
104 +
105 + test_init_ipfs
106 + test_launch_ipfs_daemon
107 + test_mount_ipfs
108 +
109 }
110
111 test_kill_repeat_10_sec() {
test/t0010-basic-commands.sh
+5 -4
@@ -17,7 +17,8 @@ test_expect_success "ipfs version succeeds" '
17 '
18
19 test_expect_success "ipfs version output looks good" '
20 - cat version.txt | egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]"
20 + cat version.txt | egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" >/dev/null ||
21 + fsh cat version.txt
22 '
23
24 test_expect_success "ipfs help succeeds" '
@@ -25,9 +26,9 @@ test_expect_success "ipfs help succeeds" '
26 '
27
28 test_expect_success "ipfs help output looks good" '
28 - cat help.txt | egrep -i "^Usage:" &&
29 - cat help.txt | egrep "ipfs .* <command>"
29 + cat help.txt | egrep -i "^Usage:" >/dev/null &&
30 + cat help.txt | egrep "ipfs .* <command>" >/dev/null ||
31 + fsh cat help.txt
32 '
33
34 test_done
33 -
test/t0020-init.sh
+2 -1
@@ -16,7 +16,8 @@ test_expect_success "ipfs init succeeds" '
16 test_expect_success ".go-ipfs/ has been created" '
17 test -d ".go-ipfs" &&
18 test -f ".go-ipfs/config" &&
19 - test -d ".go-ipfs/datastore"
19 + test -d ".go-ipfs/datastore" ||
20 + fsh ls -al .go-ipfs
21 '
22
23 test_expect_success "ipfs config succeeds" '
test/t0030-mount.sh
+18 -11
@@ -15,25 +15,32 @@ if ! test_have_prereq FUSE; then
15 test_done
16 fi
17
18 -test_launch_ipfs_daemon_and_mount
19 -
20 -test_kill_ipfs_daemon
21 -
22 -test_expect_success "mount directories can be removed" '
23 - rmdir ipfs ipns
24 -'
25 -
18 +test_init_ipfs
19 test_launch_ipfs_daemon
20
21 +# run this mount failure before mounting properly.
22 +
23 test_expect_failure "'ipfs mount' fails when no mount dir (issue #341)" '
29 - test_must_fail ipfs mount >actual
24 + test_must_fail ipfs mount -f=not_ipfs -n=not_ipns >actual
25 '
26
27 test_expect_failure "'ipfs mount' looks good when it fails (issue #341)" '
33 - ! grep "IPFS mounted at" actual &&
34 - ! grep "IPNS mounted at" actual
28 + ! grep "IPFS mounted at: $(pwd)/ipfs" actual >/dev/null &&
29 + ! grep "IPNS mounted at: $(pwd)/ipns" actual >/dev/null ||
30 + fsh cat actual
31 +'
32 +
33 +# now mount properly, and keep going
34 +test_mount_ipfs
35 +
36 +test_expect_success "mount directories cannot be removed while active" '
37 + test_must_fail rmdir ipfs ipns 2>/dev/null
38 '
39
40 test_kill_ipfs_daemon
41
42 +test_expect_success "mount directories can be removed after shutdown" '
43 + rmdir ipfs ipns
44 +'
45 +
46 test_done
test/t0040-add-and-cat.sh
+4 -2
@@ -15,7 +15,8 @@ test_expect_success "'ipfs add --help' succeeds" '
15 '
16
17 test_expect_success "'ipfs add --help' output looks good" '
18 - egrep "ipfs add.*<path>" actual
18 + egrep "ipfs add.*<path>" actual >/dev/null ||
19 + fsh cat actual
20 '
21
22 test_expect_success "'ipfs cat --help' succeeds" '
@@ -23,7 +24,8 @@ test_expect_success "'ipfs cat --help' succeeds" '
24 '
25
26 test_expect_success "'ipfs cat --help' output looks good" '
26 - egrep "ipfs cat.*<ipfs-path>" actual
27 + egrep "ipfs cat.*<ipfs-path>" actual >/dev/null ||
28 + fsh cat actual
29 '
30
31 test_expect_success "ipfs add succeeds" '
test/t0050-block.sh
+1 -4
@@ -8,10 +8,7 @@ test_description="Test block command"
8
9 . lib/test-lib.sh
10
11 -test_expect_success "ipfs init succeeds" '
12 - export IPFS_DIR="$(pwd)/.go-ipfs" &&
13 - ipfs init
14 -'
11 +test_init_ipfs
12
13 test_expect_success "'ipfs block put' succeeds" '
14 echo "Hello Mars!" >expected_in &&
test/t0060-daemon.sh
+2 -1
@@ -46,7 +46,8 @@ test_expect_success "ipfs daemon output looks good" '
46 test_expect_success ".go-ipfs/ has been created" '
47 test -d ".go-ipfs" &&
48 test -f ".go-ipfs/config" &&
49 - test -d ".go-ipfs/datastore"
49 + test -d ".go-ipfs/datastore" ||
50 + fsh ls .go-ipfs
51 '
52
53 test_expect_success "daemon is still running" '