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