1 echo Tests
for cmd's builtin commands
4 echo ------------ Testing 'echo' [ON] ------------
6 echo 'singlequotedword
'
7 echo "doublequotedword"
24 echo word@space@@space@
28 echo@tab@word@tab@@space@
34 @echo --- @ with chains and brackets
35 (echo the @ character chains until&&@echo we leave the current depth||(
38 ))&&echo and can hide brackets||(@echo command hidden)||@(echo brackets hidden)
46 echo ------------ Testing 'echo' [OFF] ------------
48 echo 'singlequotedword
'
49 echo "doublequotedword"
66 echo word@space@@space@
70 echo@tab@word@tab@@space@
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 ------------
89 call :TestParm "a b c"
90 call :TestParm "a b"\c
91 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
103 echo '%1', '%2', '%3'
107 echo ------------ Testing rem ------------
112 rem echo foo & echo bar
115 rem@tab@echo foo & echo bar
121 rem echo foo & echo bar
124 rem@tab@echo foo & echo bar
127 echo ------------ Testing redirection operators ------------
128 mkdir foobar & cd foobar
129 echo --- stdout redirection
138 echo foo@tab@1>@tab@foo
159 echo --- stdout appending
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
184 2>foo (echo foo2 >&2)
188 echo --- redirections within IF statements
189 if 1==1 echo foo1>bar
191 if 1==1 echo foo2>>bar
194 if 1==1 (echo foo2>bar) else echo baz2>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
200 if 1==0 (echo foo5>bar) else echo baz5>bar
202 if 1==0 (echo foo6) else echo baz6 1>bar
204 if 1==0 (echo foo7 1>bar) else echo baz7>bar
206 if 1==0 (echo foo8 1>bar) else echo baz8>bak
208 if 1==1 (echo foo>bar & echo baz)
215 (if 1==1 (echo A) else echo B) > C
217 (if 1==0 (echo A) else echo B) > 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
259 echo bak ^
&& echo baz
2> nul
267 set WINE_FOO
=bar ^| baz
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
273 set WINE_FOO
=bar ^^^| baz
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)'
295 echo --- chain success
300 echo d1
&echo d2
&echo d3
301 echo e1
&echo e2
&&echo e3
302 echo f1
&echo f2||
echo f3
304 echo g1
&&echo g2
&echo g3
305 echo h1
&&echo h2
&&echo h3
306 echo i1
&&echo i2||
echo i3
308 echo j1||
echo j2
&echo j3
310 echo k1||
echo k2
&&echo k3
312 echo l1||
echo l2||
echo l3
314 echo --- chain failure
315 call :cfail a1
&call :cfail a2
316 call :cfail b1
&&call :cfail b2
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
322 call :cfail f1
&call :cfail f2||
call :cfail f3
323 call :cfail g1
&&call :cfail g2
&call :cfail g3
325 call :cfail h1
&&call :cfail h2
&&call :cfail h3
327 call :cfail i1
&&call :cfail i2||
call :cfail i3
329 call :cfail j1||
call :cfail j2
&call :cfail j3
330 call :cfail k1||
call :cfail k2
&&call :cfail k3
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
)
340 echo d1
&&(echo d2
&echo d3
)
341 echo e1
&&(echo e2
&&echo e3
)
342 echo f1
&&(echo f2||
echo f3
)
344 echo g1||
(echo g2
&echo g3
)
346 echo h1||
(echo h2
&&echo h3
)
348 echo i1||
(echo i2||
echo i3
)
350 call :cfail j1
&(call :cfail j2
&call :cfail j3
)
351 call :cfail k1
&(call :cfail k2
&&call :cfail k3
)
353 call :cfail l1
&(call :cfail l2||
call :cfail l3
)
354 call :cfail m1
&&(call :cfail m2
&call :cfail m3
)
356 call :cfail n1
&&(call :cfail n2
&&call :cfail n3
)
358 call :cfail o1
&&(call :cfail o2||
call :cfail o3
)
360 call :cfail p1||
(call :cfail p2
&call :cfail p3
)
361 call :cfail q1||
(call :cfail q2
&&call :cfail q3
)
363 call :cfail r1||
(call :cfail r2||
call :cfail r3
)
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
371 echo c1
&&echo c2|
echo c3
372 echo d1||
echo d2|
echo d3
374 echo e1
&echo e2|
echo e3
375 echo f1|
echo f2
&&echo f3
376 echo g1|
echo g2||
echo g3
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]
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
412 if 1==1 if 2==0 if 3==3 (echo c1
) else (echo c2
) else echo c3
414 if 1==1 if 2==0 if 3==0 (echo d1
) else (echo d2
) else echo d3
416 if 1==0 if 2==2 if 3==3 (echo e1
) else (echo e2
) else echo e3
418 if 1==0 if 2==2 if 3==0 (echo f1
) else (echo f2
) else echo f3
420 if 1==0 if 2==0 if 3==3 (echo g1
) else (echo g2
) else echo g3
422 if 1==0 if 2==0 if 3==0 (echo h1
) else (echo h2
) else echo h3
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
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
435 if 1==1 echo i1
else echo i2
&echo i3
436 if 1==1 echo j1|
(echo j2
) else echo j3
438 if 1==1 echo k1
&&(echo k2
) else echo k3
439 if 1==1 echo l1||
(echo l2
) else echo l3
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
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
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
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
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
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!)
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
526 echo --- success
/failure
for TYPE command
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!)
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
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
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
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
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
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
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
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
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
634 call :setError 666 & (rmdir &&echo SUCCESS
!errorlevel!||
echo FAILURE
!errorlevel!)
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!)
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
645 call :setError 666 & rmdir & echo ERRORLEVEL !errorlevel!
647 call :setError 666 & rmdir abc
& echo ERRORLEVEL !errorlevel!
648 call :setError 666 & rmdir abc
\abc
& echo ERRORLEVEL !errorlevel!
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
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!)
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!)
706 call :setError 666 & (path ; &&echo SUCCESS
!errorlevel!||
echo FAILURE
!errorlevel!)
708 call :setError 666 & (path !SAVED_PATH
! &&echo SUCCESS
!errorlevel!||
echo FAILURE
!errorlevel!)
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!
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
770 setlocal DisableDelayedExpansion
771 echo ------------ Testing
'set' ------------
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
778 set WINE_FOOBAR
= baz
780 echo %WINE_FOOBAR%WINE_FOOBAR
not defined
782 set WINE_FOOBAR
2> nul
783 set WINE_FOOBAR
= baz2
792 echo %WINE_FOOBAR%WINE_FOOBAR
not defined
794 set WINE_FOOBA
2> nul
> nul
800 echo %WINE_FOO%%WINE_BAR%
803 set WINE_FOO
=%WINE_FOO%
804 echo %WINE_FOO%WINE_FOO
not defined
809 echo set "WINE_FOO=bar" should
not include the quotes in the variable value
816 set WINE_FOO
=foo@space@
818 set WINE_FOO
=foo@tab@
820 rem Space symbol must appear in `var`
821 set WINE_FOO
=value@space@
823 rem Space symbol must NOT appear in `var`
824 set "WINE_FOO=value"@space@
827 set WINE_FOO
=jim fred
829 set WINE_FOO
="jim" fred
831 set "WINE_FOO=jim fred"
833 set "WINE_FOO=jim" fred
835 rem Only the final quote ends the string
836 set "WINE_FOO=apple"banana
"grape"orange
839 rem set PATH must work with quotes
840 set PATH_BACKUP
=%PATH%
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"
851 del "fol;der\sub1.bat"
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
866 choice /C ABC
"/M:Example message" /D
:B /T
0
867 if %ERRORLEVEL% EQU
9009 (
868 echo choice unavailable
871 choice /C def
/D
:f /T
:0
872 if %ERRORLEVEL% EQU
9009 (
873 echo choice unavailable
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
885 choice /C ABC
/N
/D A
/T
0
886 if %ERRORLEVEL% EQU
9009 (
887 echo choice unavailable
890 choice /C abcABC
/CS
/D
:A /T
:0
891 if %ERRORLEVEL% EQU
9009 (
892 echo choice unavailable
895 rem intentional error
896 choice /C abcABC
/D
:A /T
:0 >NUL
2>NUL
899 echo ------------ Testing variable expansion
------------
901 echo ~p0 should be
path containing batch file
908 echo ~dp0 should be directory containing batch file
921 echo P
%WINE_UNKNOWN%S
924 echo %ERRORLEVEL%%ERRORLEVEL%
925 echo %ERRORLEVEL%ERRORLEVEL%
932 echo ------------ Testing variable substrings
------------
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%
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
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
961 for %%i in
("F G" H
) do echo %%~di
963 for %%d in
("I J" K
) do echo %%~pd
965 for %%i in
("L M" N
) do echo %%~ni
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'
971 for %%i in
("U V" W
) do echo '%%~ai'
973 for %%i in
(foo
) do echo '%%~ai'
974 for %%i in
(foo
) do echo '%%~zi'
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'
980 rem Similar issues as above
981 for %%i in
("a b" c
) do echo '%%~zi'
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
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
996 for %%i in
("F G" H
) do call :echoFunD %%i
998 for %%d in
("I J" K
) do call :echoFunP %%d
1000 for %%i in
("L M" N
) do call :echoFunN %%i
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
1042 rem some NT4 workaround
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
1078 echo [%0] [%~d0
] [%~p0
] [%~n0
] [%~x0
] [%~s0
]
1082 echo ------------ Testing variable delayed expansion
------------
1083 rem NT4 doesn't support this
1084 echo --- default
mode (load
-time expansion
)
1088 if %WINE_FOO% == foo
(
1090 if %WINE_FOO% == bar
(echo bar
) else echo foo
1094 if %WINE_FOO% == foo
(
1096 if !WINE_FOO
! == bar
(echo bar
) else echo foo
1099 echo --- runtime
(delayed
) expansion
mode
1100 setlocal EnableDelayedExpansion
1104 if %WINE_FOO% == foo
(
1106 if %WINE_FOO% == bar
(echo bar
) else echo foo
1110 if %WINE_FOO% == foo
(
1112 if !WINE_FOO
! == bar
(echo bar
) else echo foo
1115 if %WINE_FOO% == 32 (
1118 if errorlevel !WINE_FOO
! (echo gotitright
) else echo gotitwrong
1121 setlocal DisableDelayedExpansion
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
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
1149 cd ..
& rd /s
/q foobar
1150 if exist foobazbar
(
1151 echo foobar
not deleted
!
1154 ) else echo foobar deleted
1155 echo --- on success conditional and
1156 call :setError 456 && echo foo3
> 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
1170 echo ------------ Testing
cd ------------
1173 echo blabla
> singleFile
1175 echo Current
dir: %CD%
1190 if not exist foobar
(cd ..
)
1192 cd@tab@..@tab@@space@@tab@
1194 if not exist foobar
(cd ..
)
1208 cd "bar bak@space@
"@tab@@space@
1219 echo ------------ Testing type ------------
1233 type foobaz foobay > foobax 2> foobaw
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
1251 @tab@dir /b@tab@/a-d
1253 rem NUL not special everywhere
1256 if not exist foo (echo foo should have been created) else (
1260 rem Empty file creation
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
1275 copy a.a+NUL subdir\ >nul
1276 call :CheckFileSize a.a 7 subdir\a.a 8
1279 copy ..\a.a NUL >nul
1280 if exist a.a echo Failed
1284 cd .. & rd foobar /s /q
1286 echo ------------ Testing if/else ------------
1287 echo --- if/else should work with blocks
1289 echo if seems to work
1291 echo if seems to be broken
1294 echo else seems to be broken
1296 echo else seems to work
1299 echo if seems not to detect /c as parameter
1301 echo parameter detection seems to be broken
1305 SET /a elseIF=%elseIF%+1
1307 SET /a elseIF=%elseIF%+2
1309 SET /a elseIF=%elseIF%+2
1312 echo else if seems to work
1314 echo else if seems to be broken
1318 SET /a elseIF=%elseIF%+2
1320 SET /a elseIF=%elseIF%+1
1322 SET /a elseIF=%elseIF%+2
1325 echo else if seems to work
1327 echo else if seems to be broken
1331 SET /a elseIF=%elseIF%+2
1333 SET /a elseIF=%elseIF%+2
1335 SET /a elseIF=%elseIF%+1
1338 echo else if seems to work
1340 echo else if seems to be broken
1346 if "y
" == "b
" echo broken2
1347 echo expected post-embedded if
1350 echo comparison operators surrounded by brackets seem to work
1352 echo comparison operators surrounded by brackets seem to be broken
1355 echo comparison operators surrounded by brackets seem to work
1357 echo comparison operators surrounded by brackets seem to be broken
1360 echo comparison operators surrounded by brackets seem to work
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
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
1374 echo windir does exist
1377 echo 1 == 0 should not be true
1379 ) else echo block containing a line with just space seems to work
1381 echo 1 == 0 should not be true
1383 ) else echo block containing a line with just tab seems to work
1385 echo 1 == 0 should not be true
1387 ) else echo block containing a line with just space and tab seems to work
1389 echo 1 == 0 should not be true
1391 ) else echo block containing a line with just tab and space seems to work
1393 echo 1 == 0 should not be true
1396 ) else echo block containing two lines with just space seems to work
1398 echo 1 == 0 should not be true
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 ------------
1501 echo something>subdir\bar
1502 echo something else>foo
1504 echo exist explicit works
1506 echo ERROR exist explicit broken
1509 echo ERROR exist explicit unknown file broken
1511 echo exist explicit unknown file works
1513 if exist subdir\bar (
1514 echo exist explicit in subdir works
1516 echo ERROR exist explicit in subdir broken
1519 echo exist simple wildcard works
1521 echo ERROR exist simple wildcard broken
1523 if exist subdir\ba* (
1524 echo exist wildcard works
1526 echo ERROR exist wildcard broken
1528 if not exist subdir\ba* (
1529 echo ERROR negate exist wildcard broken
1531 echo negate exist wildcard works
1533 if exist idontexist\ba* (
1534 echo ERROR exist wildcard bad subdir broken
1536 echo exist wildcard bad subdir broken works
1539 echo exist subdir ok
1541 echo ERROR exist subdir not working
1544 echo exist subdir with \. ok
1546 echo ERROR exist subdir with \. not working
1549 echo exist subdir with \ ok
1551 echo ERROR exist subdir with \ not working
1553 if exist "subdir
\" (
1554 echo exist subdir with \ and quotes ok
1556 echo ERROR
exist subdir with \ and quotes
not working
1559 echo exist subdir with
/. ok
1561 echo ERROR
exist subdir with
/.
not working
1564 echo exist subdir with
/ ok
1566 echo ERROR
exist subdir with
/ not working
1568 if exist "subdir/" (
1569 echo exist subdir with
/ and quotes ok
1571 echo ERROR
exist subdir with
/ and quotes
not working
1574 echo exist empty string works
1576 echo exist empty string broken
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
1634 echo x
& if "0"=="1" echo 1 & echo 2
1636 echo x
& if "0"=="1" echo 1 & echo 2 & echo 3
1638 echo x
& if "0"=="1" (echo 1 & echo 2 & echo 3)
1640 echo x
& if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
1642 goto :endIfCompOpsSubroutines
1644 rem IF subroutines helpers
1646 if %1 LSS
%2 echo %1 LSS
%2
1649 if %1 LEQ
%2 echo %1 LEQ
%2
1652 if %1 EQU
%2 echo %1 EQU
%2
1655 if %1 NEQ %2 echo %1 NEQ %2
1658 if %1 GEQ
%2 echo %1 GEQ
%2
1661 if %1 GTR
%2 echo %1 GTR
%2
1664 :endIfCompOpsSubroutines
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
1679 rem 'set' in one-line 'if' statement does not interfere with other 'if' blocks
1680 setlocal enableDelayedExpansion
1682 if 1 == 1 set z
=zeta
1689 echo --- Testing
if + var
subst in delayed expansion
mode
1690 setlocal enableDelayedExpansion
1691 for %%i in
(abc
10.0 11.0) do (
1693 echo [DEBUG] checking
{!result
!}
1694 if "!result:~0,3!"=="10." (
1695 echo SDKVER
=!result
!
1700 echo ------------ Testing
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
1724 echo --- imbricated FORs
1731 for %%i in
(A B
) do (
1732 for %%j in
(C D
) do (
1734 for %%i in
(A B
) do (
1735 for %%j in
(C D
) do (
1736 call :forTestFun2 %%i
%%j
))
1737 goto :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}
1750 goto :test_for_loop_params_parse
1753 echo --- nesting and delayed expansion
1754 setlocal enabledelayedexpansion
1756 for %%a in
(a b
) do (
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
1769 ) do if #
==#
(echo %%a
)
1771 mkdir foobar
& cd foobar
1777 echo --- basic wildcards
1778 for %%i in
(ba
*) do echo %%i
1779 echo --- wildcards in subdirs
1780 echo something
>pop
\bar
1
1781 echo something
>pop
\bar
2.txt
1782 echo something
>pop
\bar
3
1783 for %%f in
(pop
\ba
*) do ( call echo %%f
)
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
1813 rem for /d %%i in (?a*) do echo %%i>> tmp
1816 rem for /d %%i in (*) do echo %%i>> tmp
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"
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%%%%"
1847 rem %CD% does not work on NT4 so use the following workaround
1848 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
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\.
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
1869 for /R
"%WINE_CURDIR%" %%i in
(.
) do call temp.bat
"%%i"
1870 call :ValidateExpected
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
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
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\.
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\.
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
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
1940 for /R
%%i in
(baz
* fred
* jim
) do call temp.bat
"%%i"
1941 call :ValidateExpected
1944 echo --- Complex wildcards unix and windows slash
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
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%
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 (
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 (
2007 for %%i in
(test
) do (
2014 for %%i in
(test
) do (
2021 for %%i in
(test
) do (
2033 Rem Ideally for /f can be used rather than building a command to execute
2034 rem but that does not work on NT4
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]
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
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
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
2115 set /a WINE_foo
=WINE_whateverNonExistingVar
+ WINE_bar
& call :checkenvvars WINE_foo
4 WINE_bar
4
2117 set /a WINE_foo
=WINE_bar
-= WINE_bar
+ 7 & call :checkenvvars WINE_foo
-7 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
2122 set /a WINE_foo
=WINE_bar ^
<^
<= 2 & call :checkenvvars WINE_foo
4 WINE_bar
4
2124 set /a WINE_foo
=WINE_bar ^
>^
>= 2 & call :checkenvvars WINE_foo
1 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
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
2133 call :checkenvvars 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
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
2166 set /a WINE_foo
+ = 6
2167 set /a WINE_bar
* = WINE_foo
2168 call :checkenvvars WINE_foo
10 WINE_bar
50
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
2177 echo --- invalid operator sequence
2183 set /a WINE_foo^
>^
<=4
2185 set /a WINE_foo^
>^
>^
>=4
2187 echo ----- negative prefix
2189 call :checkenvvars 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
2199 call :checkenvvars WINE_foo
2
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
2208 set /a WINE_foo
+=3+(WINE_foo
=4)
2209 call :checkenvvars WINE_foo
11
2211 set /a WINE_bar
=3+(WINE_foo
=6)
2212 call :checkenvvars WINE_foo
6 WINE_bar
9
2214 set /a WINE_bar
=3+(WINE_foo
=6,WINE_baz
=7)
2215 call :checkenvvars WINE_foo
6 WINE_bar
10 WINE_baz
7
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
2222 call :checkenvvars WINE_foo
1
2224 call :checkenvvars WINE_foo
0
2226 call :checkenvvars WINE_foo
1
2228 call :checkenvvars WINE_foo
0
2230 call :checkenvvars WINE_foo
1
2232 call :checkenvvars WINE_foo
-1
2234 call :checkenvvars WINE_foo
-1
2236 call :checkenvvars WINE_foo
1
2238 call :checkenvvars WINE_foo
0
2240 call :checkenvvars WINE_foo
-1
2242 call :checkenvvars WINE_foo
0
2244 call :checkenvvars WINE_foo
0
2246 call :checkenvvars WINE_foo
1
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
2264 set /a WINE_bar
=WINE_foo
=6
2265 call :checkenvvars WINE_foo
6 WINE_bar
6
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
2292 for /f
%%i in
(foo
) do echo %%i
2294 for /f
%%i in
(foo
) do echo %%i
2296 for /f
%%i in
(foo
) do echo %%i
2298 for /f
%%i in
(foo
) do echo %%i
2300 for /f
%%i in
(foo
) do echo %%i
2302 for /f
%%i in
(foo
) do echo %%i
2305 for /f
%%i in
(foo
) do echo %%i
2306 echo --------- multi
-line with empty lines
2313 for /f
%%b in
(foo
) do echo %%b
2314 echo --------- multiple
files
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
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
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
2347 for /l
%%i in
(1,1,7) do echo Missing functionality
- Broken
%%i
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
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
2362 goto :ContinueFORFeol
2364 for /l
%%i in
(1,1,3) do echo Broken NT4 functionality
%%i
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
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
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,*
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
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
)
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
2443 :forFParameterSplittingEnd
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
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 ------------
2456 echo deleting
'file'
2459 echo errorlevel is
0, good
2461 echo unexpected
errorlevel, got
%errorlevel%
2464 echo successfully deleted
'file'
2466 echo error deleting
'file'
2468 echo attempting to delete
'file', even though it is
not present
2471 echo errorlevel is
0, good
2473 echo unexpected
errorlevel, got
%errorlevel%
2476 echo ------------ Testing
del /a
------------
2477 del /f
/q
*.test
> nul
2480 echo not-r
> not-r.test
2482 if not exist not-r.test
echo not-r.test
not found before delete
, bad
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
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
------------
2496 echo abc
> file2.dat
2497 rem If /q doesn't work, cmd will prompt and the test case should hang
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
2504 echo ------------ Testing
del /s
------------
2509 echo there
> file2.dat
2510 echo bub
> file3.dat
2511 echo bye
> "file with spaces.dat"
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
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"
2526 echo ------------ Testing
rename ------------
2527 mkdir foobar
& cd foobar
2528 echo --- ren and
rename are synonymous
2531 if exist foo
echo foo should be renamed
!
2532 if exist bar
echo foo renamed to bar
2534 if exist bar
echo bar should be renamed
!
2535 if exist foo
echo bar renamed to foo
2536 echo --- name collision
2546 echo --- rename read
-only
files
2550 if not exist file1
(
2552 echo read
-only file renamed
2555 echo read
-only file
not renamed
!
2557 echo --- rename directories
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
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
2586 move foo bar > nul 2>&1
2589 echo file move succeeded
2594 move /Y bar baz > nul 2>&1
2597 echo file move with overwrite succeeded
2600 echo file overwrite impossible!
2606 move baz bazro > nul 2>&1
2609 echo read-only files are moveable
2610 move bazro baz > nul 2>&1
2613 echo read-only file not moved!
2617 move baz rep > nul 2>&1
2620 echo file moved in subdirectory
2624 move rep\baz . > nul 2>&1
2625 move /Y baz baz > nul 2>&1
2627 echo moving a file to itself should be a no-op!
2629 echo moving a file to itself is a no-op
2631 echo ErrorLevel: %ErrorLevel%
2634 echo --- directory move
2638 move baz foo\bar > nul 2>&1
2640 if exist foo\bar\baz\baz2 (
2641 echo simple directory move succeeded
2646 move baz baz > nul 2>&1
2647 echo moving a directory to itself gives error; errlevel %ErrorLevel%
2648 echo ------ dir in dir move
2653 move foo bar > nul 2>&1
2661 cd .. & rd /s/q foobar
2663 echo ------------ Testing mkdir ------------
2665 echo --- md and mkdir are synonymous
2672 echo --- creating an already existing directory/file must fail
2681 echo --- multilevel path creation
2693 mkdir ..\..\..\foo\bar2
2696 mkdir ..\..\..\foo\bar2
2698 rmdir ..\..\..\foo\bar2
2706 echo --- trailing backslashes
2709 if exist foo (rmdir foo & echo dir created
2710 ) else ( echo dir not created )
2712 echo --- invalid chars
2714 echo mkdir ? gives errorlevel %ErrorLevel%
2717 echo mkdir ?\foo gives errorlevel %ErrorLevel%
2720 echo mkdir foo\? gives errorlevel %ErrorLevel%
2721 if exist foo (rmdir foo & echo ok, foo created
2722 ) else ( echo foo not created )
2725 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
2728 echo bad, foo not created
2732 echo ok, foo\bar created
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
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 ------------
2756 rem rd and rmdir are synonymous
2760 if not exist foobar echo dir removed
2764 if not exist foobar echo dir removed
2765 rem Removing nonexistent directory
2768 rem Removing single-level directories
2772 if exist foo echo file not removed
2778 if exist foo echo non-empty dir not removed
2783 if exist foo echo non-empty dir not removed
2790 echo recursive rmdir succeeded
2797 echo foo > foo\bar\brol
2798 rmdir /s /Q foo 2>&1
2800 echo recursive rmdir succeeded
2807 rem multiples directories at once
2808 mkdir foobaz & cd foobaz
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
2824 echo --- pushing non-existing dir
2827 echo --- basic behaviour
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
2859 echo --- read-only attribute
2860 rem Read-only files cannot be altered or deleted, unless forced
2868 echo Read-only file not deleted
2870 echo Should not delete read-only file!
2874 echo Read-only file forcibly deleted
2876 echo Should delete read-only file with del /F!
2880 cd .. & rd /s/q foobar
2881 echo --- recursive behaviour
2882 mkdir foobar\baz & cd foobar
2888 attrib +R l*vel? /S > nul 2>&1
2894 cd .. & rd /s/q foobar
2895 echo --- folders processing
2901 attrib +r baz /s /d > nul 2>&1
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
2927 rem association set system-wide
2928 echo @
echo off
> tmp.
cmd
2929 echo echo +++>> tmp.
cmd
2930 echo assoc .foo
>> tmp.
cmd
2933 echo --- resetting association
2939 rem association removal set system-wide
2940 cmd /c tmp.
cmd > baz
2943 cd ..
& rd /s
/q foobar
2946 echo --- setting association
2952 echo --- resetting association
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
2971 ftype footype
=foo_opencmd
2975 rem association set system-wide
2976 echo @
echo off
> tmp.
cmd
2977 echo echo +++>> tmp.
cmd
2978 echo ftype footype
>> tmp.
cmd
2981 echo --- resetting association
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
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)
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
3002 cd ..
& rd /s
/q foobar
3005 echo --- setting association
3007 echo footype
=foo_opencmd
3009 echo footype
=foo_opencmd
3011 echo footype
=foo_opencmd
3012 echo --- resetting association
3016 echo ------------ Testing
CALL ------------
3017 mkdir foobar
& cd foobar
3018 echo --- external script
3019 echo echo foo
%%1> foo.
cmd
3022 echo echo %%1 %%2 > foo.
cmd
3024 call foo.
cmd foo bar
3031 echo --- internal routines
3032 call :testRoutine :testRoutine
3033 goto :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
3051 echo --- with builtins
3054 if exist foo
(echo foo created
) else echo foo should
exist!
3056 set WINE_FOOBAZ_VAR
=foobaz
3057 call echo Should expand
%WINE_FOOBAZ_VAR%
3058 set WINE_FOOBAZ_VAR
=
3062 if 1==1 call del batfile
3064 if exist batfile
echo batfile shouldn
't exist
3065 rem arcane command, first resets errorlevel, second sets it to one
3070 rem ... but not for 'if' or 'for'
3072 call if 1==1 echo bar 2> nul
3075 call for %%i in (foo bar baz) do echo %%i 2> nul
3077 rem First look for programs in the path before trying a builtin
3078 echo echo non-builtin dir> dir.cmd
3081 rem The below line equates to call (, which does nothing, then the
3082 rem subsequent lines are executed.
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
3095 call call call echo passed
3096 set WINE_FOO=WINE_BAR
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%%%%%
3104 set WINE_FOO=%%WINE_BAR%%
3106 call :call_expand %WINE_FOO% %%WINE_FOO%% %%%WINE_FOO%%%
3107 goto :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
3139 echo '%1' '%2' '%3' '%4' '%5'
3141 echo '%1' '%2' '%3' '%4' '%5'
3143 echo '%1' '%2' '%3' '%4' '%5'
3145 echo '%1' '%2' '%3' '%4' '%5'
3147 echo '%1' '%2' '%3' '%4' '%5'
3149 echo '%1' '%2' '%3' '%4' '%5'
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
3158 if not exist foo.cmd (
3159 echo file correctly deleted
3161 echo file should be deleted!
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
3171 echo file not created!
3174 echo ---------- Testing copy
3177 rem Note echo adds 0x0d 0x0a on the end of the line in the file
3180 echo CCCCCCCCC> file3
3186 echo Passed: Found expected %1
3188 echo Failed: Did not find expected %1
3190 del /q "%1" >nul 2>&1
3192 if not "%1"=="" goto :CheckExist
3197 echo Passed: Did not find %1
3199 echo Failed: Unexpectedly found %1
3200 del /q "%1" >nul 2>&1
3203 if not "%1"=="" goto :CheckNotExist
3206 rem Note: No way to check file size on NT4 so skip the test
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%]
3216 if "%WINE_filesize%"=="%%~zi" (
3217 echo Skipping file size check on NT4
3219 echo Failed: file size check on %1 [%WINE_filesize% != %2]
3222 :ContinueFileSizeChecks
3225 if not "%1"=="" goto :CheckFileSize
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
3254 copy ..\file1 >nul 2>&1
3255 if errorlevel 1 echo Incorrect errorlevel
3256 call :CheckExist file1
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 -----------------------
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
3278 copy ..\file*.* >nul 2>&1
3279 if errorlevel 1 echo Incorrect errorlevel
3280 call :CheckExist file1 file2 file3
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
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)
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
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
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 ..
\file
1 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 ..
\file
1 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 ..
\file
1 file1_plus_eof
>nul
2>&1
3365 call :CheckFileSize file1_plus_eof
6
3366 copy /a ..
\file
2 file2_plus_eof
>nul
2>&1
3367 call :CheckFileSize file2_plus_eof
9
3368 copy /a ..
\file
3 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 ..
\file
1+..
\file
2 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 ..
\file
1+..
\file
2 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 ..
\file
1+..
\file
2 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
3466 rem ---------------------------------------
3467 rem Error combinations
3468 rem ---------------------------------------
3469 rem Specify source directory but name is a file
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
\file
1
3476 rem Overwrite same file
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
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
3491 echo ------------ Testing
setlocal/endlocal ------------
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%
3499 echo ErrLev
: %ErrorLevel%
3500 echo @
echo off
> tmp.
cmd
3501 echo echo ErrLev
: %%ErrorLevel%%>> tmp.
cmd
3502 rem Enabled by default
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
3525 for /d
%%i in
(.
) do echo %%~dpnxi
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
3543 for /d
%%i in
(.
) do echo %%~dpnxi
3547 echo --- setlocal within same batch program
3551 rem %CD% does not work on NT4 so use the following workaround
3552 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
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
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
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
3579 echo --- Mismatched
set and
end locals
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 ..
\foodir
3>> 2set1end.
cmd
3591 echo setlocal>> 2set1end.
cmd
3592 echo set WINE_VAR
=2set1endvalue2
>> 2set1end.
cmd
3593 echo cd ..
\foodir
4>> 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 ..
\foodir
3>> 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
3612 rem -- setlocal1 == this batch, should never be used inside a called routine
3616 call "%WINE_CURDIR%\2set1end.cmd"
3619 for /d
%%i in
(.
) do echo %%~dpnxi
3622 for /d
%%i in
(.
) do echo %%~dpnxi
3625 echo --- Extra
endlocal in called batch
3627 rem -- setlocal1 == this batch, should never be used inside a called routine
3631 call "%WINE_CURDIR%\1set2end.cmd"
3634 for /d
%%i in
(.
) do echo %%~dpnxi
3637 for /d
%%i in
(.
) do echo %%~dpnxi
3640 echo --- endlocal in called function rather than batch pgm is ineffective
3646 call :endlocalroutine
3650 goto :endlocalfinished
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
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
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
!
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
3694 echo %ErrorLevel% should be
7
3695 if errorlevel 7 echo setting var worked too well
, bad
3697 echo %ErrorLevel% should still be
7
3698 rem Verify that (call ) sets errorlevel to 0
3700 if errorlevel 1 echo errorlevel should have been
0
3702 echo ------------ Testing
GOTO ------------
3704 echo FAILURE at dest
1
3706 echo goto with no leading space worked
3707 if a
==a
goto :dest1b
3708 echo FAILURE at dest
1b
3710 echo goto with colon and no leading space worked
3712 echo FAILURE at dest
2
3714 echo goto with a leading space worked
3716 echo FAILURE at dest
3
3718 echo goto with a leading tab worked
3720 echo FAILURE at dest
4
3722 echo goto with a following space worked
3724 echo FAILURE at dest
5
3725 :dest5&& echo FAILURE
3726 echo goto with following amphersands worked
3728 del failure.txt
>nul
2>&1
3730 echo FAILURE at dest
6
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
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
3757 del testgoto.bat
>nul
2>&1
3760 echo FAILURE at dest
9
3762 echo FAILURE at dest
91
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
3775 set nextlabel
=middle
3780 if not "%nextlabel%"=="" goto :%nextlabel%
3785 if not "%nextlabel%"=="" goto :%nextlabel%
3792 set nextlabel
=nearend
3797 if not "%nextlabel%"=="" goto :%nextlabel%
3809 if not "%nextlabel%"=="" goto :%nextlabel%
3822 echo ------------ Testing
PATH ------------
3823 set WINE_backup_path
=%path%
3831 echo ------------ Testing
PATH Evaluate
------------
3833 echo echo I
'm here! > folder\sub1.bat
3835 echo Test normal PATH usage
3836 set path=%cd%\folder
3839 echo Test PATH usage with leading semicolon
3840 set path=;%cd%\folder
3843 echo Test PATH usage with fallback path
3844 set path=%cd%;%cd%\folder
3847 echo Test PATH usage with double semicolon
3848 set path=%cd%;;%cd%\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 ----------
3866 if errorlevel 1 echo Normal drive change failed
3871 if errorlevel 1 echo Normal+space drive change failed
3873 echo Normal+space+garbage
3876 if errorlevel 1 echo Normal+space+garbage drive change failed
3879 echo Quoted should fail
3881 if not errorlevel 1 echo quoted drive change unexpectedly worked
3886 if errorlevel 1 echo Normal+tab drive change failed
3888 echo Normal+tab+garbage
3891 if errorlevel 1 echo Normal+tab+garbage drive change failed
3895 echo ------------ Testing length wrt. MAX_PATH ------------
3896 rem native cmd limits all path lengths to MAX_PATH=260
3899 for /L %%d in (0,1,25) do (
3900 mkdir abcdefghij > NUL 2>&1
3901 if exist abcdefghij (
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
3913 rmdir /s /q c:\abcdefghij
3914 echo ------------ Testing combined CALLs/GOTOs ------------
3915 echo @echo off>foo.cmd
3916 echo goto :eof>>foot.cmd
3918 echo echo world>>foo.cmd
3920 echo @echo off>foot.cmd
3921 echo echo cheball>>foot.cmd
3923 echo call :bar>>foot.cmd
3924 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
3925 echo goto :eof>>foot.cmd
3928 echo echo barbare>>foot.cmd
3929 echo goto :eof>>foot.cmd
3935 rem Script execution stops after the following line
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 -----------
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
3967 rem This line runs under cmd in windows NT 4, but not in more modern versions.