File: test-etcpath

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (140 lines) | stat: -rwxr-xr-x 4,419 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh
######################################################
#
# Test etcpath() in path.c.
#
######################################################

set -e

if test -z "${MH_OBJ_DIR}"; then
    srcdir=`dirname $0`/../..
    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi

. "${MH_OBJ_DIR}/test/common.sh"

setup_test

expected="$MH_TEST_DIR/test-etcpath$$.expected"
expected_err="$MH_TEST_DIR/test-etcpath$$.expected_err"
actual="$MH_TEST_DIR/test-etcpath$$.actual"
actual_err="$MH_TEST_DIR/test-etcpath$$.actual_err"

nonexistent_user()
{
    user=XXXX
    while id $user >/dev/null 2>&1; do
        user=${user}X
    done
    printf %s $user
}
nonexistent_file()
{
    dir="$1"
    file="$dir/XXXX"
    while test -e "$file"; do
        file="${file}X"
    done
    printf %s "$file"
}

#### These tests use mhical but not for what it does.  Its -form switch
#### relies on etcpath(), via new_fs().
#### $HOME is $MH_TEST_DIR so we know what's in it, and can add files to it.

# absolute path
start_test 'absolute path'
cat >"$expected_err" <<EOF
mhical: unable to open format file $HOME/absolute: No such file or directory
EOF
printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
    $NMH_TEST_PREFIX mhical -form "$HOME/absolute" >"$actual" 2>"$actual_err" ||
    true
check /dev/null "$actual" 'keep first'
check "$expected_err" "$actual_err"

# existent ~/file
start_test 'existent ~/file'
touch "$HOME/file"
printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
    $NMH_TEST_PREFIX mhical -form '~/file' >"$actual" 2>"$actual_err" || true
check /dev/null "$actual" 'keep first'
check /dev/null "$actual_err" 'keep first'
rm -f "$HOME/file"

# nonexistent ~/file
start_test 'nonexistent ~/file'
#### common.sh sets HOME to MH_TEST_DIR so we control what's in $HOME.
file='file_that_does_not_exist'
cat >"$expected_err" <<EOF
mhical: unable to open format file ~/$file: No such file or directory
EOF
printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
    $NMH_TEST_PREFIX mhical -form "~/$file" >"$actual" 2>"$actual_err" || true
check /dev/null "$actual" 'keep first'
check "$expected_err" "$actual_err"

# existent user (exercise successful getpwnam(3) branch in etcpath())
start_test 'existent user'
user=`id -nu`
file=`nonexistent_file $user`
cat >"$expected_err" <<EOF
mhical: unable to open format file ~$file: No such file or directory
EOF
printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
    $NMH_TEST_PREFIX mhical -form "~$file" >"$actual" 2>"$actual_err" || true
check /dev/null "$actual" 'keep first'
check "$expected_err" "$actual_err"

# nonexistent user (exercise failed getpwnam(3) branch in etcpath())
start_test 'nonexistent user'
user=$(nonexistent_user)
cat >"$expected_err" <<EOF
mhical: unable to open format file ~$user/mhical.24hour: No such file or directory
EOF
printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
    $NMH_TEST_PREFIX mhical -form "~$user/mhical.24hour" >"$actual" 2>"$actual_err" ||
    true
check /dev/null "$actual" 'keep first'
check "$expected_err" "$actual_err"

# nonexistent user without a file
# This caused a seg fault with sbr/path.c commit cd2c6750fba54cd6d938106ecd122e8976792b6e.
start_test 'nonexistent user without a file'
user=$(nonexistent_user)
cat >"$expected_err" <<EOF
mhical: unable to open format file ~$user: No such file or directory
EOF
printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
    $NMH_TEST_PREFIX mhical -form "~$user" >"$actual" 2>"$actual_err" ||
    true
check /dev/null "$actual" 'keep first'
check "$expected_err" "$actual_err"

# file in Mail dir
start_test 'file in Mail dir'
file="${MH_TEST_DIR}/Mail/file"
cat >"$expected_err" <<EOF
mhical: unable to open format file $file: No such file or directory
EOF
printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
    $NMH_TEST_PREFIX mhical -form "$file" >"$actual" 2>"$actual_err" || true
check /dev/null "$actual" 'keep first'
check "$expected_err" "$actual_err"

# file in nmh etcdir
# This only works if nmh was installed, so that `mhparam etcdir`/mhical.24hour
# exists.  "make distcheck" installs nmh, so it will be used with that.
if [ -e `mhparam etcdir`/mhical.24hour ]; then
    start_test 'file in nmh etcdir'
    rm -f "${MH_TEST_DIR}/Mail/mhical.24hour"
    printf 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
        $NMH_TEST_PREFIX mhical -form mhical.24hour >"$actual" 2>"$actual_err" || true
    check /dev/null "$actual" 'keep first'
    check /dev/null "$actual_err" 'keep first'
fi


finish_test
exit $failed