Commit 453cd17f 453cd17f7a4be5ceaa8411a8a3ebd9fddd88df8e by Sergey Poznyakoff

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.
1 parent 491bec23
...@@ -3,10 +3,8 @@ ...@@ -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
6 PATH=@abs_builddir@:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH 6 PATH=@abs_builddir@:@abs_top_builddir@/testsuite:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
7 remove_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.
......
...@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[comp]) ...@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[comp])
19 m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed]) 19 m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
20 20
21 MH_CHECK([comp -file],[comp00 comp-file],[ 21 MH_CHECK([comp -file],[comp00 comp-file],[
22 echo quit | compcmd -file ./infile | remove_curdir | sed 's/ *$//' 22 echo quit | compcmd -file $HOME/infile | cwdrepl | sed 's/ *$//'
23 sed 's/ *$//' infile 23 sed 's/ *$//' infile
24 ], 24 ],
25 [0], 25 [0],
...@@ -39,7 +39,7 @@ Seen by mhed ...@@ -39,7 +39,7 @@ Seen by mhed
39 ]) 39 ])
40 40
41 MH_CHECK([comp -file (del)],[comp01 comp-file_del],[ 41 MH_CHECK([comp -file (del)],[comp01 comp-file_del],[
42 echo 'quit -delete' | compcmd -file ./infile | remove_curdir 42 echo '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,18 +53,18 @@ What now?
53 ]) 53 ])
54 54
55 MH_CHECK([comp file],[comp02 comp_file],[ 55 MH_CHECK([comp file],[comp02 comp_file],[
56 echo 'quit' | compcmd file | remove_curdir | sed 's/ *$//' 56 echo 'quit' | compcmd file | cwdrepl | sed 's/ *$//'
57 sed 's/ *$//' Mail/file 57 sed '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:
62 To: 62 To:
63 cc: 63 cc:
64 Subject: 64 Subject:
65 -------- 65 --------
66 -- Input file end 66 -- Input file end
67 What now? draft left on "Mail/file". 67 What now? draft left on "./Mail/file".
68 To: 68 To:
69 cc: 69 cc:
70 Subject: 70 Subject:
...@@ -80,11 +80,11 @@ Subject: test input ...@@ -80,11 +80,11 @@ Subject: test input
80 message body 80 message body
81 ]) 81 ])
82 82
83 echo 'quit' | compcmd -use file | remove_curdir | sed 's/ *$//' 83 echo 'quit' | compcmd -use file | cwdrepl | sed 's/ *$//'
84 sed 's/ *$//' Mail/file 84 sed '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:
89 From: gray 89 From: gray
90 To: root 90 To: root
...@@ -92,7 +92,7 @@ Subject: test input ...@@ -92,7 +92,7 @@ Subject: test input
92 92
93 message body 93 message body
94 -- Input file end 94 -- Input file end
95 What now? draft left on "Mail/file". 95 What now? draft left on "./Mail/file".
96 From: gray 96 From: gray
97 To: root 97 To: root
98 Subject: test input 98 Subject: test input
...@@ -110,14 +110,14 @@ Subject: test input ...@@ -110,14 +110,14 @@ Subject: test input
110 message body 110 message body
111 ]) 111 ])
112 112
113 echo 'quit' | compcmd +inbox 1 | remove_curdir | sed 's/ *$//' 113 echo 'quit' | compcmd +inbox 1 | cwdrepl | sed 's/ *$//'
114 echo Mail/draft 114 echo Mail/draft
115 sed 's/ *$//' Mail/draft 115 sed 's/ *$//' Mail/draft
116 echo Message 116 echo Message
117 sed 's/ *$//' Mail/inbox/1 117 sed '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:
122 From: gray 122 From: gray
123 To: root 123 To: root
...@@ -125,7 +125,7 @@ Subject: test input ...@@ -125,7 +125,7 @@ Subject: test input
125 125
126 message body 126 message body
127 -- Input file end 127 -- Input file end
128 What now? draft left on "Mail/draft". 128 What now? draft left on "./Mail/draft".
129 Mail/draft 129 Mail/draft
130 From: gray 130 From: gray
131 To: root 131 To: root
...@@ -143,18 +143,18 @@ message body ...@@ -143,18 +143,18 @@ message body
143 143
144 MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[ 144 MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[
145 mkdir Mail/drafts 145 mkdir Mail/drafts
146 echo 'quit' | compcmd -draftfolder drafts | remove_curdir | sed 's/ *$//' 146 echo 'quit' | compcmd -draftfolder drafts | cwdrepl | sed 's/ *$//'
147 sed 's/ *$//' Mail/drafts/1 147 sed '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:
152 To: 152 To:
153 cc: 153 cc:
154 Subject: 154 Subject:
155 -------- 155 --------
156 -- Input file end 156 -- Input file end
157 What now? draft left on "Mail/drafts/1". 157 What now? draft left on "./Mail/drafts/1".
158 To: 158 To:
159 cc: 159 cc:
160 Subject: 160 Subject:
...@@ -172,11 +172,11 @@ message body ...@@ -172,11 +172,11 @@ message body
172 ]) 172 ])
173 echo "cur: 1" > Mail/drafts/.mh_sequences 173 echo "cur: 1" > Mail/drafts/.mh_sequences
174 174
175 echo 'quit' | compcmd -draftfolder drafts -use| remove_curdir | sed 's/ *$//' 175 echo 'quit' | compcmd -draftfolder drafts -use| cwdrepl | sed 's/ *$//'
176 sed 's/ *$//' Mail/drafts/1 176 sed '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:
181 From: gray 181 From: gray
182 To: root 182 To: root
...@@ -184,7 +184,7 @@ Subject: test input ...@@ -184,7 +184,7 @@ Subject: test input
184 184
185 message body 185 message body
186 -- Input file end 186 -- Input file end
187 What now? draft left on "Mail/drafts/1". 187 What now? draft left on "./Mail/drafts/1".
188 From: gray 188 From: gray
189 To: root 189 To: root
190 Subject: test input 190 Subject: test input
......
...@@ -27,7 +27,7 @@ Subject: test input ...@@ -27,7 +27,7 @@ Subject: test input
27 message body 27 message body
28 ]) 28 ])
29 29
30 echo quit | forwcmd +inbox 1 | remove_curdir 30 echo quit | forwcmd +inbox 1 | cwdrepl
31 echo == Mail/draft == 31 echo == Mail/draft ==
32 cat Mail/draft 32 cat Mail/draft
33 echo == Message == 33 echo == Message ==
...@@ -36,7 +36,7 @@ echo == Message == ...@@ -36,7 +36,7 @@ echo == Message ==
36 sed '/^X-IMAPbase/d' Mail/inbox/1 36 sed '/^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:
41 To: 41 To:
42 cc: 42 cc:
...@@ -53,7 +53,7 @@ message body ...@@ -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
56 What now? draft left on "Mail/draft". 56 What now? draft left on "./Mail/draft".
57 == Mail/draft == 57 == Mail/draft ==
58 To: 58 To:
59 cc: 59 cc:
...@@ -87,7 +87,7 @@ Subject: test input ...@@ -87,7 +87,7 @@ Subject: test input
87 message body 87 message body
88 ]) 88 ])
89 89
90 echo quit | forwcmd -format +inbox 1 | remove_curdir 90 echo quit | forwcmd -format +inbox 1 | cwdrepl
91 echo == Mail/draft == 91 echo == Mail/draft ==
92 cat Mail/draft 92 cat Mail/draft
93 echo == Message == 93 echo == Message ==
...@@ -96,7 +96,7 @@ echo == Message == ...@@ -96,7 +96,7 @@ echo == Message ==
96 sed '/^X-IMAPbase/d' Mail/inbox/1 96 sed '/^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:
101 To: 101 To:
102 cc: 102 cc:
...@@ -113,7 +113,7 @@ message body ...@@ -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
116 What now? draft left on "Mail/draft". 116 What now? draft left on "./Mail/draft".
117 == Mail/draft == 117 == Mail/draft ==
118 To: 118 To:
119 cc: 119 cc:
...@@ -153,7 +153,7 @@ Subject: 2nd message ...@@ -153,7 +153,7 @@ Subject: 2nd message
153 2nd message body 153 2nd message body
154 ]) 154 ])
155 155
156 echo quit | forwcmd +inbox 1 2 | remove_curdir 156 echo quit | forwcmd +inbox 1 2 | cwdrepl
157 echo == Mail/draft == 157 echo == Mail/draft ==
158 cat Mail/draft 158 cat Mail/draft
159 echo == Message 1 == 159 echo == Message 1 ==
...@@ -162,7 +162,7 @@ echo == Message 2 == ...@@ -162,7 +162,7 @@ echo == Message 2 ==
162 cat Mail/inbox/2 162 cat 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:
167 To: 167 To:
168 cc: 168 cc:
...@@ -188,7 +188,7 @@ Subject: 2nd message ...@@ -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
191 What now? draft left on "Mail/draft". 191 What now? draft left on "./Mail/draft".
192 == Mail/draft == 192 == Mail/draft ==
193 To: 193 To:
194 cc: 194 cc:
...@@ -237,7 +237,7 @@ Subject: test input ...@@ -237,7 +237,7 @@ Subject: test input
237 message body 237 message body
238 ]) 238 ])
239 239
240 forwcmd -build +inbox 1 | remove_curdir 240 forwcmd -build +inbox 1 | cwdrepl
241 echo == Mail/draft == 241 echo == Mail/draft ==
242 cat Mail/draft 242 cat Mail/draft
243 echo == Message == 243 echo == Message ==
...@@ -282,9 +282,9 @@ Subject: 2nd message ...@@ -282,9 +282,9 @@ Subject: 2nd message
282 2nd message body 282 2nd message body
283 ]) 283 ])
284 284
285 forwcmd -build -mime +inbox 1 2 | remove_curdir 285 forwcmd -build -mime +inbox 1 2 | cwdrepl
286 echo == Mail/draft == 286 echo == Mail/draft ==
287 remove_curdir Mail/draft 287 cwdrepl < Mail/draft
288 echo == Message 1 == 288 echo == Message 1 ==
289 sed '/^X-IMAPbase/d' Mail/inbox/1 289 sed '/^X-IMAPbase/d' Mail/inbox/1
290 echo == Message 2 == 290 echo == Message 2 ==
...@@ -296,7 +296,7 @@ To: ...@@ -296,7 +296,7 @@ To:
296 cc: 296 cc:
297 Subject: 297 Subject:
298 -------- 298 --------
299 #forw [] +Mail/inbox 1 2 299 #forw [] +./Mail/inbox 1 2
300 300
301 == Message 1 == 301 == Message 1 ==
302 From: gray 302 From: gray
...@@ -322,14 +322,14 @@ Subject: test input ...@@ -322,14 +322,14 @@ Subject: test input
322 message body 322 message body
323 ]) 323 ])
324 324
325 echo "quit" | forwcmd -draftfolder drafts 1 | remove_curdir 325 echo "quit" | forwcmd -draftfolder drafts 1 | cwdrepl
326 echo == Mail/drafts/1 == 326 echo == Mail/drafts/1 ==
327 cat Mail/drafts/1 327 cat Mail/drafts/1
328 echo == Message == 328 echo == Message ==
329 sed '/^X-IMAPbase/d' Mail/inbox/1 329 sed '/^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:
334 To: 334 To:
335 cc: 335 cc:
...@@ -346,7 +346,7 @@ message body ...@@ -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
349 What now? draft left on "Mail/drafts/1". 349 What now? draft left on "./Mail/drafts/1".
350 == Mail/drafts/1 == 350 == Mail/drafts/1 ==
351 To: 351 To:
352 cc: 352 cc:
...@@ -379,10 +379,10 @@ Subject: test input ...@@ -379,10 +379,10 @@ Subject: test input
379 message body 379 message body
380 ]) 380 ])
381 381
382 echo "quit" | forwcmd -file infile | remove_curdir 382 echo "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:
387 To: 387 To:
388 cc: 388 cc:
...@@ -394,7 +394,7 @@ Subject: test input ...@@ -394,7 +394,7 @@ Subject: test input
394 394
395 message body 395 message body
396 -- Input file end 396 -- Input file end
397 What now? draft left on "Mail/draft". 397 What now? draft left on "./Mail/draft".
398 ]) 398 ])
399 399
400 m4_popdef([forwcmd]) 400 m4_popdef([forwcmd])
......
...@@ -130,21 +130,21 @@ Be off, or I'll kick you down stairs!' ...@@ -130,21 +130,21 @@ Be off, or I'll kick you down stairs!'
130 130
131 MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[ 131 MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[
132 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 132 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
133 mhn +inbox -store -auto 4 | remove_curdir || exit $? 133 mhn +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
137 storing message 4 part 2.1 as file msg.22 137 storing message 4 part 2.1 as file ./msg.22
138 storing message 4 part 2.2.1 as file msg.23 138 storing message 4 part 2.2.1 as file ./msg.23
139 storing message 4 part 2.2.2 as file msg.24 139 storing message 4 part 2.2.2 as file ./msg.24
140 ]) 140 ])
141 141
142 MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[ 142 MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[
143 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700]) 143 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
144 mhn +inbox -store -auto -part 2.2.1 4 | remove_curdir || exit $? 144 mhn +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
150 MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[ 150 MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[
...@@ -178,13 +178,13 @@ MUT_MBCHMOD(Mail/inbox, 700) ...@@ -178,13 +178,13 @@ MUT_MBCHMOD(Mail/inbox, 700)
178 mkdir out 178 mkdir out
179 echo "mhn-storage: $HOME/out" >> $MH 179 echo "mhn-storage: $HOME/out" >> $MH
180 180
181 mhn +inbox -store 4 | remove_curdir || echo $? 181 mhn +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
185 storing message 4 part 2.1 as file out/4.2.1.octet-stream 185 storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
186 storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream 186 storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
187 storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream 187 storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
188 ]) 188 ])
189 189
190 MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[ 190 MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[
...@@ -193,7 +193,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox ...@@ -193,7 +193,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
193 MUT_MBCHMOD(Mail/inbox, 700) 193 MUT_MBCHMOD(Mail/inbox, 700)
194 194
195 echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH 195 echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH
196 mhn +inbox -store 4 | remove_curdir || exit $? 196 mhn +inbox -store 4 || exit $?
197 find . -name '%*' | sort 197 find . -name '%*' | sort
198 ], 198 ],
199 [0], 199 [0],
...@@ -213,13 +213,13 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox ...@@ -213,13 +213,13 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
213 MUT_MBCHMOD(Mail/inbox, 700) 213 MUT_MBCHMOD(Mail/inbox, 700)
214 214
215 echo "mhn-store-application: $HOME/out/%m%P.%s" >> $MH 215 echo "mhn-store-application: $HOME/out/%m%P.%s" >> $MH
216 mhn +inbox -store 4 | remove_curdir || exit $? 216 mhn +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
220 storing message 4 part 2.1 as file out/4.2.1.octet-stream 220 storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
221 storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream 221 storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
222 storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream 222 storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
223 ]) 223 ])
224 224
225 MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[ 225 MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[
...@@ -229,7 +229,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox ...@@ -229,7 +229,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
229 MUT_MBCHMOD(Mail, 700) 229 MUT_MBCHMOD(Mail, 700)
230 230
231 echo "mhn-store-application: +app" >> $MH 231 echo "mhn-store-application: +app" >> $MH
232 mhn +inbox -store 4 | remove_curdir || exit $? 232 mhn +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 ...@@ -247,7 +247,7 @@ echo "Current-Folder: inbox" > Mail/context
247 cat >> $MH <<EOT 247 cat >> $MH <<EOT
248 mhn-store-application/octet-stream: + 248 mhn-store-application/octet-stream: +
249 EOT 249 EOT
250 mhn +inbox -store -part 2.2.1 4 | remove_curdir || exit $? 250 mhn +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
......
...@@ -20,43 +20,43 @@ m4_pushdef([MH_KEYWORDS],[mhpath]) ...@@ -20,43 +20,43 @@ m4_pushdef([MH_KEYWORDS],[mhpath])
20 MH_CHECK([mhpath],[mhpath00],[ 20 MH_CHECK([mhpath],[mhpath00],[
21 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 21 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
22 echo 'Current-Folder: inbox' > Mail/context 22 echo 'Current-Folder: inbox' > Mail/context
23 mhpath | remove_curdir 23 mhpath | cwdrepl
24 ], 24 ],
25 [0], 25 [0],
26 [Mail/inbox 26 [./Mail/inbox
27 ]) 27 ])
28 28
29 MH_CHECK([mhpath +],[mhpath01 mhpath+],[ 29 MH_CHECK([mhpath +],[mhpath01 mhpath+],[
30 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 30 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
31 echo 'Current-Folder: inbox' > Mail/context 31 echo 'Current-Folder: inbox' > Mail/context
32 mhpath +| remove_curdir 32 mhpath +| cwdrepl
33 ], 33 ],
34 [0], 34 [0],
35 [Mail 35 [./Mail
36 ]) 36 ])
37 37
38 MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[ 38 MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[
39 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 39 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
40 mhpath 1-3 | remove_curdir 40 mhpath 1-3 | cwdrepl
41 ], 41 ],
42 [0], 42 [0],
43 [Mail/inbox/1 43 [./Mail/inbox/1
44 Mail/inbox/2 44 ./Mail/inbox/2
45 Mail/inbox/3 45 ./Mail/inbox/3
46 ]) 46 ])
47 47
48 MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[ 48 MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[
49 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 49 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
50 mhpath 4-10 | remove_curdir 50 mhpath 4-10 | cwdrepl
51 ], 51 ],
52 [0], 52 [0],
53 [Mail/inbox/4 53 [./Mail/inbox/4
54 Mail/inbox/5 54 ./Mail/inbox/5
55 ]) 55 ])
56 56
57 MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[ 57 MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[
58 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 58 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
59 mhpath 8-10 | remove_curdir 59 mhpath 8-10 | cwdrepl
60 ], 60 ],
61 [0], 61 [0],
62 [], 62 [],
...@@ -87,7 +87,7 @@ mhpath 8-10 | remove_curdir ...@@ -87,7 +87,7 @@ mhpath 8-10 | remove_curdir
87 87
88 MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[ 88 MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[
89 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 89 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
90 mhpath 10 | remove_curdir 90 mhpath 10 | cwdrepl
91 ], 91 ],
92 [0], 92 [0],
93 [], 93 [],
...@@ -96,10 +96,10 @@ mhpath 10 | remove_curdir ...@@ -96,10 +96,10 @@ mhpath 10 | remove_curdir
96 96
97 MH_CHECK([mhpath new],[mhpath06 mhparam_new],[ 97 MH_CHECK([mhpath new],[mhpath06 mhparam_new],[
98 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 98 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
99 mhpath new | remove_curdir 99 mhpath new | cwdrepl
100 ], 100 ],
101 [0], 101 [0],
102 [Mail/inbox/6 102 [./Mail/inbox/6
103 ]) 103 ])
104 104
105 m4_popdef[MH_KEYWORDS]) 105 m4_popdef[MH_KEYWORDS])
......
...@@ -28,19 +28,19 @@ Subject: test input ...@@ -28,19 +28,19 @@ Subject: test input
28 28
29 message body 29 message body
30 ]) 30 ])
31 echo "quit" | replcmd +inbox 1 | remove_curdir 31 echo "quit" | replcmd +inbox 1 | cwdrepl
32 echo == Mail/draft == 32 echo == Mail/draft ==
33 cat Mail/draft 33 cat Mail/draft
34 ], 34 ],
35 [0], 35 [0],
36 [-- Editor invocation: Mail/draft 36 [-- Editor invocation: ./Mail/draft
37 -- Input file: 37 -- Input file:
38 To: <gray@example.com> 38 To: <gray@example.com>
39 Subject: Re: test input 39 Subject: Re: test input
40 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) 40 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
41 -------- 41 --------
42 -- Input file end 42 -- Input file end
43 What now? draft left on "Mail/draft". 43 What now? draft left on "./Mail/draft".
44 == Mail/draft == 44 == Mail/draft ==
45 To: <gray@example.com> 45 To: <gray@example.com>
46 Subject: Re: test input 46 Subject: Re: test input
...@@ -58,19 +58,19 @@ Subject: test input ...@@ -58,19 +58,19 @@ Subject: test input
58 58
59 message body 59 message body
60 ]) 60 ])
61 echo "quit" | replcmd -draftfolder drafts +inbox 1 | remove_curdir 61 echo "quit" | replcmd -draftfolder drafts +inbox 1 | cwdrepl
62 echo == Mail/drafts/1 == 62 echo == Mail/drafts/1 ==
63 cat Mail/drafts/1 63 cat 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:
68 To: <gray@example.com> 68 To: <gray@example.com>
69 Subject: Re: test input 69 Subject: Re: test input
70 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) 70 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
71 -------- 71 --------
72 -- Input file end 72 -- Input file end
73 What now? draft left on "Mail/drafts/1". 73 What now? draft left on "./Mail/drafts/1".
74 == Mail/drafts/1 == 74 == Mail/drafts/1 ==
75 To: <gray@example.com> 75 To: <gray@example.com>
76 Subject: Re: test input 76 Subject: Re: test input
......
1 atconfig 1 atconfig
2 atlocal 2 atlocal
3 bs 3 bs
4 cwdrepl
4 fldel 5 fldel
5 lstuid 6 lstuid
6 package.m4 7 package.m4
......
...@@ -51,6 +51,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac ...@@ -51,6 +51,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
51 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ 51 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@
52 noinst_PROGRAMS = \ 52 noinst_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,11 +77,14 @@ smtpsend_LDADD = \
76 @MU_AUTHLIBS@\ 77 @MU_AUTHLIBS@\
77 ${MU_LIB_MAILUTILS} 78 ${MU_LIB_MAILUTILS}
78 79
80 cwdrepl_LDADD = ${MU_LIB_MAILUTILS}
81
79 ## ------------ ## 82 ## ------------ ##
80 ## Test suite. ## 83 ## Test suite. ##
81 ## ------------ ## 84 ## ------------ ##
82 85
83 TESTSUITE_AT = \ 86 TESTSUITE_AT = \
87 cwdrepl.at\
84 fldel.at\ 88 fldel.at\
85 lstuid00.at\ 89 lstuid00.at\
86 lstuid01.at\ 90 lstuid01.at\
......
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
17 AT_SETUP([cwdrepl tool])
18 AT_KEYWORDS([cwdrepl])
19
20 AT_CHECK([
21 pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
22 cwd=`pwd -P`
23 cwdrepl <<EOT
24 $cwd
25 CWD is "$cwd"
26 $cwd/foo "$cwd" end
27 EOT
28 ],
29 [0],
30 [.
31 CWD is "."
32 ./foo "." end
33 ])
34
35 AT_CHECK([
36 pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
37 pwd -L >/dev/null 2>&1 || AT_SKIP_TEST
38 mkdir physical logical
39 ln -s physical logical || AT_SKIP_TEST
40 cd logical
41 phy=`pwd -P`
42 log=`pwd -L`
43 cwdrepl <<EOT
44 $phy $log
45 LOG is "$log", PHY is "$phy"
46 $log/foo "$log" end
47 $phy/foo "$phy" end
48 EOT
49 ],
50 [0],
51 [. .
52 LOG is ".", PHY is "."
53 ./foo "." end
54 ./foo "." end
55 ])
56
57 AT_CLEANUP
58
59
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
19 NAME
20
21 cwdrepl - replace occurrences of CWD with .
22
23 SYNOPSIS
24
25 COMMAND | cwdrepl [DIR REPL]...
26
27 DESCRIPTION
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
54 struct dirtrans
55 {
56 char *dir;
57 size_t dirlen;
58 char const *trans;
59 ssize_t translen;
60 };
61
62 mu_list_t translist;
63
64 static int
65 transcmp (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
72 static void
73 newdir (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
107 static inline int
108 isbnd (int c)
109 {
110 return mu_c_is_class (c, MU_CTYPE_CNTRL|MU_CTYPE_PUNCT|MU_CTYPE_SPACE);
111 }
112
113 int
114 main (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 }
...@@ -38,3 +38,4 @@ m4_include([smtp-str.at]) ...@@ -38,3 +38,4 @@ m4_include([smtp-str.at])
38 38
39 AT_BANNER(Various) 39 AT_BANNER(Various)
40 m4_include([ufms.at]) 40 m4_include([ufms.at])
41 m4_include([cwdrepl.at])
......