]> diplodocus.org Git - nmh/blob - test/install-mh/test-version-check
Tweaked formatting of welcome message.
[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 #### Use minimal arguments to script(1), i.e., just the file in
26 #### which to save the output. We do pipe input to script, which is
27 #### discouraged by the NOTES and BUGS sections of its man page.
28 #### But that seems to work.
29
30 actual="$MH_TEST_DIR/test-version-check$$.actual"
31 context="${MH_TEST_DIR}"/Mail/context
32 version="Version: nmh-${MH_VERSION}"
33
34 # Removing Version will trigger the welcome message. (setup_test
35 # inserted it so that other tests wouldn't show it.)
36 grep -v Version "$context" > "$context.NEW"
37 mv -f "$context.NEW" "$context"
38
39
40 start_test 'mhparam skips the welcome message'
41 printf 'mhparam path\nexit\n' | script "$actual" >/dev/null
42 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
43 # Make sure that version wasn't added to context.
44 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
45 rm "$actual"
46
47
48 start_test 'Welcome: disable in profile skips the welcome message'
49 cp "${MH}" "${MH}-welcome"
50 printf 'Welcome: disable\n' >> "${MH}-welcome"
51 (printf 'pick last\nexit\n' | MH="${MH}-welcome" script "$actual" >/dev/null)
52 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
53 # Make sure that version wasn't added to context.
54 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null && false
55 rm "$actual"
56
57
58 start_test 'with welcome message'
59 printf 'pick last\nexit\n' | script "$actual" >/dev/null
60 grep 'Welcome to nmh version ' "$actual" >/dev/null
61 # Make sure that version was added to context.
62 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
63 rm "$actual"
64
65
66 start_test 'without welcome message'
67 # After running the previous test, this one should not have
68 # the welcome message.
69 printf 'pick last\nexit\n' | script "$actual" >/dev/null
70 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
71 # Make sure that version is still in context.
72 grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
73 rm "$actual"
74
75
76 start_test 'with MHCONTEXT, welcome only if older'
77 MHCONTEXT="${MH_TEST_DIR}/Mail/context2"; export MHCONTEXT
78 printf 'Version: nmh-1.5\n' >"${MHCONTEXT}"
79 printf 'pick last\nexit\n' | script "$actual" >/dev/null
80 grep 'Welcome to nmh version ' "$actual" >/dev/null
81 # And make sure that version did get updated in context.
82 grep "^${version}$" "${MHCONTEXT}" >/dev/null
83 rm "$actual"
84
85
86 start_test "with MHCONTEXT doesn't welcome if newer"
87 printf 'Version: nmh-10000.0\n' >"${MHCONTEXT}"
88 printf 'pick last\nexit\n' | script "$actual" >/dev/null
89 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
90 # And make sure that version didn't get updated in context.
91 grep '^Version: nmh-10000.0$' "${MHCONTEXT}" >/dev/null
92 rm "$actual"
93
94
95 start_test 'with MHCONTEXT but no version, no welcome and update'
96 printf '' >"${MHCONTEXT}"
97 printf 'pick last\nexit\n' | script "$actual" >/dev/null
98 grep 'Welcome to nmh version ' "$actual" >/dev/null && false
99 # And make sure that version did get updated in context.
100 grep "^${version}$" "${MHCONTEXT}" >/dev/null
101 rm "$actual"
102
103
104 finish_test
105 exit $failed