Debian Codegraph @

test/mhparam/test-etcpath

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 ######################################################
3 #
4 # Test etcpath() in path.c.
5 #
6 ######################################################
7
8 set -e
9
10 if testscip-shell system . . test. -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirnamescip-shell system . . dirname. $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwdscip-shell system . . 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_userscip-shell shell shell-project 0.0.0 nonexistent_user().()
25 {
26 user=XXXX
27 while idscip-shell system . . id. $user >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; do
28 user=${user}X
29 done
30 printfscip-shell system . . printf. %s $user
31 }
32 nonexistent_filescip-shell shell shell-project 0.0.0 nonexistent_file().()
33 {
34 dir="$1"
35 file="$dir/XXXX"
36 while testscip-shell system . . test. -e "$file"; do
37 file="${file}X"
38 done
39 printfscip-shell system . . 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 catscip-shell system . . cat. >"$expected_err" <<EOF
49 mhical: unable to open format file $HOME/absolute: No such file or directory
50 EOF
51 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
52 $NMH_TEST_PREFIX mhical -form "$HOME/absolute" >"$actual" 2>"$actual_err" ||
53 truescip-shell system . . true.
54 check /dev/nullscip-shell filesystem . . `/dev/null`. "$actual" 'keep first'
55 check "$expected_err" "$actual_err"
56
57 # existent ~/file
58 start_test 'existent ~/file'
59 touchscip-shell system . . touch. "$HOME/file"
60 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
61 $NMH_TEST_PREFIX mhical -form '~/file' >"$actual" 2>"$actual_err" || truescip-shell system . . true.
62 check /dev/nullscip-shell filesystem . . `/dev/null`. "$actual" 'keep first'
63 check /dev/nullscip-shell filesystem . . `/dev/null`. "$actual_err" 'keep first'
64 rmscip-shell system . . 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 catscip-shell system . . cat. >"$expected_err" <<EOF
71 mhical: unable to open format file ~/$file: No such file or directory
72 EOF
73 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
74 $NMH_TEST_PREFIX mhical -form "~/$file" >"$actual" 2>"$actual_err" || truescip-shell system . . true.
75 check /dev/nullscip-shell filesystem . . `/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=`idscip-shell system . . id. -nu`
81 file=`nonexistent_filescip-shell shell shell-project 0.0.0 nonexistent_file(). $user`
82 catscip-shell system . . cat. >"$expected_err" <<EOF
83 mhical: unable to open format file ~$file: No such file or directory
84 EOF
85 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
86 $NMH_TEST_PREFIX mhical -form "~$file" >"$actual" 2>"$actual_err" || truescip-shell system . . true.
87 check /dev/nullscip-shell filesystem . . `/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_userscip-shell shell shell-project 0.0.0 nonexistent_user().)
93 catscip-shell system . . cat. >"$expected_err" <<EOF
94 mhical: unable to open format file ~$user/mhical.24hour: No such file or directory
95 EOF
96 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
97 $NMH_TEST_PREFIX mhical -form "~$user/mhical.24hour" >"$actual" 2>"$actual_err" ||
98 truescip-shell system . . true.
99 check /dev/nullscip-shell filesystem . . `/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_userscip-shell shell shell-project 0.0.0 nonexistent_user().)
106 catscip-shell system . . cat. >"$expected_err" <<EOF
107 mhical: unable to open format file ~$user: No such file or directory
108 EOF
109 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
110 $NMH_TEST_PREFIX mhical -form "~$user" >"$actual" 2>"$actual_err" ||
111 truescip-shell system . . true.
112 check /dev/nullscip-shell filesystem . . `/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 catscip-shell system . . cat. >"$expected_err" <<EOF
119 mhical: unable to open format file $file: No such file or directory
120 EOF
121 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
122 $NMH_TEST_PREFIX mhical -form "$file" >"$actual" 2>"$actual_err" || truescip-shell system . . true.
123 check /dev/nullscip-shell filesystem . . `/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 [scip-shell system . . `[`. -e `mhparam etcdir`/mhical.24hour ]; then
130 start_test 'file in nmh etcdir'
131 rmscip-shell system . . rm. -f "${MH_TEST_DIR}/Mail/mhical.24hour"
132 printfscip-shell system . . printf. 'BEGIN:VCALENDAR\nEND:VCALENDAR\n' |
133 $NMH_TEST_PREFIX mhical -form mhical.24hour >"$actual" 2>"$actual_err" || truescip-shell system . . true.
134 check /dev/nullscip-shell filesystem . . `/dev/null`. "$actual" 'keep first'
135 check /dev/nullscip-shell filesystem . . `/dev/null`. "$actual_err" 'keep first'
136 fi
137
138
139 finish_test
140 exit $failed