]> diplodocus.org Git - nmh/blob - test/whatnow/test-cd
Fixed a few very minor issues that cppcheck noticed.
[nmh] / 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 # 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" && touch baz boz)
27
28 expectederr=$MH_TEST_DIR/$$.expectederr
29 actualerr=$MH_TEST_DIR/$$.actualerr
30 expected=$MH_TEST_DIR/$$.expected
31 actual=$MH_TEST_DIR/$$.actual
32
33 #
34 # Handle different output depending on readline version
35 #
36
37 set +e
38 whatnowtest=`echo cd | whatnow -prompt ''`
39 set -e
40
41 case ${whatnowtest} in
42 cd) cat > "$expected" <<EOF
43 cd ${MH_TEST_DIR}/foo\'s\ bar
44 pwd
45 $SPDIR
46 EOF
47 ;;
48 "") cat > "$expected" <<EOF
49 $SPDIR
50 EOF
51 ;;
52 *) echo "Unknown response to whatnow readline test"
53 echo "Response is: ${whatnowtest}"
54 exit 1
55 ;;
56 esac
57
58 cat > $expectederr <<EOF
59 EOF
60
61 # ||true to ignore whatnow's exit status
62 # watch the quoting -- shell and printf and then the shell run inside whatnow
63 printf 'cd %s/foo\\'"'"'s\\ bar\npwd\n' "$MH_TEST_DIR" | \
64 run_prog whatnow -noedit -prompt '' 2> "$actualerr" > "$actual" || true
65
66 check "$expectederr" "$actualerr"
67 check "$expected" "$actual"
68
69 test ${failed:-0} -eq 0 && rm -r "$SPDIR"
70
71 exit $failed