From be4191d800b7a1e30afe64a706f73b31217e003f Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Sun, 4 Jan 2015 22:12:55 -0800 Subject: [PATCH] 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). --- test/bin/fsh | 13 ++++++++++ test/lib/test-lib.sh | 46 +++++++++++++++++++++++------------- test/t0010-basic-commands.sh | 9 +++---- test/t0020-init.sh | 3 ++- test/t0030-mount.sh | 29 ++++++++++++++--------- test/t0040-add-and-cat.sh | 6 +++-- test/t0050-block.sh | 5 +--- test/t0060-daemon.sh | 3 ++- 8 files changed, 74 insertions(+), 40 deletions(-) create mode 100755 test/bin/fsh diff --git a/test/bin/fsh b/test/bin/fsh new file mode 100755 index 000000000..b057c0484 --- /dev/null +++ b/test/bin/fsh @@ -0,0 +1,13 @@ +#!/bin/sh +# Author: Juan Batiz-Benet +# MIT LICENSED + +# verbose eval, and exit with error, so we can avoid writing: +# echo "cat version.txt" && cat version.txt && false + +# echo "# > $@" +# eval $@ | sed -e 's/^/# /' +echo "> $@" +eval $@ +echo "" +exit 1 diff --git a/test/lib/test-lib.sh b/test/lib/test-lib.sh index 9794f35fe..50273fb19 100644 --- a/test/lib/test-lib.sh +++ b/test/lib/test-lib.sh @@ -39,7 +39,7 @@ test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE test_cmp_repeat_10_sec() { for i in 1 2 3 4 5 6 7 8 9 10 do - test_cmp "$1" "$2" && return + test_cmp "$1" "$2" >/dev/null && return sleep 1 done test_cmp "$1" "$2" @@ -57,24 +57,11 @@ test_wait_output_n_lines_60_sec() { test_cmp "expected_waitn" "actual_waitn" } -test_launch_ipfs_daemon() { - - test_expect_success FUSE "'ipfs daemon' succeeds" ' - ipfs daemon >actual & - ' - - test_expect_success FUSE "'ipfs daemon' output looks good" ' - IPFS_PID=$! && - echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >expected && - test_cmp_repeat_10_sec expected actual - ' -} - -test_launch_ipfs_daemon_and_mount() { +test_init_ipfs() { test_expect_success "ipfs init succeeds" ' export IPFS_DIR="$(pwd)/.go-ipfs" && - ipfs init -b=1024 + ipfs init -b=1024 > /dev/null ' test_expect_success "prepare config" ' @@ -83,7 +70,23 @@ test_launch_ipfs_daemon_and_mount() { ipfs config Mounts.IPNS "$(pwd)/ipns" ' - test_launch_ipfs_daemon +} + +test_launch_ipfs_daemon() { + + test_expect_success FUSE "'ipfs daemon' succeeds" ' + ipfs daemon >actual 2>daemon_err & + ' + + test_expect_success FUSE "'ipfs daemon' output looks good" ' + IPFS_PID=$! && + echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >expected && + test_cmp_repeat_10_sec expected actual || + fsh cat daemon_err + ' +} + +test_mount_ipfs() { test_expect_success FUSE "'ipfs mount' succeeds" ' ipfs mount >actual @@ -94,6 +97,15 @@ test_launch_ipfs_daemon_and_mount() { echo "IPNS mounted at: $(pwd)/ipns" >>expected && test_cmp expected actual ' + +} + +test_launch_ipfs_daemon_and_mount() { + + test_init_ipfs + test_launch_ipfs_daemon + test_mount_ipfs + } test_kill_repeat_10_sec() { diff --git a/test/t0010-basic-commands.sh b/test/t0010-basic-commands.sh index 8ddaae3f9..41a5518e0 100755 --- a/test/t0010-basic-commands.sh +++ b/test/t0010-basic-commands.sh @@ -17,7 +17,8 @@ test_expect_success "ipfs version succeeds" ' ' test_expect_success "ipfs version output looks good" ' - cat version.txt | egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" + cat version.txt | egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" >/dev/null || + fsh cat version.txt ' test_expect_success "ipfs help succeeds" ' @@ -25,9 +26,9 @@ test_expect_success "ipfs help succeeds" ' ' test_expect_success "ipfs help output looks good" ' - cat help.txt | egrep -i "^Usage:" && - cat help.txt | egrep "ipfs .* " + cat help.txt | egrep -i "^Usage:" >/dev/null && + cat help.txt | egrep "ipfs .* " >/dev/null || + fsh cat help.txt ' test_done - diff --git a/test/t0020-init.sh b/test/t0020-init.sh index 47199c811..d7b4c8dfa 100755 --- a/test/t0020-init.sh +++ b/test/t0020-init.sh @@ -16,7 +16,8 @@ test_expect_success "ipfs init succeeds" ' test_expect_success ".go-ipfs/ has been created" ' test -d ".go-ipfs" && test -f ".go-ipfs/config" && - test -d ".go-ipfs/datastore" + test -d ".go-ipfs/datastore" || + fsh ls -al .go-ipfs ' test_expect_success "ipfs config succeeds" ' diff --git a/test/t0030-mount.sh b/test/t0030-mount.sh index 3b3091e13..f38403039 100755 --- a/test/t0030-mount.sh +++ b/test/t0030-mount.sh @@ -15,25 +15,32 @@ if ! test_have_prereq FUSE; then test_done fi -test_launch_ipfs_daemon_and_mount - -test_kill_ipfs_daemon - -test_expect_success "mount directories can be removed" ' - rmdir ipfs ipns -' - +test_init_ipfs test_launch_ipfs_daemon +# run this mount failure before mounting properly. + test_expect_failure "'ipfs mount' fails when no mount dir (issue #341)" ' - test_must_fail ipfs mount >actual + test_must_fail ipfs mount -f=not_ipfs -n=not_ipns >actual ' test_expect_failure "'ipfs mount' looks good when it fails (issue #341)" ' - ! grep "IPFS mounted at" actual && - ! grep "IPNS mounted at" actual + ! grep "IPFS mounted at: $(pwd)/ipfs" actual >/dev/null && + ! grep "IPNS mounted at: $(pwd)/ipns" actual >/dev/null || + fsh cat actual +' + +# now mount properly, and keep going +test_mount_ipfs + +test_expect_success "mount directories cannot be removed while active" ' + test_must_fail rmdir ipfs ipns 2>/dev/null ' test_kill_ipfs_daemon +test_expect_success "mount directories can be removed after shutdown" ' + rmdir ipfs ipns +' + test_done diff --git a/test/t0040-add-and-cat.sh b/test/t0040-add-and-cat.sh index 95ac52f65..fe13ce553 100755 --- a/test/t0040-add-and-cat.sh +++ b/test/t0040-add-and-cat.sh @@ -15,7 +15,8 @@ test_expect_success "'ipfs add --help' succeeds" ' ' test_expect_success "'ipfs add --help' output looks good" ' - egrep "ipfs add.*" actual + egrep "ipfs add.*" actual >/dev/null || + fsh cat actual ' test_expect_success "'ipfs cat --help' succeeds" ' @@ -23,7 +24,8 @@ test_expect_success "'ipfs cat --help' succeeds" ' ' test_expect_success "'ipfs cat --help' output looks good" ' - egrep "ipfs cat.*" actual + egrep "ipfs cat.*" actual >/dev/null || + fsh cat actual ' test_expect_success "ipfs add succeeds" ' diff --git a/test/t0050-block.sh b/test/t0050-block.sh index 1a55bf420..fd511466e 100755 --- a/test/t0050-block.sh +++ b/test/t0050-block.sh @@ -8,10 +8,7 @@ test_description="Test block command" . lib/test-lib.sh -test_expect_success "ipfs init succeeds" ' - export IPFS_DIR="$(pwd)/.go-ipfs" && - ipfs init -' +test_init_ipfs test_expect_success "'ipfs block put' succeeds" ' echo "Hello Mars!" >expected_in && diff --git a/test/t0060-daemon.sh b/test/t0060-daemon.sh index f0f458272..f23f85d04 100755 --- a/test/t0060-daemon.sh +++ b/test/t0060-daemon.sh @@ -46,7 +46,8 @@ test_expect_success "ipfs daemon output looks good" ' test_expect_success ".go-ipfs/ has been created" ' test -d ".go-ipfs" && test -f ".go-ipfs/config" && - test -d ".go-ipfs/datastore" + test -d ".go-ipfs/datastore" || + fsh ls .go-ipfs ' test_expect_success "daemon is still running" '