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