summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2017-06-07 09:05:19 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-06-07 10:06:17 (GMT)
commit453cd17f7a4be5ceaa8411a8a3ebd9fddd88df8e (patch) (unidiff)
tree3c919d804a8df24c01bc26854bcec4e0c5db21b6
parent491bec23a77b19df8b9c0442696ce57e3fc5c604 (diff)
downloadmailutils-453cd17f7a4be5ceaa8411a8a3ebd9fddd88df8e.tar.gz
mailutils-453cd17f7a4be5ceaa8411a8a3ebd9fddd88df8e.tar.bz2
Fix tests when logical and physical CWD differ
MH testsuite produced false negatives when run in a directory accessed by its logical name (symlink). To fix this, avoiding at the same time the use of non-portable "pwd -P" & "pwd -L", this commit adds a filter utility that replaces both logical and physical cwd with a dot on output. The MH testsuite is updated to use this utility. * testsuite/cwdrepl.c: New utility * testsuite/Makefile.am: Build cwdrepl * testsuite/.gitignore: Update. * testsuite/cwdrepl.at: New test. * testsuite/testsuite.at: Include new test. * mh/tests/atlocal.in (PATH): Add testsuite (remove_curdir): Remove function. * mh/tests/comp.at: Use cwdrepl, fix expected output. * mh/tests/forw.at: Likewise. * mh/tests/mhn.at: Likewise. * mh/tests/mhpath.at: Likewise. * mh/tests/repl.at: Likewise.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--mh/tests/atlocal.in6
-rw-r--r--mh/tests/comp.at34
-rw-r--r--mh/tests/forw.at38
-rw-r--r--mh/tests/mhn.at38
-rw-r--r--mh/tests/mhpath.at30
-rw-r--r--mh/tests/repl.at12
-rw-r--r--testsuite/.gitignore1
-rw-r--r--testsuite/Makefile.am4
-rw-r--r--testsuite/cwdrepl.at59
-rw-r--r--testsuite/cwdrepl.c176
-rw-r--r--testsuite/testsuite.at1
11 files changed, 319 insertions, 80 deletions
diff --git a/mh/tests/atlocal.in b/mh/tests/atlocal.in
index 508e03f..6a7f405 100644
--- a/mh/tests/atlocal.in
+++ b/mh/tests/atlocal.in
@@ -3,10 +3,8 @@
3# Copyright (C) 2004, 2010-2012, 2014-2017 Free Software Foundation, 3# Copyright (C) 2004, 2010-2012, 2014-2017 Free Software Foundation,
4# Inc. 4# Inc.
5 5
6PATH=@abs_builddir@:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH 6PATH=@abs_builddir@:@abs_top_builddir@/testsuite:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
7remove_curdir() { 7
8 sed "s|$HOME/*||;s| *$||" $*
9 }
10# mimeflt [FILE] 8# mimeflt [FILE]
11# Filter out all variable information from a MIME message in FILE. 9# Filter out all variable information from a MIME message in FILE.
12# If FILE is not given, filter stdin. 10# If FILE is not given, filter stdin.
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index a8d4a41..563310c 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[comp])
19m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed]) 19m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
20 20
21MH_CHECK([comp -file],[comp00 comp-file],[ 21MH_CHECK([comp -file],[comp00 comp-file],[
22echo quit | compcmd -file ./infile | remove_curdir | sed 's/ *$//' 22echo quit | compcmd -file $HOME/infile | cwdrepl | sed 's/ *$//'
23sed 's/ *$//' infile 23sed 's/ *$//' infile
24], 24],
25[0], 25[0],
@@ -39,7 +39,7 @@ Seen by mhed
39]) 39])
40 40
41MH_CHECK([comp -file (del)],[comp01 comp-file_del],[ 41MH_CHECK([comp -file (del)],[comp01 comp-file_del],[
42echo 'quit -delete' | compcmd -file ./infile | remove_curdir 42echo 'quit -delete' | compcmd -file $HOME/infile | cwdrepl | sed 's/ *$//'
43], 43],
44[0], 44[0],
45[-- Editor invocation: ./infile 45[-- Editor invocation: ./infile
@@ -53,18 +53,18 @@ What now?
53]) 53])
54 54
55MH_CHECK([comp file],[comp02 comp_file],[ 55MH_CHECK([comp file],[comp02 comp_file],[
56echo 'quit' | compcmd file | remove_curdir | sed 's/ *$//' 56echo 'quit' | compcmd file | cwdrepl | sed 's/ *$//'
57sed 's/ *$//' Mail/file 57sed 's/ *$//' Mail/file
58], 58],
59[0], 59[0],
60[-- Editor invocation: Mail/file 60[-- Editor invocation: ./Mail/file
61-- Input file: 61-- Input file:
62To: 62To:
63cc: 63cc:
64Subject: 64Subject:
65-------- 65--------
66-- Input file end 66-- Input file end
67What now? draft left on "Mail/file". 67What now? draft left on "./Mail/file".
68To: 68To:
69cc: 69cc:
70Subject: 70Subject:
@@ -80,11 +80,11 @@ Subject: test input
80message body 80message body
81]) 81])
82 82
83echo 'quit' | compcmd -use file | remove_curdir | sed 's/ *$//' 83echo 'quit' | compcmd -use file | cwdrepl | sed 's/ *$//'
84sed 's/ *$//' Mail/file 84sed 's/ *$//' Mail/file
85], 85],
86[0], 86[0],
87[-- Editor invocation: Mail/file 87[-- Editor invocation: ./Mail/file
88-- Input file: 88-- Input file:
89From: gray 89From: gray
90To: root 90To: root
@@ -92,7 +92,7 @@ Subject: test input
92 92
93message body 93message body
94-- Input file end 94-- Input file end
95What now? draft left on "Mail/file". 95What now? draft left on "./Mail/file".
96From: gray 96From: gray
97To: root 97To: root
98Subject: test input 98Subject: test input
@@ -110,14 +110,14 @@ Subject: test input
110message body 110message body
111]) 111])
112 112
113echo 'quit' | compcmd +inbox 1 | remove_curdir | sed 's/ *$//' 113echo 'quit' | compcmd +inbox 1 | cwdrepl | sed 's/ *$//'
114echo Mail/draft 114echo Mail/draft
115sed 's/ *$//' Mail/draft 115sed 's/ *$//' Mail/draft
116echo Message 116echo Message
117sed 's/ *$//' Mail/inbox/1 117sed 's/ *$//' Mail/inbox/1
118], 118],
119[0], 119[0],
120[-- Editor invocation: Mail/draft 120[-- Editor invocation: ./Mail/draft
121-- Input file: 121-- Input file:
122From: gray 122From: gray
123To: root 123To: root
@@ -125,7 +125,7 @@ Subject: test input
125 125
126message body 126message body
127-- Input file end 127-- Input file end
128What now? draft left on "Mail/draft". 128What now? draft left on "./Mail/draft".
129Mail/draft 129Mail/draft
130From: gray 130From: gray
131To: root 131To: root
@@ -143,18 +143,18 @@ message body
143 143
144MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[ 144MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[
145mkdir Mail/drafts 145mkdir Mail/drafts
146echo 'quit' | compcmd -draftfolder drafts | remove_curdir | sed 's/ *$//' 146echo 'quit' | compcmd -draftfolder drafts | cwdrepl | sed 's/ *$//'
147sed 's/ *$//' Mail/drafts/1 147sed 's/ *$//' Mail/drafts/1
148], 148],
149[0], 149[0],
150[-- Editor invocation: Mail/drafts/1 150[-- Editor invocation: ./Mail/drafts/1
151-- Input file: 151-- Input file:
152To: 152To:
153cc: 153cc:
154Subject: 154Subject:
155-------- 155--------
156-- Input file end 156-- Input file end
157What now? draft left on "Mail/drafts/1". 157What now? draft left on "./Mail/drafts/1".
158To: 158To:
159cc: 159cc:
160Subject: 160Subject:
@@ -172,11 +172,11 @@ message body
172]) 172])
173echo "cur: 1" > Mail/drafts/.mh_sequences 173echo "cur: 1" > Mail/drafts/.mh_sequences
174 174
175echo 'quit' | compcmd -draftfolder drafts -use| remove_curdir | sed 's/ *$//' 175echo 'quit' | compcmd -draftfolder drafts -use| cwdrepl | sed 's/ *$//'
176sed 's/ *$//' Mail/drafts/1 176sed 's/ *$//' Mail/drafts/1
177], 177],
178[0], 178[0],
179[-- Editor invocation: Mail/drafts/1 179[-- Editor invocation: ./Mail/drafts/1
180-- Input file: 180-- Input file:
181From: gray 181From: gray
182To: root 182To: root
@@ -184,7 +184,7 @@ Subject: test input
184 184
185message body 185message body
186-- Input file end 186-- Input file end
187What now? draft left on "Mail/drafts/1". 187What now? draft left on "./Mail/drafts/1".
188From: gray 188From: gray
189To: root 189To: root
190Subject: test input 190Subject: test input
diff --git a/mh/tests/forw.at b/mh/tests/forw.at
index 4392fa2..e0566df 100644
--- a/mh/tests/forw.at
+++ b/mh/tests/forw.at
@@ -27,7 +27,7 @@ Subject: test input
27message body 27message body
28]) 28])
29 29
30echo quit | forwcmd +inbox 1 | remove_curdir 30echo quit | forwcmd +inbox 1 | cwdrepl
31echo == Mail/draft == 31echo == Mail/draft ==
32cat Mail/draft 32cat Mail/draft
33echo == Message == 33echo == Message ==
@@ -36,7 +36,7 @@ echo == Message ==
36sed '/^X-IMAPbase/d' Mail/inbox/1 36sed '/^X-IMAPbase/d' Mail/inbox/1
37], 37],
38[0], 38[0],
39[-- Editor invocation: Mail/draft 39[-- Editor invocation: ./Mail/draft
40-- Input file: 40-- Input file:
41To: 41To:
42cc: 42cc:
@@ -53,7 +53,7 @@ message body
53------- End of Forwarded message 53------- End of Forwarded message
54 54
55-- Input file end 55-- Input file end
56What now? draft left on "Mail/draft". 56What now? draft left on "./Mail/draft".
57== Mail/draft == 57== Mail/draft ==
58To: 58To:
59cc: 59cc:
@@ -87,7 +87,7 @@ Subject: test input
87message body 87message body
88]) 88])
89 89
90echo quit | forwcmd -format +inbox 1 | remove_curdir 90echo quit | forwcmd -format +inbox 1 | cwdrepl
91echo == Mail/draft == 91echo == Mail/draft ==
92cat Mail/draft 92cat Mail/draft
93echo == Message == 93echo == Message ==
@@ -96,7 +96,7 @@ echo == Message ==
96sed '/^X-IMAPbase/d' Mail/inbox/1 96sed '/^X-IMAPbase/d' Mail/inbox/1
97], 97],
98[0], 98[0],
99[-- Editor invocation: Mail/draft 99[-- Editor invocation: ./Mail/draft
100-- Input file: 100-- Input file:
101To: 101To:
102cc: 102cc:
@@ -113,7 +113,7 @@ message body
113------- End of Forwarded message 113------- End of Forwarded message
114 114
115-- Input file end 115-- Input file end
116What now? draft left on "Mail/draft". 116What now? draft left on "./Mail/draft".
117== Mail/draft == 117== Mail/draft ==
118To: 118To:
119cc: 119cc:
@@ -153,7 +153,7 @@ Subject: 2nd message
1532nd message body 1532nd message body
154]) 154])
155 155
156echo quit | forwcmd +inbox 1 2 | remove_curdir 156echo quit | forwcmd +inbox 1 2 | cwdrepl
157echo == Mail/draft == 157echo == Mail/draft ==
158cat Mail/draft 158cat Mail/draft
159echo == Message 1 == 159echo == Message 1 ==
@@ -162,7 +162,7 @@ echo == Message 2 ==
162cat Mail/inbox/2 162cat Mail/inbox/2
163], 163],
164[0], 164[0],
165[-- Editor invocation: Mail/draft 165[-- Editor invocation: ./Mail/draft
166-- Input file: 166-- Input file:
167To: 167To:
168cc: 168cc:
@@ -188,7 +188,7 @@ Subject: 2nd message
188------- End of Forwarded messages 188------- End of Forwarded messages
189 189
190-- Input file end 190-- Input file end
191What now? draft left on "Mail/draft". 191What now? draft left on "./Mail/draft".
192== Mail/draft == 192== Mail/draft ==
193To: 193To:
194cc: 194cc:
@@ -237,7 +237,7 @@ Subject: test input
237message body 237message body
238]) 238])
239 239
240forwcmd -build +inbox 1 | remove_curdir 240forwcmd -build +inbox 1 | cwdrepl
241echo == Mail/draft == 241echo == Mail/draft ==
242cat Mail/draft 242cat Mail/draft
243echo == Message == 243echo == Message ==
@@ -282,9 +282,9 @@ Subject: 2nd message
2822nd message body 2822nd message body
283]) 283])
284 284
285forwcmd -build -mime +inbox 1 2 | remove_curdir 285forwcmd -build -mime +inbox 1 2 | cwdrepl
286echo == Mail/draft == 286echo == Mail/draft ==
287remove_curdir Mail/draft 287cwdrepl < Mail/draft
288echo == Message 1 == 288echo == Message 1 ==
289sed '/^X-IMAPbase/d' Mail/inbox/1 289sed '/^X-IMAPbase/d' Mail/inbox/1
290echo == Message 2 == 290echo == Message 2 ==
@@ -296,7 +296,7 @@ To:
296cc: 296cc:
297Subject: 297Subject:
298-------- 298--------
299#forw [] +Mail/inbox 1 2 299#forw [] +./Mail/inbox 1 2
300 300
301== Message 1 == 301== Message 1 ==
302From: gray 302From: gray
@@ -322,14 +322,14 @@ Subject: test input
322message body 322message body
323]) 323])
324 324
325echo "quit" | forwcmd -draftfolder drafts 1 | remove_curdir 325echo "quit" | forwcmd -draftfolder drafts 1 | cwdrepl
326echo == Mail/drafts/1 == 326echo == Mail/drafts/1 ==
327cat Mail/drafts/1 327cat Mail/drafts/1
328echo == Message == 328echo == Message ==
329sed '/^X-IMAPbase/d' Mail/inbox/1 329sed '/^X-IMAPbase/d' Mail/inbox/1
330], 330],
331[0], 331[0],
332[-- Editor invocation: Mail/drafts/1 332[-- Editor invocation: ./Mail/drafts/1
333-- Input file: 333-- Input file:
334To: 334To:
335cc: 335cc:
@@ -346,7 +346,7 @@ message body
346------- End of Forwarded message 346------- End of Forwarded message
347 347
348-- Input file end 348-- Input file end
349What now? draft left on "Mail/drafts/1". 349What now? draft left on "./Mail/drafts/1".
350== Mail/drafts/1 == 350== Mail/drafts/1 ==
351To: 351To:
352cc: 352cc:
@@ -379,10 +379,10 @@ Subject: test input
379message body 379message body
380]) 380])
381 381
382echo "quit" | forwcmd -file infile | remove_curdir 382echo "quit" | forwcmd -file infile | cwdrepl
383], 383],
384[0], 384[0],
385[-- Editor invocation: Mail/draft 385[-- Editor invocation: ./Mail/draft
386-- Input file: 386-- Input file:
387To: 387To:
388cc: 388cc:
@@ -394,7 +394,7 @@ Subject: test input
394 394
395message body 395message body
396-- Input file end 396-- Input file end
397What now? draft left on "Mail/draft". 397What now? draft left on "./Mail/draft".
398]) 398])
399 399
400m4_popdef([forwcmd]) 400m4_popdef([forwcmd])
diff --git a/mh/tests/mhn.at b/mh/tests/mhn.at
index 51d579a..30755ec 100644
--- a/mh/tests/mhn.at
+++ b/mh/tests/mhn.at
@@ -130,21 +130,21 @@ Be off, or I'll kick you down stairs!'
130 130
131MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[ 131MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[
132MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 132MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
133mhn +inbox -store -auto 4 | remove_curdir || exit $? 133mhn +inbox -store -auto 4 | cwdrepl || exit $?
134], 134],
135[0], 135[0],
136[storing message 4 part 1 as file msg.21 136[storing message 4 part 1 as file ./msg.21
137storing message 4 part 2.1 as file msg.22 137storing message 4 part 2.1 as file ./msg.22
138storing message 4 part 2.2.1 as file msg.23 138storing message 4 part 2.2.1 as file ./msg.23
139storing message 4 part 2.2.2 as file msg.24 139storing message 4 part 2.2.2 as file ./msg.24
140]) 140])
141 141
142MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[ 142MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[
143MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700]) 143MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
144mhn +inbox -store -auto -part 2.2.1 4 | remove_curdir || exit $? 144mhn +inbox -store -auto -part 2.2.1 4 | cwdrepl || exit $?
145], 145],
146[0], 146[0],
147[storing message 4 part 2.2.1 as file msg.23 147[storing message 4 part 2.2.1 as file ./msg.23
148]) 148])
149 149
150MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[ 150MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[
@@ -178,13 +178,13 @@ MUT_MBCHMOD(Mail/inbox, 700)
178mkdir out 178mkdir out
179echo "mhn-storage: $HOME/out" >> $MH 179echo "mhn-storage: $HOME/out" >> $MH
180 180
181mhn +inbox -store 4 | remove_curdir || echo $? 181mhn +inbox -store 4 | cwdrepl || echo $?
182], 182],
183[0], 183[0],
184[storing message 4 part 1 as file out/4.1.plain 184[storing message 4 part 1 as file ./out/4.1.plain
185storing message 4 part 2.1 as file out/4.2.1.octet-stream 185storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
186storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream 186storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
187storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream 187storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
188]) 188])
189 189
190MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[ 190MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[
@@ -193,7 +193,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
193MUT_MBCHMOD(Mail/inbox, 700) 193MUT_MBCHMOD(Mail/inbox, 700)
194 194
195echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH 195echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH
196mhn +inbox -store 4 | remove_curdir || exit $? 196mhn +inbox -store 4 || exit $?
197find . -name '%*' | sort 197find . -name '%*' | sort
198], 198],
199[0], 199[0],
@@ -213,13 +213,13 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
213MUT_MBCHMOD(Mail/inbox, 700) 213MUT_MBCHMOD(Mail/inbox, 700)
214 214
215echo "mhn-store-application: $HOME/out/%m%P.%s" >> $MH 215echo "mhn-store-application: $HOME/out/%m%P.%s" >> $MH
216mhn +inbox -store 4 | remove_curdir || exit $? 216mhn +inbox -store 4 | cwdrepl || exit $?
217], 217],
218[0], 218[0],
219[storing message 4 part 1 as file 4.1.plain 219[storing message 4 part 1 as file 4.1.plain
220storing message 4 part 2.1 as file out/4.2.1.octet-stream 220storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
221storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream 221storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
222storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream 222storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
223]) 223])
224 224
225MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[ 225MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[
@@ -229,7 +229,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
229MUT_MBCHMOD(Mail, 700) 229MUT_MBCHMOD(Mail, 700)
230 230
231echo "mhn-store-application: +app" >> $MH 231echo "mhn-store-application: +app" >> $MH
232mhn +inbox -store 4 | remove_curdir || exit $? 232mhn +inbox -store 4 | cwdrepl || exit $?
233], 233],
234[0], 234[0],
235[storing message 4 part 1 as file 4.1.plain 235[storing message 4 part 1 as file 4.1.plain
@@ -247,7 +247,7 @@ echo "Current-Folder: inbox" > Mail/context
247cat >> $MH <<EOT 247cat >> $MH <<EOT
248mhn-store-application/octet-stream: + 248mhn-store-application/octet-stream: +
249EOT 249EOT
250mhn +inbox -store -part 2.2.1 4 | remove_curdir || exit $? 250mhn +inbox -store -part 2.2.1 4 | cwdrepl || exit $?
251], 251],
252[0], 252[0],
253[storing message 4 part 2.2.1 to folder inbox as message 5 253[storing message 4 part 2.2.1 to folder inbox as message 5
diff --git a/mh/tests/mhpath.at b/mh/tests/mhpath.at
index a048687..d07a7c7 100644
--- a/mh/tests/mhpath.at
+++ b/mh/tests/mhpath.at
@@ -20,43 +20,43 @@ m4_pushdef([MH_KEYWORDS],[mhpath])
20MH_CHECK([mhpath],[mhpath00],[ 20MH_CHECK([mhpath],[mhpath00],[
21MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 21MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
22echo 'Current-Folder: inbox' > Mail/context 22echo 'Current-Folder: inbox' > Mail/context
23mhpath | remove_curdir 23mhpath | cwdrepl
24], 24],
25[0], 25[0],
26[Mail/inbox 26[./Mail/inbox
27]) 27])
28 28
29MH_CHECK([mhpath +],[mhpath01 mhpath+],[ 29MH_CHECK([mhpath +],[mhpath01 mhpath+],[
30MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 30MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
31echo 'Current-Folder: inbox' > Mail/context 31echo 'Current-Folder: inbox' > Mail/context
32mhpath +| remove_curdir 32mhpath +| cwdrepl
33], 33],
34[0], 34[0],
35[Mail 35[./Mail
36]) 36])
37 37
38MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[ 38MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[
39MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 39MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
40mhpath 1-3 | remove_curdir 40mhpath 1-3 | cwdrepl
41], 41],
42[0], 42[0],
43[Mail/inbox/1 43[./Mail/inbox/1
44Mail/inbox/2 44./Mail/inbox/2
45Mail/inbox/3 45./Mail/inbox/3
46]) 46])
47 47
48MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[ 48MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[
49MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 49MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
50mhpath 4-10 | remove_curdir 50mhpath 4-10 | cwdrepl
51], 51],
52[0], 52[0],
53[Mail/inbox/4 53[./Mail/inbox/4
54Mail/inbox/5 54./Mail/inbox/5
55]) 55])
56 56
57MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[ 57MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[
58MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 58MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
59mhpath 8-10 | remove_curdir 59mhpath 8-10 | cwdrepl
60], 60],
61[0], 61[0],
62[], 62[],
@@ -87,7 +87,7 @@ mhpath 8-10 | remove_curdir
87 87
88MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[ 88MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[
89MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 89MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
90mhpath 10 | remove_curdir 90mhpath 10 | cwdrepl
91], 91],
92[0], 92[0],
93[], 93[],
@@ -96,10 +96,10 @@ mhpath 10 | remove_curdir
96 96
97MH_CHECK([mhpath new],[mhpath06 mhparam_new],[ 97MH_CHECK([mhpath new],[mhpath06 mhparam_new],[
98MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 98MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
99mhpath new | remove_curdir 99mhpath new | cwdrepl
100], 100],
101[0], 101[0],
102[Mail/inbox/6 102[./Mail/inbox/6
103]) 103])
104 104
105m4_popdef[MH_KEYWORDS]) 105m4_popdef[MH_KEYWORDS])
diff --git a/mh/tests/repl.at b/mh/tests/repl.at
index 3520c63..bd58e9f 100644
--- a/mh/tests/repl.at
+++ b/mh/tests/repl.at
@@ -28,19 +28,19 @@ Subject: test input
28 28
29message body 29message body
30]) 30])
31echo "quit" | replcmd +inbox 1 | remove_curdir 31echo "quit" | replcmd +inbox 1 | cwdrepl
32echo == Mail/draft == 32echo == Mail/draft ==
33cat Mail/draft 33cat Mail/draft
34], 34],
35[0], 35[0],
36[-- Editor invocation: Mail/draft 36[-- Editor invocation: ./Mail/draft
37-- Input file: 37-- Input file:
38To: <gray@example.com> 38To: <gray@example.com>
39Subject: Re: test input 39Subject: Re: test input
40X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) 40X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
41-------- 41--------
42-- Input file end 42-- Input file end
43What now? draft left on "Mail/draft". 43What now? draft left on "./Mail/draft".
44== Mail/draft == 44== Mail/draft ==
45To: <gray@example.com> 45To: <gray@example.com>
46Subject: Re: test input 46Subject: Re: test input
@@ -58,19 +58,19 @@ Subject: test input
58 58
59message body 59message body
60]) 60])
61echo "quit" | replcmd -draftfolder drafts +inbox 1 | remove_curdir 61echo "quit" | replcmd -draftfolder drafts +inbox 1 | cwdrepl
62echo == Mail/drafts/1 == 62echo == Mail/drafts/1 ==
63cat Mail/drafts/1 63cat Mail/drafts/1
64], 64],
65[0], 65[0],
66[-- Editor invocation: Mail/drafts/1 66[-- Editor invocation: ./Mail/drafts/1
67-- Input file: 67-- Input file:
68To: <gray@example.com> 68To: <gray@example.com>
69Subject: Re: test input 69Subject: Re: test input
70X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) 70X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
71-------- 71--------
72-- Input file end 72-- Input file end
73What now? draft left on "Mail/drafts/1". 73What now? draft left on "./Mail/drafts/1".
74== Mail/drafts/1 == 74== Mail/drafts/1 ==
75To: <gray@example.com> 75To: <gray@example.com>
76Subject: Re: test input 76Subject: Re: test input
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index 60475e8..d58c1e2 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -1,6 +1,7 @@
1atconfig 1atconfig
2atlocal 2atlocal
3bs 3bs
4cwdrepl
4fldel 5fldel
5lstuid 6lstuid
6package.m4 7package.m4
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 403cde2..e0eeba0 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -51,6 +51,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
51AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ 51AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@
52noinst_PROGRAMS = \ 52noinst_PROGRAMS = \
53 bs\ 53 bs\
54 cwdrepl\
54 fldel\ 55 fldel\
55 lstuid\ 56 lstuid\
56 mbdel\ 57 mbdel\
@@ -76,11 +77,14 @@ smtpsend_LDADD = \
76 @MU_AUTHLIBS@\ 77 @MU_AUTHLIBS@\
77 ${MU_LIB_MAILUTILS} 78 ${MU_LIB_MAILUTILS}
78 79
80cwdrepl_LDADD = ${MU_LIB_MAILUTILS}
81
79## ------------ ## 82## ------------ ##
80## Test suite. ## 83## Test suite. ##
81## ------------ ## 84## ------------ ##
82 85
83TESTSUITE_AT = \ 86TESTSUITE_AT = \
87 cwdrepl.at\
84 fldel.at\ 88 fldel.at\
85 lstuid00.at\ 89 lstuid00.at\
86 lstuid01.at\ 90 lstuid01.at\
diff --git a/testsuite/cwdrepl.at b/testsuite/cwdrepl.at
new file mode 100644
index 0000000..9cd15a9
--- a/dev/null
+++ b/testsuite/cwdrepl.at
@@ -0,0 +1,59 @@
1# This file is part of GNU Mailutils. -*- Autotest -*-
2# Copyright (C) 2017 Free Software Foundation, Inc.
3#
4# GNU Mailutils is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License as
6# published by the Free Software Foundation; either version 3, or (at
7# your option) any later version.
8#
9# GNU Mailutils is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12# General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([cwdrepl tool])
18AT_KEYWORDS([cwdrepl])
19
20AT_CHECK([
21pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
22cwd=`pwd -P`
23cwdrepl <<EOT
24$cwd
25CWD is "$cwd"
26$cwd/foo "$cwd" end
27EOT
28],
29[0],
30[.
31CWD is "."
32./foo "." end
33])
34
35AT_CHECK([
36pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
37pwd -L >/dev/null 2>&1 || AT_SKIP_TEST
38mkdir physical logical
39ln -s physical logical || AT_SKIP_TEST
40cd logical
41phy=`pwd -P`
42log=`pwd -L`
43cwdrepl <<EOT
44$phy $log
45LOG is "$log", PHY is "$phy"
46$log/foo "$log" end
47$phy/foo "$phy" end
48EOT
49],
50[0],
51[. .
52LOG is ".", PHY is "."
53./foo "." end
54./foo "." end
55])
56
57AT_CLEANUP
58
59
diff --git a/testsuite/cwdrepl.c b/testsuite/cwdrepl.c
new file mode 100644
index 0000000..9f6525f
--- a/dev/null
+++ b/testsuite/cwdrepl.c
@@ -0,0 +1,176 @@
1/* This file is part of GNU Mailutils testsuite.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16
17/*
18
19NAME
20
21 cwdrepl - replace occurrences of CWD with .
22
23SYNOPSIS
24
25 COMMAND | cwdrepl [DIR REPL]...
26
27DESCRIPTION
28
29 Some testcases operate programs that produce full file names as part
30 of their output. To make this output independent of the actual file
31 location, this tool replaces every occurrence of the current working
32 directory with dot. Both logical (as given by the PWD environment
33 variable) and physical (as returned by getcwd(3)) locations are replaced.
34
35 The same effect could have been achieved by using "pwd -P", "pwd -L"
36 and sed, but this would pose portability problems.
37
38 Additionally, any number of DIR REPL pairs can be supplied in the command
39 line. Each pair instructs the tool to replace every occurrence of DIR
40 with REPL on output. Note that these pairs take precedence over the
41 default ones, so running "cwdrepl $PWD 'PWD'" will replace occurrences
42 of the logical current working directory name with the string PWS, instead
43 of the default dot.
44
45*/
46
47#ifdef HAVE_CONFIG_H
48# include <config.h>
49#endif
50#include <stdlib.h>
51#include <string.h>
52#include <mailutils/mailutils.h>
53
54struct dirtrans
55{
56 char *dir;
57 size_t dirlen;
58 char const *trans;
59 ssize_t translen;
60};
61
62mu_list_t translist;
63
64static int
65transcmp (const void *a, const void *b)
66{
67 struct dirtrans const *trans1 = a;
68 struct dirtrans const *trans2 = b;
69 return strcmp (trans1->dir, trans2->dir);
70}
71
72static void
73newdir (char const *dir, char const *trans)
74{
75 if (dir)
76 {
77 size_t dirlen = strlen (dir);
78 size_t translen = strlen (trans);
79 struct dirtrans *dt = mu_alloc (sizeof *dt);
80
81 while (dirlen > 0 && dir[dirlen-1] == '/')
82 dirlen--;
83
84 dt->dir = mu_alloc (dirlen + 1);
85 memcpy (dt->dir, dir, dirlen);
86 dt->dir[dirlen] = 0;
87 dt->dirlen = dirlen;
88 dt->trans = trans;
89 dt->translen = translen;
90
91 if (!translist)
92 {
93 MU_ASSERT (mu_list_create (&translist));
94 mu_list_set_comparator (translist, transcmp);
95 }
96 else if (mu_list_locate (translist, dt, NULL) == 0)
97 {
98 free (dt->dir);
99 free (dt);
100 return;
101 }
102
103 MU_ASSERT (mu_list_append (translist, dt));
104 }
105}
106
107static inline int
108isbnd (int c)
109{
110 return mu_c_is_class (c, MU_CTYPE_CNTRL|MU_CTYPE_PUNCT|MU_CTYPE_SPACE);
111}
112
113int
114main (int argc, char **argv)
115{
116 int i;
117 int rc;
118 char *buf = NULL;
119 size_t size, n;
120 mu_iterator_t itr;
121
122 mu_set_program_name (argv[0]);
123 mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
124
125 for (i = 1; i < argc; i += 2)
126 newdir (argv[i], (i + 1 < argc) ? argv[i + 1] : "");
127
128 newdir (getenv ("PWD"), ".");
129 newdir (mu_getcwd (), ".");
130
131 MU_ASSERT (mu_list_get_iterator (translist, &itr));
132 while ((rc = mu_stream_getline (mu_strin, &buf, &size, &n)) == 0 && n > 0)
133 {
134 n = mu_rtrim_class (buf, MU_CTYPE_SPACE);
135 for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
136 mu_iterator_next (itr))
137 {
138 struct dirtrans *dt;
139 size_t start = 0;
140 char *p;
141
142 mu_iterator_current (itr, (void**) &dt);
143 while ((p = strstr (buf + start, dt->dir)))
144 {
145 if (isbnd (p[dt->dirlen]))
146 {
147 size_t off = p - buf;
148 size_t rest = n - start;
149 ssize_t d = (ssize_t)dt->translen - dt->dirlen;
150
151 if (d > 0)
152 {
153 if (n + d + 1 > size)
154 {
155 size = n + d + 1;
156 buf = mu_realloc (buf, size);
157 p = buf + off;
158 }
159 }
160
161 memmove (p + dt->translen, p + dt->dirlen,
162 rest - dt->dirlen + 1);
163 memcpy (p, dt->trans, dt->translen);
164
165 n += d;
166 start = off + dt->translen;
167 }
168 else
169 start++;
170 }
171 }
172 mu_stream_write (mu_strout, buf, n, NULL);
173 mu_stream_write (mu_strout, "\n", 1, NULL);
174 }
175 return 0;
176}
diff --git a/testsuite/testsuite.at b/testsuite/testsuite.at
index 880f778..addfed0 100644
--- a/testsuite/testsuite.at
+++ b/testsuite/testsuite.at
@@ -38,3 +38,4 @@ m4_include([smtp-str.at])
38 38
39AT_BANNER(Various) 39AT_BANNER(Various)
40m4_include([ufms.at]) 40m4_include([ufms.at])
41m4_include([cwdrepl.at])

Return to:

Send suggestions and report system problems to the System administrator.