]> diplodocus.org Git - nmh/blob - test/install-mh/test-version-check
A better fix than e87f37c27828723317a71291e31b34f39ec09098, because
[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 if test ! -t 0 || test ! -t 1 || test ! -t 2; then
21 test_skip 'must be connected to terminal'
22 fi
23
24 require_prog script
25 #### FreeBSD script, e.g., doesn't use -c to identify a command to run.
26 if script -c 'echo OK' /dev/null 2>&1 | egrep 'OK' >/dev/null; then
27 script_command_opt='-c'
28 else
29 script_command_opt=''
30 fi
31
32 #### Run a command but don't wait for user input. script(1) seems to do
33 #### what we want by not waiting when run in the background.
34 run_without_input() {
35 if [ "$script_command_opt" = -c ]; then
36 #### -c takes single argument with command + arguments.
37 script -q -f -c "$*" "$actual" >/dev/null &
38 else
39 #### E.g., FreeBSD. Don't combine command arguments.
40 script -q -t 0 "$actual" "$@" >/dev/null &
41 fi
42
43 wait $!
44 }
45
46 actual="$MH_TEST_DIR/test-version-check$$.actual"
47 context="${MH_TEST_DIR}"/Mail/context
48 version="Version: nmh-${MH_VERSION}"
49
50 # Removing Version will trigger the welcome message. (setup_test
51 # inserted it so that other tests wouldn't show it.)
52 grep -v Version "$context" > "$context.NEW"
53 mv -f "$context.NEW" "$context"
54
55
56 start_test 'mhparam skips the welcome message'
57 run_without_input mhparam path
58 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
59 # Make sure that version wasn't added to context.
60 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
61 rm "$actual"
62
63
64 start_test 'Welcome: disable in profile skips the welcome message'
65 cp "${MH}" "${MH}-welcome"
66 printf 'Welcome: disable\n' >> "${MH}-welcome"
67 (MH="${MH}-welcome" run_without_input pick last)
68 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
69 # Make sure that version wasn't added to context.
70 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
71 rm "$actual"
72
73
74 start_test 'with welcome message'
75 run_without_input pick last
76 grep 'Welcome to nmh version ' "$actual" >/dev/null
77 # Make sure that version was added to context.
78 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
79 rm "$actual"
80
81
82 start_test 'without welcome message'
83 # After running the previous test, this one should not have
84 # the welcome message.
85 run_without_input pick last
86 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
87 # Make sure that version is still in context.
88 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
89 rm "$actual"
90
91
92 start_test 'with MHCONTEXT, welcome only if older'
93 MHCONTEXT="${MH_TEST_DIR}/Mail/context2"; export MHCONTEXT
94 printf 'Version: nmh-1.5\n' >"${MHCONTEXT}"
95 run_without_input pick last
96 grep 'Welcome to nmh version ' "$actual" >/dev/null
97 # And make sure that version did get updated in context.
98 grep "^${version}$" "${MHCONTEXT}" >/dev/null
99 rm "$actual"
100
101
102 start_test "with MHCONTEXT doesn't welcome if newer"
103 printf 'Version: nmh-10000.0\n' >"${MHCONTEXT}"
104 run_without_input pick last
105 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
106 # And make sure that version didn't get updated in context.
107 grep '^Version: nmh-10000.0$' "${MHCONTEXT}" >/dev/null
108 rm "$actual"
109
110
111 start_test 'with MHCONTEXT but no version, no welcome and update'
112 printf '' >"${MHCONTEXT}"
113 run_without_input pick last
114 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
115 # And make sure that version did get updated in context.
116 grep "^${version}$" "${MHCONTEXT}" >/dev/null
117 rm "$actual"
118
119
120 finish_test
121 exit $failed