| 1 | #!/bin/sh |
| 2 | ###################################################### |
| 3 | # |
| 4 | # Test etcpath() in path.c. |
| 5 | # |
| 6 | ###################################################### |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | if test -z "${MH_OBJ_DIR}"; then |
| 11 | srcdir=`dirname $0`/../.. |
| 12 | MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR |
| 13 | fi |
| 14 | |
| 15 | . "${MH_OBJ_DIR}/test/common.sh" |
| 16 | |
| 17 | setup_test |
| 18 | |
| 19 | expected="$MH_TEST_DIR/test-etcpath$$.expected" |
| 20 | expected_err="$MH_TEST_DIR/test-etcpath$$.expected_err" |
| 21 | actual="$MH_TEST_DIR/test-etcpath$$.actual" |
| 22 | actual_err="$MH_TEST_DIR/test-etcpath$$.actual_err" |
| 23 | |
| 24 | nonexistent_user() |
| 25 | { |
| 26 | user=XXXX |
| 27 | while id $user >/dev/null 2>&1; do |
| 28 | user=${user}X |
| 29 | done |
| 30 | printf %s $user |
| 31 | } |
| 32 | nonexistent_file() |
| 33 | { |
| 34 | dir="$1" |
| 35 | file="$dir/XXXX" |
| 36 | while test -e "$file"; do |
| 37 | file="${file}X" |
| 38 | done |
| 39 | printf %s "$file" |
| 40 | } |
| 41 | |
| 42 | #### These tests use mhical but not for what it does. Its -form switch |
| 43 | #### relies on etcpath(), via new_fs(). |
| 44 | #### $HOME is $MH_TEST_DIR so we know what's in it, and can add files to it. |
| 45 | |
| 46 | # absolute path |
| 47 | start_test 'absolute path' |
| 48 | cat >"$expected_err" <<EOF |
| 49 | mhical: unable to open format file $HOME/absolute: No such file or directory |
| 50 | EOF |
| 51 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 52 | $NMH_TEST_PREFIX mhical -form "$HOME/absolute" >"$actual" 2>"$actual_err" || |
| 53 | true |
| 54 | check /dev/null "$actual" 'keep first' |
| 55 | check "$expected_err" "$actual_err" |
| 56 | |
| 57 | # existent ~/file |
| 58 | start_test 'existent ~/file' |
| 59 | touch "$HOME/file" |
| 60 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 61 | $NMH_TEST_PREFIX mhical -form '~/file' >"$actual" 2>"$actual_err" || true |
| 62 | check /dev/null "$actual" 'keep first' |
| 63 | check /dev/null "$actual_err" 'keep first' |
| 64 | rm -f "$HOME/file" |
| 65 | |
| 66 | # nonexistent ~/file |
| 67 | start_test 'nonexistent ~/file' |
| 68 | #### common.sh sets HOME to MH_TEST_DIR so we control what's in $HOME. |
| 69 | file='file_that_does_not_exist' |
| 70 | cat >"$expected_err" <<EOF |
| 71 | mhical: unable to open format file ~/$file: No such file or directory |
| 72 | EOF |
| 73 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 74 | $NMH_TEST_PREFIX mhical -form "~/$file" >"$actual" 2>"$actual_err" || true |
| 75 | check /dev/null "$actual" 'keep first' |
| 76 | check "$expected_err" "$actual_err" |
| 77 | |
| 78 | # existent user (exercise successful getpwnam(3) branch in etcpath()) |
| 79 | start_test 'existent user' |
| 80 | user=`id -nu` |
| 81 | file=`nonexistent_file $user` |
| 82 | cat >"$expected_err" <<EOF |
| 83 | mhical: unable to open format file ~$file: No such file or directory |
| 84 | EOF |
| 85 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 86 | $NMH_TEST_PREFIX mhical -form "~$file" >"$actual" 2>"$actual_err" || true |
| 87 | check /dev/null "$actual" 'keep first' |
| 88 | check "$expected_err" "$actual_err" |
| 89 | |
| 90 | # nonexistent user (exercise failed getpwnam(3) branch in etcpath()) |
| 91 | start_test 'nonexistent user' |
| 92 | user=$(nonexistent_user) |
| 93 | cat >"$expected_err" <<EOF |
| 94 | mhical: unable to open format file ~$user/mhical.24hour: No such file or directory |
| 95 | EOF |
| 96 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 97 | $NMH_TEST_PREFIX mhical -form "~$user/mhical.24hour" >"$actual" 2>"$actual_err" || |
| 98 | true |
| 99 | check /dev/null "$actual" 'keep first' |
| 100 | check "$expected_err" "$actual_err" |
| 101 | |
| 102 | # nonexistent user without a file |
| 103 | # This caused a seg fault with sbr/path.c commit cd2c6750fba54cd6d938106ecd122e8976792b6e. |
| 104 | start_test 'nonexistent user without a file' |
| 105 | user=$(nonexistent_user) |
| 106 | cat >"$expected_err" <<EOF |
| 107 | mhical: unable to open format file ~$user: No such file or directory |
| 108 | EOF |
| 109 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 110 | $NMH_TEST_PREFIX mhical -form "~$user" >"$actual" 2>"$actual_err" || |
| 111 | true |
| 112 | check /dev/null "$actual" 'keep first' |
| 113 | check "$expected_err" "$actual_err" |
| 114 | |
| 115 | # file in Mail dir |
| 116 | start_test 'file in Mail dir' |
| 117 | file="${MH_TEST_DIR}/Mail/file" |
| 118 | cat >"$expected_err" <<EOF |
| 119 | mhical: unable to open format file $file: No such file or directory |
| 120 | EOF |
| 121 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 122 | $NMH_TEST_PREFIX mhical -form "$file" >"$actual" 2>"$actual_err" || true |
| 123 | check /dev/null "$actual" 'keep first' |
| 124 | check "$expected_err" "$actual_err" |
| 125 | |
| 126 | # file in nmh etcdir |
| 127 | # This only works if nmh was installed, so that `mhparam etcdir`/mhical.24hour |
| 128 | # exists. "make distcheck" installs nmh, so it will be used with that. |
| 129 | if [ -e `mhparam etcdir`/mhical.24hour ]; then |
| 130 | start_test 'file in nmh etcdir' |
| 131 | rm -f "${MH_TEST_DIR}/Mail/mhical.24hour" |
| 132 | printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' | |
| 133 | $NMH_TEST_PREFIX mhical -form mhical.24hour >"$actual" 2>"$actual_err" || true |
| 134 | check /dev/null "$actual" 'keep first' |
| 135 | check /dev/null "$actual_err" 'keep first' |
| 136 | fi |
| 137 | |
| 138 | |
| 139 | finish_test |
| 140 | exit $failed |