]> diplodocus.org Git - nmh/blob - test/whatnow/test-cd
Replace a few calculations of string lengths with concat().
[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 case ${whatnowtest} in
41 cd) cat > "$expected" <<EOF
42 cd ${MH_TEST_DIR}/foo\'s\ bar
43 pwd
44 $SPDIR
45 EOF
46 # If path to $SPDIR is too long, readline will wrap and disturb
47 # the actual output. It obeys COLUMNS, so set that to a value
48 # that should be longer that $SPDIR plus a bit more.
49 COLUMNS=`getconf PATH_MAX . 2>/dev/null` || COLUMNS=8192
50 export COLUMNS
51 ;;
52 "") cat > "$expected" <<EOF
53 $SPDIR
54 EOF
55 ;;
56 *) echo "Unknown response to whatnow readline test"
57 echo "Response is: ${whatnowtest}"
58 exit 1
59 ;;
60 esac
61
62 cat > $expectederr <<EOF
63 EOF
64
65 # ||true to ignore whatnow's exit status
66 # watch the quoting -- shell and printf and then the shell run inside whatnow
67 printf 'cd %s/foo\\'"'"'s\\ bar\npwd\n' "$MH_TEST_DIR" | \
68 run_prog whatnow -noedit -prompt '' 2> "$actualerr" > "$actual" || true
69
70 check "$expectederr" "$actualerr"
71 check "$expected" "$actual"
72
73 test ${failed:-0} -eq 0 && rm -r "$SPDIR"
74
75 exit $failed