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