]> diplodocus.org Git - nmh/blob - test/install-mh/test-version-check
Alter mh-chart(7)'s NAME to be lowercase.
[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 require_prog script
21
22 actual="${MH_TEST_DIR}/test-version-check$$.actual"
23 context="${MH_TEST_DIR}"/Mail/context
24 version="Version: nmh-${MH_VERSION}"
25 cmd="${MH_TEST_DIR}/Mail/cmd"
26
27 #### Hack: especially on multicore/multiprocessor machines, need
28 #### to allow time for the output file to be closed. If the output
29 #### file never reaches a size greater than zero after waiting for
30 #### a short while, let a subsequent check fail to find what it needs.
31 #### $1: pid to wait for
32 #### $2: output file that must eventually have non-zero size
33 wait_for_script() {
34 wait $1
35
36 for i in 1 2 3 4 5 6 7 8 9 10; do
37 test -s "$2" && break || sleep 1
38 done
39 }
40
41
42 if script -S /bin/sh 'echo OK' /dev/null 2>&1 | egrep 'OK' >/dev/null; then
43 #### script(1) uses -S to set the shell that it runs.
44 use_dash_S=1
45 else
46 cat >"${cmd}" <<EOF
47 #! /bin/sh
48 echo OK
49 EOF
50 chmod +x "${cmd}"
51
52 (SHELL="${cmd}"; export SHELL; script "${actual}" >/dev/null &
53 wait_for_script $! "${actual}")
54 if grep OK "${actual}" >/dev/null; then
55 #### script(1) supports SHELL environment variable.
56 use_dash_S=0
57 else
58 test_skip "can't find mechanism to set SHELL for script(1)"
59 fi
60 fi
61
62 #### Run a command but don't wait for user input. script(1) seems to do
63 #### what we want by not waiting when run in the background. But check
64 #### that it makes the command look like it's connected to a terminal below.
65 run_without_input() {
66 #### Create a command to use as a shell for script.
67 cat >"${cmd}" <<EOF
68 #! /bin/sh
69 $*
70 EOF
71 chmod +x "${cmd}"
72
73 if [ ${use_dash_S} -eq 1 ]; then
74 script -S "${cmd}" "${actual}" >/dev/null &
75 else
76 SHELL="${cmd}" script "${actual}" >/dev/null &
77 fi
78
79 wait_for_script $! "${actual}"
80 }
81
82 #### Ensure that script(1) makes the program look like it's connected to a
83 #### terminal. The welcome message code in sbr/utils.c needs that.
84 run_without_input 'if test -t 0 -a -t 1 -a -t 2; then echo tty; fi'
85 grep tty "${actual}" >/dev/null || test_skip "script(1) doesn't simulate tty"
86
87
88 # Removing Version will trigger the welcome message. (setup_test
89 # inserted it so that other tests wouldn't show it.)
90 grep -v Version "${context}" > "${context}.NEW"
91 mv -f "${context}.NEW" "${context}"
92
93
94 start_test 'mhparam skips the welcome message'
95 run_without_input mhparam path
96 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
97 # Make sure that version wasn't added to context.
98 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
99 rm "${actual}"
100
101
102 start_test 'Welcome: disable in profile skips the welcome message'
103 cp "${MH}" "${MH}-welcome"
104 printf 'Welcome: disable\n' >> "${MH}-welcome"
105 # Run the function in subshell instead of augmenting the environment
106 # for a single command, so that the environment does not retain the
107 # MH setting. That can happen when run under distcheck, depending
108 # on the user's shell.
109 (MH="${MH}-welcome"; run_without_input pick last)
110 rm "${MH}-welcome"
111 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
112 # Make sure that version wasn't added to context.
113 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
114 rm "${actual}"
115
116
117 start_test 'with welcome message'
118 run_without_input pick last
119 grep 'Welcome to nmh version ' "${actual}" >/dev/null
120 # Make sure that version was added to context.
121 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
122 rm "${actual}"
123
124
125 start_test 'without welcome message'
126 # After running the previous test, this one should not have
127 # the welcome message.
128 run_without_input pick last
129 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
130 # Make sure that version is still in context.
131 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
132 rm "${actual}"
133
134
135 start_test 'with MHCONTEXT, welcome only if older'
136 MHCONTEXT="${MH_TEST_DIR}/Mail/context2"; export MHCONTEXT
137 printf 'Version: nmh-1.5\n' >"${MHCONTEXT}"
138 run_without_input pick last
139 grep 'Welcome to nmh version ' "${actual}" >/dev/null
140 # And make sure that version did get updated in context.
141 grep "^${version}$" "${MHCONTEXT}" >/dev/null
142 rm "${actual}"
143
144
145 start_test "with MHCONTEXT doesn't welcome if newer"
146 printf 'Version: nmh-10000.0\n' >"${MHCONTEXT}"
147 run_without_input pick last
148 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
149 # And make sure that version didn't get updated in context.
150 grep '^Version: nmh-10000.0$' "${MHCONTEXT}" >/dev/null
151 rm "${actual}"
152
153
154 start_test 'with MHCONTEXT but no version, no welcome and update'
155 printf '' >"${MHCONTEXT}"
156 run_without_input pick last
157 grep 'Welcome to nmh version ' "${actual}" >/dev/null && false
158 # And make sure that version did get updated in context.
159 grep "^${version}$" "${MHCONTEXT}" >/dev/null
160 rm "${actual}"
161
162
163 finish_test
164 exit ${failed}