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