ef6175d9f51c78091b296bd47f829c18e9736ed5
[mmh] / test / whatnow / test-cd
1 #!/bin/sh
2 ######################################################
3 #
4 # Test that whatnow's "cd" copes with directory names
5 # which have spaces and quotes 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 SPDIR="$MH_TEST_DIR/foo's bar"
21 rm -rf "$SPDIR"
22 mkdir "$SPDIR"
23 (cd "$SPDIR"  &&  touch baz boz)
24
25 expectederr=$MH_TEST_DIR/$$.expectederr
26 actualerr=$MH_TEST_DIR/$$.actualerr
27 expected=$MH_TEST_DIR/$$.expected
28 actual=$MH_TEST_DIR/$$.actual
29
30 #
31 # Handle different output depending on readline version
32 #
33
34 set +e
35 whatnowtest=`echo cd | TERM=dumb whatnow -prompt ''`
36 set -e
37
38 case ${whatnowtest} in
39     cd) cat > "$expected" <<EOF
40 cd ${MH_TEST_DIR}/foo\'s\ bar
41 pwd
42 $SPDIR
43 EOF
44     ;;
45     "") cat > "$expected" <<EOF
46 $SPDIR
47 EOF
48     ;;
49     *) echo "Unknown response to whatnow readline test"
50     echo "Response is: ${whatnowtest}"
51     exit 1
52     ;;
53 esac
54
55 cat > $expectederr <<EOF
56 EOF
57
58 # ||true to ignore whatnow's exit status
59 # watch the quoting -- shell and printf and then the shell run inside whatnow
60 printf "cd $MH_TEST_DIR/foo\\\\'s\\\\ bar\npwd\n" | \
61   TERM=dumb whatnow -noedit -prompt '' 2> "$actualerr" > "$actual" || true
62
63 check "$expectederr" "$actualerr"
64 check "$expected" "$actual"
65
66 test ${failed:-0} -eq 0  &&  rm -r "$SPDIR"
67
68 exit $failed