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 --- redirections within IF statements
180 if 1==1 echo foo1>bar
182 if 1==1 echo foo2>>bar
185 if 1==1 (echo foo2>bar) else echo baz2>bar
187 if 1==1 (echo foo3) else echo baz3>bar
188 type bar || echo file does not exist, ok
189 if 1==1 (echo foo4>bar) else echo baz4>bar
191 if 1==0 (echo foo5>bar) else echo baz5>bar
193 if 1==0 (echo foo6) else echo baz6 1>bar
195 if 1==0 (echo foo7 1>bar) else echo baz7>bar
197 if 1==0 (echo foo8 1>bar) else echo baz8>bak
199 if 1==1 (echo foo>bar & echo baz)
206 (if 1==1 (echo A) else echo B) > C
208 (if 1==0 (echo A) else echo B) > C
210 (if 1==0 (echo A > B) else echo C)
211 cd .. & rd /s/q foobar
213 echo ------------ Testing circumflex escape character ------------
214 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
236 echo bak ^
&& echo baz
2> nul
244 set WINE_FOO
=bar ^| baz
246 rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
247 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
250 set WINE_FOO
=bar ^^^| baz
256 echo ------------ Testing chains
------------
257 rem The chain operators have the following bottom-up precedence:
258 rem 'else' precedes nothing and matches the closest unmatched 'if' in the same bracket depth
259 rem '&' precedes 'else'
260 rem '||' precedes '&' and 'else'
261 rem '&&' precedes '||', '&' and 'else'
262 rem '|' precedes '&&', '||', '&' and 'else'
264 rem Example: 'if 1==1 if 2==2 if 3==3 a | b && c || d & e else f else g' is interpreted as
265 rem 'if 1==1 (if 2==2 (if 3==3 ((((a | b) && c) || d) & e) else f) else g)'
272 echo --- chain success
277 echo d1
&echo d2
&echo d3
278 echo e1
&echo e2
&&echo e3
279 echo f1
&echo f2||
echo f3
281 echo g1
&&echo g2
&echo g3
282 echo h1
&&echo h2
&&echo h3
283 echo i1
&&echo i2||
echo i3
285 echo j1||
echo j2
&echo j3
287 echo k1||
echo k2
&&echo k3
289 echo l1||
echo l2||
echo l3
291 echo --- chain failure
292 call :cfail a1
&call :cfail a2
293 call :cfail b1
&&call :cfail b2
295 call :cfail c1||
call :cfail c2
296 call :cfail d1
&call :cfail d2
&call :cfail d3
297 call :cfail e1
&call :cfail e2
&&call :cfail e3
299 call :cfail f1
&call :cfail f2||
call :cfail f3
300 call :cfail g1
&&call :cfail g2
&call :cfail g3
302 call :cfail h1
&&call :cfail h2
&&call :cfail h3
304 call :cfail i1
&&call :cfail i2||
call :cfail i3
306 call :cfail j1||
call :cfail j2
&call :cfail j3
307 call :cfail k1||
call :cfail k2
&&call :cfail k3
309 call :cfail l1||
call :cfail l2||
call :cfail l3
310 echo --- chain brackets
311 rem Brackets are like regular commands, they support redirections
312 rem and have the same precedence as regular commands.
313 echo a1
&(echo a2
&echo a3
)
314 echo b1
&(echo b2
&&echo b3
)
315 echo c1
&(echo c2||
echo c3
)
317 echo d1
&&(echo d2
&echo d3
)
318 echo e1
&&(echo e2
&&echo e3
)
319 echo f1
&&(echo f2||
echo f3
)
321 echo g1||
(echo g2
&echo g3
)
323 echo h1||
(echo h2
&&echo h3
)
325 echo i1||
(echo i2||
echo i3
)
327 call :cfail j1
&(call :cfail j2
&call :cfail j3
)
328 call :cfail k1
&(call :cfail k2
&&call :cfail k3
)
330 call :cfail l1
&(call :cfail l2||
call :cfail l3
)
331 call :cfail m1
&&(call :cfail m2
&call :cfail m3
)
333 call :cfail n1
&&(call :cfail n2
&&call :cfail n3
)
335 call :cfail o1
&&(call :cfail o2||
call :cfail o3
)
337 call :cfail p1||
(call :cfail p2
&call :cfail p3
)
338 call :cfail q1||
(call :cfail q2
&&call :cfail q3
)
340 call :cfail r1||
(call :cfail r2||
call :cfail r3
)
342 rem Piped commands run at the same time, so the print order varies.
343 rem Additionally, they don't run in the batch script context, as shown by
344 rem 'call :existing_label|echo read the error message'.
345 (echo a
1>&2|
echo a
1>&2) 2>&1
348 echo c1
&&echo c2|
echo c3
349 echo d1||
echo d2|
echo d3
351 echo e1
&echo e2|
echo e3
352 echo f1|
echo f2
&&echo f3
353 echo g1|
echo g2||
echo g3
355 echo h1|
echo h2
&echo h3
356 echo i1|
echo i2|
echo i3
357 echo --- chain pipe input
358 rem The output data of the left side of a pipe can disappear, probably
359 rem because it finished too fast and closed the pipe before it could be read,
360 rem which means we can get broken results for the tests of this section.
361 echo @
echo off
> tmp.
cmd
362 echo set IN
=X
>> tmp.
cmd
363 echo set /p IN
=%%1:>> tmp.
cmd
364 echo setlocal EnableDelayedExpansion
>> tmp.
cmd
365 echo echo [!IN
!,%%1]>> tmp.
cmd
366 echo endlocal>> tmp.
cmd
367 echo set IN
=>> tmp.
cmd
368 echo a1|
cmd /ctmp.
cmd a2
369 echo b1|
cmd /ctmp.
cmd b2|
cmd /ctmp.
cmd b3
370 echo c1|
cmd /ctmp.
cmd c2|
cmd /ctmp.
cmd c3|
cmd /ctmp.
cmd c4
371 echo d1|
call tmp.
cmd d2
372 echo e1|
call tmp.
cmd e2|
call tmp.
cmd e3
373 echo f1|
call tmp.
cmd f2|
call tmp.
cmd f3|
call tmp.
cmd f4
374 rem FIXME these 3 tests cause "unexpected end of output"
375 rem test : echo g1|tmp.cmd g2
376 rem result: g2:[g1,g2]
377 rem test : echo h1|tmp.cmd h2|tmp.cmd h3
378 rem result: h3:[h2:[h1,h2],h3]@or_broken@h3:[h2:,h3]
379 rem test : echo i1|tmp.cmd i2|tmp.cmd i3|tmp.cmd i4
380 rem result: i4:[i3:[i2:[i1,i2],i3],i4]@or_broken@i4:[i3:[i2:,i3],i4]@or_broken@i4:[i3:,i4]
383 rem Command arguments are gready and eat up the 'else' unless terminated by
384 rem brackets, which means the 'else' can only be recognized when the
385 rem 'if true' command chain ends with brackets.
386 if 1==1 if 2==2 if 3==3 (echo a1
) else (echo a2
) else echo a3
387 if 1==1 if 2==2 if 3==0 (echo b1
) else (echo b2
) else echo b3
389 if 1==1 if 2==0 if 3==3 (echo c1
) else (echo c2
) else echo c3
391 if 1==1 if 2==0 if 3==0 (echo d1
) else (echo d2
) else echo d3
393 if 1==0 if 2==2 if 3==3 (echo e1
) else (echo e2
) else echo e3
395 if 1==0 if 2==2 if 3==0 (echo f1
) else (echo f2
) else echo f3
397 if 1==0 if 2==0 if 3==3 (echo g1
) else (echo g2
) else echo g3
399 if 1==0 if 2==0 if 3==0 (echo h1
) else (echo h2
) else echo h3
401 echo --- chain
else (if true
)
402 if 1==1 echo a1
else echo a2
403 if 1==1 echo b1|
echo b2
else echo b3
404 if 1==1 echo c1
&&echo c2
else echo c3
405 if 1==1 echo d1||
echo d2
else echo d3
407 if 1==1 echo e1
&echo e2
else echo e3
408 if 1==1 echo f1
else echo f2|
echo f3
409 if 1==1 echo g1
else echo g2
&&echo g3
410 if 1==1 echo h1
else echo h2||
echo h3
412 if 1==1 echo i1
else echo i2
&echo i3
413 if 1==1 echo j1|
(echo j2
) else echo j3
415 if 1==1 echo k1
&&(echo k2
) else echo k3
416 if 1==1 echo l1||
(echo l2
) else echo l3
418 if 1==1 echo m1
&(echo m2
) else echo m3
419 if 1==1 (echo n1
) else echo n2|
echo n3
420 if 1==1 (echo o1
) else echo o2
&&echo o3
421 if 1==1 (echo p1
) else echo p2||
echo p3
422 if 1==1 (echo q1
) else echo q2
&echo q3
424 echo --- chain
else (if false
)
425 if 1==0 echo a1
else echo a2
426 if 1==0 echo b1|
echo b2
else echo b3
427 if 1==0 echo c1
&&echo c2
else echo c3
428 if 1==0 echo d1||
echo d2
else echo d3
429 if 1==0 echo e1
&echo e2
else echo e3
430 if 1==0 echo f1
else echo f2|
echo f3
431 if 1==0 echo g1
else echo g2
&&echo g3
432 if 1==0 echo h1
else echo h2||
echo h3
433 if 1==0 echo i1
else echo i2
&echo i3
434 if 1==0 echo j1|
(echo j2
) else echo j3
436 if 1==0 echo k1
&&(echo k2
) else echo k3
437 if 1==0 echo l1||
(echo l2
) else echo l3
438 if 1==0 echo m1
&(echo m2
) else echo m3
439 if 1==0 (echo n1
) else echo n2|
echo n3
440 if 1==0 (echo o1
) else echo o2
&&echo o3
441 if 1==0 (echo p1
) else echo p2||
echo p3
443 if 1==0 (echo q1
) else echo q2
&echo q3
444 echo ------------ Testing
'set' ------------
446 rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
447 for /f
"delims==" %%i in
('set WINE_ba') do set %%i
=
448 for /f
"delims==" %%i in
('set WINE_foo') do set %%i
=
449 set WINE_FOOBAR
2> nul
> nul
451 set WINE_FOOBAR
= baz
453 echo %WINE_FOOBAR%WINE_FOOBAR
not defined
455 set WINE_FOOBAR
2> nul
456 set WINE_FOOBAR
= baz2
465 echo %WINE_FOOBAR%WINE_FOOBAR
not defined
467 set WINE_FOOBA
2> nul
> nul
473 echo %WINE_FOO%%WINE_BAR%
476 set WINE_FOO
=%WINE_FOO%
477 echo %WINE_FOO%WINE_FOO
not defined
482 echo set "WINE_FOO=bar" should
not include the quotes in the variable value
489 set WINE_FOO
=foo@space@
491 set WINE_FOO
=foo@tab@
493 rem Space symbol must appear in `var`
494 set WINE_FOO
=value@space@
496 rem Space symbol must NOT appear in `var`
497 set "WINE_FOO=value"@space@
500 set WINE_FOO
=jim fred
502 set WINE_FOO
="jim" fred
504 set "WINE_FOO=jim fred"
506 set "WINE_FOO=jim" fred
508 rem Only the final quote ends the string
509 set "WINE_FOO=apple"banana
"grape"orange
512 rem set PATH must work with quotes
513 set PATH_BACKUP
=%PATH%
516 echo echo I
'm here! > "fol;der\sub1.bat"
517 echo echo I'm here
! > folder\sub1.bat
518 set PATH=nothing
;"fol;der"
524 del "fol;der\sub1.bat"
530 echo ------------ Testing variable expansion
------------
532 echo ~p0 should be
path containing batch file
539 echo ~dp0 should be directory containing batch file
552 echo P
%WINE_UNKNOWN%S
555 echo %ERRORLEVEL%%ERRORLEVEL%
556 echo %ERRORLEVEL%ERRORLEVEL%
563 echo ------------ Testing variable substrings
------------
568 echo '%WINE_VAR:~-2,3%'
569 echo '%WINE_VAR:~-2,1%'
570 echo %WINE_VAR
:~
2,-1%
571 echo %WINE_VAR
:~
2,-3%
572 echo '%WINE_VAR:~-2,-4%'
573 echo %WINE_VAR
:~
-3,-2%
576 echo ------------ Testing variable substitution
------------
577 echo --- in
FOR variables
578 for %%i in
("A B" C
) do echo %%i
579 rem check works when prefix with @
580 @
for %%i in
("A B" C
) do echo %%i
582 for %%i in
("A B" C
) do echo '%%~i'
583 rem fully qualified path
584 for %%f in
("C D" E
) do echo %%~ff
586 for %%i in
("F G" H
) do echo %%~di
588 for %%d in
("I J" K
) do echo %%~pd
590 for %%i in
("L M" N
) do echo %%~ni
592 for %%i in
("O. P.OOL" Q.TABC hello
) do echo '%%~xi'
593 rem path with short path names
594 for %%I in
("R S" T ABCDEFGHIJK.LMNOP
) do echo '%%~sI'
596 for %%i in
("U V" W
) do echo '%%~ai'
598 for %%i in
(foo
) do echo '%%~ai'
599 for %%i in
(foo
) do echo '%%~zi'
602 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
603 for %%i in
("a b" c
) do echo '%%~ti'
605 rem Similar issues as above
606 for %%i in
("a b" c
) do echo '%%~zi'
608 for %%i in
("d e" f
) do echo %%~dpi
609 for %%i in
("g h" i
) do echo %%~sdi
610 for %%i in
("g h" i
) do echo %%~dsi
611 for %%i in
("j k" l.eh
) do echo '%%~xsi'
612 for %%i in
("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
614 echo --- in parameters
615 for %%i in
("A B" C
) do call :echoFun %%i
617 for %%i in
("A B" C
) do call :echoFunQ %%i
618 rem fully qualified path
619 for %%f in
("C D" E
) do call :echoFunF %%f
621 for %%i in
("F G" H
) do call :echoFunD %%i
623 for %%d in
("I J" K
) do call :echoFunP %%d
625 for %%i in
("L M" N
) do call :echoFunN %%i
627 for %%i in
("O. P.OOL" Q.TABC hello
) do call :echoFunX %%i
628 rem path with short path names
629 for %%I in
("R S" T ABCDEFGHIJK.LMNOP
) do call :echoFunS %%I
630 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
632 for %%i in
("d e" f
) do call :echoFunDP %%i
633 for %%i in
("g h" i
) do call :echoFunSD %%i
634 for %%i in
("g h" i
) do call :echoFunDS %%i
635 for %%i in
("j k" l.eh
) do call :echoFunXS %%i
667 rem some NT4 workaround
690 echo ------------ Testing parameter zero
------------
691 call :func parm1 parm2
695 echo [%0] [%~d0
] [%~p0
] [%~n0
] [%~x0
] [%~s0
]
699 echo ------------ Testing variable delayed expansion
------------
700 rem NT4 doesn't support this
701 echo --- default
mode (load
-time expansion
)
705 if %WINE_FOO% == foo
(
707 if %WINE_FOO% == bar
(echo bar
) else echo foo
711 if %WINE_FOO% == foo
(
713 if !WINE_FOO
! == bar
(echo bar
) else echo foo
716 echo --- runtime
(delayed
) expansion
mode
717 setlocal EnableDelayedExpansion
721 if %WINE_FOO% == foo
(
723 if %WINE_FOO% == bar
(echo bar
) else echo foo
727 if %WINE_FOO% == foo
(
729 if !WINE_FOO
! == bar
(echo bar
) else echo foo
732 setlocal DisableDelayedExpansion
738 echo --- using
/V
cmd flag
739 echo @
echo off
> tmp.
cmd
740 echo set WINE_FOO
=foo
>> tmp.
cmd
741 echo echo %%WINE_FOO%%>> tmp.
cmd
742 echo echo !WINE_FOO
!>> tmp.
cmd
743 echo set WINE_FOO
=>> tmp.
cmd
745 cmd /V
:OfF /C tmp.
cmd
748 echo ------------ Testing conditional execution
------------
749 echo --- unconditional ampersand
750 call :setError 123 & echo foo1
751 echo bar2
& echo foo2
752 mkdir foobar
& cd foobar
754 cd ..
& rd /s
/q foobar
756 echo foobar
not deleted
!
759 ) else echo foobar deleted
760 echo --- on success conditional and
761 call :setError 456 && echo foo3
> foo3
765 ) else echo foo3
not created
766 echo bar4
&& echo foo4
767 echo --- on failure conditional or
768 call :setError 789 ||
echo foo5
769 echo foo6 ||
echo bar6
> bar6
775 echo ------------ Testing
cd ------------
778 echo blabla
> singleFile
780 echo Current
dir: %CD%
795 if not exist foobar
(cd ..
)
797 cd@tab@..@tab@@space@@tab@
799 if not exist foobar
(cd ..
)
813 cd "bar bak@space@
"@tab@@space@
824 echo ------------ Testing type ------------
838 echo ------------ Testing NUL ------------
839 md foobar & cd foobar
840 rem NUL file (non) creation + case insensitivity
841 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
850 rem NUL not special everywhere
853 if not exist foo (echo foo should have been created) else (
857 rem Empty file creation
867 copy a.a+NUL b.b >nul
868 call :CheckFileSize a.a 7 b.b 8
869 copy NUL+a.a b.b >nul
870 call :CheckFileSize a.a 7 b.b 8
872 copy a.a+NUL subdir\ >nul
873 call :CheckFileSize a.a 7 subdir\a.a 8
877 if exist a.a echo Failed
881 cd .. & rd foobar /s /q
883 echo ------------ Testing if/else ------------
884 echo --- if/else should work with blocks
886 echo if seems to work
888 echo if seems to be broken
891 echo else seems to be broken
893 echo else seems to work
896 echo if seems not to detect /c as parameter
898 echo parameter detection seems to be broken
902 SET /a elseIF=%elseIF%+1
904 SET /a elseIF=%elseIF%+2
906 SET /a elseIF=%elseIF%+2
909 echo else if seems to work
911 echo else if seems to be broken
915 SET /a elseIF=%elseIF%+2
917 SET /a elseIF=%elseIF%+1
919 SET /a elseIF=%elseIF%+2
922 echo else if seems to work
924 echo else if seems to be broken
928 SET /a elseIF=%elseIF%+2
930 SET /a elseIF=%elseIF%+2
932 SET /a elseIF=%elseIF%+1
935 echo else if seems to work
937 echo else if seems to be broken
943 if "y
" == "b
" echo broken2
944 echo expected post-embedded if
946 echo --- case sensitivity with and without /i option
947 if bar==BAR echo if does not default to case sensitivity
948 if not bar==BAR echo if seems to default to case sensitivity
949 if /i foo==FOO echo if /i seems to work
950 if /i not foo==FOO echo if /i seems to be broken
951 if /I foo==FOO echo if /I seems to work
952 if /I not foo==FOO echo if /I seems to be broken
954 echo --- string comparisons
955 if abc == abc (echo equal) else echo non equal
956 if abc =="abc
" (echo equal) else echo non equal
957 if "abc
"== abc (echo equal) else echo non equal
958 if "abc
"== "abc
" (echo equal) else echo non equal
960 echo --- tabs handling
961 if@tab@1==1 echo doom
962 if @tab@1==1 echo doom
963 if 1==1 (echo doom) else@tab@echo quake
964 if@tab@not @tab@1==@tab@0 @tab@echo lol
965 if 1==0@tab@(echo doom) else echo quake
966 if 1==0 (echo doom)@tab@else echo quake
967 if 1==0 (echo doom) else@tab@echo quake
969 echo --- comparison operators
970 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
971 echo ------ for strings
972 rem NT4 stops processing of the whole batch file as soon as it finds a
973 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
974 rem can't test those here.
975 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
976 if LSS LSS LSS (echo bar)
977 if 1.1 LSS 1.10 (echo floats are handled as strings)
978 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
979 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
980 if /i foo LSS FoOc echo if /i seems to work for LSS
981 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
982 set WINE_STR_PARMS=A B AB BA AA
983 for %%i in (%WINE_STR_PARMS%) do (
984 for %%j in (%WINE_STR_PARMS%) do (
985 call :LSStest %%i %%j))
986 if b LSS B (echo b LSS B) else echo NT4
987 if /I b LSS B echo b LSS B insensitive
988 if b LSS A echo b LSS A
989 if /I b LSS A echo b LSS A insensitive
990 if a LSS B (echo a LSS B) else echo NT4
991 if /I a LSS B echo a LSS B insensitive
992 if A LSS b echo A LSS b
993 if /I A LSS b echo A LSS b insensitive
994 for %%i in (%WINE_STR_PARMS%) do (
995 for %%j in (%WINE_STR_PARMS%) do (
996 call :LEQtest %%i %%j))
997 if b LEQ B (echo b LEQ B) else echo NT4
998 if /I b LEQ B echo b LEQ B insensitive
999 if b LEQ A echo b LEQ A
1000 if /I b LEQ A echo b LEQ A insensitive
1001 if a LEQ B (echo a LEQ B) else echo NT4
1002 if /I a LEQ B echo a LEQ B insensitive
1003 if A LEQ b echo A LEQ b
1004 if /I A LEQ b echo A LEQ b insensitive
1005 for %%i in (%WINE_STR_PARMS%) do (
1006 for %%j in (%WINE_STR_PARMS%) do (
1007 call :EQUtest %%i %%j))
1008 if /I A EQU a echo A EQU a insensitive
1009 for %%i in (%WINE_STR_PARMS%) do (
1010 for %%j in (%WINE_STR_PARMS%) do (
1011 call :NEQtest %%i %%j))
1012 for %%i in (%WINE_STR_PARMS%) do (
1013 for %%j in (%WINE_STR_PARMS%) do (
1014 call :GEQtest %%i %%j))
1015 for %%i in (%WINE_STR_PARMS%) do (
1016 for %%j in (%WINE_STR_PARMS%) do (
1017 call :GTRtest %%i %%j))
1019 echo ------------ Testing if/exist ------------
1021 echo something>subdir\bar
1022 echo something else>foo
1024 echo exist explicit works
1026 echo ERROR exist explicit broken
1029 echo ERROR exist explicit unknown file broken
1031 echo exist explicit unknown file works
1033 if exist subdir\bar (
1034 echo exist explicit in subdir works
1036 echo ERROR exist explicit in subdir broken
1039 echo exist simple wildcard works
1041 echo ERROR exist simple wildcard broken
1043 if exist subdir\ba* (
1044 echo exist wildcard works
1046 echo ERROR exist wildcard broken
1048 if not exist subdir\ba* (
1049 echo ERROR negate exist wildcard broken
1051 echo negate exist wildcard works
1053 if exist idontexist\ba* (
1054 echo ERROR exist wildcard bad subdir broken
1056 echo exist wildcard bad subdir broken works
1059 echo exist subdir ok
1061 echo ERROR exist subdir not working
1064 echo exist subdir with . ok
1066 echo ERROR exist subdir with . not working
1069 echo exist subdir with \ ok
1071 echo ERROR exist subdir with \ not working
1073 if exist "subdir
\" (
1074 echo exist subdir with \ and quotes ok
1076 echo ERROR
exist subdir with \ and quotes
not working
1081 echo ------ for numbers
1082 if -1 LSS
1 (echo negative numbers handled
)
1083 if not -1 LSS
-10 (echo negative numbers handled
)
1084 if not 9 LSS
010 (echo octal handled
)
1085 if not -010 LSS
-8 (echo also in negative form
)
1086 if 4 LSS
0x5 (echo hexa handled
)
1087 if not -1 LSS
-0x1A (echo also in negative form
)
1088 if 11 LSS
101 (echo 11 LSS
101)
1089 set WINE_INT_PARMS
=0 1 10 9
1090 for %%i in
(%WINE_INT_PARMS%) do (
1091 for %%j in
(%WINE_INT_PARMS%) do (
1092 call :LSStest %%i
%%j
))
1093 for %%i in
(%WINE_INT_PARMS%) do (
1094 for %%j in
(%WINE_INT_PARMS%) do (
1095 call :LEQtest %%i
%%j
))
1096 for %%i in
(%WINE_INT_PARMS%) do (
1097 for %%j in
(%WINE_INT_PARMS%) do (
1098 call :EQUtest %%i
%%j
))
1099 if 011 EQU
9 (echo octal ok
)
1100 if 0xA1 EQU
161 (echo hexa ok
)
1101 if 0xA1 EQU
"161" (echo hexa should be recognized
) else (echo string
/hexa compare ok
)
1102 if "0xA1" EQU
161 (echo hexa should be recognized
) else (echo string
/hexa compare ok
)
1103 for %%i in
(%WINE_INT_PARMS%) do (
1104 for %%j in
(%WINE_INT_PARMS%) do (
1105 call :NEQtest %%i
%%j
))
1106 for %%i in
(%WINE_INT_PARMS%) do (
1107 for %%j in
(%WINE_INT_PARMS%) do (
1108 call :GEQtest %%i
%%j
))
1109 for %%i in
(%WINE_INT_PARMS%) do (
1110 for %%j in
(%WINE_INT_PARMS%) do (
1111 call :GTRtest %%i
%%j
))
1112 echo ------ for numbers and stringified numbers
1113 if not "1" EQU
1 (echo strings and integers
not equal
) else echo foo
1114 if not 1 EQU
"1" (echo strings and integers
not equal
) else echo foo
1115 if '1' EQU
1 echo '1' EQU
1
1116 if 1 EQU
'1' echo 1 EQU
'1'
1117 if not "1" GEQ
1 (echo foo
) else echo bar
1118 if "10" GEQ
"1" echo "10" GEQ
"1"
1119 if '1' GEQ
1 (echo '1' GEQ
1) else echo NT4
1120 if 1 GEQ
"1" echo 1 GEQ
"1"
1121 if "1" GEQ
"1" echo "1" GEQ
"1"
1122 if '1' GEQ
"1" echo '1' GEQ
"1"
1123 if "10" GEQ
"1" echo "10" GEQ
"1"
1124 if not 1 GEQ
'1' (echo non NT4
) else echo 1 GEQ
'1'
1125 for %%i in
("1" '1') do call :GEQtest %%i
'1'
1126 if "10" GEQ
'1' (echo "10" GEQ
'1') else echo foo
1127 if 1 GEQ
"10" (echo 1 GEQ
"10") else echo foo
1128 if "1" GEQ
"10" (echo 1 GEQ
"10") else echo foo
1129 if '1' GEQ
"10" (echo '1' GEQ
"10") else echo foo
1130 if "10" GEQ
"10" (echo "10" GEQ
"10")
1131 echo --- unconditional ampersand after
if one line
1132 if "0"=="0" echo 1 & echo 2 & echo 3 else echo 4
1134 echo x
& if "0"=="1" echo 1 & echo 2
1136 echo x
& if "0"=="1" echo 1 & echo 2 & echo 3
1138 echo x
& if "0"=="1" (echo 1 & echo 2 & echo 3)
1140 echo x
& if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
1142 goto :endIfCompOpsSubroutines
1144 rem IF subroutines helpers
1146 if %1 LSS
%2 echo %1 LSS
%2
1149 if %1 LEQ
%2 echo %1 LEQ
%2
1152 if %1 EQU
%2 echo %1 EQU
%2
1155 if %1 NEQ %2 echo %1 NEQ %2
1158 if %1 GEQ
%2 echo %1 GEQ
%2
1161 if %1 GTR
%2 echo %1 GTR
%2
1164 :endIfCompOpsSubroutines
1168 echo ------------ Testing
for ------------
1170 for %%i in
(A B C
) do echo %%i
1171 for %%i in
(A B C
) do echo %%I
1172 for %%i in
(A B C
) do echo %%j
1173 for %%i in
(A B C
) do call :forTestFun1 %%i
1174 for %%i in
(1,4,1) do echo %%i
1175 for %%i in
(A
, B
,C
) do echo %%i
1176 for %%i in
(X
) do echo %%i
1177 for@tab@
%%i in
(X2
) do echo %%i
1178 for %%i in@tab@
(X3
) do echo %%i
1179 for %%i in
(@tab@ foo@tab@
) do echo %%i
1180 for@tab@
%%i in@tab@
(@tab@M
) do echo %%i
1181 for %%i@tab@in
(X
)@tab@
do@tab@
echo %%i
1182 for@tab@
%%j in@tab@
(@tab@M
, N
, O@tab@
) do echo %%j
1183 for %%i in
(`
echo A B`
) do echo %%i
1184 for %%i in
('echo A B') do echo %%i
1185 for %%i in
("echo A B") do echo %%i
1186 for %%i in
("A B" C
) do echo %%i
1187 goto :endForTestFun1
1192 echo --- imbricated FORs
1199 for %%i in
(A B
) do (
1200 for %%j in
(C D
) do (
1202 for %%i in
(A B
) do (
1203 for %%j in
(C D
) do (
1204 call :forTestFun2 %%i
%%j
))
1205 goto :endForTestFun2
1210 mkdir foobar
& cd foobar
1216 echo --- basic wildcards
1217 for %%i in
(ba
*) do echo %%i
1218 echo --- wildcards in subdirs
1219 echo something
>pop
\bar
1
1220 echo something
>pop
\bar
2.txt
1221 echo something
>pop
\bar
3
1222 for %%f in
(pop
\ba
*) do ( call echo %%f
)
1225 for /d
%%i in
(baz foo bar
) do echo %%i
2>&1
1226 rem Confirm we don't match files:
1227 for /d
%%i in
(bazb
*) do echo %%i
2>&1
1228 for /d
%%i in
(bazb2
*) do echo %%i
2>&1
1229 rem Show we pass through non wildcards
1230 for /d
%%i in
(PASSED
) do echo %%i
1231 for /d
%%i in
(xxx
) do (
1232 echo %%i
- Should be xxx
1233 echo Expected second line
1235 rem Show we issue no messages on failures
1236 for /d
%%i in
(FAILED?
) do echo %%i
2>&1
1237 for /d
%%i in
(FAILED?
) do (
1238 echo %%i
- Unexpected
!
1239 echo FAILED Unexpected second line
1241 for /d
%%i in
(FAILED
*) do echo %%i
2>&1
1242 for /d
%%i in
(FAILED
*) do (
1243 echo %%i
- Unexpected
!
1244 echo FAILED Unexpected second line
1246 rem FIXME can't test wildcard expansion here since it's listed in directory
1247 rem order, and not in alphabetic order.
1248 rem Proper testing would need a currently missing "sort" program implementation.
1249 rem for /d %%i in (ba*) do echo %%i>> tmp
1252 rem for /d %%i in (?a*) do echo %%i>> tmp
1255 rem for /d %%i in (*) do echo %%i>> tmp
1263 call :WriteLine set WINE_found
=N
1264 for /l
%%i in
(1,1,%WINE_expectedresults%) do (
1265 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%~1" set WINE_found
=Y
1266 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.
%%i
=
1267 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
1269 call :WriteLine echo Got unexpected result
: "%%%%~1"
1278 for /l
%%i in
(1,1,%WINE_expectedresults%) do (
1279 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result
: "%%%%WINE_expectedresults.%%i%%%%"
1286 rem %CD% does not work on NT4 so use the following workaround
1287 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
1290 echo Plain directory enumeration
1291 set WINE_expectedresults
=4
1292 set WINE_expectedresults
.1=%WINE_CURDIR%\.
1293 set WINE_expectedresults
.2=%WINE_CURDIR%\bar\.
1294 set WINE_expectedresults
.3=%WINE_CURDIR%\baz\.
1295 set WINE_expectedresults
.4=%WINE_CURDIR%\foo\.
1297 for /R
%%i in
(.
) do call temp.bat
"%%i"
1298 call :ValidateExpected
1300 echo Plain directory enumeration from provided root
1301 set WINE_expectedresults
=4
1302 set WINE_expectedresults
.1=%WINE_CURDIR%\.
1303 set WINE_expectedresults
.2=%WINE_CURDIR%\bar\.
1304 set WINE_expectedresults
.3=%WINE_CURDIR%\baz\.
1305 set WINE_expectedresults
.4=%WINE_CURDIR%\foo\.
1306 if "%CD%"=="" goto :SkipBrokenNT4
1308 for /R
"%WINE_CURDIR%" %%i in
(.
) do call temp.bat
"%%i"
1309 call :ValidateExpected
1312 echo File enumeration
1313 set WINE_expectedresults
=2
1314 set WINE_expectedresults
.1=%WINE_CURDIR%\baz
\bazbaz
1315 set WINE_expectedresults
.2=%WINE_CURDIR%\bazbaz
1317 for /R
%%i in
(baz
*) do call temp.bat
"%%i"
1318 call :ValidateExpected
1320 echo File enumeration from provided root
1321 set WINE_expectedresults
=2
1322 set WINE_expectedresults
.1=%WINE_CURDIR%\baz
\bazbaz
1323 set WINE_expectedresults
.2=%WINE_CURDIR%\bazbaz
1325 for /R
%%i in
(baz
*) do call temp.bat
"%%i"
1326 call :ValidateExpected
1328 echo Mixed enumeration
1329 set WINE_expectedresults
=6
1330 set WINE_expectedresults
.1=%WINE_CURDIR%\.
1331 set WINE_expectedresults
.2=%WINE_CURDIR%\bar\.
1332 set WINE_expectedresults
.3=%WINE_CURDIR%\baz\.
1333 set WINE_expectedresults
.4=%WINE_CURDIR%\baz
\bazbaz
1334 set WINE_expectedresults
.5=%WINE_CURDIR%\bazbaz
1335 set WINE_expectedresults
.6=%WINE_CURDIR%\foo\.
1337 for /R
%%i in
(. baz
*) do call temp.bat
"%%i"
1338 call :ValidateExpected
1340 echo Mixed enumeration from provided root
1341 set WINE_expectedresults
=6
1342 set WINE_expectedresults
.1=%WINE_CURDIR%\.
1343 set WINE_expectedresults
.2=%WINE_CURDIR%\bar\.
1344 set WINE_expectedresults
.3=%WINE_CURDIR%\baz\.
1345 set WINE_expectedresults
.4=%WINE_CURDIR%\baz
\bazbaz
1346 set WINE_expectedresults
.5=%WINE_CURDIR%\bazbaz
1347 set WINE_expectedresults
.6=%WINE_CURDIR%\foo\.
1349 for /R
%%i in
(. baz
*) do call temp.bat
"%%i"
1350 call :ValidateExpected
1352 echo With duplicates enumeration
1353 set WINE_expectedresults
=12
1354 set WINE_expectedresults
.1=%WINE_CURDIR%\bar
\bazbaz
1355 set WINE_expectedresults
.2=%WINE_CURDIR%\bar
\fred
1356 set WINE_expectedresults
.3=%WINE_CURDIR%\baz
\bazbaz
1357 set WINE_expectedresults
.4=%WINE_CURDIR%\baz
\bazbaz
1358 set WINE_expectedresults
.5=%WINE_CURDIR%\baz
\bazbaz
1359 set WINE_expectedresults
.6=%WINE_CURDIR%\baz
\fred
1360 set WINE_expectedresults
.7=%WINE_CURDIR%\bazbaz
1361 set WINE_expectedresults
.8=%WINE_CURDIR%\bazbaz
1362 set WINE_expectedresults
.9=%WINE_CURDIR%\bazbaz
1363 set WINE_expectedresults
.10=%WINE_CURDIR%\foo
\bazbaz
1364 set WINE_expectedresults
.11=%WINE_CURDIR%\foo
\fred
1365 set WINE_expectedresults
.12=%WINE_CURDIR%\fred
1367 for /R
%%i in
(baz
* bazbaz fred ba
*) do call temp.bat
"%%i"
1368 call :ValidateExpected
1370 echo Strip missing wildcards
, keep unwildcarded names
1371 set WINE_expectedresults
=6
1372 set WINE_expectedresults
.1=%WINE_CURDIR%\bar\jim
1373 set WINE_expectedresults
.2=%WINE_CURDIR%\baz
\bazbaz
1374 set WINE_expectedresults
.3=%WINE_CURDIR%\baz\jim
1375 set WINE_expectedresults
.4=%WINE_CURDIR%\bazbaz
1376 set WINE_expectedresults
.5=%WINE_CURDIR%\foo\jim
1377 set WINE_expectedresults
.6=%WINE_CURDIR%\jim
1379 for /R
%%i in
(baz
* fred
* jim
) do call temp.bat
"%%i"
1380 call :ValidateExpected
1383 echo --- Complex wildcards unix and windows slash
1385 echo Windows slashes
, valid
path
1386 for %%f in
(foobar
\baz
\bazbaz
) do echo ASIS
: %%f
1387 for %%f in
(foobar
\baz\
*) do echo WC
: %%f
1388 echo Windows slashes
, invalid
path
1389 for %%f in
(foobar\jim
\bazbaz
) do echo ASIS
: %%f
1390 for %%f in
(foobar\jim\
*) do echo WC
: %%f
1391 echo Unix slashes
, valid
path
1392 for %%f in
(foobar
/baz
/bazbaz
) do echo ASIS
: %%f
1393 for %%f in
(foobar
/baz
/*) do echo WC
: %%f
1394 echo Unix slashes
, invalid
path
1395 for %%f in
(foobar
/jim
/bazbaz
) do echo ASIS
: %%f
1396 for %%f in
(foobar
/jim
/*) do echo WC
: %%f
1400 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
1401 for /L
%%i in
(1,2,0) do echo %%i
1402 for@tab@
/L
%%i in
(1,2,0) do echo %%i
1403 for /L
%%i in
(1,2,6) do echo %%i
1404 for /l
%%i in
(1 ,2,6) do echo %%i
1405 for /L
%%i in
(a
,2,3) do echo %%i
1406 for /L
%%i in
(1,2,-1) do echo %%i
1407 for /L
%%i in
(-4,-1,-1) do echo %%i
1408 for /L
%%i in
(1,-2,-2) do echo %%i
1409 for /L
%%i in
(1,2,a
) do echo %%i
1410 echo ErrorLevel %ErrorLevel%
1411 for /L
%%i in
(1,a
,b
) do echo %%i
1412 echo ErrorLevel %ErrorLevel%
1414 for /l
%%i in
(1,1,4) do echo %%i
1415 for /l
%%i in
(1,2,4) do echo %%i
1416 for /l
%%i in
(4,-1,1) do echo %%i
1417 for /l
%%i in
(4,-2,1) do echo %%i
1418 for /l
%%i in
(1,-1,4) do echo %%i
1419 for /l
%%i in
(4,1,1) do echo %%i
1420 for /L
%%i in
(a
,2,b
) do echo %%i
1421 for /L
%%i in
(1,1,1) do echo %%i
1422 for /L
%%i in
(1,-2,-1) do echo %%i
1423 for /L
%%i in
(-1,-1,-1) do echo %%i
1424 for /L
%%i in
(1,2, 3) do echo %%i
1425 rem Test zero iteration skips the body of the for
1426 for /L
%%i in
(2,2,1) do (
1430 echo --- ifs inside
for loops
1431 for %%i in
(test
) do (
1440 for %%i in
(test
) do (
1447 for %%i in
(test
) do (
1454 for %%i in
(test
) do (
1466 Rem Ideally for /f can be used rather than building a command to execute
1467 rem but that does not work on NT4
1469 if "%1"=="" goto :eof
1470 call :executecmd set wine_result
=%%%1%%
1471 if "%wine_result%"=="%2" (
1472 echo %1 correctly
%2
1473 ) else echo ERROR
: %1 incorrectly
%wine_result% [%2]
1484 rem No output when using "set expr" syntax, unless in interactive mode
1485 rem Need to use "set envvar=expr" to use in a batch script
1486 echo ------ individual operations
1488 set /a WINE_foo
=1 +2 & call :checkenvvars WINE_foo
3
1489 set /a WINE_foo
=1 +-2 & call :checkenvvars WINE_foo
-1
1490 set /a WINE_foo
=1 --2 & call :checkenvvars WINE_foo
3
1491 set /a WINE_foo
=2* 3 & call :checkenvvars WINE_foo
6
1492 set /a WINE_foo
=-2* -5 & call :checkenvvars WINE_foo
10
1493 set /a WINE_foo
=12/3 & call :checkenvvars WINE_foo
4
1494 set /a WINE_foo
=13/3 & call :checkenvvars WINE_foo
4
1495 set /a WINE_foo
=-13/3 & call :checkenvvars WINE_foo
-4
1496 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1497 set /a WINE_foo
=5 %% 5 & call :checkenvvars WINE_foo
0
1498 set /a WINE_foo
=5 %% 3 & call :checkenvvars WINE_foo
2
1499 set /a WINE_foo
=5 %% -3 & call :checkenvvars WINE_foo
2
1500 set /a WINE_foo
=-5 %% -3 & call :checkenvvars WINE_foo
-2
1501 set /a WINE_foo
=1 ^
<^
< 0 & call :checkenvvars WINE_foo
1
1502 set /a WINE_foo
=1 ^
<^
< 2 & call :checkenvvars WINE_foo
4
1503 set /a WINE_foo
=1 ^
<^
< -2 & call :checkenvvars WINE_foo
0
1504 set /a WINE_foo
=-1 ^
<^
< -2 & call :checkenvvars WINE_foo
0
1505 set /a WINE_foo
=-1 ^
<^
< 2 & call :checkenvvars WINE_foo
-4
1506 set /a WINE_foo
=9 ^
>^
> 0 & call :checkenvvars WINE_foo
9
1507 set /a WINE_foo
=9 ^
>^
> 2 & call :checkenvvars WINE_foo
2
1508 set /a WINE_foo
=9 ^
>^
> -2 & call :checkenvvars WINE_foo
0
1509 set /a WINE_foo
=-9 ^
>^
> -2 & call :checkenvvars WINE_foo
-1
1510 set /a WINE_foo
=-9 ^
>^
> 2 & call :checkenvvars WINE_foo
-3
1511 set /a WINE_foo
=5 ^
& 0 & call :checkenvvars WINE_foo
0
1512 set /a WINE_foo
=5 ^
& 1 & call :checkenvvars WINE_foo
1
1513 set /a WINE_foo
=5 ^
& 3 & call :checkenvvars WINE_foo
1
1514 set /a WINE_foo
=5 ^
& 4 & call :checkenvvars WINE_foo
4
1515 set /a WINE_foo
=5 ^
& 1 & call :checkenvvars WINE_foo
1
1516 set /a WINE_foo
=5 ^|
0 & call :checkenvvars WINE_foo
5
1517 set /a WINE_foo
=5 ^|
1 & call :checkenvvars WINE_foo
5
1518 set /a WINE_foo
=5 ^|
3 & call :checkenvvars WINE_foo
7
1519 set /a WINE_foo
=5 ^|
4 & call :checkenvvars WINE_foo
5
1520 set /a WINE_foo
=5 ^|
1 & call :checkenvvars WINE_foo
5
1521 set /a WINE_foo
=5 ^^
0 & call :checkenvvars WINE_foo
5
1522 set /a WINE_foo
=5 ^^
1 & call :checkenvvars WINE_foo
4
1523 set /a WINE_foo
=5 ^^
3 & call :checkenvvars WINE_foo
6
1524 set /a WINE_foo
=5 ^^
4 & call :checkenvvars WINE_foo
1
1525 set /a WINE_foo
=5 ^^
1 & call :checkenvvars WINE_foo
4
1526 echo ------ precedence and grouping
1527 set /a WINE_foo
=4 + 2*3 & call :checkenvvars WINE_foo
10
1528 set /a WINE_foo
=(4+2)*3 & call :checkenvvars WINE_foo
18
1529 set /a WINE_foo
=4 * 3/5 & call :checkenvvars WINE_foo
2
1530 set /a WINE_foo
=(4 * 3)/5 & call :checkenvvars WINE_foo
2
1531 set /a WINE_foo
=4 * 5 %% 4 & call :checkenvvars WINE_foo
0
1532 set /a WINE_foo
=4 * (5 %% 4) & call :checkenvvars WINE_foo
4
1533 set /a WINE_foo
=3 %% (5 + 8 %% 3 ^^
2) & call :checkenvvars WINE_foo
3
1534 set /a WINE_foo
=3 %% (5 + 8 %% 3 ^^
-2) & call :checkenvvars WINE_foo
3
1535 echo ------ octal and hexadecimal
1536 set /a WINE_foo
=0xf + 3 & call :checkenvvars WINE_foo
18
1537 set /a WINE_foo
=0xF + 3 & call :checkenvvars WINE_foo
18
1538 set /a WINE_foo
=015 + 2 & call :checkenvvars WINE_foo
15
1539 set /a WINE_foo
=3, 8+3,0 & call :checkenvvars WINE_foo
3
1540 echo ------ variables
1541 set /a WINE_foo
=WINE_bar
=3, WINE_bar
+1 & call :checkenvvars WINE_foo
3 WINE_bar
3
1542 set /a WINE_foo
=WINE_bar
=3, WINE_bar
+=1 & call :checkenvvars WINE_foo
3 WINE_bar
4
1543 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
1545 set /a WINE_foo
=WINE_bar
*= WINE_bar
& call :checkenvvars WINE_foo
9 WINE_bar
9
1546 set /a WINE_foo
=WINE_whateverNonExistingVar
& call :checkenvvars WINE_foo
0
1548 set /a WINE_foo
=WINE_whateverNonExistingVar
+ WINE_bar
& call :checkenvvars WINE_foo
4 WINE_bar
4
1550 set /a WINE_foo
=WINE_bar
-= WINE_bar
+ 7 & call :checkenvvars WINE_foo
-7 WINE_bar
-7
1552 set /a WINE_foo
=WINE_bar
/= 3 + 2 & call :checkenvvars WINE_foo
-1 WINE_bar
-1
1553 set /a WINE_foo
=WINE_bar
=5, WINE_bar
%%=2 & call :checkenvvars WINE_foo
5 WINE_bar
1
1555 set /a WINE_foo
=WINE_bar ^
<^
<= 2 & call :checkenvvars WINE_foo
4 WINE_bar
4
1557 set /a WINE_foo
=WINE_bar ^
>^
>= 2 & call :checkenvvars WINE_foo
1 WINE_bar
1
1559 set /a WINE_foo
=WINE_bar ^
&= 2 & call :checkenvvars WINE_foo
0 WINE_bar
0
1560 set /a WINE_foo
=WINE_bar
=5, WINE_bar ^|
= 2 & call :checkenvvars WINE_foo
5 WINE_bar
7
1561 set /a WINE_foo
=WINE_bar
=5, WINE_bar ^^
= 2 & call :checkenvvars WINE_foo
5 WINE_bar
7
1563 set /a WINE_foo
=WINE_bar
=19, WINE_bar
%%= 4 + (WINE_baz
%%= 7) & call :checkenvvars WINE_foo
19 WINE_bar
3 WINE_baz
4
1566 call :checkenvvars WINE_foo
1
1568 call :checkenvvars WINE_foo
1
1569 set /a WINE_foo
=1,WINE_bar
=2
1570 call :checkenvvars WINE_foo
1 WINE_bar
2
1571 set /a
"WINE_foo=1,WINE_bar=2"
1572 call :checkenvvars WINE_foo
1 WINE_bar
2
1573 set /a
"WINE_foo=1","WINE_bar=2"
1574 call :checkenvvars WINE_foo
1 WINE_bar
2
1575 set /a
""WINE_foo
=1","WINE_bar
=2""
1576 call :checkenvvars WINE_foo
1 WINE_bar
2
1577 set /a WINE_foo
=1,WINE_bar
=2,WINE_baz
=3
1578 call :checkenvvars WINE_foo
1 WINE_bar
2 WINE_baz
3
1579 set /a
"WINE_foo=1,WINE_bar=2,WINE_baz=3"
1580 call :checkenvvars WINE_foo
1 WINE_bar
2 WINE_baz
3
1581 set /a
"WINE_foo=1","WINE_bar=2","WINE_baz=3"
1582 call :checkenvvars WINE_foo
1 WINE_bar
2 WINE_baz
3
1583 set /a
""WINE_foo
=1","WINE_bar
=2","WINE_baz
=3""
1584 call :checkenvvars WINE_foo
1 WINE_bar
2 WINE_baz
3
1585 set /a
""WINE_foo
=1","WINE_bar
=2"","WINE_baz=3"
1586 call :checkenvvars WINE_foo
1 WINE_bar
2 WINE_baz
3
1587 set /a
""""""WINE_foo
=1""""""
1588 call :checkenvvars WINE_foo
1
1589 set /a
""""""WINE_foo
=1","WINE_bar
=5""","WINE_baz
=2""
1590 call :checkenvvars WINE_foo
1 WINE_bar
5 WINE_baz
2
1591 set /a WINE_foo
="3"+"4"+"5+6"
1592 call :checkenvvars WINE_foo
18
1594 set /a WINE_bar
="WINE_""foo"+4
1595 call :checkenvvars WINE_foo
3 WINE_bar
7
1596 echo --- whitespace are ignored between double char operators
1599 set /a WINE_foo
+ = 6
1600 set /a WINE_bar
* = WINE_foo
1601 call :checkenvvars WINE_foo
10 WINE_bar
50
1604 set /a WINE_foo
+ = "6 < < 7"
1605 set /a WINE_bar
* = WINE_foo
+ WINE_foo
1606 call :checkenvvars WINE_foo
772 WINE_bar
7720
1610 echo --- invalid operator sequence
1616 set /a WINE_foo^
>^
<=4
1618 set /a WINE_foo^
>^
>^
>=4
1620 echo ----- negative prefix
1622 call :checkenvvars WINE_foo
-1
1624 call :checkenvvars WINE_foo
1
1625 set /a WINE_foo
=3--3
1626 call :checkenvvars WINE_foo
6
1627 set /a WINE_foo
=3---3
1628 call :checkenvvars WINE_foo
0
1629 set /a WINE_foo
=3----3
1630 call :checkenvvars WINE_foo
6
1632 call :checkenvvars WINE_foo
2
1634 call :checkenvvars WINE_foo
0
1635 set /a WINE_foo
=3+-~
1
1636 call :checkenvvars WINE_foo
5
1637 set /a WINE_foo
=3+~
-1
1638 call :checkenvvars WINE_foo
3
1639 echo ----- assignment tests involving the
end destination
1641 set /a WINE_foo
+=3+(WINE_foo
=4)
1642 call :checkenvvars WINE_foo
11
1644 set /a WINE_bar
=3+(WINE_foo
=6)
1645 call :checkenvvars WINE_foo
6 WINE_bar
9
1647 set /a WINE_bar
=3+(WINE_foo
=6,WINE_baz
=7)
1648 call :checkenvvars WINE_foo
6 WINE_bar
10 WINE_baz
7
1650 set /a WINE_bar
=WINE_foo
=7
1651 call :checkenvvars WINE_foo
7 WINE_bar
7
1652 echo ----- equal precedence on stack
1653 rem Unary - don't reduce if precedence is equal
1655 call :checkenvvars WINE_foo
1
1657 call :checkenvvars WINE_foo
0
1659 call :checkenvvars WINE_foo
1
1661 call :checkenvvars WINE_foo
0
1663 call :checkenvvars WINE_foo
1
1665 call :checkenvvars WINE_foo
-1
1667 call :checkenvvars WINE_foo
-1
1669 call :checkenvvars WINE_foo
1
1671 call :checkenvvars WINE_foo
0
1673 call :checkenvvars WINE_foo
-1
1675 call :checkenvvars WINE_foo
0
1677 call :checkenvvars WINE_foo
0
1679 call :checkenvvars WINE_foo
1
1681 call :checkenvvars WINE_foo
-1
1682 rem Aritmatic - Reduce if precedence is equal
1683 set /a WINE_foo
=10*5/2
1684 call :checkenvvars WINE_foo
25
1685 set /a WINE_foo
=5/2*10
1686 call :checkenvvars WINE_foo
20
1687 set /a WINE_foo
=10/5/2
1688 call :checkenvvars WINE_foo
1
1689 set /a WINE_foo
=5%%2*4
1690 call :checkenvvars WINE_foo
4
1691 set /a WINE_foo
=10-5+2
1692 call :checkenvvars WINE_foo
7
1693 set /a WINE_foo
=1^
<^
<4^
>^
>1
1694 call :checkenvvars WINE_foo
8
1695 rem Assignment - don't reduce if precedence is equal
1697 set /a WINE_bar
=WINE_foo
=6
1698 call :checkenvvars WINE_foo
6 WINE_bar
6
1701 mkdir foobar
& cd foobar
1702 echo ------ string argument
1703 rem NT4 does not support usebackq
1704 for /F
%%i in
("a b c") do echo %%i
1705 for /F
%%i in
( "a b c" ) do echo X
%%iX
1706 for /f usebackq
%%i in
('a b c') do echo %%i
>output_file
1707 if not exist output_file
(echo no output
) else (type output_file
& del output_file
)
1708 for /f usebackq
%%i in
( 'a b c' ) do echo X
%%iX
>output_file
1709 if not exist output_file
(echo no output
) else (type output_file
& del output_file
)
1710 for /f
%%i in
("a ") do echo %%i
1711 for /f usebackq
%%i in
('a ') do echo %%i
>output_file
1712 if not exist output_file
(echo no output
) else (type output_file
& del output_file
)
1713 for /f
%%i in
("a") do echo %%i
1714 for /f usebackq
%%i in
('a') do echo %%i
>output_file
1715 if not exist output_file
(echo no output
) else (type output_file
& del output_file
)
1716 fOr /f
%%i in
(" a") do echo %%i
1717 for /f usebackq
%%i in
(' a') do echo %%i
>output_file
1718 if not exist output_file
(echo no output
) else (type output_file
& del output_file
)
1719 for /f
%%i in
(" a ") do echo %%i
1720 for /f usebackq
%%i in
(' a ') do echo %%i
>output_file
1721 if not exist output_file
(echo no output
) else (type output_file
& del output_file
)
1722 echo ------ fileset argument
1723 echo --------- basic blank handling
1725 for /f
%%i in
(foo
) do echo %%i
1727 for /f
%%i in
(foo
) do echo %%i
1729 for /f
%%i in
(foo
) do echo %%i
1731 for /f
%%i in
(foo
) do echo %%i
1733 for /f
%%i in
(foo
) do echo %%i
1735 for /f
%%i in
(foo
) do echo %%i
1738 for /f
%%i in
(foo
) do echo %%i
1739 echo --------- multi
-line with empty lines
1746 for /f
%%b in
(foo
) do echo %%b
1747 echo --------- multiple
files
1751 for /f
%%k in
(foo bar
) do echo %%k
1752 for /f
%%k in
(bar foo
) do echo %%k
1753 echo ------ command argument
1754 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1755 if "%CD%"=="" goto :SkipFORFcmdNT4
1756 for /f
%%i in
('echo.Passed1') do echo %%i
1757 for /f
"usebackq" %%i in
(`
echo.Passed2`
) do echo %%i
1758 for /f usebackq
%%i in
(`
echo.Passed3`
) do echo %%i
1759 for /f
"usebackq" %%i in
(`
"c:\windows\system32\cmd.exe" /C
echo Passed4`
) do echo %%i
1760 for /f
"usebackq" %%i in
(`
""c
:\windows\system32\
cmd.exe
" /C echo Passed5"`
) do echo %%i
1761 for /f
%%i in
( 'echo.Passed6' ) do echo %%i
1762 for /f
"usebackq" %%i in
( `
echo.Passed7`
) do echo %%i
1765 for /l
%%i in
(1,1,7) do echo Missing functionality
- Broken
%%i
1767 rem FIXME: Rest not testable right now in wine: not implemented and would need
1768 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1769 rem for a simple todo_wine test
1770 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1771 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1772 echo ------ eol option
1773 if "%CD%"=="" goto :SkipFORFeolNT4
1775 echo and Line two
>>foo
1776 echo Line three
>>foo
1777 for /f
"eol=L" %%i in
(foo
) do echo %%i
1778 for /f
"eol=a" %%i in
(foo
) do echo %%i
1780 goto :ContinueFORFeol
1782 for /l
%%i in
(1,1,3) do echo Broken NT4 functionality
%%i
1784 for /f
"eol=@" %%i in
(" ad") do echo %%i
1785 for /f
"eol=@" %%i in
(" z@y") do echo %%i
1786 for /f
"eol=|" %%i in
("a|d") do echo %%i
1787 for /f
"eol=@" %%i in
("@y") do echo %%i
> output_file
1788 if not exist output_file
(echo no output
) else (del output_file
)
1789 for /f
"eol==" %%i in
("=y") do echo %%i
> output_file
1790 if not exist output_file
(echo no output
) else (del output_file
)
1791 echo ------ delims option
1792 for /f
"delims=|" %%i in
("a|d") do echo %%i
1793 for /f
"delims=|" %%i in
("a |d") do echo %%i
1794 for /f
"delims=|" %%i in
("a d|") do echo %%i
1795 for /f
"delims=| " %%i in
("a d|") do echo %%i
1796 for /f
"delims==" %%i in
("C r=d|") do echo %%i
1797 for /f
"delims=" %%i in
("foo bar baz") do echo %%i
1798 for /f
"delims=" %%i in
("c:\foo bar baz\..") do echo %%~fi
1799 echo ------ skip option
1803 for /f
"skip=2" %%i in
(foo
) do echo %%i
1804 for /f
"skip=3" %%i in
(foo
) do echo %%i
> output_file
1805 if not exist output_file
(echo no output
) else (del output_file
)
1806 for /f
"skip=4" %%i in
(foo
) do echo %%i
> output_file
1807 if not exist output_file
(echo no output
) else (del output_file
)
1808 for /f
"skip=02" %%i in
(foo
) do echo %%i
1809 for /f
"skip=0x2" %%i in
(foo
) do echo %%i
1810 for /f
"skip=1" %%i in
("skipme") do echo %%i
> output_file
1811 if not exist output_file
(echo no output
) else (del output_file
)
1812 echo ------ tokens
= option
1814 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
1815 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
1816 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
1817 rem Show * means the rest
1818 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
1819 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
1820 rem Show * means the rest (not tokenized and rebuilt)
1821 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
1822 rem Order is irrelevant
1823 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
1824 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
1825 rem Duplicates are ignored
1826 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
1827 rem Large tokens are allowed
1828 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
1829 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1830 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
1831 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
1832 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1833 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
1834 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
1835 rem Show negative ranges have no effect
1836 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
1837 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
1838 rem Show duplicates stop * from working
1839 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
1840 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
1841 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
1842 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
1843 rem Special case tokens=* or tokens=n,*
1845 FOR /F
"tokens=*" %%A IN
(testfile
) DO @
echo 1:%%A
,%%B
1846 FOR /F
"tokens=1*" %%A IN
(testfile
) DO @
echo 2:%%A
,%%B
1847 FOR /F
"tokens=2*" %%A IN
(testfile
) DO @
echo 3:%%A
,%%B
1848 FOR /F
"tokens=1,* delims=." %%A IN
(testfile
) DO @
echo 4:%%A
,%%B
1852 echo ------ parameter splitting
1853 echo forFParameterSplittingFunc
"myparam1=myvalue1 myparam2=myparam2" mytest
> foo
1854 for /f
"tokens=1 delims=;" %%i in
(foo
) do (call :%%i
)
1856 for /f
"tokens=1 delims=;" %%i in
("forFParameterSplittingFunc "myparam1^
=myvalue1 myparam2^
=myparam2
" mytest") do (call :%%i
)
1857 goto :forFParameterSplittingEnd
1858 :forFParameterSplittingFunc
1859 echo %~
0 %~
1 %~
2 %~
3 %~
4 %~
5
1861 :forFParameterSplittingEnd
1863 FOR /F
"delims=. tokens=*" %%A IN
(testfile
) DO @
echo 4:%%A
,%%B
1864 FOR /F
"delims=. tokens=1*" %%A IN
(testfile
) DO @
echo 5:%%A
,%%B
1865 FOR /F
"delims=. tokens=2*" %%A IN
(testfile
) DO @
echo 6:%%A
,%%B
1866 FOR /F
"delims=. tokens=3*" %%A IN
(testfile
) DO @
echo 7:%%A
,%%B
1869 echo ------------ Testing
del ------------
1871 echo deleting
'file'
1874 echo errorlevel is
0, good
1876 echo unexpected
errorlevel, got
%errorlevel%
1879 echo successfully deleted
'file'
1881 echo error deleting
'file'
1883 echo attempting to delete
'file', even though it is
not present
1886 echo errorlevel is
0, good
1888 echo unexpected
errorlevel, got
%errorlevel%
1891 echo ------------ Testing
del /a
------------
1892 del /f
/q
*.test
> nul
1895 echo not-r
> not-r.test
1897 if not exist not-r.test
echo not-r.test
not found before delete
, bad
1899 if not exist not-r.test
echo not-r.test
not found after delete
, good
1901 if not exist r.test
echo r.test
not found before delete
, bad
1902 if exist r.test
echo r.test found before delete
, good
1904 if not exist r.test
echo r.test
not found after delete
, good
1905 if exist r.test
echo r.test found after delete
, bad
1907 echo ------------ Testing
del /q
------------
1911 echo abc
> file2.dat
1912 rem If /q doesn't work, cmd will prompt and the test case should hang
1914 for %%a in
(1 2.dat
) do if exist file
%%a
echo del /q
* failed on file
%%a
1915 for %%a in
(1 2.dat
) do if not exist file
%%a
echo del /q
* succeeded on file
%%a
1919 echo ------------ Testing
del /s
------------
1924 echo there
> file2.dat
1925 echo bub
> file3.dat
1926 echo bye
> "file with spaces.dat"
1928 del /s file1.dat
> nul
1929 del file2.dat
/s
> nul
1930 del "file3.dat" /s
> nul
1931 del "file with spaces.dat" /s
> nul
1933 for %%f in
(1 2 3) do if exist file
%%f.dat
echo Del /s failed on file
%%f
1934 for %%f in
(1 2 3) do if exist file
%%f.dat
del file
%%f.dat
1935 if exist "file with spaces.dat" echo Del /s failed on
"file with spaces.dat"
1936 if exist "file with spaces.dat" del "file with spaces.dat"
1941 echo ------------ Testing
rename ------------
1942 mkdir foobar
& cd foobar
1943 echo --- ren and
rename are synonymous
1946 if exist foo
echo foo should be renamed
!
1947 if exist bar
echo foo renamed to bar
1949 if exist bar
echo bar should be renamed
!
1950 if exist foo
echo bar renamed to foo
1951 echo --- name collision
1961 echo --- rename read
-only
files
1965 if not exist file1
(
1967 echo read
-only file renamed
1970 echo read
-only file
not renamed
!
1972 echo --- rename directories
1984 echo read
-only
dir renamed
1987 echo --- rename in other directory
1988 if not exist baz
\abc
(
1989 echo rename impossible in other directory
1990 if exist foo
echo original file still present
1992 echo shouldn
't rename in other directory!
1993 if not exist foo echo original file not present anymore
1995 cd .. & rd /s/q foobar
1997 echo ------------ Testing move ------------
1998 mkdir foobar & cd foobar
2001 move foo bar > nul 2>&1
2004 echo file move succeeded
2009 move /Y bar baz > nul 2>&1
2012 echo file move with overwrite succeeded
2015 echo file overwrite impossible!
2021 move baz bazro > nul 2>&1
2024 echo read-only files are moveable
2025 move bazro baz > nul 2>&1
2028 echo read-only file not moved!
2032 move baz rep > nul 2>&1
2035 echo file moved in subdirectory
2039 move rep\baz . > nul 2>&1
2040 move /Y baz baz > nul 2>&1
2042 echo moving a file to itself should be a no-op!
2044 echo moving a file to itself is a no-op
2046 echo ErrorLevel: %ErrorLevel%
2049 echo --- directory move
2053 move baz foo\bar > nul 2>&1
2055 if exist foo\bar\baz\baz2 (
2056 echo simple directory move succeeded
2061 move baz baz > nul 2>&1
2062 echo moving a directory to itself gives error; errlevel %ErrorLevel%
2063 echo ------ dir in dir move
2068 move foo bar > nul 2>&1
2076 cd .. & rd /s/q foobar
2078 echo ------------ Testing mkdir ------------
2080 echo --- md and mkdir are synonymous
2087 echo --- creating an already existing directory/file must fail
2096 echo --- multilevel path creation
2108 mkdir ..\..\..\foo\bar2
2111 mkdir ..\..\..\foo\bar2
2113 rmdir ..\..\..\foo\bar2
2121 echo --- trailing backslashes
2124 if exist foo (rmdir foo & echo dir created
2125 ) else ( echo dir not created )
2127 echo --- invalid chars
2129 echo mkdir ? gives errorlevel %ErrorLevel%
2132 echo mkdir ?\foo gives errorlevel %ErrorLevel%
2135 echo mkdir foo\? gives errorlevel %ErrorLevel%
2136 if exist foo (rmdir foo & echo ok, foo created
2137 ) else ( echo foo not created )
2140 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
2143 echo bad, foo not created
2147 echo ok, foo\bar created
2153 echo --- multiple directories at once
2154 mkdir foobaz & cd foobaz
2155 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
2156 if exist foo (echo foo created) else echo foo not created!
2157 if exist bar (echo bar created) else echo bar not created!
2158 if exist foobar (echo foobar created) else echo foobar not created!
2159 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
2160 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
2161 if exist zabzab (echo zabzab created) else echo zabzab not created!
2162 cd .. & rd /s/q foobaz
2165 echo mkdir foo\* errorlevel %ErrorLevel%
2166 if exist foo (rmdir foo & echo ok, foo created
2167 ) else ( echo bad, foo not created )
2169 echo ------------ Testing rmdir ------------
2171 rem rd and rmdir are synonymous
2175 if not exist foobar echo dir removed
2179 if not exist foobar echo dir removed
2180 rem Removing nonexistent directory
2183 rem Removing single-level directories
2187 if exist foo echo file not removed
2193 if exist foo echo non-empty dir not removed
2198 if exist foo echo non-empty dir not removed
2205 echo recursive rmdir succeeded
2212 echo foo > foo\bar\brol
2213 rmdir /s /Q foo 2>&1
2215 echo recursive rmdir succeeded
2222 rem multiples directories at once
2223 mkdir foobaz & cd foobaz
2227 rd /s/q foo bar foobar
2228 if not exist foo (echo foo removed) else echo foo not removed!
2229 if not exist bar (echo bar removed) else echo bar not removed!
2230 if not exist foobar (echo foobar removed) else echo foobar not removed!
2231 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
2232 cd .. & rd /s/q foobaz
2234 echo ------------ Testing pushd/popd ------------
2236 echo --- popd is no-op when dir stack is empty
2239 echo --- pushing non-existing dir
2242 echo --- basic behaviour
2267 echo ------------ Testing attrib ------------
2268 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
2269 mkdir foobar & cd foobar
2270 echo foo original contents> foo
2273 echo --- read-only attribute
2274 rem Read-only files cannot be altered or deleted, unless forced
2282 echo Read-only file not deleted
2284 echo Should not delete read-only file!
2288 echo Read-only file forcibly deleted
2290 echo Should delete read-only file with del /F!
2294 cd .. & rd /s/q foobar
2295 echo --- recursive behaviour
2296 mkdir foobar\baz & cd foobar
2302 attrib +R l*vel? /S > nul 2>&1
2308 cd .. & rd /s/q foobar
2309 echo --- folders processing
2315 attrib +r baz /s /d > nul 2>&1
2321 rem Oddly windows allows file creation in a read-only directory...
2322 if exist baz\lala (echo file created in read-only dir) else echo file not created
2323 cd .. & rd /s/q foobar
2325 echo ------------ Testing assoc ------------
2326 rem Modifying associations requires some privileges...
2327 net session >nul 2>&1
2328 if errorlevel 1 goto :SkipAssoc
2330 rem FIXME Can't test error messages in the current test system
, so we have to
use some kludges
2331 rem FIXME Revise once || conditional execution is fixed
2332 mkdir foobar
& cd foobar
2333 echo --- setting association
2341 rem association set system-wide
2342 echo @
echo off
> tmp.
cmd
2343 echo echo +++>> tmp.
cmd
2344 echo assoc .foo
>> tmp.
cmd
2347 echo --- resetting association
2353 rem association removal set system-wide
2354 cmd /c tmp.
cmd > baz
2357 cd ..
& rd /s
/q foobar
2360 echo --- setting association
2366 echo --- resetting association
2373 echo ------------ Testing ftype
------------
2374 rem Modifying associations requires some privileges...
2375 net session
>nul
2>&1
2376 if errorlevel 1 goto :SkipFType
2377 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2378 rem FIXME Revise once || conditional execution is fixed
2379 mkdir foobar
& cd foobar
2380 echo --- setting association
2385 ftype footype
=foo_opencmd
2389 rem association set system-wide
2390 echo @
echo off
> tmp.
cmd
2391 echo echo +++>> tmp.
cmd
2392 echo ftype footype
>> tmp.
cmd
2395 echo --- resetting association
2398 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2399 setlocal EnableDelayedExpansion
2400 set WINE_FOO
=original value
2403 for /F
%%i in
('type baz') do (set WINE_FOO
=buggyXP
)
2404 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2405 rem FIXME Revisit once a grep-like program like ftype is implemented
2406 rem (e.g. to check baz's size using dir /b instead)
2409 rem cleanup registry
2410 echo REGEDIT4
> regCleanup.reg
2411 echo.
>> regCleanup.reg
2412 echo [-HKEY_CLASSES_ROOT
\footype
]>> regCleanup.reg
2413 regedit
/s regCleanup.reg
2416 cd ..
& rd /s
/q foobar
2419 echo --- setting association
2421 echo footype
=foo_opencmd
2423 echo footype
=foo_opencmd
2425 echo footype
=foo_opencmd
2426 echo --- resetting association
2430 echo ------------ Testing
CALL ------------
2431 mkdir foobar
& cd foobar
2432 echo --- external script
2433 echo echo foo
%%1> foo.
cmd
2436 echo echo %%1 %%2 > foo.
cmd
2438 call foo.
cmd foo bar
2445 echo --- internal routines
2446 call :testRoutine :testRoutine
2447 goto :endTestRoutine
2453 call :testRoutineArgs foo
2454 call :testRoutineArgs foo bar
2455 call :testRoutineArgs foo
""
2456 call :testRoutineArgs "" bar
2457 call :testRoutineArgs foo
''
2458 call :testRoutineArgs '' bar
2459 goto :endTestRoutineArgs
2465 echo --- with builtins
2468 if exist foo
(echo foo created
) else echo foo should
exist!
2470 set WINE_FOOBAZ_VAR
=foobaz
2471 call echo Should expand
%WINE_FOOBAZ_VAR%
2472 set WINE_FOOBAZ_VAR
=
2476 if 1==1 call del batfile
2478 if exist batfile
echo batfile shouldn
't exist
2479 rem ... but not for 'if' or 'for'
2480 call if 1==1 echo bar 2> nul
2483 call for %%i in (foo bar baz) do echo %%i 2> nul
2485 rem First look for programs in the path before trying a builtin
2486 echo echo non-builtin dir> dir.cmd
2489 rem The below line equates to call (, which does nothing, then the
2490 rem subsequent lines are executed.
2495 rem The below line equates to call if, which always fails, then the
2496 rem subsequent lines are executed. Note cmd.exe swallows all lines
2503 call call call echo passed
2504 cd .. & rd /s/q foobar
2506 echo ------------ Testing SHIFT ------------
2508 call :shiftFun p1 p2 p3 p4 p5
2512 echo '%1' '%2' '%3' '%4' '%5'
2514 echo '%1' '%2' '%3' '%4' '%5'
2516 echo '%1' '%2' '%3' '%4' '%5'
2518 echo '%1' '%2' '%3' '%4' '%5'
2520 echo '%1' '%2' '%3' '%4' '%5'
2522 echo '%1' '%2' '%3' '%4' '%5'
2526 echo ------------ Testing cmd invocation ------------
2527 rem FIXME: only a stub ATM
2528 echo --- a batch file can delete itself
2529 echo del foo.cmd>foo.cmd
2531 if not exist foo.cmd (
2532 echo file correctly deleted
2534 echo file should be deleted!
2537 echo --- a batch file can alter itself
2538 echo echo bar^>foo.cmd>foo.cmd
2539 cmd /q /c foo.cmd > NUL 2>&1
2544 echo file not created!
2547 echo ---------- Testing copy
2550 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2553 echo CCCCCCCCC> file3
2559 echo Passed: Found expected %1
2561 echo Failed: Did not find expected %1
2563 del /q "%1" >nul 2>&1
2565 if not "%1"=="" goto :CheckExist
2570 echo Passed: Did not find %1
2572 echo Failed: Unexpectedly found %1
2573 del /q "%1" >nul 2>&1
2576 if not "%1"=="" goto :CheckNotExist
2579 rem Note: No way to check file size on NT4 so skip the test
2582 echo Failed: File missing when requested filesize check [%2]
2583 goto :ContinueFileSizeChecks
2585 for %%i in (%1) do set WINE_filesize=%%~zi
2586 if "%WINE_filesize%"=="%2" (
2587 echo Passed: file size check on %1 [%WINE_filesize%]
2589 if "%WINE_filesize%"=="%%~zi" (
2590 echo Skipping file size check on NT4
2592 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2595 :ContinueFileSizeChecks
2598 if not "%1"=="" goto :CheckFileSize
2603 rem -----------------------
2604 rem Simple single file copy
2605 rem -----------------------
2606 rem Simple single file copy, normally used syntax
2607 copy file1 dummy.file >nul 2>&1
2608 if errorlevel 1 echo Incorrect errorlevel
2609 call :CheckExist dummy.file
2611 rem Simple single file copy, destination supplied as two forms of directory
2612 copy file1 dir1 >nul 2>&1
2613 if errorlevel 1 echo Incorrect errorlevel
2614 call :CheckExist dir1\file1
2616 copy file1 dir1\ >nul 2>&1
2617 if errorlevel 1 echo Incorrect errorlevel
2618 call :CheckExist dir1\file1
2620 rem Simple single file copy, destination supplied as fully qualified destination
2621 copy file1 dir1\file99 >nul 2>&1
2622 if errorlevel 1 echo Incorrect errorlevel
2623 call :CheckExist dir1\file99
2625 rem Simple single file copy, destination not supplied
2627 copy ..\file1 >nul 2>&1
2628 if errorlevel 1 echo Incorrect errorlevel
2629 call :CheckExist file1
2632 rem Simple single file copy, destination supplied as nonexistent directory
2633 copy file1 dir2\ >nul 2>&1
2634 if not errorlevel 1 echo Incorrect errorlevel
2635 call :CheckNotExist dir2 dir2\file1
2637 rem -----------------------
2639 rem -----------------------
2640 rem Simple single file copy, destination supplied as two forms of directory
2641 copy file? dir1 >nul 2>&1
2642 if errorlevel 1 echo Incorrect errorlevel
2643 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2645 copy file* dir1\ >nul 2>&1
2646 if errorlevel 1 echo Incorrect errorlevel
2647 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2649 rem Simple single file copy, destination not supplied
2651 copy ..\file*.* >nul 2>&1
2652 if errorlevel 1 echo Incorrect errorlevel
2653 call :CheckExist file1 file2 file3
2656 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2657 copy file? dir2\ >nul 2>&1
2658 if not errorlevel 1 echo Incorrect errorlevel
2659 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2661 rem ------------------------------------------------
2662 rem Confirm overwrite works (cannot test prompting!)
2663 rem ------------------------------------------------
2664 copy file1 testfile >nul 2>&1
2665 copy /y file2 testfile >nul 2>&1
2666 call :CheckExist testfile
2668 rem ------------------------------------------------
2669 rem Test concatenation
2670 rem ------------------------------------------------
2671 rem simple case, no wildcards
2672 copy file1+file2 testfile >nul 2>&1
2673 if errorlevel 1 echo Incorrect errorlevel
2674 call :CheckExist testfile
2676 rem simple case, wildcards, no concatenation
2677 copy file* testfile >nul 2>&1
2678 if errorlevel 1 echo Incorrect errorlevel
2679 call :CheckExist testfile
2681 rem simple case, wildcards, and concatenation
2683 copy file*+fred testfile >nul 2>&1
2684 if errorlevel 1 echo Incorrect errorlevel
2685 call :CheckExist testfile
2687 rem simple case, wildcards, and concatenation
2688 copy fred+file* testfile >nul 2>&1
2689 if errorlevel 1 echo Incorrect errorlevel
2690 call :CheckExist testfile
2692 rem Calculate destination name
2693 copy fred+file* dir1 >nul 2>&1
2694 if errorlevel 1 echo Incorrect errorlevel
2695 call :CheckExist dir1\fred
2697 rem Calculate destination name
2698 copy fred+file* dir1\ >nul 2>&1
2699 if errorlevel 1 echo Incorrect errorlevel
2700 call :CheckExist dir1\fred
2702 rem Calculate destination name (none supplied)
2704 copy ..\fred+..\file* >nul 2>&1
2705 if errorlevel 1 echo Incorrect errorlevel
2706 call :CheckExist fred
2708 copy ..\fr*+..\file1 >nul 2>&1
2709 if errorlevel 1 echo Incorrect errorlevel
2710 call :CheckExist fred
2713 rem ******************************************************************
2714 rem ASCII and BINARY tests
2715 rem Note: hard coded numbers deliberate because need to ensure whether
2716 rem an additional EOF has been added or not. There is no way to handle
2717 rem EOFs in batch, so assume if a single byte appears, it's an EOF
!
2718 rem ******************************************************************
2720 rem Confirm original sizes of file1,2,3
2721 call :CheckFileSize file1
5 file2
8 file3
11
2725 rem ----------------------------------------------
2726 rem Show concatenation defaults copy to ascii mode
2727 rem ----------------------------------------------
2728 rem Simple default copy source to destination (should not append EOF 5)
2729 copy ..
\file
1 file1_default
>nul
2>&1
2730 call :CheckFileSize file1_default
5
2732 rem Simple binary copy source to destination (should not append EOF 5)
2733 copy /b ..
\file
1 file1_default2
>nul
2>&1
2734 call :CheckFileSize file1_default2
5
2736 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2737 copy /a ..
\file
1 file1_plus_eof
>nul
2>&1
2738 call :CheckFileSize file1_plus_eof
6
2739 copy /a ..
\file
2 file2_plus_eof
>nul
2>&1
2740 call :CheckFileSize file2_plus_eof
9
2741 copy /a ..
\file
3 file3_plus_eof
>nul
2>&1
2742 call :CheckFileSize file3_plus_eof
12
2744 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2745 copy /a ..
\file
1+..
\file
2 file12_plus_eof
>nul
2>&1
2746 call :CheckFileSize file12_plus_eof
14
2748 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2749 copy /b ..
\file
1+..
\file
2 file12_no_eof
>nul
2>&1
2750 call :CheckFileSize file12_no_eof
13
2752 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2753 copy ..
\file
1+..
\file
2 file12_eof2
>nul
2>&1
2754 call :CheckFileSize file12_eof2
14
2756 rem Test copying when destination is one of the sources.
2757 rem Concat file1+file2+file3 into file1, should produce file1+file2+file3 = 24
2758 copy /y ..
\file? .\
>nul
2>&1
2759 copy /y
/b file1
+file2
+file3 file1
>nul
2>&1
2760 call :CheckFileSize file1
24
2762 rem Concat file1+file2+file3 into file2, should produce file1+file3 = 16
2763 copy /y ..
\file? .\
>nul
2>&1
2764 copy /y
/b file1
+file2
+file3 file2
>nul
2>&1
2765 call :CheckFileSize file2
16
2767 rem Concat file1+file2+file3 into file3, should produce file1+file2 = 13
2768 copy /y ..
\file? .\
>nul
2>&1
2769 copy /y
/b file1
+file2
+file3 file3
>nul
2>&1
2770 call :CheckFileSize file3
13
2772 rem --------------------------------------------------------------
2773 rem Show ascii source copy stops at first EOF, binary does the lot
2774 rem --------------------------------------------------------------
2775 copy file1_plus_eof
/b file1_binary_srccopy
/b
>nul
2>&1
2776 call :CheckFileSize file1_binary_srccopy
6
2778 copy file1_plus_eof
/a file1_ascii_srccopy
/b
>nul
2>&1
2779 call :CheckFileSize file1_ascii_srccopy
5
2781 rem --------------------------------------------------------------
2782 rem Show results of concatenating files (ending in EOFs) and /a /b
2783 rem --------------------------------------------------------------
2785 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2786 copy file1_plus_eof
+file2_plus_eof
+file3_plus_eof file123_default_copy
>nul
2>&1
2787 call :CheckFileSize file123_default_copy
25
2788 copy /a file1_plus_eof
+file2_plus_eof
+file3_plus_eof file123_ascii_copy
>nul
2>&1
2789 call :CheckFileSize file123_ascii_copy
25
2791 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2792 copy /b file1_plus_eof
+ file2_plus_eof
+ file3_plus_eof file123_binary_copy
>nul
2>&1
2793 call :CheckFileSize file123_binary_copy
27
2795 rem We can select which we want the eofs from by postfixing it with /a or /b
2796 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2797 copy file1_plus_eof
/b
+ file2_plus_eof
/a
+ file3_plus_eof
/b file123_mixed_copy1
>nul
2>&1
2798 call :CheckFileSize file123_mixed_copy1
26
2800 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2801 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2802 rem Note the delta between this and the previous one also shows that the destination
2803 rem ascii/binary is inherited from the last /a or /b on the line
2804 copy file1_plus_eof
/b
+ file2_plus_eof
/a
+ file3_plus_eof
/b file123_mixed_copy2
/a
>nul
2>&1
2805 call :CheckFileSize file123_mixed_copy2
27
2807 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2808 rem Note the delta between the next two also shows that the destination ascii/binary is
2809 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2810 copy file1_plus_eof
/a
+ file2_plus_eof
/b
+ file3_plus_eof
/a file123_mixed_copy3
>nul
2>&1
2811 call :CheckFileSize file123_mixed_copy3
26
2812 copy file1_plus_eof
/a
+ file2_plus_eof
/b
+ file3_plus_eof
/a file123_mixed_copy4
/b
>nul
2>&1
2813 call :CheckFileSize file123_mixed_copy4
25
2815 rem -------------------------------------------------------------------------------------------
2816 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2817 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2818 rem -------------------------------------------------------------------------------------------
2820 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2821 copy /b file1_plus_eof
+ file2_plus_eof
+ file3_plus_eof file123_mixed_copy5
/a
>nul
2>&1
2822 call :CheckFileSize file123_mixed_copy5
28
2824 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2825 copy /b file1_plus_eof
+ file3_plus_eof file123_mixed_copy6
/a
>nul
2>&1
2826 call :CheckFileSize file123_mixed_copy6
19
2828 rem One file has EOF, but doesn't get an extra one, i.e. 6
2829 copy /b file1_plus_eof file123_mixed_copy7
/a
>nul
2>&1
2830 call :CheckFileSize file123_mixed_copy7
6
2832 rem Syntax means concatenate so ascii destination kicks in
2833 copy /b file1_plus_eof
* file123_mixed_copy8
/a
>nul
2>&1
2834 call :CheckFileSize file123_mixed_copy8
7
2839 rem ---------------------------------------
2840 rem Error combinations
2841 rem ---------------------------------------
2842 rem Specify source directory but name is a file
2844 copy file1\ dir1\
>NUL
2>&1
2845 if errorlevel 1 echo Passed
: errorlevel invalid check
1
2846 if not errorlevel 1 echo Failed
: errorlevel invalid check
1
2847 call :CheckNotExist dir1
\file
1
2849 rem Overwrite same file
2851 copy file1 file1
>NUL
2>&1
2852 if errorlevel 1 echo Passed
: errorlevel invalid check
2
2853 if not errorlevel 1 echo Failed
: errorlevel invalid check
2
2855 rem Supply same file identified as a directory
2857 copy file1 file1\
>NUL
2>&1
2858 if errorlevel 1 echo Passed
: errorlevel invalid check
3
2859 if not errorlevel 1 echo Failed
: errorlevel invalid check
3
2864 echo ------------ Testing
setlocal/endlocal ------------
2866 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2867 mkdir foobar
& cd foobar
2868 echo --- enable
/disable extensions
2869 setlocal DisableEXTensions
2870 echo ErrLev
: %ErrorLevel%
2872 echo ErrLev
: %ErrorLevel%
2873 echo @
echo off
> tmp.
cmd
2874 echo echo ErrLev
: %%ErrorLevel%%>> tmp.
cmd
2875 rem Enabled by default
2877 cmd /E
:OfF /C tmp.
cmd
2878 cmd /e
:oN /C tmp.
cmd
2880 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2881 echo --- setlocal with corresponding
endlocal
2882 rem %CD% does not work on NT4 so use the following workaround
2883 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2884 echo @
echo off
> test.
cmd
2885 echo echo %%WINE_VAR%%>> test.
cmd
2886 echo setlocal>> test.
cmd
2887 echo set WINE_VAR
=localval
>> test.
cmd
2888 echo md foobar2
>> test.
cmd
2889 echo cd foobar2
>> test.
cmd
2890 echo echo %%WINE_VAR%%>> test.
cmd
2891 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2892 echo endlocal>> test.
cmd
2893 echo echo %%WINE_VAR%%>> test.
cmd
2894 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2895 set WINE_VAR
=globalval
2898 for /d
%%i in
(.
) do echo %%~dpnxi
2902 echo --- setlocal with no corresponding
endlocal
2903 echo @
echo off
> test.
cmd
2904 echo echo %%WINE_VAR%%>> test.
cmd
2905 echo setlocal>> test.
cmd
2906 echo set WINE_VAR
=localval
>> test.
cmd
2907 echo md foobar2
>> test.
cmd
2908 echo cd foobar2
>> test.
cmd
2909 echo echo %%WINE_VAR%%>> test.
cmd
2910 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2911 set WINE_VAR
=globalval
2912 rem %CD% does not work on NT4 so use the following workaround
2913 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2916 for /d
%%i in
(.
) do echo %%~dpnxi
2920 echo --- setlocal within same batch program
2924 rem %CD% does not work on NT4 so use the following workaround
2925 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2932 if "%WINE_var1%"=="one" echo Var1 ok
1
2933 if "%WINE_var2%"=="two" echo Var2 ok
2
2934 if "%WINE_var3%"=="three" echo Var3 ok
3
2935 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2936 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok
1
2938 if "%WINE_var1%"=="one" echo Var1 ok
1
2939 if "%WINE_var2%"=="two" echo Var2 ok
2
2940 if "%WINE_var3%"=="" echo Var3 ok
3
2941 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2942 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok
2
2944 if "%WINE_var1%"=="one" echo Var1 ok
1
2945 if "%WINE_var2%"=="" echo Var2 ok
2
2946 if "%WINE_var3%"=="" echo Var3 ok
3
2947 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2948 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok
3
2952 echo --- Mismatched
set and
end locals
2956 rem %CD% does not work on NT4 so use the following workaround
2957 for /d
%%i in
(.
) do set WINE_curdir
=%%~dpnxi
2959 echo @
echo off
> 2set1end.
cmd
2960 echo echo %%WINE_var%%>> 2set1end.
cmd
2961 echo setlocal>> 2set1end.
cmd
2962 echo set WINE_VAR
=2set1endvalue1
>> 2set1end.
cmd
2963 echo cd ..
\foodir
3>> 2set1end.
cmd
2964 echo setlocal>> 2set1end.
cmd
2965 echo set WINE_VAR
=2set1endvalue2
>> 2set1end.
cmd
2966 echo cd ..
\foodir
4>> 2set1end.
cmd
2967 echo endlocal>> 2set1end.
cmd
2968 echo echo %%WINE_var%%>> 2set1end.
cmd
2969 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 2set1end.
cmd
2971 echo @
echo off
> 1set2end.
cmd
2972 echo echo %%WINE_var%%>> 1set2end.
cmd
2973 echo setlocal>> 1set2end.
cmd
2974 echo set WINE_VAR
=1set2endvalue1
>> 1set2end.
cmd
2975 echo cd ..
\foodir
3>> 1set2end.
cmd
2976 echo endlocal>> 1set2end.
cmd
2977 echo echo %%WINE_var%%>> 1set2end.
cmd
2978 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 1set2end.
cmd
2979 echo endlocal>> 1set2end.
cmd
2980 echo echo %%WINE_var%%>> 1set2end.
cmd
2981 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 1set2end.
cmd
2983 echo --- Extra
setlocal in called batch
2985 rem -- setlocal1 == this batch, should never be used inside a called routine
2989 call "%WINE_CURDIR%\2set1end.cmd"
2992 for /d
%%i in
(.
) do echo %%~dpnxi
2995 for /d
%%i in
(.
) do echo %%~dpnxi
2998 echo --- Extra
endlocal in called batch
3000 rem -- setlocal1 == this batch, should never be used inside a called routine
3004 call "%WINE_CURDIR%\1set2end.cmd"
3007 for /d
%%i in
(.
) do echo %%~dpnxi
3010 for /d
%%i in
(.
) do echo %%~dpnxi
3013 echo --- endlocal in called function rather than batch pgm is ineffective
3019 call :endlocalroutine
3023 goto :endlocalfinished
3041 cd ..
& rd /q
/s foobar
3043 echo ------------ Testing
Errorlevel ------------
3044 rem WARNING: Do *not* add tests using ErrorLevel after this section
3045 should_not_exist
2> nul
> nul
3047 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
3048 rem See http://www.robvanderwoude.com/exit.php
3051 if errorlevel 2 echo errorlevel too high
, bad
3052 if errorlevel 1 echo errorlevel just right
, good
3053 if errorlevel 01 echo errorlevel with leading zero just right
, good
3054 if errorlevel -1 echo errorlevel with negative number OK
3055 if errorlevel 0x1 echo hexa should
not be recognized
!
3056 if errorlevel 1a
echo invalid error level recognized
!
3058 echo abc
%ErrorLevel%def
3059 if errorlevel 1 echo errorlevel nonzero
, bad
3060 if not errorlevel 1 echo errorlevel zero
, good
3061 if not errorlevel 0x1 echo hexa should
not be recognized
!
3062 if not errorlevel 1a
echo invalid error level recognized
!
3063 rem Now verify that setting a real variable hides its magic variable
3065 echo %ErrorLevel% should be
7
3066 if errorlevel 7 echo setting var worked too well
, bad
3068 echo %ErrorLevel% should still be
7
3070 echo ------------ Testing
GOTO ------------
3072 echo FAILURE at dest
1
3074 echo goto with no leading space worked
3075 if a
==a
goto :dest1b
3076 echo FAILURE at dest
1b
3078 echo goto with colon and no leading space worked
3080 echo FAILURE at dest
2
3082 echo goto with a leading space worked
3084 echo FAILURE at dest
3
3086 echo goto with a leading tab worked
3088 echo FAILURE at dest
4
3090 echo goto with a following space worked
3092 echo FAILURE at dest
5
3093 :dest5&& echo FAILURE
3094 echo goto with following amphersands worked
3096 del failure.txt
>nul
2>&1
3098 echo FAILURE at dest
6
3100 if exist FAILURE.TXT
echo FAILURE at dest
6 as file exists
3101 echo goto with redirections worked
3102 del FAILURE.TXT
>nul
2>&1
3104 :: some text that is ignored |
dir >cmd_output | another test
3105 if exist cmd_output
echo FAILURE at dest
6 as file exists
3106 echo Ignoring double colons worked
3107 del cmd_output
>nul
2>&1
3109 rem goto a label which does not exist issues an error message and
3110 rem acts the same as goto :EOF, and ensure ::label is never matched
3111 del testgoto.bat
>nul
2>&1
3112 echo goto :dest7 ^
>nul
2^
>^
&1 >> testgoto.bat
3113 echo echo FAILURE at dest
7 - Should have
not found
label and issued an error plus ended the batch
>> testgoto.bat
3114 echo ::dest7>> testgoto.bat
3115 echo echo FAILURE at dest
7 - Incorrectly went to
label >> testgoto.bat
3117 del testgoto.bat
>nul
2>&1
3119 del testgoto.bat
>nul
2>&1
3120 echo goto ::dest8 ^
>nul
2^
>^
&1 >> testgoto.bat
3121 echo echo FAILURE at dest
8 - Should have
not found
label and issued an error plus ended the batch
>> testgoto.bat
3122 echo ::dest8>> testgoto.bat
3123 echo echo FAILURE at dest
8 - Incorrectly went to
label >> testgoto.bat
3125 del testgoto.bat
>nul
2>&1
3128 echo FAILURE at dest
9
3130 echo FAILURE at dest
91
3132 echo label with mixed whitespace and no
echo worked
3134 if h
==h
goto :dest10:this is ignored
3135 echo FAILURE at dest
10
3136 :dest10:this is also ignored
3137 echo Correctly ignored trailing information
3139 rem Testing which label is reached when there are many options
3143 set nextlabel
=middle
3148 if not "%nextlabel%"=="" goto :%nextlabel%
3153 if not "%nextlabel%"=="" goto :%nextlabel%
3160 set nextlabel
=nearend
3165 if not "%nextlabel%"=="" goto :%nextlabel%
3177 if not "%nextlabel%"=="" goto :%nextlabel%
3190 echo ------------ Testing
PATH ------------
3191 set WINE_backup_path
=%path%
3198 set path=%WINE_backup_path%
3199 set WINE_backup_path
=
3201 echo ------------ Testing
start /W
------------
3202 echo start /W failed to wait
>foobar.txt
3203 start /W
"" cmd /C
"ping -n1 & echo start /W seems to really wait>foobar.txt"& type foobar.txt
& del foobar.txt
3205 echo ------------ Testing changing the drive letter
----------
3211 if errorlevel 1 echo Normal drive change failed
3216 if errorlevel 1 echo Normal
+space drive change failed
3218 echo Normal
+space
+garbage
3221 if errorlevel 1 echo Normal
+space
+garbage drive change failed
3224 echo Quoted should fail
3226 if not errorlevel 1 echo quoted drive change unexpectedly worked
3231 if errorlevel 1 echo Normal
+tab drive change failed
3233 echo Normal
+tab
+garbage
3236 if errorlevel 1 echo Normal
+tab
+garbage drive change failed
3240 echo ------------ Testing combined CALLs
/GOTOs
------------
3241 echo @
echo off
>foo.
cmd
3242 echo goto :eof>>foot.
cmd
3244 echo echo world
>>foo.
cmd
3246 echo @
echo off
>foot.
cmd
3247 echo echo cheball
>>foot.
cmd
3249 echo call :bar>>foot.
cmd
3250 echo if "%%1"=="deleteMe" (del foot.
cmd)>>foot.
cmd
3251 echo goto :eof>>foot.
cmd
3254 echo echo barbare
>>foot.
cmd
3255 echo goto :eof>>foot.
cmd
3261 rem Script execution stops after the following line
3284 echo Final message is
not output since earlier
'foot' processing stops script execution
3285 echo Do NOT add any tests below this line
3287 echo ------------ Done
, jumping to EOF
-----------
3289 rem Subroutine to set errorlevel and return
3290 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
3293 rem This line runs under cmd in windows NT 4, but not in more modern versions.