2 ######################################################
4 # Test display of new version welcome message. This
5 # doesn't really belong in install-mh.
7 ######################################################
11 if test -z "${MH_OBJ_DIR}"; then
12 srcdir
=`dirname $0`/..
/..
13 MH_OBJ_DIR
=`cd $srcdir && pwd`; export MH_OBJ_DIR
16 .
"${MH_OBJ_DIR}/test/common.sh"
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"
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
36 for i
in 1 2 3 4 5 6 7 8 9 10; do
37 test -s "$2" && break || sleep 1
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.
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.
58 test_skip
"can't find mechanism to set SHELL for script(1)"
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.
66 #### Create a command to use as a shell for script.
73 if [ ${use_dash_S} -eq 1 ]; then
74 script -S "${cmd}" "${actual}" >/dev
/null
&
76 SHELL
="${cmd}" script "${actual}" >/dev
/null
&
79 wait_for_script $
! "${actual}"
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"
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}"
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
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
)
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
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
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
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
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
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