Have each test clean up after itself if it completes successfully.
[mmh] / test / whatnow / test-attach-detach
1 #!/bin/sh
2 ######################################################
3 #
4 # Test that whatnow's "ls" copes with directory names
5 # which have spaces in them (see bug #23319)
6 #
7 ######################################################
8
9 set -e
10
11 if test -z "${MH_OBJ_DIR}"; then
12     srcdir=`dirname "$0"`/../..
13     MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
14 fi
15
16 . "$MH_OBJ_DIR/test/common.sh"
17
18 setup_test
19
20 cd "$MH_TEST_DIR"
21 testname="baz's boz"
22 testname_quoted="baz\'s\ boz"
23 touch "$testname"
24 # whatnow's attach stuff needs a draft to work on
25 cp "$MH_TEST_DIR/Mail/inbox/1" "$MH_TEST_DIR/Mail/draft"
26
27 expectederr=$MH_TEST_DIR/$$.expectederr
28 actualerr=$MH_TEST_DIR/$$.actualerr
29 expected=$MH_TEST_DIR/$$.expected
30 actual=$MH_TEST_DIR/$$.actual
31
32 rm -f $expected $expectederr $actual $actualerr
33 touch $expected $expectederr $actual $actualerr
34
35 cat > $expected <<EOF
36 $testname
37 EOF
38
39 # whatnow's exit status is always 1 so that is not a failure
40 set +e
41 echo "attach $testname_quoted" | \
42   whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
43 echo "alist" | whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
44 echo "detach $testname_quoted" | \
45   whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
46 echo "alist" | whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
47 set -e
48
49 check "$expectederr" "$actualerr"
50 check "$expected" "$actual"
51
52 test ${failed:-0} -eq 0  &&  rm "$testname"
53
54 exit $failed