t0030-mount.sh: improve stdout stderr fail tests
Konstantin Koroviev committed
Mar 23, 2015 at 03:15 UTC
490c88599d96af20b1a0c809b78449063f2af005
2 files changed
+24
-6
test/sharness/lib/test-lib.sh
+19
@@ -276,3 +276,22 @@ test_curl_resp_http_code() {
276
cat curl_output
277
return 1
278
}
279
+
280
+test_must_be_empty() {
281
+ if test -s "$1"
282
+ then
283
+ echo "'$1' is not empty, it contains:"
284
+ cat "$1"
285
+ return 1
286
+ fi
287
+}
288
+
289
+test_should_contain() {
290
+ test "$#" = 2 || error "bug in the test script: not 2 parameters to test_should_contain"
291
+ if ! grep -q "$1" "$2"
292
+ then
293
+ echo "'$2' does not contain '$1', it contains:"
294
+ cat "$2"
295
+ return 1
296
+ fi
297
+}
test/sharness/t0030-mount.sh
+5
-6
@@ -20,14 +20,13 @@ test_launch_ipfs_daemon
20
21
# test mount failure before mounting properly.
22
23
-test_expect_success "'ipfs mount' fails when no mount dir" '
24
- test_must_fail ipfs mount -f=not_ipfs -n=not_ipns >actual
23
+test_expect_success "'ipfs mount' fails when there is no mount dir" '
24
+ test_must_fail ipfs mount -f=not_ipfs -n=not_ipns >output 2>output.err
25
'
26
27
-test_expect_success "'ipfs mount' output looks good when it fails" '
28
- ! grep "IPFS mounted at: $(pwd)/ipfs" actual >/dev/null &&
29
- ! grep "IPNS mounted at: $(pwd)/ipns" actual >/dev/null ||
30
- test_fsh cat actual
27
+test_expect_success "'ipfs mount' output looks good" '
28
+ test_must_be_empty output &&
29
+ test_should_contain "not_ipns\|not_ipfs" output.err
30
'
31
32
# now mount properly, and keep going