include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / programs / cmd / tests / test_builtins.cmd
blob945b68e25a9861067c1e445733eb33340361d928
1 echo Tests for cmd's builtin commands
3 @echo on
4 echo ------------ Testing 'echo' [ON] ------------
5 echo word
6 echo 'singlequotedword'
7 echo "doublequotedword"
8 @echo at-echoed-word
9 echo "/?"
10 echo.
11 echo .
12 echo.word
13 echo .word
14 echo:
15 echo :
16 echo:word
17 echo :word
18 echo/
19 echo /
20 echo/word
21 echo /word
22 echo off now
23 echo word@space@
24 echo word@space@@space@
25 echo word
26 echo@tab@word
27 echo@tab@word @tab@
28 echo@tab@word@tab@@space@
29 @tab@echo word
30 echo @tab@word
31 echo @tab@word
32 echo@tab@@tab@word
33 echo @tab@ on @space@
34 @echo --- @ with chains and brackets
35 (echo the @ character chains until&&@echo we leave the current depth||(
36 echo hidden
37 @echo hidden
38 ))&&echo and can hide brackets||(@echo command hidden)||@(echo brackets hidden)
39 @echo ---
41 @echo off
42 echo off@tab@@space@
43 @echo noecho1
44 @echo noecho2
45 @@@@@echo echo3
46 echo ------------ Testing 'echo' [OFF] ------------
47 echo word
48 echo 'singlequotedword'
49 echo "doublequotedword"
50 @echo at-echoed-word
51 echo "/?"
52 echo.
53 echo .
54 echo.word
55 echo .word
56 echo:
57 echo :
58 echo:word
59 echo :word
60 echo/
61 echo /
62 echo/word
63 echo /word
64 echo on again
65 echo word@space@
66 echo word@space@@space@
67 echo word
68 echo@tab@word
69 echo@tab@word @tab@
70 echo@tab@word@tab@@space@
71 @tab@echo word
72 echo @tab@word
73 echo @tab@word
74 echo@tab@@tab@word
76 echo ------------ Testing mixed echo modes ------------
77 echo @echo on> mixedEchoModes.cmd
78 echo if 1==1 echo foo>> mixedEchoModes.cmd
79 echo if 1==1 @echo bar>> mixedEchoModes.cmd
80 echo @echo off>> mixedEchoModes.cmd
81 echo if 1==1 echo foo2>> mixedEchoModes.cmd
82 echo if 1==1 @echo bar2>> mixedEchoModes.cmd
83 type mixedEchoModes.cmd
84 cmd /c mixedEchoModes.cmd
85 del mixedEchoModes.cmd
87 echo ------------ Testing parameterization ------------
88 call :TestParm a b c
89 call :TestParm "a b c"
90 call :TestParm "a b"\c
91 call :TestParm a=~`+,.{}!+b
92 call :TestParm a;b
93 call :TestParm "a;b"
94 call :TestParm a^;b
95 call :TestParm a[b]{c}(d)e
96 call :TestParm a&echo second line
97 call :TestParm a b,,,c
98 call :TestParm a==b;;c
99 call :TestParm a,,, b
100 goto :TestRem
102 :TestParm
103 echo '%1', '%2', '%3'
104 goto :eof
106 :TestRem
107 echo ------------ Testing rem ------------
108 rem Hello
109 rem Hello
110 rem Hello || foo
111 rem echo lol
112 rem echo foo & echo bar
113 rem @tab@ Hello
114 rem@tab@ Hello
115 rem@tab@echo foo & echo bar
116 @echo on
117 rem Hello
118 rem Hello
119 rem Hello || foo
120 rem echo lol
121 rem echo foo & echo bar
122 rem @tab@ Hello
123 rem@tab@ Hello
124 rem@tab@echo foo & echo bar
125 @echo off
127 echo ------------ Testing redirection operators ------------
128 mkdir foobar & cd foobar
129 echo --- stdout redirection
130 echo foo>foo
131 type foo
132 echo foo 1> foo
133 type foo
134 echo foo@tab@1> foo
135 type foo
136 echo foo 1>@tab@foo
137 type foo
138 echo foo@tab@1>@tab@foo
139 type foo
140 echo foo7 7> foo
141 type foo
142 echo foo9 9> foo
143 type foo
144 echo foo1> foo
145 type foo
146 echo foo11> foo
147 type foo
148 echo foo12> foo
149 type foo
150 echo foo13>"foo"
151 type foo
152 echo foo14>."\foo"
153 type foo
154 echo foo15>."\f"oo
155 type foo
156 del foo
157 echo1>foo
158 type foo
159 echo --- stdout appending
160 echo foo>foo
161 echo foo >>foo
162 type foo
163 del foo
164 echo foob >> foo
165 type foo
166 echo fooc 1>>foo
167 type foo
168 echo food1>>foo
169 type foo
170 echo food2>>"foo"
171 type foo
172 del foo
173 echo food21>>foo
174 type foo
175 del foo
176 echo foo> foo
177 echo foo7 7>> foo || (echo not supported & del foo)
178 if exist foo (type foo) else echo not supported
179 echo --- redirect at beginning of line
180 >foo (echo foo)
181 type foo
182 1>foo (echo foo1)
183 type foo
184 2>foo (echo foo2 >&2)
185 type foo
186 >>foo (echo fooA)
187 type foo
188 echo --- redirections within IF statements
189 if 1==1 echo foo1>bar
190 type bar & del bar
191 if 1==1 echo foo2>>bar
192 type bar & del bar
193 echo -----
194 if 1==1 (echo foo2>bar) else echo baz2>bar
195 type bar & del bar
196 if 1==1 (echo foo3) else echo baz3>bar
197 type bar || echo file does not exist, ok
198 if 1==1 (echo foo4>bar) else echo baz4>bar
199 type bar & del bar
200 if 1==0 (echo foo5>bar) else echo baz5>bar
201 type bar & del bar
202 if 1==0 (echo foo6) else echo baz6 1>bar
203 type bar & del bar
204 if 1==0 (echo foo7 1>bar) else echo baz7>bar
205 type bar & del bar
206 if 1==0 (echo foo8 1>bar) else echo baz8>bak
207 type bak
208 if 1==1 (echo foo>bar & echo baz)
209 type bar
210 if 1==1 (
211 echo foo>bar
212 echo baz
214 type bar
215 (if 1==1 (echo A) else echo B) > C
216 type C
217 (if 1==0 (echo A) else echo B) > C
218 type C
219 (if 1==0 (echo A > B) else echo C)
220 echo --- multiredirections
221 erase /q a b & (echo >a >b)
222 if exist a echo a shouldn't exist
223 if not exist b echo b should exist
224 erase /q a b & (echo >a >>b)
225 if exist a echo a shouldn't exist
226 if not exist b echo b should exist
227 erase /q a b & (echo >a | (echo b > b))
228 if not exist a echo a should exist
229 if not exist b echo b should exist
230 erase /q a b & (echo cc1 2>a 1>&2 2>b)
231 if exist a echo a shouldn't exist
232 if not exist b (echo b should exist) else (echo cc2 & type b)
234 cd .. & rd /s/q foobar
236 echo ------------ Testing circumflex escape character ------------
237 rem Using something like "echo foo^" asks for an additional char after a "More?" prompt on the following line; it's not possible to currently test that non-interactively
238 echo ^hell^o, world
239 echo hell^o, world
240 echo hell^^o, world
241 echo hell^^^o, world
242 echo hello^
243 world
244 echo hello^
246 world
247 echo hello^
250 echo finished
251 mkdir foobar
252 echo baz> foobar\baz
253 type foobar\baz
254 type foobar^\baz
255 rd /s/q foobar
256 echo foo ^| echo bar
257 echo foo ^& echo bar
258 call :setError 0
259 echo bak ^&& echo baz 2> nul
260 echo %ErrorLevel%
261 echo foo ^> foo
262 echo ^<> foo
263 type foo
264 del foo
265 set WINE_FOO=oof
266 echo ff^%WINE_FOO%
267 set WINE_FOO=bar ^| baz
268 set WINE_FOO
269 rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
270 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
271 echo %ErrorLevel%
272 call :setError 0
273 set WINE_FOO=bar ^^^| baz
274 set WINE_FOO
275 echo %WINE_FOO%
276 echo %ErrorLevel%
277 set WINE_FOO=
279 echo ------------ Testing chains ------------
280 rem The chain operators have the following bottom-up precedence:
281 rem 'else' precedes nothing and matches the closest unmatched 'if' in the same bracket depth
282 rem '&' precedes 'else'
283 rem '||' precedes '&' and 'else'
284 rem '&&' precedes '||', '&' and 'else'
285 rem '|' precedes '&&', '||', '&' and 'else'
287 rem Example: 'if 1==1 if 2==2 if 3==3 a | b && c || d & e else f else g' is interpreted as
288 rem 'if 1==1 (if 2==2 (if 3==3 ((((a | b) && c) || d) & e) else f) else g)'
289 goto :cfailend
290 :cfail
291 echo %1
292 call :setError 1
293 goto :eof
294 :cfailend
295 echo --- chain success
296 echo a1&echo a2
297 echo b1&&echo b2
298 echo c1||echo c2
299 echo ---
300 echo d1&echo d2&echo d3
301 echo e1&echo e2&&echo e3
302 echo f1&echo f2||echo f3
303 echo ---
304 echo g1&&echo g2&echo g3
305 echo h1&&echo h2&&echo h3
306 echo i1&&echo i2||echo i3
307 echo ---
308 echo j1||echo j2&echo j3
309 echo ---
310 echo k1||echo k2&&echo k3
311 echo ---
312 echo l1||echo l2||echo l3
313 echo ---
314 echo --- chain failure
315 call :cfail a1&call :cfail a2
316 call :cfail b1&&call :cfail b2
317 echo ---
318 call :cfail c1||call :cfail c2
319 call :cfail d1&call :cfail d2&call :cfail d3
320 call :cfail e1&call :cfail e2&&call :cfail e3
321 echo ---
322 call :cfail f1&call :cfail f2||call :cfail f3
323 call :cfail g1&&call :cfail g2&call :cfail g3
324 echo ---
325 call :cfail h1&&call :cfail h2&&call :cfail h3
326 echo ---
327 call :cfail i1&&call :cfail i2||call :cfail i3
328 echo ---
329 call :cfail j1||call :cfail j2&call :cfail j3
330 call :cfail k1||call :cfail k2&&call :cfail k3
331 echo ---
332 call :cfail l1||call :cfail l2||call :cfail l3
333 echo --- chain brackets
334 rem Brackets are like regular commands, they support redirections
335 rem and have the same precedence as regular commands.
336 echo a1&(echo a2&echo a3)
337 echo b1&(echo b2&&echo b3)
338 echo c1&(echo c2||echo c3)
339 echo ---
340 echo d1&&(echo d2&echo d3)
341 echo e1&&(echo e2&&echo e3)
342 echo f1&&(echo f2||echo f3)
343 echo ---
344 echo g1||(echo g2&echo g3)
345 echo ---
346 echo h1||(echo h2&&echo h3)
347 echo ---
348 echo i1||(echo i2||echo i3)
349 echo ---
350 call :cfail j1&(call :cfail j2&call :cfail j3)
351 call :cfail k1&(call :cfail k2&&call :cfail k3)
352 echo ---
353 call :cfail l1&(call :cfail l2||call :cfail l3)
354 call :cfail m1&&(call :cfail m2&call :cfail m3)
355 echo ---
356 call :cfail n1&&(call :cfail n2&&call :cfail n3)
357 echo ---
358 call :cfail o1&&(call :cfail o2||call :cfail o3)
359 echo ---
360 call :cfail p1||(call :cfail p2&call :cfail p3)
361 call :cfail q1||(call :cfail q2&&call :cfail q3)
362 echo ---
363 call :cfail r1||(call :cfail r2||call :cfail r3)
364 echo --- chain pipe
365 rem Piped commands run at the same time, so the print order varies.
366 rem Additionally, they don't run in the batch script context, as shown by
367 rem 'call :existing_label|echo read the error message'.
368 (echo a 1>&2|echo a 1>&2) 2>&1
369 echo ---
370 echo b1|echo b2
371 echo c1&&echo c2|echo c3
372 echo d1||echo d2|echo d3
373 echo ---
374 echo e1&echo e2|echo e3
375 echo f1|echo f2&&echo f3
376 echo g1|echo g2||echo g3
377 echo ---
378 echo h1|echo h2&echo h3
379 echo i1|echo i2|echo i3
380 echo --- chain pipe input
381 rem The output data of the left side of a pipe can disappear, probably
382 rem because it finished too fast and closed the pipe before it could be read,
383 rem which means we can get broken results for the tests of this section.
384 echo @echo off> tmp.cmd
385 echo set IN=X>> tmp.cmd
386 echo set /p IN=%%1:>> tmp.cmd
387 echo setlocal EnableDelayedExpansion>> tmp.cmd
388 echo echo [!IN!,%%1]>> tmp.cmd
389 echo endlocal>> tmp.cmd
390 echo set IN=>> tmp.cmd
391 echo a1|cmd /ctmp.cmd a2
392 echo b1|cmd /ctmp.cmd b2|cmd /ctmp.cmd b3
393 echo c1|cmd /ctmp.cmd c2|cmd /ctmp.cmd c3|cmd /ctmp.cmd c4
394 echo d1|call tmp.cmd d2
395 echo e1|call tmp.cmd e2|call tmp.cmd e3
396 echo f1|call tmp.cmd f2|call tmp.cmd f3|call tmp.cmd f4
397 rem FIXME these 3 tests cause "unexpected end of output"
398 rem test : echo g1|tmp.cmd g2
399 rem result: g2:[g1,g2]
400 rem test : echo h1|tmp.cmd h2|tmp.cmd h3
401 rem result: h3:[h2:[h1,h2],h3]@or_broken@h3:[h2:,h3]
402 rem test : echo i1|tmp.cmd i2|tmp.cmd i3|tmp.cmd i4
403 rem result: i4:[i3:[i2:[i1,i2],i3],i4]@or_broken@i4:[i3:[i2:,i3],i4]@or_broken@i4:[i3:,i4]
404 del tmp.cmd
405 echo --- chain else
406 rem Command arguments are greedy and eat up the 'else' unless terminated by
407 rem brackets, which means the 'else' can only be recognized when the
408 rem 'if true' command chain ends with brackets.
409 if 1==1 if 2==2 if 3==3 (echo a1) else (echo a2) else echo a3
410 if 1==1 if 2==2 if 3==0 (echo b1) else (echo b2) else echo b3
411 echo ---
412 if 1==1 if 2==0 if 3==3 (echo c1) else (echo c2) else echo c3
413 echo ---
414 if 1==1 if 2==0 if 3==0 (echo d1) else (echo d2) else echo d3
415 echo ---
416 if 1==0 if 2==2 if 3==3 (echo e1) else (echo e2) else echo e3
417 echo ---
418 if 1==0 if 2==2 if 3==0 (echo f1) else (echo f2) else echo f3
419 echo ---
420 if 1==0 if 2==0 if 3==3 (echo g1) else (echo g2) else echo g3
421 echo ---
422 if 1==0 if 2==0 if 3==0 (echo h1) else (echo h2) else echo h3
423 echo ---
424 echo --- chain else (if true)
425 if 1==1 echo a1 else echo a2
426 if 1==1 echo b1|echo b2 else echo b3
427 if 1==1 echo c1&&echo c2 else echo c3
428 if 1==1 echo d1||echo d2 else echo d3
429 echo ---
430 if 1==1 echo e1&echo e2 else echo e3
431 if 1==1 echo f1 else echo f2|echo f3
432 if 1==1 echo g1 else echo g2&&echo g3
433 if 1==1 echo h1 else echo h2||echo h3
434 echo ---
435 if 1==1 echo i1 else echo i2&echo i3
436 if 1==1 echo j1|(echo j2) else echo j3
437 echo ---
438 if 1==1 echo k1&&(echo k2) else echo k3
439 if 1==1 echo l1||(echo l2) else echo l3
440 echo ---
441 if 1==1 echo m1&(echo m2) else echo m3
442 if 1==1 (echo n1) else echo n2|echo n3
443 if 1==1 (echo o1) else echo o2&&echo o3
444 if 1==1 (echo p1) else echo p2||echo p3
445 if 1==1 (echo q1) else echo q2&echo q3
446 echo ---
447 echo --- chain else (if false)
448 if 1==0 echo a1 else echo a2
449 if 1==0 echo b1|echo b2 else echo b3
450 if 1==0 echo c1&&echo c2 else echo c3
451 if 1==0 echo d1||echo d2 else echo d3
452 if 1==0 echo e1&echo e2 else echo e3
453 if 1==0 echo f1 else echo f2|echo f3
454 if 1==0 echo g1 else echo g2&&echo g3
455 if 1==0 echo h1 else echo h2||echo h3
456 if 1==0 echo i1 else echo i2&echo i3
457 if 1==0 echo j1|(echo j2) else echo j3
458 echo ---
459 if 1==0 echo k1&&(echo k2) else echo k3
460 if 1==0 echo l1||(echo l2) else echo l3
461 if 1==0 echo m1&(echo m2) else echo m3
462 if 1==0 (echo n1) else echo n2|echo n3
463 if 1==0 (echo o1) else echo o2&&echo o3
464 if 1==0 (echo p1) else echo p2||echo p3
465 echo ---
466 if 1==0 (echo q1) else echo q2&echo q3
467 echo ------------- Testing internal commands return codes
468 setlocal EnableDelayedExpansion
470 echo --- success/failure for basics
471 call :setError 0 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
472 call :setError 33 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
473 call :setError 666 & (echo foo &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
474 call :setError 666 & (echo foo >> h:\i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
475 call :setError 666 & echo foo >> h:\i\dont\exist\at\all.txt & echo ERRORLEVEL !errorlevel!
476 echo --- success/failure for IF/FOR blocks
477 call :setError 666 & ((if 1==1 echo "">NUL) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
478 call :setError 666 & ((if 1==0 echo "">NUL) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
479 call :setError 666 & ((if 1==1 (call :setError 33)) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
480 call :setError 666 & ((if 1==0 (call :setError 33) else call :setError 34) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
481 call :setError 666 & ((for %%i in () do echo "") &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
482 call :setError 666 & ((for %%i in () do call :setError 33) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
483 call :setError 666 & ((for %%i in (a) do call :setError 0) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
484 call :setError 666 & ((for %%i in (a) do call :setError 33) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
485 echo --- success/failure for external command
486 mkdir foo & cd foo
487 call :setError 666 & (I\dont\exist.exe &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
488 call :setError 666 & I\dont\exist.exe & echo ERRORLEVEL !errorlevel!
489 call :setError 666 & (Idontexist.exe &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
490 call :setError 666 & Idontexist.exe & echo ERRORLEVEL !errorlevel!
491 call :setError 666 & (cmd.exe /c "echo foo & exit /b 0" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
492 call :setError 666 & (cmd.exe /c "echo foo & exit /b 1024" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
493 cd .. && rd /q /s foo
494 echo --- success/failure for CALL command
495 mkdir foo & cd foo
496 echo exit /b %%1 > foobar.bat
497 rem call :setError 666 & (call I\dont\exist.exe &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
498 rem terminates batch exec on native...
499 call :setError 666 & (call Idontexist.exe &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
500 call :setError 666 & (call .\foobar.bat 0 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
501 call :setError 666 & (call .\foobar.bat 1024 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
502 call :setError 666 & (call cmd.exe /c "echo foo & exit /b 0" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
503 call :setError 666 & (call cmd.exe /c "echo foo & exit /b 1025" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
504 call :setError 666 & (call rmdir foobar.dir &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
505 cd .. && rd /q /s foo
506 echo --- success/failure for pipes
507 call :setError 666 & ((echo a | echo b) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
508 call :setError 666 & ((echo a | call :setError 34) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
509 call :setError 666 & ((call :setError 33 | echo a) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
510 call :setError 666 & ((echo a | rmdir I\dont\exist\at\all) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
511 call :setError 666 & ((rmdir I\dont\exist\at\all | echo a) &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
512 rem in a pipe, if LHS or RHS can't be started, the whole cmd is abandonned (not just the pipe!!)
513 echo ^( %%1 ^| %%2 ^) > foo.bat
514 echo echo AFTER %%ERRORLEVEL%% >> foo.bat
515 call :setError 666 & (cmd.exe /q /c "call foo.bat echo I\dont\exist.exe" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
516 call :setError 666 & (cmd.exe /q /c "call foo.bat I\dont\exist.exe echo" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
517 erase /q foo.bat
518 echo --- success/failure for START command
519 call :setError 666 & (start "" /foobar >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
520 rem call :setError 666 & (start /B I\dont\exist.exe &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
521 rem can't run this test, generates a nice popup under windows
522 call :setError 666 & (start "" /B /WAIT cmd.exe /c "echo foo & exit /b 1024" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
523 rem A call :setError 666 & (start "" /B cmd.exe /c "(choice /C:YN /T:3 /D:Y > NUL) & exit /b 1024" &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
524 rem can't do on Wine until /T is properly handled in CHOICE
525 rem SUCCESS 666
526 echo --- success/failure for TYPE command
527 mkdir foo & cd foo
528 echo a > fileA
529 echo b > fileB
530 call :setError 666 & (type &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
531 call :setError 666 & (type NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
532 call :setError 666 & (type i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
533 call :setError 666 & (type file* i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
534 echo ---
535 call :setError 666 & (type i\dont\exist\at\all.txt file* &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
536 cd .. && rd /q /s foo
538 echo --- success/failure for COPY command
539 mkdir foo & cd foo
540 echo a > fileA
541 echo b > fileB
542 call :setError 666 & (copy fileA >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
543 call :setError 666 & (copy fileA fileZ >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
544 call :setError 666 & (copy fileA fileZ /-Y >NUL <NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
545 call :setError 666 & (copy fileA+fileD fileZ /-Y >NUL <NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
546 call :setError 666 & (copy fileD+fileA fileZ /-Y >NUL <NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
547 if exist fileD echo Unexpected fileD
548 cd .. && rd /q /s foo
550 echo --- success/failure for MOVE command
551 mkdir foo & cd foo
552 echo a > fileA
553 echo b > fileB
554 call :setError 666 & (move >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
555 call :setError 666 & (move fileA fileC >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
556 call :setError 666 & (move fileC nowhere\fileC >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
557 call :setError 666 & (move fileD fileE >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
558 call :setError 666 & (move fileC fileB /-Y >NUL <NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
559 cd .. && rd /q /s foo
561 echo --- success/failure for RENAME command
562 mkdir foo & cd foo
563 echo a > fileA
564 echo b > fileB
565 call :setError 666 & (rename fileB >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
566 call :setError 666 & (rename fileB fileA >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
567 call :setError 666 & (rename fileB nowhere\fileB >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
568 call :setError 666 & (rename fileD fileC >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
569 call :setError 666 & (rename fileB fileC >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
570 cd .. && rd /q /s foo
572 echo --- success/failure for ERASE command
573 mkdir foo & cd foo
574 echo a > fileA
575 echo b > fileB
576 echo e > fileE
577 call :setError 666 & (erase &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
578 call :setError 666 & (erase fileE &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
579 call :setError 666 & (erase i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
580 call :setError 666 & (erase file* i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
581 cd .. && rd /q /s foo
583 echo --- success/failure for change drive command
584 call :setError 666 & (c: &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
585 call :setError 666 & (1: &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
586 call :setError 666 & (call c: &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
587 call :setError 666 & (call 1: &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
589 echo --- success/failure for MKDIR,MD command
590 mkdir foo & cd foo
591 call :setError 666 & (mkdir &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
592 call :setError 666 & (mkdir abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
593 call :setError 666 & (mkdir abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
594 call :setError 666 & (mkdir @:\cba\abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
595 call :setError 666 & (mkdir NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
596 cd .. && rd /q /s foo
598 echo --- success/failure for CD command
599 mkdir foo & cd foo
600 mkdir abc
601 call :setError 666 & (cd abc >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
602 call :setError 666 & (cd abc >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
603 call :setError 666 & (cd .. >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
604 call :setError 666 & (cd >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
605 cd .. && rd /q /s foo
607 echo --- success/failure for PUSHD/POPD commands
608 mkdir foo & cd foo
609 mkdir abc
610 call :setError 666 & (pushd &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
611 call :setError 666 & (pushd abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
612 call :setError 666 & (pushd abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
613 call :setError 666 & (popd abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
614 call :setError 666 & (popd &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
615 call :setError 666 & popd & echo ERRORLEVEL !errorlevel!
616 cd .. && rd /q /s foo
618 echo --- success/failure for DIR command
619 mkdir foo & cd foo
620 echo a > fileA
621 echo b > fileB
622 mkdir dir
623 echo b > dir\fileB
624 call :setError 666 & (dir /e >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
625 call :setError 666 & (dir zzz >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
626 call :setError 666 & (dir fileA zzz >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
627 call :setError 666 & (dir zzz fileA >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
628 call :setError 666 & (dir dir\zzz >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
629 call :setError 666 & (dir file* >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
630 cd .. && rd /q /s foo
631 echo --- success/failure for RMDIR/RD command
632 mkdir foo & cd foo
633 mkdir abc
634 call :setError 666 & (rmdir &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
635 echo "">abc\abc
636 call :setError 666 & (rmdir abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
637 call :setError 666 & (rmdir abc\abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
638 erase abc\abc
639 call :setError 666 & (rmdir abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
640 call :setError 666 & (rmdir abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
641 call :setError 666 & (rmdir @:\cba\abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
642 cd .. && rd /q /s foo
643 mkdir foo & cd foo
644 mkdir abc
645 call :setError 666 & rmdir & echo ERRORLEVEL !errorlevel!
646 echo "">abc\abc
647 call :setError 666 & rmdir abc & echo ERRORLEVEL !errorlevel!
648 call :setError 666 & rmdir abc\abc & echo ERRORLEVEL !errorlevel!
649 erase abc\abc
650 call :setError 666 & rmdir abc & echo ERRORLEVEL !errorlevel!
651 call :setError 666 & rmdir abc & echo ERRORLEVEL !errorlevel!
652 call :setError 666 & rmdir @:\cba\abc & echo ERRORLEVEL !errorlevel!
653 cd .. && rd /q /s foo
655 echo --- success/failure for MKLINK command
656 mkdir foo & cd foo
657 call :setError 666 & (mklink &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
658 call :setError 666 & (mklink /h foo &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
659 call :setError 666 & (mklink /h foo foo &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
660 call :setError 666 & (mklink /z foo foo &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
661 echo bar > foo
662 call :setError 666 & (mklink /h foo foo &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
663 call :setError 666 & (mklink /h bar foo >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
664 call :setError 666 & (mklink /h bar foo &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
665 cd .. && rd /q /s foo
667 echo --- success/failure for SETLOCAL/ENDLOCAL commands
668 call :setError 666 & (setlocal foobar &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
669 call :setError 666 & (setlocal &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
670 call :setError 666 & (endlocal foobar &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
671 call :setError 666 & (setlocal DisableExtensions &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
672 call :setError 666 & (setlocal EnableExtensions &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
673 echo --- success/failure for DATE command
674 call :setError 666 & (date /t >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
675 call :setError 666 & (date AAAA >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
676 rem need evelated priviledges to set the date
677 echo --- success/failure for TIME command
678 call :setError 666 & (time /t >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
679 call :setError 666 & (time AAAA >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
680 rem need evelated priviledges to set the time
681 echo --- success/failure for BREAK command
682 call :setError 666 & (break &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
683 call :setError 666 & (break 345 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
684 echo --- success/failure for VER command
685 call :setError 666 & (ver >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
686 call :setError 666 & (ver foo >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
687 call :setError 666 & (ver /f >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
688 echo --- success/failure for VERIFY command
689 call :setError 666 & (verify >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
690 call :setError 666 & (verify on >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
691 call :setError 666 & (verify foobar >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
692 echo --- success/failure for VOL command
693 call :setError 666 & (vol >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
694 call :setError 666 & (vol c: >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
695 call :setError 666 & (vol foobar >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
696 call :setError 666 & (vol /Z >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
697 echo --- success/failure for LABEL command
698 call :setError 666 & (<NUL label >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
699 rem need evelated priviledges to test
701 echo --- success/failure for PATH command
702 call :setError 666 & (path >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
703 set SAVED_PATH=%PATH% > NUL
704 call :setError 666 & (path @:\I\dont\Exist &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
705 path
706 call :setError 666 & (path ; &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
707 path
708 call :setError 666 & (path !SAVED_PATH! &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
709 set "SAVED_PATH="
710 echo --- success/failure for SET command
711 call :setError 666 & (set >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
712 call :setError 666 & (set "SAVED_PATH=%PATH%" >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
713 call :setError 666 & (set S >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
714 call :setError 666 & (set "SAVED_PATH=" >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
715 call :setError 666 & (set "SAVED_PATH=" >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
716 call :setError 666 & (set /Q >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
717 call :setError 666 & (set ThisVariableLikelyDoesntExist >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
718 rem missing /A and /p tests
719 echo --- success/failure for ASSOC command
720 call :setError 666 & (assoc >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
721 call :setError 666 & (assoc cmd >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
722 call :setError 666 & (assoc .idontexist >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
723 rem testing changing the assoc requires elevated privilege
724 echo --- success/failure for FTYPE command
725 call :setError 666 & (ftype >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
726 call :setError 666 & (ftype cmdfile >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
727 call :setError 666 & (ftype fileidontexist >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
728 rem testing changing the ftype requires elevated privilege
729 echo --- success/failure for SHIFT command
730 call :setError 666 & shift /abc &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
731 call :testSuccessFailureShift 1
732 goto :afterSuccessFailureShift
733 :testSuccessFailureShift
734 call :setError 666 & shift &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
735 call :setError 666 & shift &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
736 goto :eof
737 :afterSuccessFailureShift
738 echo --- success/failure for HELP command
739 call :setError 666 & help >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
740 call :setError 666 & help dir >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
741 call :setError 666 & help ACommandThatLikelyDoesntExist >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
742 echo --- success/failure for PROMPT command
743 call :setError 666 & prompt >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!
744 rem doesn't seem to set errors either on invalid $ escapes, nor qualifiers
746 echo --- success/failure for CLS command
747 call :setError 666 & (cls &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
748 call :setError 666 & (cls foobar &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
749 call :setError 666 & (cls /X &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
750 echo --- success/failure for COLOR command
751 call :setError 666 & (color fc < NUL > NUL 2>&1 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
752 rem TODO: color is also hard to test: it requires fd 1 to be bound to a console, so we can't redirect its output
753 echo --- success/failure for TITLE command
754 call :setError 666 & (title a new title &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
755 call :setError 666 & (title &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
756 echo --- success/failure for CHOICE command
757 call :setError 666 & (choice <NUL >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
758 call :setError 666 & (choice /c <NUL >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
759 call :setError 666 & ((echo A | choice /C:BA) >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
760 call :setError 666 & (choice /C:BA <NUL >NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
761 rem syntax errors in command return INVALID_FUNCTION, need to find a test for returning 255
762 echo --- success/failure for MORE command
763 call :setError 666 & (more NUL &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
764 call :setError 666 & (more I\dont\exist.txt > NUL 2>&1 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
765 call :setError 666 & (echo foo | more &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
766 echo --- success/failure for PAUSE command
767 call :setError 666 & (pause < NUL > NUL 2>&1 &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!)
768 rem TODO: pause is harder to test when fd 1 is a console handle as we don't control output
769 echo ---
770 setlocal DisableDelayedExpansion
771 echo ------------ Testing 'set' ------------
772 call :setError 0
773 rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
774 for /f "delims==" %%i in ('set WINE_ba') do set %%i=
775 for /f "delims==" %%i in ('set WINE_foo') do set %%i=
776 set WINE_FOOBAR 2> nul > nul
777 echo %ErrorLevel%
778 set WINE_FOOBAR = baz
779 echo %ErrorLevel%
780 echo %WINE_FOOBAR%WINE_FOOBAR not defined
781 echo %WINE_FOOBAR %
782 set WINE_FOOBAR 2> nul
783 set WINE_FOOBAR = baz2
784 echo %ErrorLevel%
785 echo %WINE_fOObAr %
786 set WINE_FOOBAR= bar
787 echo %ErrorLevel%
788 echo %WINE_FOOBAR%
789 set WINE_FOO
790 set WINE_FOOBAR=
791 set WINE_FOOB
792 echo %WINE_FOOBAR%WINE_FOOBAR not defined
793 set WINE_FOOBAR =
794 set WINE_FOOBA 2> nul > nul
795 echo %ErrorLevel%
796 set WINE_FOO=bar
797 echo %WINE_FOO%
798 set WINE_FOO=foo
799 set WINE_BAR=bar
800 echo %WINE_FOO%%WINE_BAR%
801 set WINE_BAR=
802 set WINE_FOO=
803 set WINE_FOO=%WINE_FOO%
804 echo %WINE_FOO%WINE_FOO not defined
805 set WINE_BAZ%=bazbaz
806 set WINE_BA
807 echo %WINE_BAZ%%
808 set WINE_BAZ%=
809 echo set "WINE_FOO=bar" should not include the quotes in the variable value
810 set "WINE_FOO=bar"
811 echo %WINE_FOO%
812 set@tab@WINE_FOO=foo
813 echo %WINE_FOO%
814 set@tab@WINE_FOO=
815 echo '%WINE_FOO%'
816 set WINE_FOO=foo@space@
817 echo '%WINE_FOO%'
818 set WINE_FOO=foo@tab@
819 echo '%WINE_FOO%'
820 rem Space symbol must appear in `var`
821 set WINE_FOO=value@space@
822 echo '%WINE_FOO%'
823 rem Space symbol must NOT appear in `var`
824 set "WINE_FOO=value"@space@
825 echo '%WINE_FOO%'
826 rem Mixed examples:
827 set WINE_FOO=jim fred
828 echo '%WINE_FOO%'
829 set WINE_FOO="jim" fred
830 echo '%WINE_FOO%'
831 set "WINE_FOO=jim fred"
832 echo '%WINE_FOO%'
833 set "WINE_FOO=jim" fred
834 echo '%WINE_FOO%'
835 rem Only the final quote ends the string
836 set "WINE_FOO=apple"banana"grape"orange
837 echo '%WINE_FOO%'
838 set WINE_FOO=
839 rem set PATH must work with quotes
840 set PATH_BACKUP=%PATH%
841 mkdir folder
842 mkdir "fol;der"
843 echo echo I'm here! > "fol;der\sub1.bat"
844 echo echo I'm here! > folder\sub1.bat
845 set PATH=nothing;"fol;der"
846 call sub1
847 set PATH="folder
848 call sub1
849 set PATH=folder"
850 call sub1
851 del "fol;der\sub1.bat"
852 del folder\sub1.bat
853 rmdir "fol;der"
854 rmdir folder
855 PATH=%PATH_BACKUP%
857 echo ------------ Testing 'choice' ------------
859 rem Windows XP and Windows 2000 do not come with choice
860 rem echo is used for @or_broken@ formatting
861 choice /C:ABC /M "Example message" /D A /T:0
862 if %ERRORLEVEL% EQU 9009 (
863 echo choice unavailable
865 echo %ERRORLEVEL%
866 choice /C ABC "/M:Example message" /D:B /T 0
867 if %ERRORLEVEL% EQU 9009 (
868 echo choice unavailable
870 echo %ERRORLEVEL%
871 choice /C def /D:f /T:0
872 if %ERRORLEVEL% EQU 9009 (
873 echo choice unavailable
875 echo %ERRORLEVEL%
876 REM If a pipe fails due to a nonexistent command
877 REM it will stop the whole program's execution
878 if %ERRORLEVEL% NEQ 9009 (
879 echo Y | choice /C ABCXYZ /D A /T 2
881 if %ERRORLEVEL% EQU 9009 (
882 echo choice unavailable
884 echo %ERRORLEVEL%
885 choice /C ABC /N /D A /T 0
886 if %ERRORLEVEL% EQU 9009 (
887 echo choice unavailable
889 echo %ERRORLEVEL%
890 choice /C abcABC /CS /D:A /T:0
891 if %ERRORLEVEL% EQU 9009 (
892 echo choice unavailable
894 echo %ERRORLEVEL%
895 rem intentional error
896 choice /C abcABC /D:A /T:0 >NUL 2>NUL
897 echo %ERRORLEVEL%
899 echo ------------ Testing variable expansion ------------
900 call :setError 0
901 echo ~p0 should be path containing batch file
902 echo %~p0
903 mkdir dummydir
904 cd dummydir
905 echo %~p0
906 cd ..
907 rmdir dummydir
908 echo ~dp0 should be directory containing batch file
909 echo %~dp0
910 mkdir dummydir
911 cd dummydir
912 echo %~dp0
913 cd ..
914 rmdir dummydir
915 echo CD value %CD%
916 echo %%
917 echo P%
918 echo %P
919 echo %WINE_UNKNOWN%S
920 echo P%WINE_UNKNOWN%
921 echo P%WINE_UNKNOWN%S
922 echo %ERRORLEVEL
923 echo %ERRORLEVEL%
924 echo %ERRORLEVEL%%ERRORLEVEL%
925 echo %ERRORLEVEL%ERRORLEVEL%
926 echo %ERRORLEVEL%%
927 echo %ERRORLEVEL%%%
928 echo P%ERRORLEVEL%
929 echo %ERRORLEVEL%S
930 echo P%ERRORLEVEL%S
932 echo ------------ Testing variable substrings ------------
933 set WINE_VAR=qwerty
934 echo %WINE_VAR:~0,1%
935 echo %WINE_VAR:~0,3%
936 echo %WINE_VAR:~2,2%
937 echo '%WINE_VAR:~-2,3%'
938 echo '%WINE_VAR:~-2,1%'
939 echo %WINE_VAR:~2,-1%
940 echo %WINE_VAR:~2,-3%
941 echo '%WINE_VAR:~-2,-4%'
942 echo %WINE_VAR:~-3,-2%
943 echo %WINE_VAR:~4,4%
944 set WINE_VAR=
945 mkdir dummydir
946 cd dummydir
947 echo %CD:~-6,6%
948 cd ..
949 rmdir dummydir
951 echo ------------ Testing variable substitution ------------
952 echo --- in FOR variables
953 for %%i in ("A B" C) do echo %%i
954 rem check works when prefix with @
955 @for %%i in ("A B" C) do echo %%i
956 rem quotes removal
957 for %%i in ("A B" C) do echo '%%~i'
958 rem fully qualified path
959 for %%f in ("C D" E) do echo %%~ff
960 rem drive letter
961 for %%i in ("F G" H) do echo %%~di
962 rem path
963 for %%d in ("I J" K) do echo %%~pd
964 rem filename
965 for %%i in ("L M" N) do echo %%~ni
966 rem file extension
967 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
968 rem path with short path names
969 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
970 rem file attribute
971 for %%i in ("U V" W) do echo '%%~ai'
972 echo foo> foo
973 for %%i in (foo) do echo '%%~ai'
974 for %%i in (foo) do echo '%%~zi'
975 del foo
976 rem file date/time
977 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
978 for %%i in ("a b" c) do echo '%%~ti'
979 rem file size
980 rem Similar issues as above
981 for %%i in ("a b" c) do echo '%%~zi'
982 rem combined options
983 for %%i in ("d e" f) do echo %%~dpi
984 for %%i in ("g h" i) do echo %%~sdi
985 for %%i in ("g h" i) do echo %%~dsi
986 for %%i in ("j k" l.eh) do echo '%%~xsi'
987 for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
989 echo --- in parameters
990 for %%i in ("A B" C) do call :echoFun %%i
991 rem quotes removal
992 for %%i in ("A B" C) do call :echoFunQ %%i
993 rem fully qualified path
994 for %%f in ("C D" E) do call :echoFunF %%f
995 rem drive letter
996 for %%i in ("F G" H) do call :echoFunD %%i
997 rem path
998 for %%d in ("I J" K) do call :echoFunP %%d
999 rem filename
1000 for %%i in ("L M" N) do call :echoFunN %%i
1001 rem file extension
1002 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
1003 rem path with short path names
1004 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
1005 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
1006 rem combined options
1007 for %%i in ("d e" f) do call :echoFunDP %%i
1008 for %%i in ("g h" i) do call :echoFunSD %%i
1009 for %%i in ("g h" i) do call :echoFunDS %%i
1010 for %%i in ("j k" l.eh) do call :echoFunXS %%i
1012 goto :endEchoFuns
1013 :echoFun
1014 echo %1
1015 goto :eof
1017 :echoFunQ
1018 echo '%~1'
1019 goto :eof
1021 :echoFunF
1022 echo %~f1
1023 goto :eof
1025 :echoFunD
1026 echo %~d1
1027 goto :eof
1029 :echoFunP
1030 echo %~p1
1031 goto :eof
1033 :echoFunN
1034 echo %~n1
1035 goto :eof
1037 :echoFunX
1038 echo '%~x1'
1039 goto :eof
1041 :echoFunS
1042 rem some NT4 workaround
1043 set WINE_VAR='%~s1'
1044 echo %WINE_VAR%
1045 set WINE_VAR=
1046 goto :eof
1048 :echoFunDP
1049 echo %~dp1
1050 goto :eof
1052 :echoFunSD
1053 echo %~sd1
1054 goto :eof
1056 :echoFunDS
1057 echo %~ds1
1058 goto :eof
1060 :echoFunXS
1061 echo '%~xs1'
1062 goto :eof
1063 :endEchoFuns
1065 setlocal EnableDelayedExpansion
1066 set WINE_FOO=foo bar
1067 for %%i in ("!WINE_FOO!") do echo %%i
1068 for %%i in (!WINE_FOO!) do echo %%i
1069 setlocal DisableDelayedExpansion
1071 echo --- in digit variables
1072 for %%0 in (a b) do echo %%0 %%1 %%2
1073 echo ------------ Testing parameter zero ------------
1074 call :func parm1 parm2
1075 goto :endParm0
1076 :func
1077 echo %~0 %~1
1078 echo [%0] [%~d0] [%~p0] [%~n0] [%~x0] [%~s0]
1079 goto :EOF
1080 :endParm0
1082 echo ------------ Testing variable delayed expansion ------------
1083 rem NT4 doesn't support this
1084 echo --- default mode (load-time expansion)
1085 set WINE_FOO=foo
1086 echo %WINE_FOO%
1087 echo !WINE_FOO!
1088 if %WINE_FOO% == foo (
1089 set WINE_FOO=bar
1090 if %WINE_FOO% == bar (echo bar) else echo foo
1093 set WINE_FOO=foo
1094 if %WINE_FOO% == foo (
1095 set WINE_FOO=bar
1096 if !WINE_FOO! == bar (echo bar) else echo foo
1099 echo --- runtime (delayed) expansion mode
1100 setlocal EnableDelayedExpansion
1101 set WINE_FOO=foo
1102 echo %WINE_FOO%
1103 echo !WINE_FOO!
1104 if %WINE_FOO% == foo (
1105 set WINE_FOO=bar
1106 if %WINE_FOO% == bar (echo bar) else echo foo
1109 set WINE_FOO=foo
1110 if %WINE_FOO% == foo (
1111 set WINE_FOO=bar
1112 if !WINE_FOO! == bar (echo bar) else echo foo
1114 set WINE_FOO=32
1115 if %WINE_FOO% == 32 (
1116 set WINE_FOO=33
1117 call :setError 33
1118 if errorlevel !WINE_FOO! (echo gotitright) else echo gotitwrong
1120 echo %ErrorLevel%
1121 setlocal DisableDelayedExpansion
1122 echo %ErrorLevel%
1123 set WINE_FOO=foo
1124 echo %WINE_FOO%
1125 echo !WINE_FOO!
1126 set WINE_FOO=
1128 setlocal EnableDelayedExpansion
1129 set WINE_FOO=foo bar
1130 if !WINE_FOO!=="" (echo empty) else echo not empty
1131 setlocal DisableDelayedExpansion
1133 echo --- using /V cmd flag
1134 echo @echo off> tmp.cmd
1135 echo set WINE_FOO=foo>> tmp.cmd
1136 echo echo %%WINE_FOO%%>> tmp.cmd
1137 echo echo !WINE_FOO!>> tmp.cmd
1138 echo set WINE_FOO=>> tmp.cmd
1139 cmd /V:ON /C tmp.cmd
1140 cmd /V:OfF /C tmp.cmd
1141 del tmp.cmd
1143 echo ------------ Testing conditional execution ------------
1144 echo --- unconditional ampersand
1145 call :setError 123 & echo foo1
1146 echo bar2 & echo foo2
1147 mkdir foobar & cd foobar
1148 echo > foobazbar
1149 cd .. & rd /s/q foobar
1150 if exist foobazbar (
1151 echo foobar not deleted!
1152 cd ..
1153 rd /s/q foobar
1154 ) else echo foobar deleted
1155 echo --- on success conditional and
1156 call :setError 456 && echo foo3 > foo3
1157 if exist foo3 (
1158 echo foo3 created
1159 del foo3
1160 ) else echo foo3 not created
1161 echo bar4 && echo foo4
1162 echo --- on failure conditional or
1163 call :setError 789 || echo foo5
1164 echo foo6 || echo bar6 > bar6
1165 if exist bar6 (
1166 echo bar6 created
1167 del bar6
1170 echo ------------ Testing cd ------------
1171 mkdir foobar
1172 cd foobar
1173 echo blabla > singleFile
1174 dir /b
1175 echo Current dir: %CD%
1177 cd ..
1179 cd foobar@space@
1181 cd ..
1183 cd @space@foobar
1185 cd..
1187 cd foobar
1188 cd..@space@
1190 if not exist foobar (cd ..)
1191 cd foobar
1192 cd@tab@..@tab@@space@@tab@
1194 if not exist foobar (cd ..)
1195 cd foobar
1196 mkdir "bar bak"
1197 cd "bar bak"
1199 cd ..
1200 cd ".\bar bak"
1202 cd ..
1203 cd .\"bar bak"
1205 cd ..
1206 cd bar bak
1208 cd "bar bak@space@"@tab@@space@
1210 cd ..\..
1212 rd /Q/s foobar
1213 mkdir foobar
1214 cd /d@tab@foobar
1216 cd ..
1217 rd /q/s foobar
1219 echo ------------ Testing type ------------
1220 echo bar> foobaz
1221 @echo on
1222 type foobaz
1223 echo ---
1224 @echo off
1225 type foobaz@tab@
1226 echo ---1
1227 type ."\foobaz"
1228 echo ---2
1229 type ".\foobaz"
1230 echo ---3
1231 echo foo> foobay
1232 echo ---4
1233 type foobaz foobay > foobax 2> foobaw
1234 echo ---5
1235 type foobax
1236 echo ---6
1237 type foobaw
1238 echo ---7
1239 del foobaz foobay foobax foobaw
1241 echo ------------ Testing NUL ------------
1242 md foobar & cd foobar
1243 rem NUL file (non) creation + case insensitivity
1244 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
1245 echo > bar
1246 echo foo > NUL
1247 dir /b /a-d
1248 echo foo > nul
1249 dir /b /a-d
1250 echo foo > NuL
1251 @tab@dir /b@tab@/a-d
1252 del bar
1253 rem NUL not special everywhere
1254 call :setError 123
1255 echo NUL> foo
1256 if not exist foo (echo foo should have been created) else (
1257 type foo
1258 del foo
1260 rem Empty file creation
1261 copy nul foo > nul
1262 if exist foo (
1263 echo foo created
1264 del foo
1265 type foo
1266 ) else (
1267 echo ***
1269 echo 1234 >a.a
1270 copy a.a+NUL b.b >nul
1271 call :CheckFileSize a.a 7 b.b 8
1272 copy NUL+a.a b.b >nul
1273 call :CheckFileSize a.a 7 b.b 8
1274 mkdir subdir
1275 copy a.a+NUL subdir\ >nul
1276 call :CheckFileSize a.a 7 subdir\a.a 8
1277 del subdir\a.a
1278 cd subdir
1279 copy ..\a.a NUL >nul
1280 if exist a.a echo Failed
1281 cd ..
1282 rd subdir /s /q
1283 del a.a b.b
1284 cd .. & rd foobar /s /q
1286 echo ------------ Testing if/else ------------
1287 echo --- if/else should work with blocks
1288 if 0 == 0 (
1289 echo if seems to work
1290 ) else (
1291 echo if seems to be broken
1293 if 1 == 0 (
1294 echo else seems to be broken
1295 ) else (
1296 echo else seems to work
1298 if /c==/c (
1299 echo if seems not to detect /c as parameter
1300 ) else (
1301 echo parameter detection seems to be broken
1303 SET elseIF=0
1304 if 1 == 1 (
1305 SET /a elseIF=%elseIF%+1
1306 ) else if 1 == 1 (
1307 SET /a elseIF=%elseIF%+2
1308 ) else (
1309 SET /a elseIF=%elseIF%+2
1311 if %elseIF% == 1 (
1312 echo else if seems to work
1313 ) else (
1314 echo else if seems to be broken
1316 SET elseIF=0
1317 if 1 == 2 (
1318 SET /a elseIF=%elseIF%+2
1319 ) else if 1 == 1 (
1320 SET /a elseIF=%elseIF%+1
1321 ) else (
1322 SET /a elseIF=%elseIF%+2
1324 if %elseIF% == 1 (
1325 echo else if seems to work
1326 ) else (
1327 echo else if seems to be broken
1329 SET elseIF=0
1330 if 1 == 2 (
1331 SET /a elseIF=%elseIF%+2
1332 ) else if 1 == 2 (
1333 SET /a elseIF=%elseIF%+2
1334 ) else (
1335 SET /a elseIF=%elseIF%+1
1337 if %elseIF% == 1 (
1338 echo else if seems to work
1339 ) else (
1340 echo else if seems to be broken
1342 if "x" == "a" (
1343 echo broken1
1344 ) else (
1345 echo expected1
1346 if "y" == "b" echo broken2
1347 echo expected post-embedded if
1349 if ()==() (
1350 echo comparison operators surrounded by brackets seem to work
1351 ) else (
1352 echo comparison operators surrounded by brackets seem to be broken
1354 if 1(==1( (
1355 echo comparison operators surrounded by brackets seem to work
1356 ) else (
1357 echo comparison operators surrounded by brackets seem to be broken
1359 if )==) (
1360 echo comparison operators surrounded by brackets seem to work
1361 ) else (
1362 echo comparison operators surrounded by brackets seem to be broken
1364 if /i not (a)==(b) (
1365 echo comparison operators surrounded by brackets seem to work
1366 ) else (
1367 echo comparison operators surrounded by brackets seem to be broken
1369 if defined windir echo windir is defined
1370 if not defined windir echo windir is defined
1371 if not exist %windir% (
1372 echo windir does not exist
1373 ) else (
1374 echo windir does exist
1376 if 1 == 0 (
1377 echo 1 == 0 should not be true
1378 @space@
1379 ) else echo block containing a line with just space seems to work
1380 if 1 == 0 (
1381 echo 1 == 0 should not be true
1382 @tab@
1383 ) else echo block containing a line with just tab seems to work
1384 if 1 == 0 (
1385 echo 1 == 0 should not be true
1386 @space@@tab@
1387 ) else echo block containing a line with just space and tab seems to work
1388 if 1 == 0 (
1389 echo 1 == 0 should not be true
1390 @tab@@space@
1391 ) else echo block containing a line with just tab and space seems to work
1392 if 1 == 0 (
1393 echo 1 == 0 should not be true
1394 @space@
1395 @space@
1396 ) else echo block containing two lines with just space seems to work
1397 if 1 == 0 (
1398 echo 1 == 0 should not be true
1399 @tab@
1400 @tab@
1401 ) else echo block containing two lines with just tab seems to work
1403 echo @if 1 == 1 (> blockclosing.cmd
1404 echo echo with closing bracket>> blockclosing.cmd
1405 echo )>> blockclosing.cmd
1406 cmd.exe /Q /C blockclosing.cmd
1407 echo %ERRORLEVEL% ok
1409 echo @if 1 == 1 (> blockclosing.cmd
1410 echo echo without closing bracket first>> blockclosing.cmd
1411 echo echo without closing bracket second>> blockclosing.cmd
1412 cmd.exe /Q /C blockclosing.cmd
1413 echo %ERRORLEVEL% two lines
1415 echo echo before both blocks> blockclosing.cmd
1416 echo @if 1 == 1 (>> blockclosing.cmd
1417 echo echo before nested block without closing bracket>> blockclosing.cmd
1418 echo @if 2 == 2 (>> blockclosing.cmd
1419 echo echo without closing bracket>> blockclosing.cmd
1420 echo )>> blockclosing.cmd
1421 echo echo outside of block without closing bracket>> blockclosing.cmd
1422 cmd.exe /Q /C blockclosing.cmd
1423 echo %ERRORLEVEL% nested
1425 del blockclosing.cmd
1426 echo --- case sensitivity with and without /i option
1427 if bar==BAR echo if does not default to case sensitivity
1428 if not bar==BAR echo if seems to default to case sensitivity
1429 if /i foo==FOO echo if /i seems to work
1430 if /i not foo==FOO echo if /i seems to be broken
1431 if /I foo==FOO echo if /I seems to work
1432 if /I not foo==FOO echo if /I seems to be broken
1434 echo --- string comparisons
1435 if abc == abc (echo equal) else echo non equal
1436 if abc =="abc" (echo equal) else echo non equal
1437 if "abc"== abc (echo equal) else echo non equal
1438 if "abc"== "abc" (echo equal) else echo non equal
1440 echo --- tabs handling
1441 if@tab@1==1 echo doom
1442 if @tab@1==1 echo doom
1443 if 1==1 (echo doom) else@tab@echo quake
1444 if@tab@not @tab@1==@tab@0 @tab@echo lol
1445 if 1==0@tab@(echo doom) else echo quake
1446 if 1==0 (echo doom)@tab@else echo quake
1447 if 1==0 (echo doom) else@tab@echo quake
1449 echo --- comparison operators
1450 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
1451 echo ------ for strings
1452 rem NT4 stops processing of the whole batch file as soon as it finds a
1453 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
1454 rem can't test those here.
1455 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
1456 if LSS LSS LSS (echo bar)
1457 if 1.1 LSS 1.10 (echo floats are handled as strings)
1458 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
1459 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
1460 if /i foo LSS FoOc echo if /i seems to work for LSS
1461 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
1462 set WINE_STR_PARMS=A B AB BA AA
1463 for %%i in (%WINE_STR_PARMS%) do (
1464 for %%j in (%WINE_STR_PARMS%) do (
1465 call :LSStest %%i %%j))
1466 if b LSS B (echo b LSS B) else echo NT4
1467 if /I b LSS B echo b LSS B insensitive
1468 if b LSS A echo b LSS A
1469 if /I b LSS A echo b LSS A insensitive
1470 if a LSS B (echo a LSS B) else echo NT4
1471 if /I a LSS B echo a LSS B insensitive
1472 if A LSS b echo A LSS b
1473 if /I A LSS b echo A LSS b insensitive
1474 for %%i in (%WINE_STR_PARMS%) do (
1475 for %%j in (%WINE_STR_PARMS%) do (
1476 call :LEQtest %%i %%j))
1477 if b LEQ B (echo b LEQ B) else echo NT4
1478 if /I b LEQ B echo b LEQ B insensitive
1479 if b LEQ A echo b LEQ A
1480 if /I b LEQ A echo b LEQ A insensitive
1481 if a LEQ B (echo a LEQ B) else echo NT4
1482 if /I a LEQ B echo a LEQ B insensitive
1483 if A LEQ b echo A LEQ b
1484 if /I A LEQ b echo A LEQ b insensitive
1485 for %%i in (%WINE_STR_PARMS%) do (
1486 for %%j in (%WINE_STR_PARMS%) do (
1487 call :EQUtest %%i %%j))
1488 if /I A EQU a echo A EQU a insensitive
1489 for %%i in (%WINE_STR_PARMS%) do (
1490 for %%j in (%WINE_STR_PARMS%) do (
1491 call :NEQtest %%i %%j))
1492 for %%i in (%WINE_STR_PARMS%) do (
1493 for %%j in (%WINE_STR_PARMS%) do (
1494 call :GEQtest %%i %%j))
1495 for %%i in (%WINE_STR_PARMS%) do (
1496 for %%j in (%WINE_STR_PARMS%) do (
1497 call :GTRtest %%i %%j))
1499 echo ------------ Testing if/exist ------------
1500 mkdir subdir
1501 echo something>subdir\bar
1502 echo something else>foo
1503 if exist foo (
1504 echo exist explicit works
1505 ) else (
1506 echo ERROR exist explicit broken
1508 if exist bar (
1509 echo ERROR exist explicit unknown file broken
1510 ) else (
1511 echo exist explicit unknown file works
1513 if exist subdir\bar (
1514 echo exist explicit in subdir works
1515 ) else (
1516 echo ERROR exist explicit in subdir broken
1518 if exist fo* (
1519 echo exist simple wildcard works
1520 ) else (
1521 echo ERROR exist simple wildcard broken
1523 if exist subdir\ba* (
1524 echo exist wildcard works
1525 ) else (
1526 echo ERROR exist wildcard broken
1528 if not exist subdir\ba* (
1529 echo ERROR negate exist wildcard broken
1530 ) else (
1531 echo negate exist wildcard works
1533 if exist idontexist\ba* (
1534 echo ERROR exist wildcard bad subdir broken
1535 ) else (
1536 echo exist wildcard bad subdir broken works
1538 if exist subdir (
1539 echo exist subdir ok
1540 ) else (
1541 echo ERROR exist subdir not working
1543 if exist subdir\. (
1544 echo exist subdir with \. ok
1545 ) else (
1546 echo ERROR exist subdir with \. not working
1548 if exist subdir\ (
1549 echo exist subdir with \ ok
1550 ) else (
1551 echo ERROR exist subdir with \ not working
1553 if exist "subdir\" (
1554 echo exist subdir with \ and quotes ok
1555 ) else (
1556 echo ERROR exist subdir with \ and quotes not working
1558 if exist subdir/. (
1559 echo exist subdir with /. ok
1560 ) else (
1561 echo ERROR exist subdir with /. not working
1563 if exist subdir/ (
1564 echo exist subdir with / ok
1565 ) else (
1566 echo ERROR exist subdir with / not working
1568 if exist "subdir/" (
1569 echo exist subdir with / and quotes ok
1570 ) else (
1571 echo ERROR exist subdir with / and quotes not working
1573 if not exist "" (
1574 echo exist empty string works
1575 ) else (
1576 echo exist empty string broken
1578 del foo subdir\bar
1579 rd subdir
1581 echo ------ for numbers
1582 if -1 LSS 1 (echo negative numbers handled)
1583 if not -1 LSS -10 (echo negative numbers handled)
1584 if not 9 LSS 010 (echo octal handled)
1585 if not -010 LSS -8 (echo also in negative form)
1586 if 4 LSS 0x5 (echo hexa handled)
1587 if not -1 LSS -0x1A (echo also in negative form)
1588 if 11 LSS 101 (echo 11 LSS 101)
1589 set WINE_INT_PARMS=0 1 10 9
1590 for %%i in (%WINE_INT_PARMS%) do (
1591 for %%j in (%WINE_INT_PARMS%) do (
1592 call :LSStest %%i %%j))
1593 for %%i in (%WINE_INT_PARMS%) do (
1594 for %%j in (%WINE_INT_PARMS%) do (
1595 call :LEQtest %%i %%j))
1596 for %%i in (%WINE_INT_PARMS%) do (
1597 for %%j in (%WINE_INT_PARMS%) do (
1598 call :EQUtest %%i %%j))
1599 if 011 EQU 9 (echo octal ok)
1600 if 0xA1 EQU 161 (echo hexa ok)
1601 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
1602 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
1603 for %%i in (%WINE_INT_PARMS%) do (
1604 for %%j in (%WINE_INT_PARMS%) do (
1605 call :NEQtest %%i %%j))
1606 for %%i in (%WINE_INT_PARMS%) do (
1607 for %%j in (%WINE_INT_PARMS%) do (
1608 call :GEQtest %%i %%j))
1609 for %%i in (%WINE_INT_PARMS%) do (
1610 for %%j in (%WINE_INT_PARMS%) do (
1611 call :GTRtest %%i %%j))
1612 echo ------ for numbers and stringified numbers
1613 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
1614 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
1615 if '1' EQU 1 echo '1' EQU 1
1616 if 1 EQU '1' echo 1 EQU '1'
1617 if not "1" GEQ 1 (echo foo) else echo bar
1618 if "10" GEQ "1" echo "10" GEQ "1"
1619 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
1620 if 1 GEQ "1" echo 1 GEQ "1"
1621 if "1" GEQ "1" echo "1" GEQ "1"
1622 if '1' GEQ "1" echo '1' GEQ "1"
1623 if "10" GEQ "1" echo "10" GEQ "1"
1624 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
1625 for %%i in ("1" '1') do call :GEQtest %%i '1'
1626 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
1627 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
1628 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
1629 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
1630 if "10" GEQ "10" (echo "10" GEQ "10")
1631 echo --- unconditional ampersand after if one line
1632 if "0"=="0" echo 1 & echo 2 & echo 3 else echo 4
1633 echo ---
1634 echo x & if "0"=="1" echo 1 & echo 2
1635 echo ---
1636 echo x & if "0"=="1" echo 1 & echo 2 & echo 3
1637 echo ---
1638 echo x & if "0"=="1" (echo 1 & echo 2 & echo 3)
1639 echo ---
1640 echo x & if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
1641 echo ---
1642 goto :endIfCompOpsSubroutines
1644 rem IF subroutines helpers
1645 :LSStest
1646 if %1 LSS %2 echo %1 LSS %2
1647 goto :eof
1648 :LEQtest
1649 if %1 LEQ %2 echo %1 LEQ %2
1650 goto :eof
1651 :EQUtest
1652 if %1 EQU %2 echo %1 EQU %2
1653 goto :eof
1654 :NEQtest
1655 if %1 NEQ %2 echo %1 NEQ %2
1656 goto :eof
1657 :GEQtest
1658 if %1 GEQ %2 echo %1 GEQ %2
1659 goto :eof
1660 :GTRtest
1661 if %1 GTR %2 echo %1 GTR %2
1662 goto :eof
1664 :endIfCompOpsSubroutines
1665 set WINE_STR_PARMS=
1666 set WINE_INT_PARMS=
1668 echo ------------ Testing if/for ------------
1669 if ""=="" for %%i in (A) DO (echo %%i)
1670 if not ""=="" for %%i in (B) DO (echo %%i)
1672 echo ------------ Testing if/set ------------
1673 rem a left parenthesis is part of the value, not the start of an 'if' block
1674 set x=C:\Program Files (x86)
1675 if ""=="" set y=%x%\dummy
1676 echo %y%
1677 if 1 == 1 set z= (
1678 echo '%z%'
1679 rem 'set' in one-line 'if' statement does not interfere with other 'if' blocks
1680 setlocal enableDelayedExpansion
1681 if 1 == 1 (
1682 if 1 == 1 set z=zeta
1683 if 1 == 1 (
1684 echo !z!
1687 endlocal
1689 echo --- Testing if + var subst in delayed expansion mode
1690 setlocal enableDelayedExpansion
1691 for %%i in (abc 10.0 11.0) do (
1692 set result=%%i
1693 echo [DEBUG] checking {!result!}
1694 if "!result:~0,3!"=="10." (
1695 echo SDKVER=!result!
1698 endlocal
1700 echo ------------ Testing for ------------
1701 echo --- plain FOR
1702 for %%i in (A B C) do echo %%i
1703 for %%i in (A B C) do echo %%I
1704 for %%i in (A B C) do echo %%j
1705 for %%i in (A B C) do call :forTestFun1 %%i
1706 for %%i in (1,4,1) do echo %%i
1707 for %%i in (A, B,C) do echo %%i
1708 for %%i in (X) do echo %%i
1709 for@tab@%%i in (X2) do echo %%i
1710 for %%i in@tab@(X3) do echo %%i
1711 for %%i in (@tab@ foo@tab@) do echo %%i
1712 for@tab@ %%i in@tab@(@tab@M) do echo %%i
1713 for %%i@tab@in (X)@tab@do@tab@echo %%i
1714 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
1715 for %%i in (`echo A B`) do echo %%i
1716 for %%i in ('echo A B') do echo %%i
1717 for %%i in ("echo A B") do echo %%i
1718 for %%i in ("A B" C) do echo %%i
1719 goto :endForTestFun1
1720 :forTestFun1
1721 echo %1
1722 goto :eof
1723 :endForTestFun1
1724 echo --- imbricated FORs
1725 for %%i in (X) do (
1726 for %%j in (Y) do (
1727 echo %%i %%j))
1728 for %%i in (X) do (
1729 for %%I in (Y) do (
1730 echo %%i %%I))
1731 for %%i in (A B) do (
1732 for %%j in (C D) do (
1733 echo %%i %%j))
1734 for %%i in (A B) do (
1735 for %%j in (C D) do (
1736 call :forTestFun2 %%i %%j ))
1737 goto :endForTestFun2
1738 :forTestFun2
1739 echo %1 %2
1740 goto :eof
1741 :endForTestFun2
1742 echo --- nested FORs and args tempering
1743 set "WINE_ARGS= -foo=bar -x=y"
1744 :test_for_loop_params_parse
1745 for /F "tokens=1,* delims= " %%a in ("%WINE_ARGS%") do (
1746 for /F "tokens=1,2 delims==" %%1 in ("%%a") do (
1747 echo inner argument {%%1, %%2}
1749 set "WINE_ARGS=%%b"
1750 goto :test_for_loop_params_parse
1752 set "WINE_ARGS="
1753 echo --- nesting and delayed expansion
1754 setlocal enabledelayedexpansion
1755 set WINE_ARGS=1
1756 for %%a in (a b) do (
1757 set /a WINE_ARGS+=1
1758 echo %%a %WINE_ARGS% !WINE_ARGS!
1759 for /l %%b in (1 1 !WINE_ARGS!) do (
1760 if !WINE_ARGS!==%%b (echo %%b-A1) else echo %%b-A2
1761 if %WINE_ARGS%==%%b (echo %%b-B1) else echo %%b-B2
1764 setlocal disabledelayedexpansion
1765 echo --- nesting if/for
1766 for %%a in ("f"
1769 ) do if #==# (echo %%a)
1771 mkdir foobar & cd foobar
1772 mkdir foo
1773 mkdir bar
1774 mkdir baz
1775 mkdir pop
1776 echo > bazbaz
1777 echo --- basic wildcards
1778 for %%i in (ba*) do echo %%i
1779 echo --- wildcards in subdirs
1780 echo something>pop\bar1
1781 echo something>pop\bar2.txt
1782 echo something>pop\bar3
1783 for %%f in (pop\ba*) do ( call echo %%f )
1784 rmdir /s/q pop
1785 echo --- for /d
1786 for /d %%i in (baz foo bar) do echo %%i 2>&1
1787 rem Confirm we don't match files:
1788 for /d %%i in (bazb*) do echo %%i 2>&1
1789 for /d %%i in (bazb2*) do echo %%i 2>&1
1790 rem Show we pass through non wildcards
1791 for /d %%i in (PASSED) do echo %%i
1792 for /d %%i in (xxx) do (
1793 echo %%i - Should be xxx
1794 echo Expected second line
1796 rem Show we issue no messages on failures
1797 for /d %%i in (FAILED?) do echo %%i 2>&1
1798 for /d %%i in (FAILED?) do (
1799 echo %%i - Unexpected!
1800 echo FAILED Unexpected second line
1802 for /d %%i in (FAILED*) do echo %%i 2>&1
1803 for /d %%i in (FAILED*) do (
1804 echo %%i - Unexpected!
1805 echo FAILED Unexpected second line
1807 rem FIXME can't test wildcard expansion here since it's listed in directory
1808 rem order, and not in alphabetic order.
1809 rem Proper testing would need a currently missing "sort" program implementation.
1810 rem for /d %%i in (ba*) do echo %%i>> tmp
1811 rem sort < tmp
1812 rem del tmp
1813 rem for /d %%i in (?a*) do echo %%i>> tmp
1814 rem sort < tmp
1815 rem del tmp
1816 rem for /d %%i in (*) do echo %%i>> tmp
1817 rem sort < tmp
1818 rem del tmp
1819 echo > baz\bazbaz
1820 goto :TestForR
1822 :SetExpected
1823 del temp.bat 2>nul
1824 call :WriteLine set WINE_found=N
1825 for /l %%i in (1,1,%WINE_expectedresults%) do (
1826 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%~1" set WINE_found=Y
1827 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
1828 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
1830 call :WriteLine echo Got unexpected result: "%%%%~1"
1831 goto :eof
1833 :WriteLine
1834 echo %*>> temp.bat
1835 goto :EOF
1837 :ValidateExpected
1838 del temp.bat 2>nul
1839 for /l %%i in (1,1,%WINE_expectedresults%) do (
1840 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
1842 call temp.bat
1843 del temp.bat 2>nul
1844 goto :eof
1846 :TestForR
1847 rem %CD% does not work on NT4 so use the following workaround
1848 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
1850 echo --- for /R
1851 echo Plain directory enumeration
1852 set WINE_expectedresults=4
1853 set WINE_expectedresults.1=%WINE_CURDIR%\.
1854 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1855 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1856 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1857 call :SetExpected
1858 for /R %%i in (.) do call temp.bat "%%i"
1859 call :ValidateExpected
1861 echo Plain directory enumeration from provided root
1862 set WINE_expectedresults=4
1863 set WINE_expectedresults.1=%WINE_CURDIR%\.
1864 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1865 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1866 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1867 if "%CD%"=="" goto :SkipBrokenNT4
1868 call :SetExpected
1869 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat "%%i"
1870 call :ValidateExpected
1871 :SkipBrokenNT4
1873 echo File enumeration
1874 set WINE_expectedresults=2
1875 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1876 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1877 call :SetExpected
1878 for /R %%i in (baz*) do call temp.bat "%%i"
1879 call :ValidateExpected
1881 echo File enumeration from provided root
1882 set WINE_expectedresults=2
1883 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1884 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1885 call :SetExpected
1886 for /R %%i in (baz*) do call temp.bat "%%i"
1887 call :ValidateExpected
1889 echo Mixed enumeration
1890 set WINE_expectedresults=6
1891 set WINE_expectedresults.1=%WINE_CURDIR%\.
1892 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1893 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1894 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1895 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1896 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1897 call :SetExpected
1898 for /R %%i in (. baz*) do call temp.bat "%%i"
1899 call :ValidateExpected
1901 echo Mixed enumeration from provided root
1902 set WINE_expectedresults=6
1903 set WINE_expectedresults.1=%WINE_CURDIR%\.
1904 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1905 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1906 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1907 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1908 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1909 call :SetExpected
1910 for /R %%i in (. baz*) do call temp.bat "%%i"
1911 call :ValidateExpected
1913 echo With duplicates enumeration
1914 set WINE_expectedresults=12
1915 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
1916 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
1917 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
1918 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1919 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
1920 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
1921 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
1922 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
1923 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1924 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1925 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1926 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1927 call :SetExpected
1928 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat "%%i"
1929 call :ValidateExpected
1931 echo Strip missing wildcards, keep unwildcarded names
1932 set WINE_expectedresults=6
1933 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1934 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1935 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1936 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1937 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1938 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1939 call :SetExpected
1940 for /R %%i in (baz* fred* jim) do call temp.bat "%%i"
1941 call :ValidateExpected
1943 echo for /R passed
1944 echo --- Complex wildcards unix and windows slash
1945 cd ..
1946 echo Windows slashes, valid path
1947 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1948 for %%f in (foobar\baz\*) do echo WC : %%f
1949 echo Windows slashes, invalid path
1950 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1951 for %%f in (foobar\jim\*) do echo WC : %%f
1952 echo Unix slashes, valid path
1953 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1954 for %%f in (foobar/baz/*) do echo WC : %%f
1955 echo Unix slashes, invalid path
1956 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1957 for %%f in (foobar/jim/*) do echo WC : %%f
1958 echo Done
1959 rd /s/Q foobar
1960 echo --- for /L
1961 rem Some cases loop forever writing 0s, like e.g. (1,0,1), (1,a,3) or (a,b,c); those can't be tested here
1962 for /L %%i in (1,2,0) do echo %%i
1963 for@tab@/L %%i in (1,2,0) do echo %%i
1964 for /L %%i in (1,2,6) do echo %%i
1965 for /l %%i in (1 ,2,6) do echo %%i
1966 for /L %%i in (a,2,3) do echo %%i
1967 for /L %%i in (1,2,-1) do echo %%i
1968 for /L %%i in (-4,-1,-1) do echo %%i
1969 for /L %%i in (1,-2,-2) do echo %%i
1970 for /L %%i in (1,2,a) do echo %%i
1971 echo ErrorLevel %ErrorLevel%
1972 for /L %%i in (1,a,b) do echo %%i
1973 echo ErrorLevel %ErrorLevel%
1974 rem Test boundaries
1975 for /l %%i in (1,1,4) do echo %%i
1976 for /l %%i in (1,2,4) do echo %%i
1977 for /l %%i in (4,-1,1) do echo %%i
1978 for /l %%i in (4,-2,1) do echo %%i
1979 for /l %%i in (1,-1,4) do echo %%i
1980 for /l %%i in (4,1,1) do echo %%i
1981 for /L %%i in (a,2,b) do echo %%i
1982 for /L %%i in (1,1,1) do echo %%i
1983 for /L %%i in (1,-2,-1) do echo %%i
1984 for /L %%i in (-1,-1,-1) do echo %%i
1985 for /L %%i in (1,2, 3) do echo %%i
1986 rem Test zero iteration skips the body of the for
1987 for /L %%i in (2,2,1) do (
1988 echo %%i
1989 echo FAILED
1991 echo --- rems inside for loops
1992 for /f %%i IN ("hello") DO (
1993 REM foo|echo ERROR unexpected execution 1
1994 @REM foo|echo ERROR unexpected execution 2
1995 @ REM foo|echo ERROR unexpected execution 3
1997 echo --- ifs inside for loops
1998 for %%i in (test) do (
1999 echo a1
2000 if 1==1 (
2001 echo b1
2002 ) else (
2003 echo c1
2005 echo d1
2007 for %%i in (test) do (
2008 echo a2
2009 if 1==1 (
2010 echo b2
2011 ) else echo c2
2012 echo d2
2014 for %%i in (test) do (
2015 echo a3
2016 if 1==0 (
2017 echo b3
2018 ) else echo c3
2019 echo d3
2021 for %%i in (test) do (
2022 echo a4
2023 if 1==0 (
2024 echo b4
2025 ) else (
2026 echo c4
2028 echo d4
2030 echo --- set /a
2031 goto :testseta
2033 Rem Ideally for /f can be used rather than building a command to execute
2034 rem but that does not work on NT4
2035 :checkenvvars
2036 if "%1"=="" goto :eof
2037 call :executecmd set wine_result=%%%1%%
2038 if "%wine_result%"=="%2" (
2039 echo %1 correctly %2
2040 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
2041 set %1=
2042 shift
2043 shift
2044 rem shift
2045 goto :checkenvvars
2046 :executecmd
2048 goto :eof
2050 :testseta
2051 rem No output when using "set expr" syntax, unless in interactive mode
2052 rem Need to use "set envvar=expr" to use in a batch script
2053 echo ------ individual operations
2054 set WINE_foo=0
2055 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
2056 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
2057 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
2058 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
2059 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
2060 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
2061 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
2062 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
2063 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
2064 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
2065 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
2066 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
2067 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
2068 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
2069 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
2070 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
2071 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
2072 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
2073 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
2074 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
2075 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
2076 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
2077 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
2078 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
2079 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
2080 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
2081 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
2082 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
2083 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
2084 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
2085 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
2086 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
2087 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
2088 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
2089 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
2090 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
2091 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
2092 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
2093 echo ------ precedence and grouping
2094 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
2095 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
2096 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
2097 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
2098 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
2099 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
2100 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
2101 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
2102 echo ------ octal and hexadecimal
2103 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
2104 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
2105 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
2106 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
2107 echo ------ variables
2108 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
2109 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
2110 set /a WINE_foo=WINE_bar=3, WINE_baz=1, WINE_baz+=WINE_bar, WINE_baz & call :checkenvvars WINE_foo 3 WINE_bar 3 WINE_baz 4
2111 set WINE_bar=3
2112 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
2113 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
2114 set WINE_bar=4
2115 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
2116 set WINE_bar=4
2117 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
2118 set WINE_bar=-7
2119 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
2120 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
2121 set WINE_bar=1
2122 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
2123 set WINE_bar=4
2124 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
2125 set WINE_bar=1
2126 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
2127 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
2128 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
2129 set WINE_baz=4
2130 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
2131 echo --- quotes
2132 set /a WINE_foo=1
2133 call :checkenvvars WINE_foo 1
2134 set /a "WINE_foo=1"
2135 call :checkenvvars WINE_foo 1
2136 set /a WINE_foo=1,WINE_bar=2
2137 call :checkenvvars WINE_foo 1 WINE_bar 2
2138 set /a "WINE_foo=1,WINE_bar=2"
2139 call :checkenvvars WINE_foo 1 WINE_bar 2
2140 set /a "WINE_foo=1","WINE_bar=2"
2141 call :checkenvvars WINE_foo 1 WINE_bar 2
2142 set /a ""WINE_foo=1","WINE_bar=2""
2143 call :checkenvvars WINE_foo 1 WINE_bar 2
2144 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
2145 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
2146 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
2147 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
2148 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
2149 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
2150 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
2151 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
2152 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
2153 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
2154 set /a """"""WINE_foo=1""""""
2155 call :checkenvvars WINE_foo 1
2156 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
2157 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
2158 set /a WINE_foo="3"+"4"+"5+6"
2159 call :checkenvvars WINE_foo 18
2160 set WINE_foo=3
2161 set /a WINE_bar="WINE_""foo"+4
2162 call :checkenvvars WINE_foo 3 WINE_bar 7
2163 echo --- whitespace are ignored between double char operators
2164 set WINE_foo=4
2165 set WINE_bar=5
2166 set /a WINE_foo + = 6
2167 set /a WINE_bar * = WINE_foo
2168 call :checkenvvars WINE_foo 10 WINE_bar 50
2169 set WINE_foo=4
2170 set WINE_bar=5
2171 set /a WINE_foo + = "6 < < 7"
2172 set /a WINE_bar * = WINE_foo + WINE_foo
2173 call :checkenvvars WINE_foo 772 WINE_bar 7720
2174 set /a WINE_foo=6 7
2175 set /a WINE_ var1=8
2176 set WINE_foo=
2177 echo --- invalid operator sequence
2178 set WINE_foo=4
2179 set /a =4
2180 set /a *=4
2181 set /a ^>=4"
2182 set /a ^<=4"
2183 set /a WINE_foo^>^<=4
2184 echo %WINE_foo%
2185 set /a WINE_foo^>^>^>=4
2186 echo %WINE_foo%
2187 echo ----- negative prefix
2188 set /a WINE_foo=-1
2189 call :checkenvvars WINE_foo -1
2190 set /a WINE_foo=--1
2191 call :checkenvvars WINE_foo 1
2192 set /a WINE_foo=3--3
2193 call :checkenvvars WINE_foo 6
2194 set /a WINE_foo=3---3
2195 call :checkenvvars WINE_foo 0
2196 set /a WINE_foo=3----3
2197 call :checkenvvars WINE_foo 6
2198 set /a WINE_foo=-~1
2199 call :checkenvvars WINE_foo 2
2200 set /a WINE_foo=~-1
2201 call :checkenvvars WINE_foo 0
2202 set /a WINE_foo=3+-~1
2203 call :checkenvvars WINE_foo 5
2204 set /a WINE_foo=3+~-1
2205 call :checkenvvars WINE_foo 3
2206 echo ----- assignment tests involving the end destination
2207 set WINE_foo=3
2208 set /a WINE_foo+=3+(WINE_foo=4)
2209 call :checkenvvars WINE_foo 11
2210 set WINE_foo=2
2211 set /a WINE_bar=3+(WINE_foo=6)
2212 call :checkenvvars WINE_foo 6 WINE_bar 9
2213 set WINE_foo=2
2214 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
2215 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
2216 set WINE_foo=2
2217 set /a WINE_bar=WINE_foo=7
2218 call :checkenvvars WINE_foo 7 WINE_bar 7
2219 echo ----- equal precedence on stack
2220 rem Unary - don't reduce if precedence is equal
2221 set /a WINE_foo=!!1
2222 call :checkenvvars WINE_foo 1
2223 set /a WINE_foo=!!0
2224 call :checkenvvars WINE_foo 0
2225 set /a WINE_foo=~~1
2226 call :checkenvvars WINE_foo 1
2227 set /a WINE_foo=~~0
2228 call :checkenvvars WINE_foo 0
2229 set /a WINE_foo=--1
2230 call :checkenvvars WINE_foo 1
2231 set /a WINE_foo=+-1
2232 call :checkenvvars WINE_foo -1
2233 set /a WINE_foo=-+1
2234 call :checkenvvars WINE_foo -1
2235 set /a WINE_foo=++1
2236 call :checkenvvars WINE_foo 1
2237 set /a WINE_foo=!~1
2238 call :checkenvvars WINE_foo 0
2239 set /a WINE_foo=~!1
2240 call :checkenvvars WINE_foo -1
2241 set /a WINE_foo=!-1
2242 call :checkenvvars WINE_foo 0
2243 set /a WINE_foo=-!1
2244 call :checkenvvars WINE_foo 0
2245 set /a WINE_foo=!-0
2246 call :checkenvvars WINE_foo 1
2247 set /a WINE_foo=-!0
2248 call :checkenvvars WINE_foo -1
2249 rem Aritmatic - Reduce if precedence is equal
2250 set /a WINE_foo=10*5/2
2251 call :checkenvvars WINE_foo 25
2252 set /a WINE_foo=5/2*10
2253 call :checkenvvars WINE_foo 20
2254 set /a WINE_foo=10/5/2
2255 call :checkenvvars WINE_foo 1
2256 set /a WINE_foo=5%%2*4
2257 call :checkenvvars WINE_foo 4
2258 set /a WINE_foo=10-5+2
2259 call :checkenvvars WINE_foo 7
2260 set /a WINE_foo=1^<^<4^>^>1
2261 call :checkenvvars WINE_foo 8
2262 rem Assignment - don't reduce if precedence is equal
2263 set /a WINE_foo=5
2264 set /a WINE_bar=WINE_foo=6
2265 call :checkenvvars WINE_foo 6 WINE_bar 6
2267 echo --- for /F
2268 mkdir foobar & cd foobar
2269 echo ------ string argument
2270 rem NT4 does not support usebackq
2271 for /F %%i in ("a b c") do echo %%i
2272 for /F %%i in ( "a b c" ) do echo X%%iX
2273 for /f usebackq %%i in ('a b c') do echo %%i>output_file
2274 if not exist output_file (echo no output) else (type output_file & del output_file)
2275 for /f usebackq %%i in ( 'a b c' ) do echo X%%iX>output_file
2276 if not exist output_file (echo no output) else (type output_file & del output_file)
2277 for /f %%i in ("a ") do echo %%i
2278 for /f usebackq %%i in ('a ') do echo %%i>output_file
2279 if not exist output_file (echo no output) else (type output_file & del output_file)
2280 for /f %%i in ("a") do echo %%i
2281 for /f usebackq %%i in ('a') do echo %%i>output_file
2282 if not exist output_file (echo no output) else (type output_file & del output_file)
2283 fOr /f %%i in (" a") do echo %%i
2284 for /f usebackq %%i in (' a') do echo %%i>output_file
2285 if not exist output_file (echo no output) else (type output_file & del output_file)
2286 for /f %%i in (" a ") do echo %%i
2287 for /f usebackq %%i in (' a ') do echo %%i>output_file
2288 if not exist output_file (echo no output) else (type output_file & del output_file)
2289 echo ------ fileset argument
2290 echo --------- basic blank handling
2291 echo a b c>foo
2292 for /f %%i in (foo) do echo %%i
2293 echo a >foo
2294 for /f %%i in (foo) do echo %%i
2295 echo a>foo
2296 for /f %%i in (foo) do echo %%i
2297 echo a>foo
2298 for /f %%i in (foo) do echo %%i
2299 echo a >foo
2300 for /f %%i in (foo) do echo %%i
2301 echo. > foo
2302 for /f %%i in (foo) do echo %%i
2303 echo. >> foo
2304 echo b > foo
2305 for /f %%i in (foo) do echo %%i
2306 echo --------- multi-line with empty lines
2307 echo a Z f> foo
2308 echo. >> foo
2309 echo.>> foo
2310 echo b bC>> foo
2311 echo c>> foo
2312 echo. >> foo
2313 for /f %%b in (foo) do echo %%b
2314 echo --------- multiple files
2315 echo q w > bar
2316 echo.>> bar
2317 echo kkk>>bar
2318 for /f %%k in (foo bar) do echo %%k
2319 for /f %%k in (bar foo) do echo %%k
2320 echo ------ quoting and file access
2321 echo a > f.zzz
2322 echo b >> f.zzz
2323 erase f2.zzz
2324 for /f %%a in (f.zzz) do echo A%%a
2325 for /f %%a in ("f.zzz") do echo B%%a
2326 for /f %%a in (f2.zzz) do echo C%%a
2327 for /f %%a in ("f2.zzz") do echo D%%a
2328 for /f "usebackq" %%a in (f.zzz) do echo E%%a
2329 for /f "usebackq" %%a in ("f.zzz") do echo F%%a
2330 for /f "usebackq" %%a in (f2.zzz) do echo G%%a
2331 for /f "usebackq" %%a in ("f2.zzz") do echo H%%a
2332 for /f %%a in (f*.zzz) do echo I%%a
2333 for /f %%a in ("f*.zzz") do echo J%%a
2334 erase f.zzz
2335 echo ------ command argument
2336 rem Not implemented on NT4, need to skip it as no way to get output otherwise
2337 if "%CD%"=="" goto :SkipFORFcmdNT4
2338 for /f %%i in ('echo.Passed1') do echo %%i
2339 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
2340 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
2341 for /f "usebackq" %%i in (`"c:\windows\system32\cmd.exe" /C echo Passed4`) do echo %%i
2342 for /f "usebackq" %%i in (`""c:\windows\system32\cmd.exe" /C echo Passed5"`) do echo %%i
2343 for /f %%i in ( 'echo.Passed6' ) do echo %%i
2344 for /f "usebackq" %%i in ( `echo.Passed7` ) do echo %%i
2345 goto :ContinueFORF
2346 :SkipFORFcmdNT4
2347 for /l %%i in (1,1,7) do echo Missing functionality - Broken%%i
2348 :ContinueFORF
2349 rem FIXME: Rest not testable right now in wine: not implemented and would need
2350 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
2351 rem for a simple todo_wine test
2352 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
2353 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
2354 echo ------ eol option
2355 if "%CD%"=="" goto :SkipFORFeolNT4
2356 echo Line one>foo
2357 echo and Line two>>foo
2358 echo Line three>>foo
2359 for /f "eol=L" %%i in (foo) do echo %%i
2360 for /f "eol=a" %%i in (foo) do echo %%i
2361 del foo
2362 goto :ContinueFORFeol
2363 :SkipFORFeolNT4
2364 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
2365 :ContinueFORFeol
2366 for /f "eol=@" %%i in (" ad") do echo %%i
2367 for /f "eol=@" %%i in (" z@y") do echo %%i
2368 for /f "eol=|" %%i in ("a|d") do echo %%i
2369 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
2370 if not exist output_file (echo no output) else (del output_file)
2371 for /f "eol==" %%i in ("=y") do echo %%i > output_file
2372 if not exist output_file (echo no output) else (del output_file)
2373 echo ------ delims option
2374 for /f "delims=|" %%i in ("a|d") do echo %%i
2375 for /f "delims=|" %%i in ("a |d") do echo %%i
2376 for /f "delims=|" %%i in ("a d|") do echo %%i
2377 for /f "delims=| " %%i in ("a d|") do echo %%i
2378 for /f "delims==" %%i in ("C r=d|") do echo %%i
2379 for /f "delims=" %%i in ("foo bar baz") do echo %%i
2380 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
2381 echo ------ skip option
2382 echo a > foo
2383 echo b >> foo
2384 echo c >> foo
2385 for /f "skip=2" %%i in (foo) do echo %%i
2386 for /f "skip=3" %%i in (foo) do echo %%i > output_file
2387 if not exist output_file (echo no output) else (del output_file)
2388 for /f "skip=4" %%i in (foo) do echo %%i > output_file
2389 if not exist output_file (echo no output) else (del output_file)
2390 for /f "skip=02" %%i in (foo) do echo %%i
2391 for /f "skip=0x2" %%i in (foo) do echo %%i
2392 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
2393 if not exist output_file (echo no output) else (del output_file)
2394 echo ------ tokens= option
2395 rem Basic
2396 for /f %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2397 for /f "tokens=2" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2398 for /f "tokens=1,3,5-7" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2399 rem Show * means the rest
2400 for /f "tokens=1,5*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2401 for /f "tokens=6,9*" %%i in ("a b c d e f g h i j k l m n o p q r s t u v w x y z") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2402 rem Show * means the rest (not tokenized and rebuilt)
2403 for /f "tokens=6,9*" %%i in ("a b c d e f g h i j k l m n;;== o p q r s t u v w x y z") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2404 rem Order is irrelevant
2405 for /f "tokens=1,2,3*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2406 for /f "tokens=3,2,1*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2407 rem Duplicates are ignored
2408 for /f "tokens=1,2,1*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2409 rem Large tokens are allowed
2410 for /f "tokens=25,1,5*" %%i in ("a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2411 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
2412 for /f "tokens=1,1,1,2*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2413 for /f "tokens=1-2,1-2,1-2" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2414 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
2415 for /f "tokens=1-20" %%u in ("a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z") do echo u=%%u v=%%v w=%%w x=%%x y=%%y z=%%z A=%%A a=%%a
2416 for /f "tokens=1-20" %%U in ("a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z") do echo U=%%U V=%%V W=%%W X=%%X Y=%%Y Z=%%Z A=%%A a=%%a
2417 rem Show negative ranges have no effect
2418 for /f "tokens=1-3,5" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2419 for /f "tokens=3-1,5" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m o=%%o
2420 rem Show duplicates stop * from working
2421 for /f "tokens=1,2,3*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2422 for /f "tokens=1,1,3*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2423 for /f "tokens=2,2,3*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2424 for /f "tokens=3,2,3*" %%i in ("a b c d e f g") do echo h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o
2425 rem Special case tokens=* or tokens=n,*
2426 echo 3.14>testfile
2427 FOR /F "tokens=*" %%A IN (testfile) DO @echo 1:%%A,%%B
2428 FOR /F "tokens=1*" %%A IN (testfile) DO @echo 2:%%A,%%B
2429 FOR /F "tokens=2*" %%A IN (testfile) DO @echo 3:%%A,%%B
2430 FOR /F "tokens=1,*@tab@delims=." %%A IN (testfile) DO @echo 4:%%A,%%B
2431 del testfile
2432 cd ..
2433 rd /s/q foobar
2434 echo ------ parameter splitting
2435 echo forFParameterSplittingFunc "myparam1=myvalue1 myparam2=myparam2" mytest> foo
2436 for /f "tokens=1 delims=;" %%i in (foo) do (call :%%i)
2437 del foo
2438 for /f "tokens=1 delims=;" %%i in ("forFParameterSplittingFunc "myparam1^=myvalue1 myparam2^=myparam2" mytest") do (call :%%i)
2439 goto :forFParameterSplittingEnd
2440 :forFParameterSplittingFunc
2441 echo %~0 %~1 %~2 %~3 %~4 %~5
2442 goto :eof
2443 :forFParameterSplittingEnd
2444 echo 3.14>testfile
2445 FOR /F "delims=. tokens=*" %%A IN (testfile) DO @echo 4:%%A,%%B
2446 FOR /F "delims=. tokens=1*" %%A IN (testfile) DO @echo 5:%%A,%%B
2447 FOR /F "delims=. tokens=2*" %%A IN (testfile) DO @echo 6:%%A,%%B
2448 FOR /F "delims=. tokens=3*" %%A IN (testfile) DO @echo 7:%%A,%%B
2449 del testfile
2450 rem file contains NUL, created by the .exe
2451 for /f %%A in (nul_test_file) DO echo %%A
2452 for /f "tokens=*" %%A in (nul_test_file) DO echo %%A
2454 echo ------------ Testing del ------------
2455 echo abc > file
2456 echo deleting 'file'
2457 del file
2458 if errorlevel 0 (
2459 echo errorlevel is 0, good
2460 ) else (
2461 echo unexpected errorlevel, got %errorlevel%
2463 if not exist file (
2464 echo successfully deleted 'file'
2465 ) else (
2466 echo error deleting 'file'
2468 echo attempting to delete 'file', even though it is not present
2469 del file
2470 if errorlevel 0 (
2471 echo errorlevel is 0, good
2472 ) else (
2473 echo unexpected errorlevel, got %errorlevel%
2476 echo ------------ Testing del /a ------------
2477 del /f/q *.test > nul
2478 echo r > r.test
2479 attrib +r r.test
2480 echo not-r > not-r.test
2482 if not exist not-r.test echo not-r.test not found before delete, bad
2483 del /a:-r *.test
2484 if not exist not-r.test echo not-r.test not found after delete, good
2486 if not exist r.test echo r.test not found before delete, bad
2487 if exist r.test echo r.test found before delete, good
2488 del /a:r *.test
2489 if not exist r.test echo r.test not found after delete, good
2490 if exist r.test echo r.test found after delete, bad
2492 echo ------------ Testing del /q ------------
2493 mkdir del_q_dir
2494 cd del_q_dir
2495 echo abc > file1
2496 echo abc > file2.dat
2497 rem If /q doesn't work, cmd will prompt and the test case should hang
2498 del /q * > nul
2499 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
2500 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
2501 cd ..
2502 rmdir del_q_dir
2504 echo ------------ Testing del /s ------------
2505 mkdir "foo bar"
2506 cd "foo bar"
2507 mkdir "foo:"
2508 echo hi > file1.dat
2509 echo there > file2.dat
2510 echo bub > file3.dat
2511 echo bye > "file with spaces.dat"
2512 cd ..
2513 del /s file1.dat > nul
2514 del file2.dat /s > nul
2515 del "file3.dat" /s > nul
2516 del "file with spaces.dat" /s > nul
2517 cd "foo bar"
2518 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
2519 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
2520 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
2521 if exist "file with spaces.dat" del "file with spaces.dat"
2522 rmdir "foo:"
2523 cd ..
2524 rmdir "foo bar"
2526 echo ------------ Testing rename ------------
2527 mkdir foobar & cd foobar
2528 echo --- ren and rename are synonymous
2529 echo > foo
2530 rename foo bar
2531 if exist foo echo foo should be renamed!
2532 if exist bar echo foo renamed to bar
2533 ren bar foo
2534 if exist bar echo bar should be renamed!
2535 if exist foo echo bar renamed to foo
2536 echo --- name collision
2537 echo foo>foo
2538 echo bar>bar
2539 ren foo bar 2> nul
2540 type foo
2541 type bar
2542 rem no-op
2543 ren foo foo
2544 mkdir baz
2545 ren foo baz\abc
2546 echo --- rename read-only files
2547 echo > file1
2548 attrib +r file1
2549 ren file1 file2
2550 if not exist file1 (
2551 if exist file2 (
2552 echo read-only file renamed
2554 ) else (
2555 echo read-only file not renamed!
2557 echo --- rename directories
2558 mkdir rep1
2559 ren rep1 rep2
2560 if not exist rep1 (
2561 if exist rep2 (
2562 echo dir renamed
2565 attrib +r rep2
2566 ren rep2 rep1
2567 if not exist rep2 (
2568 if exist rep1 (
2569 echo read-only dir renamed
2572 echo --- rename in other directory
2573 if not exist baz\abc (
2574 echo rename impossible in other directory
2575 if exist foo echo original file still present
2576 ) else (
2577 echo shouldn't rename in other directory!
2578 if not exist foo echo original file not present anymore
2580 cd .. & rd /s/q foobar
2582 echo ------------ Testing move ------------
2583 mkdir foobar & cd foobar
2584 echo --- file move
2585 echo >foo
2586 move foo bar > nul 2>&1
2587 if not exist foo (
2588 if exist bar (
2589 echo file move succeeded
2592 echo bar>bar
2593 echo baz> baz
2594 move /Y bar baz > nul 2>&1
2595 if not exist bar (
2596 if exist baz (
2597 echo file move with overwrite succeeded
2599 ) else (
2600 echo file overwrite impossible!
2601 del bar
2603 type baz
2605 attrib +r baz
2606 move baz bazro > nul 2>&1
2607 if not exist baz (
2608 if exist bazro (
2609 echo read-only files are moveable
2610 move bazro baz > nul 2>&1
2612 ) else (
2613 echo read-only file not moved!
2615 attrib -r baz
2616 mkdir rep
2617 move baz rep > nul 2>&1
2618 if not exist baz (
2619 if exist rep\baz (
2620 echo file moved in subdirectory
2623 call :setError 0
2624 move rep\baz . > nul 2>&1
2625 move /Y baz baz > nul 2>&1
2626 if errorlevel 1 (
2627 echo moving a file to itself should be a no-op!
2628 ) else (
2629 echo moving a file to itself is a no-op
2631 echo ErrorLevel: %ErrorLevel%
2632 call :setError 0
2633 del baz
2634 echo --- directory move
2635 mkdir foo\bar
2636 mkdir baz
2637 echo baz2>baz\baz2
2638 move baz foo\bar > nul 2>&1
2639 if not exist baz (
2640 if exist foo\bar\baz\baz2 (
2641 echo simple directory move succeeded
2644 call :setError 0
2645 mkdir baz
2646 move baz baz > nul 2>&1
2647 echo moving a directory to itself gives error; errlevel %ErrorLevel%
2648 echo ------ dir in dir move
2649 rd /s/q foo
2650 mkdir foo bar
2651 echo foo2>foo\foo2
2652 echo bar2>bar\bar2
2653 move foo bar > nul 2>&1
2654 if not exist foo (
2655 if exist bar (
2656 dir /b /ad bar
2657 dir /b /a-d bar
2658 dir /b bar\foo
2661 cd .. & rd /s/q foobar
2663 echo ------------ Testing mkdir ------------
2664 call :setError 0
2665 echo --- md and mkdir are synonymous
2666 mkdir foobar
2667 echo %ErrorLevel%
2668 rmdir foobar
2669 md foobar
2670 echo %ErrorLevel%
2671 rmdir foobar
2672 echo --- creating an already existing directory/file must fail
2673 mkdir foobar
2674 md foobar
2675 echo %ErrorLevel%
2676 rmdir foobar
2677 echo > foobar
2678 mkdir foobar
2679 echo %ErrorLevel%
2680 del foobar
2681 echo --- multilevel path creation
2682 mkdir foo
2683 echo %ErrorLevel%
2684 mkdir foo\bar\baz
2685 echo %ErrorLevel%
2686 cd foo
2687 echo %ErrorLevel%
2688 cd bar
2689 echo %ErrorLevel%
2690 cd baz
2691 echo %ErrorLevel%
2692 echo > ..\..\bar2
2693 mkdir ..\..\..\foo\bar2
2694 echo %ErrorLevel%
2695 del ..\..\bar2
2696 mkdir ..\..\..\foo\bar2
2697 echo %ErrorLevel%
2698 rmdir ..\..\..\foo\bar2
2699 cd ..
2700 rmdir baz
2701 cd ..
2702 rmdir bar
2703 cd ..
2704 rmdir foo
2705 echo %ErrorLevel%
2706 echo --- trailing backslashes
2707 mkdir foo\\\\
2708 echo %ErrorLevel%
2709 if exist foo (rmdir foo & echo dir created
2710 ) else ( echo dir not created )
2711 echo %ErrorLevel%
2712 echo --- invalid chars
2713 mkdir ?
2714 echo mkdir ? gives errorlevel %ErrorLevel%
2715 call :setError 0
2716 mkdir ?\foo
2717 echo mkdir ?\foo gives errorlevel %ErrorLevel%
2718 call :setError 0
2719 mkdir foo\?
2720 echo mkdir foo\? gives errorlevel %ErrorLevel%
2721 if exist foo (rmdir foo & echo ok, foo created
2722 ) else ( echo foo not created )
2723 call :setError 0
2724 mkdir foo\bar\?
2725 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
2726 call :setError 0
2727 if not exist foo (
2728 echo bad, foo not created
2729 ) else (
2730 cd foo
2731 if exist bar (
2732 echo ok, foo\bar created
2733 rmdir bar
2735 cd ..
2736 rmdir foo
2738 echo --- multiple directories at once
2739 mkdir foobaz & cd foobaz
2740 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
2741 if exist foo (echo foo created) else echo foo not created!
2742 if exist bar (echo bar created) else echo bar not created!
2743 if exist foobar (echo foobar created) else echo foobar not created!
2744 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
2745 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
2746 if exist zabzab (echo zabzab created) else echo zabzab not created!
2747 cd .. & rd /s/q foobaz
2748 call :setError 0
2749 mkdir foo\*
2750 echo mkdir foo\* errorlevel %ErrorLevel%
2751 if exist foo (rmdir foo & echo ok, foo created
2752 ) else ( echo bad, foo not created )
2754 echo ------------ Testing rmdir ------------
2755 call :setError 0
2756 rem rd and rmdir are synonymous
2757 mkdir foobar
2758 rmdir foobar
2759 echo %ErrorLevel%
2760 if not exist foobar echo dir removed
2761 mkdir foobar
2762 rd foobar
2763 echo %ErrorLevel%
2764 if not exist foobar echo dir removed
2765 rem Removing nonexistent directory
2766 rmdir foobar
2767 echo %ErrorLevel%
2768 rem Removing single-level directories
2769 echo > foo
2770 rmdir foo
2771 echo %ErrorLevel%
2772 if exist foo echo file not removed
2773 del foo
2774 mkdir foo
2775 echo > foo\bar
2776 rmdir foo
2777 echo %ErrorLevel%
2778 if exist foo echo non-empty dir not removed
2779 del foo\bar
2780 mkdir foo\bar
2781 rmdir foo
2782 echo %ErrorLevel%
2783 if exist foo echo non-empty dir not removed
2784 rmdir foo\bar
2785 rmdir foo
2786 rem Recursive rmdir
2787 mkdir foo\bar\baz
2788 rmdir /s /Q foo
2789 if not exist foo (
2790 echo recursive rmdir succeeded
2791 ) else (
2792 rd foo\bar\baz
2793 rd foo\bar
2794 rd foo
2796 mkdir foo\bar\baz
2797 echo foo > foo\bar\brol
2798 rmdir /s /Q foo 2>&1
2799 if not exist foo (
2800 echo recursive rmdir succeeded
2801 ) else (
2802 rd foo\bar\baz
2803 del foo\bar\brol
2804 rd foo\bar
2805 rd foo
2807 rem multiples directories at once
2808 mkdir foobaz & cd foobaz
2809 mkdir foo
2810 mkdir bar\baz
2811 mkdir foobar
2812 rd /s/q foo bar foobar
2813 if not exist foo (echo foo removed) else echo foo not removed!
2814 if not exist bar (echo bar removed) else echo bar not removed!
2815 if not exist foobar (echo foobar removed) else echo foobar not removed!
2816 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
2817 cd .. & rd /s/q foobaz
2819 echo ------------ Testing pushd/popd ------------
2821 echo --- popd is no-op when dir stack is empty
2822 popd
2824 echo --- pushing non-existing dir
2825 pushd foobar
2827 echo --- basic behaviour
2828 mkdir foobar\baz
2829 pushd foobar
2831 popd
2833 pushd foobar
2834 pushd baz
2836 popd
2838 pushd baz
2839 popd
2841 popd
2843 pushd .
2844 cd foobar\baz
2845 pushd ..
2847 popd
2848 popd
2850 rd /s/q foobar
2852 echo ------------ Testing attrib ------------
2853 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
2854 mkdir foobar & cd foobar
2855 echo foo original contents> foo
2856 attrib
2857 attrib foo
2858 echo > bar
2859 echo --- read-only attribute
2860 rem Read-only files cannot be altered or deleted, unless forced
2861 attrib +R foo
2862 attrib foo
2863 dir /Ar /B
2864 echo bar>> foo
2865 type foo
2866 del foo > NUL 2>&1
2867 if exist foo (
2868 echo Read-only file not deleted
2869 ) else (
2870 echo Should not delete read-only file!
2872 del /F foo
2873 if not exist foo (
2874 echo Read-only file forcibly deleted
2875 ) else (
2876 echo Should delete read-only file with del /F!
2877 attrib -r foo
2878 del foo
2880 cd .. & rd /s/q foobar
2881 echo --- recursive behaviour
2882 mkdir foobar\baz & cd foobar
2883 echo > level1
2884 echo > whatever
2885 echo > baz\level2
2886 attrib baz\level2
2887 cd ..
2888 attrib +R l*vel? /S > nul 2>&1
2889 cd foobar
2890 attrib level1
2891 attrib baz\level2
2892 echo > bar
2893 attrib bar
2894 cd .. & rd /s/q foobar
2895 echo --- folders processing
2896 mkdir foobar
2897 attrib foobar
2898 cd foobar
2899 mkdir baz
2900 echo toto> baz\toto
2901 attrib +r baz /s /d > nul 2>&1
2902 attrib baz
2903 attrib baz\toto
2904 echo lulu>>baz\toto
2905 type baz\toto
2906 echo > baz\lala
2907 rem Oddly windows allows file creation in a read-only directory...
2908 if exist baz\lala (echo file created in read-only dir) else echo file not created
2909 cd .. & rd /s/q foobar
2911 echo ------------ Testing assoc ------------
2912 rem Modifying associations requires some privileges...
2913 net session >nul 2>&1
2914 if errorlevel 1 goto :SkipAssoc
2916 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2917 rem FIXME Revise once || conditional execution is fixed
2918 mkdir foobar & cd foobar
2919 echo --- setting association
2920 assoc .foo > baz
2921 type baz
2922 echo ---
2924 assoc .foo=bar
2925 assoc .foo
2927 rem association set system-wide
2928 echo @echo off> tmp.cmd
2929 echo echo +++>> tmp.cmd
2930 echo assoc .foo>> tmp.cmd
2931 cmd /c tmp.cmd
2933 echo --- resetting association
2934 assoc .foo=
2935 assoc .foo > baz
2936 type baz
2937 echo ---
2939 rem association removal set system-wide
2940 cmd /c tmp.cmd > baz
2941 type baz
2942 echo ---
2943 cd .. & rd /s/q foobar
2944 goto ContinueFType
2945 :SkipAssoc
2946 echo --- setting association
2947 echo ---
2948 echo .foo=bar
2949 echo .foo=bar
2950 echo +++
2951 echo .foo=bar
2952 echo --- resetting association
2953 echo ---
2954 echo +++
2955 echo ---
2958 :ContinueFType
2959 echo ------------ Testing ftype ------------
2960 rem Modifying associations requires some privileges...
2961 net session >nul 2>&1
2962 if errorlevel 1 goto :SkipFType
2963 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2964 rem FIXME Revise once || conditional execution is fixed
2965 mkdir foobar & cd foobar
2966 echo --- setting association
2967 ftype footype> baz
2968 type baz
2969 echo ---
2971 ftype footype=foo_opencmd
2972 assoc .foo=footype
2973 ftype footype
2975 rem association set system-wide
2976 echo @echo off> tmp.cmd
2977 echo echo +++>> tmp.cmd
2978 echo ftype footype>> tmp.cmd
2979 cmd /c tmp.cmd
2981 echo --- resetting association
2982 assoc .foo=
2984 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2985 setlocal EnableDelayedExpansion
2986 set WINE_FOO=original value
2987 ftype footype=
2988 ftype footype > baz
2989 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
2990 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2991 rem FIXME Revisit once a grep-like program like ftype is implemented
2992 rem (e.g. to check baz's size using dir /b instead)
2993 echo !WINE_FOO!
2995 rem cleanup registry
2996 echo REGEDIT4> regCleanup.reg
2997 echo.>> regCleanup.reg
2998 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
2999 regedit /s regCleanup.reg
3000 set WINE_FOO=
3001 endlocal
3002 cd .. & rd /s/q foobar
3003 goto ContinueCall
3004 :SkipFType
3005 echo --- setting association
3006 echo ---
3007 echo footype=foo_opencmd
3008 echo .foo=footype
3009 echo footype=foo_opencmd
3010 echo +++
3011 echo footype=foo_opencmd
3012 echo --- resetting association
3013 echo original value
3015 :ContinueCall
3016 echo ------------ Testing CALL ------------
3017 mkdir foobar & cd foobar
3018 echo --- external script
3019 echo echo foo %%1> foo.cmd
3020 call foo
3021 call foo.cmd 8
3022 echo echo %%1 %%2 > foo.cmd
3023 call foo.cmd foo
3024 call foo.cmd foo bar
3025 call foo.cmd foo ""
3026 call foo.cmd "" bar
3027 call foo.cmd foo ''
3028 call foo.cmd '' bar
3029 del foo.cmd
3031 echo --- internal routines
3032 call :testRoutine :testRoutine
3033 goto :endTestRoutine
3034 :testRoutine
3035 echo bar %1
3036 goto :eof
3037 :endTestRoutine
3039 call :testRoutineArgs foo
3040 call :testRoutineArgs foo bar
3041 call :testRoutineArgs foo ""
3042 call :testRoutineArgs "" bar
3043 call :testRoutineArgs foo ''
3044 call :testRoutineArgs '' bar
3045 goto :endTestRoutineArgs
3046 :testRoutineArgs
3047 echo %1 %2
3048 goto :eof
3049 :endTestRoutineArgs
3051 echo --- with builtins
3052 call mkdir foo
3053 echo %ErrorLevel%
3054 if exist foo (echo foo created) else echo foo should exist!
3055 rmdir foo
3056 set WINE_FOOBAZ_VAR=foobaz
3057 call echo Should expand %WINE_FOOBAZ_VAR%
3058 set WINE_FOOBAZ_VAR=
3059 echo>batfile
3060 call dir /b
3061 echo>robinfile
3062 if 1==1 call del batfile
3063 dir /b
3064 if exist batfile echo batfile shouldn't exist
3065 rem arcane command, first resets errorlevel, second sets it to one
3066 (call )
3067 echo %ErrorLevel%
3068 (call)
3069 echo %ErrorLevel%
3070 rem ... but not for 'if' or 'for'
3071 call :setError 0
3072 call if 1==1 echo bar 2> nul
3073 echo %ErrorLevel%
3074 call :setError 0
3075 call for %%i in (foo bar baz) do echo %%i 2> nul
3076 echo %ErrorLevel%
3077 rem First look for programs in the path before trying a builtin
3078 echo echo non-builtin dir> dir.cmd
3079 call dir /b
3080 del dir.cmd
3081 rem The below line equates to call (, which does nothing, then the
3082 rem subsequent lines are executed.
3083 call (
3084 echo Line one
3085 echo Line two
3087 rem The below line equates to call if, which always fails, then the
3088 rem subsequent lines are executed. Note cmd.exe swallows all lines
3089 rem starting with )
3090 call if 1==1 (
3091 echo Get if
3092 ) else (
3093 echo ... and else!
3095 call call call echo passed
3096 set WINE_FOO=WINE_BAR
3097 set WINE_BAR=abc
3098 call echo %%%WINE_FOO%%%
3099 call cmd.exe /c echo %%%WINE_FOO%%%
3100 call echo %%%%%WINE_FOO%%%%%
3101 call cmd.exe /c echo %%%%%WINE_FOO%%%%%
3103 set WINE_BAR=abc
3104 set WINE_FOO=%%WINE_BAR%%
3106 call :call_expand %WINE_FOO% %%WINE_FOO%% %%%WINE_FOO%%%
3107 goto :call_expand_done
3109 :call_expand
3110 set WINE_BAR=def
3111 echo %1 %2 %3
3112 call echo %1 %2 %3
3113 exit /b 0
3115 :call_expand_done
3117 cd .. & rd /s/q foobar
3119 echo --- mixing batch and builtins
3120 erase /q echo.bat test.bat 2> NUL
3121 echo @echo foo> echo.bat
3122 echo @echo bar> test.bat & call test.bat
3123 echo @echo.bat bar> test.bat & call test.bat
3124 echo @call echo bar> test.bat & call test.bat
3125 echo @call echo.bat bar> test.bat & call test.bat
3126 erase /q echo.bat 2> NUL
3127 echo @echo bar> test.bat & call test.bat
3128 echo @echo.bat bar> test.bat & call test.bat
3129 echo @call echo bar> test.bat & call test.bat
3130 echo @call echo.bat bar> test.bat & call test.bat
3131 erase /q test.bat 2> NUL
3133 echo ------------ Testing SHIFT ------------
3135 call :shiftFun p1 p2 p3 p4 p5
3136 goto :endShiftFun
3138 :shiftFun
3139 echo '%1' '%2' '%3' '%4' '%5'
3140 shift
3141 echo '%1' '%2' '%3' '%4' '%5'
3142 shift@tab@ /1
3143 echo '%1' '%2' '%3' '%4' '%5'
3144 shift /2
3145 echo '%1' '%2' '%3' '%4' '%5'
3146 shift /-1
3147 echo '%1' '%2' '%3' '%4' '%5'
3148 shift /0
3149 echo '%1' '%2' '%3' '%4' '%5'
3150 goto :eof
3151 :endShiftFun
3153 echo ------------ Testing cmd invocation ------------
3154 rem FIXME: only a stub ATM
3155 echo --- a batch file can delete itself
3156 echo del foo.cmd>foo.cmd
3157 cmd /q /c foo.cmd
3158 if not exist foo.cmd (
3159 echo file correctly deleted
3160 ) else (
3161 echo file should be deleted!
3162 del foo.cmd
3164 echo --- a batch file can alter itself
3165 echo echo bar^>foo.cmd>foo.cmd
3166 cmd /q /c foo.cmd > NUL 2>&1
3167 if exist foo.cmd (
3168 type foo.cmd
3169 del foo.cmd
3170 ) else (
3171 echo file not created!
3174 echo ---------- Testing copy
3175 md foobar2
3176 cd foobar2
3177 rem Note echo adds 0x0d 0x0a on the end of the line in the file
3178 echo AAA> file1
3179 echo BBBBBB> file2
3180 echo CCCCCCCCC> file3
3181 md dir1
3182 goto :testcopy
3184 :CheckExist
3185 if exist "%1" (
3186 echo Passed: Found expected %1
3187 ) else (
3188 echo Failed: Did not find expected %1
3190 del /q "%1" >nul 2>&1
3191 shift
3192 if not "%1"=="" goto :CheckExist
3193 goto :eof
3195 :CheckNotExist
3196 if not exist "%1" (
3197 echo Passed: Did not find %1
3198 ) else (
3199 echo Failed: Unexpectedly found %1
3200 del /q "%1" >nul 2>&1
3202 shift
3203 if not "%1"=="" goto :CheckNotExist
3204 goto :eof
3206 rem Note: No way to check file size on NT4 so skip the test
3207 :CheckFileSize
3208 if not exist "%1" (
3209 echo Failed: File missing when requested filesize check [%2]
3210 goto :ContinueFileSizeChecks
3212 for %%i in (%1) do set WINE_filesize=%%~zi
3213 if "%WINE_filesize%"=="%2" (
3214 echo Passed: file size check on %1 [%WINE_filesize%]
3215 ) else (
3216 if "%WINE_filesize%"=="%%~zi" (
3217 echo Skipping file size check on NT4
3218 ) else (
3219 echo Failed: file size check on %1 [%WINE_filesize% != %2]
3222 :ContinueFileSizeChecks
3223 shift
3224 shift
3225 if not "%1"=="" goto :CheckFileSize
3226 goto :eof
3228 :testcopy
3230 rem -----------------------
3231 rem Simple single file copy
3232 rem -----------------------
3233 rem Simple single file copy, normally used syntax
3234 copy file1 dummy.file >nul 2>&1
3235 if errorlevel 1 echo Incorrect errorlevel
3236 call :CheckExist dummy.file
3238 rem Simple single file copy, destination supplied as two forms of directory
3239 copy file1 dir1 >nul 2>&1
3240 if errorlevel 1 echo Incorrect errorlevel
3241 call :CheckExist dir1\file1
3243 copy file1 dir1\ >nul 2>&1
3244 if errorlevel 1 echo Incorrect errorlevel
3245 call :CheckExist dir1\file1
3247 rem Simple single file copy, destination supplied as fully qualified destination
3248 copy file1 dir1\file99 >nul 2>&1
3249 if errorlevel 1 echo Incorrect errorlevel
3250 call :CheckExist dir1\file99
3252 rem Simple single file copy, destination not supplied
3253 cd dir1
3254 copy ..\file1 >nul 2>&1
3255 if errorlevel 1 echo Incorrect errorlevel
3256 call :CheckExist file1
3257 cd ..
3259 rem Simple single file copy, destination supplied as nonexistent directory
3260 copy file1 dir2\ >nul 2>&1
3261 if not errorlevel 1 echo Incorrect errorlevel
3262 call :CheckNotExist dir2 dir2\file1
3264 rem -----------------------
3265 rem Wildcarded copy
3266 rem -----------------------
3267 rem Simple single file copy, destination supplied as two forms of directory
3268 copy file? dir1 >nul 2>&1
3269 if errorlevel 1 echo Incorrect errorlevel
3270 call :CheckExist dir1\file1 dir1\file2 dir1\file3
3272 copy file* dir1\ >nul 2>&1
3273 if errorlevel 1 echo Incorrect errorlevel
3274 call :CheckExist dir1\file1 dir1\file2 dir1\file3
3276 rem Simple single file copy, destination not supplied
3277 cd dir1
3278 copy ..\file*.* >nul 2>&1
3279 if errorlevel 1 echo Incorrect errorlevel
3280 call :CheckExist file1 file2 file3
3281 cd ..
3283 rem Simple wildcarded file copy, destination supplied as nonexistent directory
3284 copy file? dir2\ >nul 2>&1
3285 if not errorlevel 1 echo Incorrect errorlevel
3286 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
3288 rem ------------------------------------------------
3289 rem Confirm overwrite works (cannot test prompting!)
3290 rem ------------------------------------------------
3291 copy file1 testfile >nul 2>&1
3292 copy /y file2 testfile >nul 2>&1
3293 call :CheckExist testfile
3295 rem ------------------------------------------------
3296 rem Test concatenation
3297 rem ------------------------------------------------
3298 rem simple case, no wildcards
3299 copy file1+file2 testfile >nul 2>&1
3300 if errorlevel 1 echo Incorrect errorlevel
3301 call :CheckExist testfile
3303 rem simple case, wildcards, no concatenation
3304 copy file* testfile >nul 2>&1
3305 if errorlevel 1 echo Incorrect errorlevel
3306 call :CheckExist testfile
3308 rem simple case, wildcards, and concatenation
3309 echo ddddd > fred
3310 copy file*+fred testfile >nul 2>&1
3311 if errorlevel 1 echo Incorrect errorlevel
3312 call :CheckExist testfile
3314 rem simple case, wildcards, and concatenation
3315 copy fred+file* testfile >nul 2>&1
3316 if errorlevel 1 echo Incorrect errorlevel
3317 call :CheckExist testfile
3319 rem Calculate destination name
3320 copy fred+file* dir1 >nul 2>&1
3321 if errorlevel 1 echo Incorrect errorlevel
3322 call :CheckExist dir1\fred
3324 rem Calculate destination name
3325 copy fred+file* dir1\ >nul 2>&1
3326 if errorlevel 1 echo Incorrect errorlevel
3327 call :CheckExist dir1\fred
3329 rem Calculate destination name (none supplied)
3330 cd dir1
3331 copy ..\fred+..\file* >nul 2>&1
3332 if errorlevel 1 echo Incorrect errorlevel
3333 call :CheckExist fred
3335 copy ..\fr*+..\file1 >nul 2>&1
3336 if errorlevel 1 echo Incorrect errorlevel
3337 call :CheckExist fred
3338 cd ..
3340 rem ******************************************************************
3341 rem ASCII and BINARY tests
3342 rem Note: hard coded numbers deliberate because need to ensure whether
3343 rem an additional EOF has been added or not. There is no way to handle
3344 rem EOFs in batch, so assume if a single byte appears, it's an EOF!
3345 rem ******************************************************************
3347 rem Confirm original sizes of file1,2,3
3348 call :CheckFileSize file1 5 file2 8 file3 11
3350 cd dir1
3352 rem ----------------------------------------------
3353 rem Show concatenation defaults copy to ascii mode
3354 rem ----------------------------------------------
3355 rem Simple default copy source to destination (should not append EOF 5)
3356 copy ..\file1 file1_default >nul 2>&1
3357 call :CheckFileSize file1_default 5
3359 rem Simple binary copy source to destination (should not append EOF 5)
3360 copy /b ..\file1 file1_default2 >nul 2>&1
3361 call :CheckFileSize file1_default2 5
3363 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
3364 copy /a ..\file1 file1_plus_eof >nul 2>&1
3365 call :CheckFileSize file1_plus_eof 6
3366 copy /a ..\file2 file2_plus_eof >nul 2>&1
3367 call :CheckFileSize file2_plus_eof 9
3368 copy /a ..\file3 file3_plus_eof >nul 2>&1
3369 call :CheckFileSize file3_plus_eof 12
3371 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
3372 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
3373 call :CheckFileSize file12_plus_eof 14
3375 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
3376 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
3377 call :CheckFileSize file12_no_eof 13
3379 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
3380 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
3381 call :CheckFileSize file12_eof2 14
3383 rem Test copying when destination is one of the sources.
3384 rem Concat file1+file2+file3 into file1, should produce file1+file2+file3 = 24
3385 copy /y ..\file? .\ >nul 2>&1
3386 copy /y /b file1+file2+file3 file1 >nul 2>&1
3387 call :CheckFileSize file1 24
3389 rem Concat file1+file2+file3 into file2, should produce file1+file3 = 16
3390 copy /y ..\file? .\ >nul 2>&1
3391 copy /y /b file1+file2+file3 file2 >nul 2>&1
3392 call :CheckFileSize file2 16
3394 rem Concat file1+file2+file3 into file3, should produce file1+file2 = 13
3395 copy /y ..\file? .\ >nul 2>&1
3396 copy /y /b file1+file2+file3 file3 >nul 2>&1
3397 call :CheckFileSize file3 13
3399 rem --------------------------------------------------------------
3400 rem Show ascii source copy stops at first EOF, binary does the lot
3401 rem --------------------------------------------------------------
3402 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
3403 call :CheckFileSize file1_binary_srccopy 6
3405 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
3406 call :CheckFileSize file1_ascii_srccopy 5
3408 rem --------------------------------------------------------------
3409 rem Show results of concatenating files (ending in EOFs) and /a /b
3410 rem --------------------------------------------------------------
3412 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
3413 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
3414 call :CheckFileSize file123_default_copy 25
3415 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
3416 call :CheckFileSize file123_ascii_copy 25
3418 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
3419 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
3420 call :CheckFileSize file123_binary_copy 27
3422 rem We can select which we want the eofs from by postfixing it with /a or /b
3423 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
3424 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
3425 call :CheckFileSize file123_mixed_copy1 26
3427 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
3428 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
3429 rem Note the delta between this and the previous one also shows that the destination
3430 rem ascii/binary is inherited from the last /a or /b on the line
3431 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
3432 call :CheckFileSize file123_mixed_copy2 27
3434 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
3435 rem Note the delta between the next two also shows that the destination ascii/binary is
3436 rem inherited from the last /a or /b on the line, so the first has an extra EOF
3437 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
3438 call :CheckFileSize file123_mixed_copy3 26
3439 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
3440 call :CheckFileSize file123_mixed_copy4 25
3442 rem -------------------------------------------------------------------------------------------
3443 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
3444 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
3445 rem -------------------------------------------------------------------------------------------
3447 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
3448 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
3449 call :CheckFileSize file123_mixed_copy5 28
3451 rem All 2 have eof's, plus an extra = 6 + 12 + eof
3452 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
3453 call :CheckFileSize file123_mixed_copy6 19
3455 rem One file has EOF, but doesn't get an extra one, i.e. 6
3456 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
3457 call :CheckFileSize file123_mixed_copy7 6
3459 rem Syntax means concatenate so ascii destination kicks in
3460 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
3461 call :CheckFileSize file123_mixed_copy8 7
3463 del *.* /q
3464 cd ..
3466 rem ---------------------------------------
3467 rem Error combinations
3468 rem ---------------------------------------
3469 rem Specify source directory but name is a file
3470 call :setError 0
3471 copy file1\ dir1\ >NUL 2>&1
3472 if errorlevel 1 echo Passed: errorlevel invalid check 1
3473 if not errorlevel 1 echo Failed: errorlevel invalid check 1
3474 call :CheckNotExist dir1\file1
3476 rem Overwrite same file
3477 call :setError 0
3478 copy file1 file1 >NUL 2>&1
3479 if errorlevel 1 echo Passed: errorlevel invalid check 2
3480 if not errorlevel 1 echo Failed: errorlevel invalid check 2
3482 rem Supply same file identified as a directory
3483 call :setError 0
3484 copy file1 file1\ >NUL 2>&1
3485 if errorlevel 1 echo Passed: errorlevel invalid check 3
3486 if not errorlevel 1 echo Failed: errorlevel invalid check 3
3488 cd ..
3489 rd foobar2 /s /q
3491 echo ------------ Testing setlocal/endlocal ------------
3492 call :setError 0
3493 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
3494 mkdir foobar & cd foobar
3495 echo --- enable/disable extensions
3496 setlocal DisableEXTensions
3497 echo ErrLev: %ErrorLevel%
3498 endlocal
3499 echo ErrLev: %ErrorLevel%
3500 echo @echo off> tmp.cmd
3501 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
3502 rem Enabled by default
3503 cmd /C tmp.cmd
3504 cmd /E:OfF /C tmp.cmd
3505 cmd /e:oN /C tmp.cmd
3507 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
3508 echo --- setlocal with corresponding endlocal
3509 rem %CD% does not work on NT4 so use the following workaround
3510 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
3511 echo @echo off> test.cmd
3512 echo echo %%WINE_VAR%%>> test.cmd
3513 echo setlocal>> test.cmd
3514 echo set WINE_VAR=localval>> test.cmd
3515 echo md foobar2>> test.cmd
3516 echo cd foobar2>> test.cmd
3517 echo echo %%WINE_VAR%%>> test.cmd
3518 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
3519 echo endlocal>> test.cmd
3520 echo echo %%WINE_VAR%%>> test.cmd
3521 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
3522 set WINE_VAR=globalval
3523 call test.cmd
3524 echo %WINE_VAR%
3525 for /d %%i in (.) do echo %%~dpnxi
3526 cd /d %WINE_CURDIR%
3527 rd foobar2
3528 set WINE_VAR=
3529 echo --- setlocal with no corresponding endlocal
3530 echo @echo off> test.cmd
3531 echo echo %%WINE_VAR%%>> test.cmd
3532 echo setlocal>> test.cmd
3533 echo set WINE_VAR=localval>> test.cmd
3534 echo md foobar2>> test.cmd
3535 echo cd foobar2>> test.cmd
3536 echo echo %%WINE_VAR%%>> test.cmd
3537 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
3538 set WINE_VAR=globalval
3539 rem %CD% does not work on NT4 so use the following workaround
3540 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
3541 call test.cmd
3542 echo %WINE_VAR%
3543 for /d %%i in (.) do echo %%~dpnxi
3544 cd /d %WINE_CURDIR%
3545 rd foobar2
3546 set WINE_VAR=
3547 echo --- setlocal within same batch program
3548 set WINE_var1=one
3549 set WINE_var2=
3550 set WINE_var3=
3551 rem %CD% does not work on NT4 so use the following workaround
3552 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
3553 setlocal
3554 set WINE_var2=two
3555 mkdir foobar2
3556 cd foobar2
3557 setlocal
3558 set WINE_var3=three
3559 if "%WINE_var1%"=="one" echo Var1 ok 1
3560 if "%WINE_var2%"=="two" echo Var2 ok 2
3561 if "%WINE_var3%"=="three" echo Var3 ok 3
3562 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
3563 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
3564 endlocal
3565 if "%WINE_var1%"=="one" echo Var1 ok 1
3566 if "%WINE_var2%"=="two" echo Var2 ok 2
3567 if "%WINE_var3%"=="" echo Var3 ok 3
3568 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
3569 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
3570 endlocal
3571 if "%WINE_var1%"=="one" echo Var1 ok 1
3572 if "%WINE_var2%"=="" echo Var2 ok 2
3573 if "%WINE_var3%"=="" echo Var3 ok 3
3574 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
3575 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
3576 rd foobar2 /s /q
3577 set WINE_var1=
3579 echo --- Mismatched set and end locals
3580 mkdir foodir2 2>nul
3581 mkdir foodir3 2>nul
3582 mkdir foodir4 2>nul
3583 rem %CD% does not work on NT4 so use the following workaround
3584 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
3586 echo @echo off> 2set1end.cmd
3587 echo echo %%WINE_var%%>> 2set1end.cmd
3588 echo setlocal>> 2set1end.cmd
3589 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
3590 echo cd ..\foodir3>> 2set1end.cmd
3591 echo setlocal>> 2set1end.cmd
3592 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
3593 echo cd ..\foodir4>> 2set1end.cmd
3594 echo endlocal>> 2set1end.cmd
3595 echo echo %%WINE_var%%>> 2set1end.cmd
3596 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
3598 echo @echo off> 1set2end.cmd
3599 echo echo %%WINE_var%%>> 1set2end.cmd
3600 echo setlocal>> 1set2end.cmd
3601 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
3602 echo cd ..\foodir3>> 1set2end.cmd
3603 echo endlocal>> 1set2end.cmd
3604 echo echo %%WINE_var%%>> 1set2end.cmd
3605 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
3606 echo endlocal>> 1set2end.cmd
3607 echo echo %%WINE_var%%>> 1set2end.cmd
3608 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
3610 echo --- Extra setlocal in called batch
3611 set WINE_VAR=value1
3612 rem -- setlocal1 == this batch, should never be used inside a called routine
3613 setlocal
3614 set WINE_var=value2
3615 cd foodir2
3616 call "%WINE_CURDIR%\2set1end.cmd"
3617 echo Finished:
3618 echo %WINE_VAR%
3619 for /d %%i in (.) do echo %%~dpnxi
3620 endlocal
3621 echo %WINE_VAR%
3622 for /d %%i in (.) do echo %%~dpnxi
3623 cd /d %WINE_CURDIR%
3625 echo --- Extra endlocal in called batch
3626 set WINE_VAR=value1
3627 rem -- setlocal1 == this batch, should never be used inside a called routine
3628 setlocal
3629 set WINE_var=value2
3630 cd foodir2
3631 call "%WINE_CURDIR%\1set2end.cmd"
3632 echo Finished:
3633 echo %WINE_VAR%
3634 for /d %%i in (.) do echo %%~dpnxi
3635 endlocal
3636 echo %WINE_VAR%
3637 for /d %%i in (.) do echo %%~dpnxi
3638 cd /d %WINE_CURDIR%
3640 echo --- endlocal in called function rather than batch pgm is ineffective
3641 @echo off
3642 set WINE_var=1
3643 set WINE_var2=1
3644 setlocal
3645 set WINE_var=2
3646 call :endlocalroutine
3647 echo %WINE_var%
3648 endlocal
3649 echo %WINE_var%
3650 goto :endlocalfinished
3651 :endlocalroutine
3652 echo %WINE_var%
3653 endlocal
3654 echo %WINE_var%
3655 setlocal
3656 set WINE_var2=2
3657 endlocal
3658 echo %WINE_var2%
3659 endlocal
3660 echo %WINE_var%
3661 echo %WINE_var2%
3662 goto :eof
3663 :endlocalfinished
3664 echo %WINE_var%
3666 set WINE_var=
3667 set WINE_var2=
3668 cd .. & rd /q/s foobar
3670 echo ------------ Testing Errorlevel ------------
3671 rem WARNING: Do *not* add tests using ErrorLevel after this section
3672 should_not_exist 2> nul > nul
3673 echo %ErrorLevel%
3674 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
3675 rem See http://www.robvanderwoude.com/exit.php
3676 call :setError -9999
3677 echo %ErrorLevel%
3678 call :setError 1
3679 echo %ErrorLevel%
3680 if errorlevel 2 echo errorlevel too high, bad
3681 if errorlevel 1 echo errorlevel just right, good
3682 if errorlevel 01 echo errorlevel with leading zero just right, good
3683 if errorlevel -1 echo errorlevel with negative number OK
3684 if errorlevel 0x1 echo hexa should not be recognized!
3685 if errorlevel 1a echo invalid error level recognized!
3686 call :setError 0
3687 echo abc%ErrorLevel%def
3688 if errorlevel 1 echo errorlevel nonzero, bad
3689 if not errorlevel 1 echo errorlevel zero, good
3690 if not errorlevel 0x1 echo hexa should not be recognized!
3691 if not errorlevel 1a echo invalid error level recognized!
3692 rem Now verify that setting a real variable hides its magic variable
3693 set errorlevel=7
3694 echo %ErrorLevel% should be 7
3695 if errorlevel 7 echo setting var worked too well, bad
3696 call :setError 3
3697 echo %ErrorLevel% should still be 7
3698 rem Verify that (call ) sets errorlevel to 0
3699 (call )
3700 if errorlevel 1 echo errorlevel should have been 0
3702 echo ------------ Testing GOTO ------------
3703 if a==a goto dest1
3704 echo FAILURE at dest 1
3705 :dest1
3706 echo goto with no leading space worked
3707 if a==a goto :dest1b
3708 echo FAILURE at dest 1b
3709 :dest1b
3710 echo goto with colon and no leading space worked
3711 if b==b goto dest2
3712 echo FAILURE at dest 2
3713 :dest2
3714 echo goto with a leading space worked
3715 if c==c goto dest3
3716 echo FAILURE at dest 3
3717 :dest3
3718 echo goto with a leading tab worked
3719 if d==d goto dest4
3720 echo FAILURE at dest 4
3721 :dest4@space@
3722 echo goto with a following space worked
3723 if e==e goto dest5
3724 echo FAILURE at dest 5
3725 :dest5&& echo FAILURE
3726 echo goto with following amphersands worked
3728 del failure.txt >nul 2>&1
3729 if f==f goto dest6
3730 echo FAILURE at dest 6
3731 :dest6>FAILURE.TXT
3732 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
3733 echo goto with redirections worked
3734 del FAILURE.TXT >nul 2>&1
3736 :: some text that is ignored | dir >cmd_output | another test
3737 if exist cmd_output echo FAILURE at dest 6 as file exists
3738 echo Ignoring double colons worked
3739 del cmd_output >nul 2>&1
3741 rem goto a label which does not exist issues an error message and
3742 rem acts the same as goto :EOF, and ensure ::label is never matched
3743 del testgoto.bat >nul 2>&1
3744 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
3745 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
3746 echo ::dest7>> testgoto.bat
3747 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
3748 call testgoto.bat
3749 del testgoto.bat >nul 2>&1
3751 del testgoto.bat >nul 2>&1
3752 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
3753 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
3754 echo ::dest8>> testgoto.bat
3755 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
3756 call testgoto.bat
3757 del testgoto.bat >nul 2>&1
3759 if g==g goto dest9
3760 echo FAILURE at dest 9
3761 :dest91
3762 echo FAILURE at dest 91
3763 @ : dest9>rubbish
3764 echo label with mixed whitespace and no echo worked
3766 if h==h goto :dest10:this is ignored
3767 echo FAILURE at dest 10
3768 :dest10:this is also ignored
3769 echo Correctly ignored trailing information
3771 rem Testing which label is reached when there are many options
3772 echo Begin:
3773 set nextlabel=
3774 call :sub
3775 set nextlabel=middle
3776 goto :sub
3778 :sub
3779 echo ..First sub
3780 if not "%nextlabel%"=="" goto :%nextlabel%
3781 goto :EOF
3783 :sub
3784 echo ..Second sub
3785 if not "%nextlabel%"=="" goto :%nextlabel%
3786 goto :EOF
3788 :middle
3789 echo Middle:
3790 set nextlabel=
3791 call :sub
3792 set nextlabel=nearend
3793 goto :sub
3795 :sub
3796 echo ..Third sub
3797 if not "%nextlabel%"=="" goto :%nextlabel%
3798 goto :EOF
3800 :nearend
3801 echo Near end:
3802 set nextlabel=
3803 call :sub
3804 set nextlabel=end
3805 goto :sub
3807 :sub
3808 echo ..Fourth sub
3809 if not "%nextlabel%"=="" goto :%nextlabel%
3810 goto :EOF
3812 :end
3813 echo At end:
3814 set nextlabel=
3815 call :sub
3816 set nextlabel=done
3817 goto :sub
3819 :done
3820 echo Finished
3822 echo ------------ Testing PATH ------------
3823 set WINE_backup_path=%path%
3824 set path=original
3825 path
3826 path try2
3827 path
3828 path=try3
3829 path
3831 echo ------------ Testing PATH Evaluate ------------
3832 mkdir folder
3833 echo echo I'm here! > folder\sub1.bat
3835 echo Test normal PATH usage
3836 set path=%cd%\folder
3837 call sub1.bat
3839 echo Test PATH usage with leading semicolon
3840 set path=;%cd%\folder
3841 call sub1.bat
3843 echo Test PATH usage with fallback path
3844 set path=%cd%;%cd%\folder
3845 call sub1.bat
3847 echo Test PATH usage with double semicolon
3848 set path=%cd%;;%cd%\folder
3849 call sub1.bat
3851 del folder\sub1.bat
3852 rmdir folder
3853 set path=%WINE_backup_path%
3854 set WINE_backup_path=
3856 echo ------------ Testing start /W ------------
3857 echo start /W failed to wait>foobar.txt
3858 start /W "" cmd /C "ping -n1 & echo start /W seems to really wait>foobar.txt"& type foobar.txt& del foobar.txt
3860 echo ------------ Testing changing the drive letter ----------
3861 pushd C:\
3863 echo Normal:
3864 call :setError 0
3866 if errorlevel 1 echo Normal drive change failed
3868 echo Normal+space
3869 call :setError 0
3870 C:@space@
3871 if errorlevel 1 echo Normal+space drive change failed
3873 echo Normal+space+garbage
3874 call :setError 0
3875 C: garbage
3876 if errorlevel 1 echo Normal+space+garbage drive change failed
3878 call :setError 0
3879 echo Quoted should fail
3880 "C:"
3881 if not errorlevel 1 echo quoted drive change unexpectedly worked
3883 echo Normal+tab
3884 call :setError 0
3885 C:@tab@
3886 if errorlevel 1 echo Normal+tab drive change failed
3888 echo Normal+tab+garbage
3889 call :setError 0
3890 C:@tab@garbagetab
3891 if errorlevel 1 echo Normal+tab+garbage drive change failed
3893 popd
3895 echo ------------ Testing length wrt. MAX_PATH ------------
3896 rem native cmd limits all path lengths to MAX_PATH=260
3897 pushd c:\
3898 set depth=25
3899 for /L %%d in (0,1,25) do (
3900 mkdir abcdefghij > NUL 2>&1
3901 if exist abcdefghij (
3902 cd abcdefghij
3903 set depth=%%d
3906 echo %depth%
3907 rem even relative paths are transformed to absolute, and tested against MAX_PATH
3908 echo abc > 01234567890123
3909 if exist 01234567890123 (echo Success) else echo Failure
3910 echo abc > 012345678901234
3911 if exist 012345678901234 (echo Failure) else echo Success
3912 popd
3913 rmdir /s /q c:\abcdefghij
3914 echo ------------ Testing combined CALLs/GOTOs ------------
3915 echo @echo off>foo.cmd
3916 echo goto :eof>>foot.cmd
3917 echo :eof>>foot.cmd
3918 echo echo world>>foo.cmd
3920 echo @echo off>foot.cmd
3921 echo echo cheball>>foot.cmd
3922 echo.>>foot.cmd
3923 echo call :bar>>foot.cmd
3924 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
3925 echo goto :eof>>foot.cmd
3926 echo.>>foot.cmd
3927 echo :bar>>foot.cmd
3928 echo echo barbare>>foot.cmd
3929 echo goto :eof>>foot.cmd
3931 call foo.cmd
3932 call foot
3933 call :bar
3934 del foo.cmd
3935 rem Script execution stops after the following line
3936 foot deleteMe
3937 call :foo
3938 call :foot
3939 goto :endFuns
3941 :foot
3942 echo foot
3944 :foo
3945 echo foo
3946 goto :eof
3948 :endFuns
3950 :bar
3951 echo bar
3952 call :foo
3954 :baz
3955 echo baz
3956 goto :eof
3958 echo Final message is not output since earlier 'foot' processing stops script execution
3959 echo Do NOT add any tests below this line
3961 echo ------------ Done, jumping to EOF -----------
3962 goto :eof
3963 rem Subroutine to set errorlevel and return
3964 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
3965 :setError
3966 exit /B %1
3967 rem This line runs under cmd in windows NT 4, but not in more modern versions.