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