Removed double quotes around case arguments in test scripts.
[mmh] / test / whatnow / test-ls
1 #!/bin/sh
2 ######################################################
3 #
4 # Test that whatnow's "ls" 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"
24 touch baz boz
25
26 expectederr=$MH_TEST_DIR/$$.expectederr
27 actualerr=$MH_TEST_DIR/$$.actualerr
28 expected=$MH_TEST_DIR/$$.expected
29 actual=$MH_TEST_DIR/$$.actual
30
31 #
32 # Handle different output depending on readline version
33 #
34
35 set +e
36 whatnowtest=`echo cd | TERM=dumb whatnow -prompt ''`
37 set -e
38
39 case ${whatnowtest} in
40     cd) cat > "$expected" <<EOF
41 baz
42 boz
43 ls
44 EOF
45     ;;
46     "") cat > "$expected" <<EOF
47 baz
48 boz
49 EOF
50     ;;
51     *) echo "Unknown response to whatnow readline test"
52     echo "Response is: ${whatnowtest}"
53     exit 1
54     ;;
55 esac
56
57 cat > $expectederr <<EOF
58 EOF
59
60 # NB use of sort as the order of output of ls is not guaranteed
61 echo 'ls' | TERM=dumb whatnow -noedit -prompt '' 2> "$actualerr" | \
62         sort > "$actual"
63
64 check "$expectederr" "$actualerr" 'keep first'
65 check "$expected" "$actual" 'keep first'
66
67 # Check with SHELL unset.  This won't reveal any problems if
68 # /bin/sh sets SHELL, which bash does.
69 unset SHELL
70
71 echo 'ls' | TERM=dumb whatnow -noedit -prompt '' 2> "$actualerr" | \
72         sort > "$actual"
73
74 check "$expectederr" "$actualerr"
75 check "$expected" "$actual"
76
77 # On some platforms, need to be out of $SPDIR in order to remove it.
78 cd "$MH_TEST_DIR"
79 test ${failed:-0} -eq 0  &&  rm -r "$SPDIR"
80
81 exit $failed