]> diplodocus.org Git - nmh/blob - test/install-mh/test-version-check
Fix invalid pointer arithmetic.
[nmh] / test / install-mh / test-version-check
1 #!/bin/sh
2 ######################################################
3 #
4 # Test display of new version welcome message. This
5 # doesn't really belong in install-mh.
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 actual="${MH_TEST_DIR}/test-version-check$$.actual"
21 context="${MH_TEST_DIR}"/Mail/context
22 version="Version: nmh-${MH_VERSION}"
23 cmd="${MH_TEST_DIR}/Mail/cmd"
24 runpty="${MH_OBJ_DIR}/test/runpty"
25
26 #### Run a command but don't wait for user input. We switched from script(1)
27 #### to our own utility, runpty. Check that it makes the command look like
28 #### it's connected to a terminal below.
29 run_without_input() {
30 #### Create a command to use as a shell for script.
31 cat >"${cmd}" <<EOF
32 #! /bin/sh
33 $*
34 EOF
35 chmod +x "${cmd}"
36
37 "$runpty" "${actual}" "${cmd}"
38 }
39
40 #### Ensure that runpty makes the program look like it's connected to a
41 #### terminal. The welcome message code in sbr/utils.c needs that.
42 run_without_input 'if test -t 0 -a -t 1 -a -t 2; then echo tty; fi'
43 grep tty "${actual}" >/dev/null || test_skip "runpty doesn't simulate tty"
44
45
46 # Removing Version will trigger the welcome message. (setup_test
47 # inserted it so that other tests wouldn't show it.)
48 grep -v Version "${context}" > "${context}.NEW"
49 mv -f "${context}.NEW" "${context}"
50
51
52 start_test 'mhparam skips the welcome message'
53 run_without_input mhparam path
54 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
55 # Make sure that version wasn't added to context.
56 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
57 rm "${actual}"
58
59
60 start_test 'Welcome: disable in profile skips the welcome message'
61 cp "${MH}" "${MH}-welcome"
62 printf 'Welcome: disable\n' >> "${MH}-welcome"
63 # Run the function in subshell instead of augmenting the environment
64 # for a single command, so that the environment does not retain the
65 # MH setting. That can happen when run under distcheck, depending
66 # on the user's shell.
67 (MH="${MH}-welcome"; run_without_input pick last)
68 rm "${MH}-welcome"
69 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
70 # Make sure that version wasn't added to context.
71 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
72 rm "${actual}"
73
74
75 start_test 'with welcome message'
76 run_without_input pick last
77 grep 'Welcome to nmh version ' "${actual}" >/dev/null
78 # Make sure that version was added to context.
79 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
80 rm "${actual}"
81
82
83 start_test 'without welcome message'
84 # After running the previous test, this one should not have
85 # the welcome message.
86 run_without_input pick last
87 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
88 # Make sure that version is still in context.
89 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
90 rm "${actual}"
91
92
93 start_test 'with MHCONTEXT, welcome only if older'
94 MHCONTEXT="${MH_TEST_DIR}/Mail/context2"; export MHCONTEXT
95 printf 'Version: nmh-1.5\n' >"${MHCONTEXT}"
96 run_without_input pick last
97 grep 'Welcome to nmh version ' "${actual}" >/dev/null
98 # And make sure that version did get updated in context.
99 grep "^${version}$" "${MHCONTEXT}" >/dev/null
100 rm "${actual}"
101
102
103 start_test "with MHCONTEXT doesn't welcome if newer"
104 printf 'Version: nmh-10000.0\n' >"${MHCONTEXT}"
105 run_without_input pick last
106 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
107 # And make sure that version didn't get updated in context.
108 grep '^Version: nmh-10000.0$' "${MHCONTEXT}" >/dev/null
109 rm "${actual}"
110
111
112 start_test 'with MHCONTEXT but no version, no welcome and update'
113 printf '' >"${MHCONTEXT}"
114 run_without_input pick last
115 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
116 # And make sure that version did get updated in context.
117 grep "^${version}$" "${MHCONTEXT}" >/dev/null
118 rm "${actual}"
119
120
121 finish_test
122 exit ${failed}