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
183 if 1==1 (echo foo2>bar) else echo baz2>bar
185 if 1==1 (echo foo3) else echo baz3>bar
186 type bar || echo file does not exist, ok
187 if 1==1 (echo foo4>bar) else echo baz4>bar
189 if 1==0 (echo foo5>bar) else echo baz5>bar
191 if 1==0 (echo foo6) else echo baz6 1>bar
193 if 1==0 (echo foo7 1>bar) else echo baz7>bar
195 if 1==0 (echo foo8 1>bar) else echo baz8>bak
197 if 1==1 (echo foo>bar & echo baz)
204 (if 1==1 (echo A) else echo B) > C
206 (if 1==0 (echo A) else echo B) > C
208 (if 1==0 (echo A > B) else echo C)
209 cd .. & rd /s/q foobar
211 echo ------------ Testing circumflex escape character ------------
212 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
234 echo bak ^&& echo baz 2> nul
242 set WINE_FOO=bar ^| baz
244 rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
245 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
248 set WINE_FOO=bar ^^^| baz
254 echo ------------ Testing chains ------------
255 rem The chain operators have the following bottom-up precedence:
256 rem 'else' precedes nothing and matches the closest unmatched 'if' in the same bracket depth
257 rem '&' precedes 'else'
258 rem '||' precedes '&' and 'else'
259 rem '&&' precedes '||', '&' and 'else'
260 rem '|' precedes '&&', '||', '&' and 'else'
262 rem Example: 'if 1==1 if 2==2 if 3==3 a | b && c || d & e else f else g' is interpreted as
263 rem 'if 1==1 (if 2==2 (if 3==3 ((((a | b) && c) || d) & e) else f) else g)'
270 echo --- chain success
275 echo d1&echo d2&echo d3
276 echo e1&echo e2&&echo e3
277 echo f1&echo f2||echo f3
279 echo g1&&echo g2&echo g3
280 echo h1&&echo h2&&echo h3
281 echo i1&&echo i2||echo i3
283 echo j1||echo j2&echo j3
285 echo k1||echo k2&&echo k3
287 echo l1||echo l2||echo l3
289 echo --- chain failure
290 call :cfail a1&call :cfail a2
291 call :cfail b1&&call :cfail b2
293 call :cfail c1||call :cfail c2
294 call :cfail d1&call :cfail d2&call :cfail d3
295 call :cfail e1&call :cfail e2&&call :cfail e3
297 call :cfail f1&call :cfail f2||call :cfail f3
298 call :cfail g1&&call :cfail g2&call :cfail g3
300 call :cfail h1&&call :cfail h2&&call :cfail h3
302 call :cfail i1&&call :cfail i2||call :cfail i3
304 call :cfail j1||call :cfail j2&call :cfail j3
305 call :cfail k1||call :cfail k2&&call :cfail k3
307 call :cfail l1||call :cfail l2||call :cfail l3
308 echo --- chain brackets
309 rem Brackets are like regular commands, they support redirections
310 rem and have the same precedence as regular commands.
311 echo a1&(echo a2&echo a3)
312 echo b1&(echo b2&&echo b3)
313 echo c1&(echo c2||echo c3)
315 echo d1&&(echo d2&echo d3)
316 echo e1&&(echo e2&&echo e3)
317 echo f1&&(echo f2||echo f3)
319 echo g1||(echo g2&echo g3)
321 echo h1||(echo h2&&echo h3)
323 echo i1||(echo i2||echo i3)
325 call :cfail j1&(call :cfail j2&call :cfail j3)
326 call :cfail k1&(call :cfail k2&&call :cfail k3)
328 call :cfail l1&(call :cfail l2||call :cfail l3)
329 call :cfail m1&&(call :cfail m2&call :cfail m3)
331 call :cfail n1&&(call :cfail n2&&call :cfail n3)
333 call :cfail o1&&(call :cfail o2||call :cfail o3)
335 call :cfail p1||(call :cfail p2&call :cfail p3)
336 call :cfail q1||(call :cfail q2&&call :cfail q3)
338 call :cfail r1||(call :cfail r2||call :cfail r3)
340 rem Piped commands run at the same time, so the print order varies.
341 rem Additionally, they don't run in the batch script context, as shown by
342 rem 'call :existing_label|echo read the error message'.
343 (echo a 1>&2|echo a 1>&2) 2>&1
346 echo c1&&echo c2|echo c3
347 echo d1||echo d2|echo d3
349 echo e1&echo e2|echo e3
350 echo f1|echo f2&&echo f3
351 echo g1|echo g2||echo g3
353 echo h1|echo h2&echo h3
354 echo i1|echo i2|echo i3
355 echo --- chain pipe input
356 rem The output data of the left side of a pipe can disappear, probably
357 rem because it finished too fast and closed the pipe before it could be read,
358 rem which means we can get broken results for the tests of this section.
359 echo @echo off> tmp.cmd
360 echo set IN=X>> tmp.cmd
361 echo set /p IN=%%1:>> tmp.cmd
362 echo setlocal EnableDelayedExpansion>> tmp.cmd
363 echo echo [!IN!,%%1]>> tmp.cmd
364 echo endlocal>> tmp.cmd
365 echo set IN=>> tmp.cmd
366 echo a1|cmd /ctmp.cmd a2
367 echo b1|cmd /ctmp.cmd b2|cmd /ctmp.cmd b3
368 echo c1|cmd /ctmp.cmd c2|cmd /ctmp.cmd c3|cmd /ctmp.cmd c4
369 echo d1|call tmp.cmd d2
370 echo e1|call tmp.cmd e2|call tmp.cmd e3
371 echo f1|call tmp.cmd f2|call tmp.cmd f3|call tmp.cmd f4
372 rem FIXME these 3 tests cause "unexpected end of output"
373 rem test : echo g1|tmp.cmd g2
374 rem result: g2:[g1,g2]
375 rem test : echo h1|tmp.cmd h2|tmp.cmd h3
376 rem result: h3:[h2:[h1,h2],h3]@or_broken@h3:[h2:,h3]
377 rem test : echo i1|tmp.cmd i2|tmp.cmd i3|tmp.cmd i4
378 rem result: i4:[i3:[i2:[i1,i2],i3],i4]@or_broken@i4:[i3:[i2:,i3],i4]@or_broken@i4:[i3:,i4]
381 rem Command arguments are gready and eat up the 'else' unless terminated by
382 rem brackets, which means the 'else' can only be recognized when the
383 rem 'if true' command chain ends with brackets.
384 if 1==1 if 2==2 if 3==3 (echo a1) else (echo a2) else echo a3
385 if 1==1 if 2==2 if 3==0 (echo b1) else (echo b2) else echo b3
387 if 1==1 if 2==0 if 3==3 (echo c1) else (echo c2) else echo c3
389 if 1==1 if 2==0 if 3==0 (echo d1) else (echo d2) else echo d3
391 if 1==0 if 2==2 if 3==3 (echo e1) else (echo e2) else echo e3
393 if 1==0 if 2==2 if 3==0 (echo f1) else (echo f2) else echo f3
395 if 1==0 if 2==0 if 3==3 (echo g1) else (echo g2) else echo g3
397 if 1==0 if 2==0 if 3==0 (echo h1) else (echo h2) else echo h3
399 echo --- chain else (if true)
400 if 1==1 echo a1 else echo a2
401 if 1==1 echo b1|echo b2 else echo b3
402 if 1==1 echo c1&&echo c2 else echo c3
403 if 1==1 echo d1||echo d2 else echo d3
405 if 1==1 echo e1&echo e2 else echo e3
406 if 1==1 echo f1 else echo f2|echo f3
407 if 1==1 echo g1 else echo g2&&echo g3
408 if 1==1 echo h1 else echo h2||echo h3
410 if 1==1 echo i1 else echo i2&echo i3
411 if 1==1 echo j1|(echo j2) else echo j3
413 if 1==1 echo k1&&(echo k2) else echo k3
414 if 1==1 echo l1||(echo l2) else echo l3
416 if 1==1 echo m1&(echo m2) else echo m3
417 if 1==1 (echo n1) else echo n2|echo n3
418 if 1==1 (echo o1) else echo o2&&echo o3
419 if 1==1 (echo p1) else echo p2||echo p3
420 if 1==1 (echo q1) else echo q2&echo q3
421 echo --- chain else (if false)
422 if 1==0 echo a1 else echo a2
423 if 1==0 echo b1|echo b2 else echo b3
424 if 1==0 echo c1&&echo c2 else echo c3
425 if 1==0 echo d1||echo d2 else echo d3
426 if 1==0 echo e1&echo e2 else echo e3
427 if 1==0 echo f1 else echo f2|echo f3
428 if 1==0 echo g1 else echo g2&&echo g3
429 if 1==0 echo h1 else echo h2||echo h3
430 if 1==0 echo i1 else echo i2&echo i3
431 if 1==0 echo j1|(echo j2) else echo j3
433 if 1==0 echo k1&&(echo k2) else echo k3
434 if 1==0 echo l1||(echo l2) else echo l3
435 if 1==0 echo m1&(echo m2) else echo m3
436 if 1==0 (echo n1) else echo n2|echo n3
437 if 1==0 (echo o1) else echo o2&&echo o3
438 if 1==0 (echo p1) else echo p2||echo p3
440 if 1==0 (echo q1) else echo q2&echo q3
441 echo ------------ Testing 'set' ------------
443 rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
444 for /f "delims==" %%i in ('set WINE_ba') do set %%i=
445 for /f "delims==" %%i in ('set WINE_foo') do set %%i=
446 set WINE_FOOBAR 2> nul > nul
448 set WINE_FOOBAR = baz
450 echo %WINE_FOOBAR%WINE_FOOBAR not defined
452 set WINE_FOOBAR 2> nul
453 set WINE_FOOBAR = baz2
462 echo %WINE_FOOBAR%WINE_FOOBAR not defined
464 set WINE_FOOBA 2> nul > nul
470 echo %WINE_FOO%%WINE_BAR%
473 set WINE_FOO=%WINE_FOO%
474 echo %WINE_FOO%WINE_FOO not defined
479 echo set "WINE_FOO=bar" should not include the quotes in the variable value
486 set WINE_FOO=foo@space@
488 set WINE_FOO=foo@tab@
490 rem Space symbol must appear in `var`
491 set WINE_FOO=value@space@
493 rem Space symbol must NOT appear in `var`
494 set "WINE_FOO=value"@space@
497 set WINE_FOO=jim fred
499 set WINE_FOO="jim" fred
501 set "WINE_FOO=jim fred"
503 set "WINE_FOO=jim" fred
505 rem Only the final quote ends the string
506 set "WINE_FOO=apple"banana"grape"orange
510 echo ------------ Testing variable expansion ------------
512 echo ~p0 should be path containing batch file
519 echo ~dp0 should be directory containing batch file
532 echo P%WINE_UNKNOWN%S
535 echo %ERRORLEVEL%%ERRORLEVEL%
536 echo %ERRORLEVEL%ERRORLEVEL%
543 echo ------------ Testing variable substrings ------------
548 echo '%WINE_VAR:~-2,3%'
549 echo '%WINE_VAR:~-2,1%'
550 echo %WINE_VAR:~2,-1%
551 echo %WINE_VAR:~2,-3%
552 echo '%WINE_VAR:~-2,-4%'
553 echo %WINE_VAR:~-3,-2%
556 echo ------------ Testing variable substitution ------------
557 echo --- in FOR variables
558 for %%i in ("A B" C) do echo %%i
559 rem check works when prefix with @
560 @for %%i in ("A B" C) do echo %%i
562 for %%i in ("A B" C) do echo '%%~i'
563 rem fully qualified path
564 for %%f in ("C D" E) do echo %%~ff
566 for %%i in ("F G" H) do echo %%~di
568 for %%d in ("I J" K) do echo %%~pd
570 for %%i in ("L M" N) do echo %%~ni
572 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
573 rem path with short path names
574 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
576 for %%i in ("U V" W) do echo '%%~ai'
578 for %%i in (foo) do echo '%%~ai'
579 for %%i in (foo) do echo '%%~zi'
582 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
583 for %%i in ("a b" c) do echo '%%~ti'
585 rem Similar issues as above
586 for %%i in ("a b" c) do echo '%%~zi'
588 for %%i in ("d e" f) do echo %%~dpi
589 for %%i in ("g h" i) do echo %%~sdi
590 for %%i in ("g h" i) do echo %%~dsi
591 for %%i in ("j k" l.eh) do echo '%%~xsi'
592 for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
594 echo --- in parameters
595 for %%i in ("A B" C) do call :echoFun %%i
597 for %%i in ("A B" C) do call :echoFunQ %%i
598 rem fully qualified path
599 for %%f in ("C D" E) do call :echoFunF %%f
601 for %%i in ("F G" H) do call :echoFunD %%i
603 for %%d in ("I J" K) do call :echoFunP %%d
605 for %%i in ("L M" N) do call :echoFunN %%i
607 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
608 rem path with short path names
609 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
610 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
612 for %%i in ("d e" f) do call :echoFunDP %%i
613 for %%i in ("g h" i) do call :echoFunSD %%i
614 for %%i in ("g h" i) do call :echoFunDS %%i
615 for %%i in ("j k" l.eh) do call :echoFunXS %%i
647 rem some NT4 workaround
670 echo ------------ Testing variable delayed expansion ------------
671 rem NT4 doesn't support this
672 echo --- default mode (load-time expansion)
676 if %WINE_FOO% == foo (
678 if %WINE_FOO% == bar (echo bar) else echo foo
682 if %WINE_FOO% == foo (
684 if !WINE_FOO! == bar (echo bar) else echo foo
687 echo --- runtime (delayed) expansion mode
688 setlocal EnableDelayedExpansion
692 if %WINE_FOO% == foo (
694 if %WINE_FOO% == bar (echo bar) else echo foo
698 if %WINE_FOO% == foo (
700 if !WINE_FOO! == bar (echo bar) else echo foo
703 setlocal DisableDelayedExpansion
709 echo --- using /V cmd flag
710 echo @echo off> tmp.cmd
711 echo set WINE_FOO=foo>> tmp.cmd
712 echo echo %%WINE_FOO%%>> tmp.cmd
713 echo echo !WINE_FOO!>> tmp.cmd
714 echo set WINE_FOO=>> tmp.cmd
716 cmd /V:OfF /C tmp.cmd
719 echo ------------ Testing conditional execution ------------
720 echo --- unconditional ampersand
721 call :setError 123 & echo foo1
722 echo bar2 & echo foo2
723 mkdir foobar & cd foobar
725 cd .. & rd /s/q foobar
727 echo foobar not deleted!
730 ) else echo foobar deleted
731 echo --- on success conditional and
732 call :setError 456 && echo foo3 > foo3
736 ) else echo foo3 not created
737 echo bar4 && echo foo4
738 echo --- on failure conditional or
739 call :setError 789 || echo foo5
740 echo foo6 || echo bar6 > bar6
746 echo ------------ Testing cd ------------
749 echo blabla > singleFile
751 echo Current dir: %CD%
766 if not exist foobar (cd ..)
768 cd@tab@..@tab@@space@@tab@
770 if not exist foobar (cd ..)
784 cd "bar bak@space@"@tab@@space@
795 echo ------------ Testing type ------------
809 echo ------------ Testing NUL ------------
810 md foobar & cd foobar
811 rem NUL file (non) creation + case insensitivity
812 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
821 rem NUL not special everywhere
824 if not exist foo (echo foo should have been created) else (
828 rem Empty file creation
838 copy a.a+NUL b.b >nul
839 call :CheckFileSize a.a 7 b.b 8
840 copy NUL+a.a b.b >nul
841 call :CheckFileSize a.a 7 b.b 8
843 copy a.a+NUL subdir\ >nul
844 call :CheckFileSize a.a 7 subdir\a.a 8
848 if exist a.a echo Failed
852 cd .. & rd foobar /s /q
854 echo ------------ Testing if/else ------------
855 echo --- if/else should work with blocks
857 echo if seems to work
859 echo if seems to be broken
862 echo else seems to be broken
864 echo else seems to work
867 echo if seems not to detect /c as parameter
869 echo parameter detection seems to be broken
873 SET /a elseIF=%elseIF%+1
875 SET /a elseIF=%elseIF%+2
877 SET /a elseIF=%elseIF%+2
880 echo else if seems to work
882 echo else if seems to be broken
886 SET /a elseIF=%elseIF%+2
888 SET /a elseIF=%elseIF%+1
890 SET /a elseIF=%elseIF%+2
893 echo else if seems to work
895 echo else if seems to be broken
899 SET /a elseIF=%elseIF%+2
901 SET /a elseIF=%elseIF%+2
903 SET /a elseIF=%elseIF%+1
906 echo else if seems to work
908 echo else if seems to be broken
910 echo --- case sensitivity with and without /i option
911 if bar==BAR echo if does not default to case sensitivity
912 if not bar==BAR echo if seems to default to case sensitivity
913 if /i foo==FOO echo if /i seems to work
914 if /i not foo==FOO echo if /i seems to be broken
915 if /I foo==FOO echo if /I seems to work
916 if /I not foo==FOO echo if /I seems to be broken
918 echo --- string comparisons
919 if abc == abc (echo equal) else echo non equal
920 if abc =="abc" (echo equal) else echo non equal
921 if "abc"== abc (echo equal) else echo non equal
922 if "abc"== "abc" (echo equal) else echo non equal
924 echo --- tabs handling
925 if@tab@1==1 echo doom
926 if @tab@1==1 echo doom
927 if 1==1 (echo doom) else@tab@echo quake
928 if@tab@not @tab@1==@tab@0 @tab@echo lol
929 if 1==0@tab@(echo doom) else echo quake
930 if 1==0 (echo doom)@tab@else echo quake
931 if 1==0 (echo doom) else@tab@echo quake
933 echo --- comparison operators
934 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
935 echo ------ for strings
936 rem NT4 stops processing of the whole batch file as soon as it finds a
937 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
938 rem can't test those here.
939 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
940 if LSS LSS LSS (echo bar)
941 if 1.1 LSS 1.10 (echo floats are handled as strings)
942 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
943 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
944 if /i foo LSS FoOc echo if /i seems to work for LSS
945 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
946 set WINE_STR_PARMS=A B AB BA AA
947 for %%i in (%WINE_STR_PARMS%) do (
948 for %%j in (%WINE_STR_PARMS%) do (
949 call :LSStest %%i %%j))
950 if b LSS B (echo b LSS B) else echo NT4
951 if /I b LSS B echo b LSS B insensitive
952 if b LSS A echo b LSS A
953 if /I b LSS A echo b LSS A insensitive
954 if a LSS B (echo a LSS B) else echo NT4
955 if /I a LSS B echo a LSS B insensitive
956 if A LSS b echo A LSS b
957 if /I A LSS b echo A LSS b insensitive
958 for %%i in (%WINE_STR_PARMS%) do (
959 for %%j in (%WINE_STR_PARMS%) do (
960 call :LEQtest %%i %%j))
961 if b LEQ B (echo b LEQ B) else echo NT4
962 if /I b LEQ B echo b LEQ B insensitive
963 if b LEQ A echo b LEQ A
964 if /I b LEQ A echo b LEQ A insensitive
965 if a LEQ B (echo a LEQ B) else echo NT4
966 if /I a LEQ B echo a LEQ B insensitive
967 if A LEQ b echo A LEQ b
968 if /I A LEQ b echo A LEQ b insensitive
969 for %%i in (%WINE_STR_PARMS%) do (
970 for %%j in (%WINE_STR_PARMS%) do (
971 call :EQUtest %%i %%j))
972 if /I A EQU a echo A EQU a insensitive
973 for %%i in (%WINE_STR_PARMS%) do (
974 for %%j in (%WINE_STR_PARMS%) do (
975 call :NEQtest %%i %%j))
976 for %%i in (%WINE_STR_PARMS%) do (
977 for %%j in (%WINE_STR_PARMS%) do (
978 call :GEQtest %%i %%j))
979 for %%i in (%WINE_STR_PARMS%) do (
980 for %%j in (%WINE_STR_PARMS%) do (
981 call :GTRtest %%i %%j))
982 echo ------ for numbers
983 if -1 LSS 1 (echo negative numbers handled)
984 if not -1 LSS -10 (echo negative numbers handled)
985 if not 9 LSS 010 (echo octal handled)
986 if not -010 LSS -8 (echo also in negative form)
987 if 4 LSS 0x5 (echo hexa handled)
988 if not -1 LSS -0x1A (echo also in negative form)
989 if 11 LSS 101 (echo 11 LSS 101)
990 set WINE_INT_PARMS=0 1 10 9
991 for %%i in (%WINE_INT_PARMS%) do (
992 for %%j in (%WINE_INT_PARMS%) do (
993 call :LSStest %%i %%j))
994 for %%i in (%WINE_INT_PARMS%) do (
995 for %%j in (%WINE_INT_PARMS%) do (
996 call :LEQtest %%i %%j))
997 for %%i in (%WINE_INT_PARMS%) do (
998 for %%j in (%WINE_INT_PARMS%) do (
999 call :EQUtest %%i %%j))
1000 if 011 EQU 9 (echo octal ok)
1001 if 0xA1 EQU 161 (echo hexa ok)
1002 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
1003 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
1004 for %%i in (%WINE_INT_PARMS%) do (
1005 for %%j in (%WINE_INT_PARMS%) do (
1006 call :NEQtest %%i %%j))
1007 for %%i in (%WINE_INT_PARMS%) do (
1008 for %%j in (%WINE_INT_PARMS%) do (
1009 call :GEQtest %%i %%j))
1010 for %%i in (%WINE_INT_PARMS%) do (
1011 for %%j in (%WINE_INT_PARMS%) do (
1012 call :GTRtest %%i %%j))
1013 echo ------ for numbers and stringified numbers
1014 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
1015 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
1016 if '1' EQU 1 echo '1' EQU 1
1017 if 1 EQU '1' echo 1 EQU '1'
1018 if not "1" GEQ 1 (echo foo) else echo bar
1019 if "10" GEQ "1" echo "10" GEQ "1"
1020 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
1021 if 1 GEQ "1" echo 1 GEQ "1"
1022 if "1" GEQ "1" echo "1" GEQ "1"
1023 if '1' GEQ "1" echo '1' GEQ "1"
1024 if "10" GEQ "1" echo "10" GEQ "1"
1025 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
1026 for %%i in ("1" '1') do call :GEQtest %%i '1'
1027 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
1028 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
1029 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
1030 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
1031 if "10" GEQ "10" (echo "10" GEQ "10")
1032 echo --- unconditional ampersand after if one line
1033 if "0"=="0" echo 1 & echo 2 & echo 3 else echo 4
1035 echo x & if "0"=="1" echo 1 & echo 2
1037 echo x & if "0"=="1" echo 1 & echo 2 & echo 3
1039 echo x & if "0"=="1" (echo 1 & echo 2 & echo 3)
1041 echo x & if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
1043 goto :endIfCompOpsSubroutines
1045 rem IF subroutines helpers
1047 if %1 LSS %2 echo %1 LSS %2
1050 if %1 LEQ %2 echo %1 LEQ %2
1053 if %1 EQU %2 echo %1 EQU %2
1056 if %1 NEQ %2 echo %1 NEQ %2
1059 if %1 GEQ %2 echo %1 GEQ %2
1062 if %1 GTR %2 echo %1 GTR %2
1065 :endIfCompOpsSubroutines
1069 echo ------------ Testing for ------------
1071 for %%i in (A B C) do echo %%i
1072 for %%i in (A B C) do echo %%I
1073 for %%i in (A B C) do echo %%j
1074 for %%i in (A B C) do call :forTestFun1 %%i
1075 for %%i in (1,4,1) do echo %%i
1076 for %%i in (A, B,C) do echo %%i
1077 for %%i in (X) do echo %%i
1078 for@tab@%%i in (X2) do echo %%i
1079 for %%i in@tab@(X3) do echo %%i
1080 for %%i in (@tab@ foo@tab@) do echo %%i
1081 for@tab@ %%i in@tab@(@tab@M) do echo %%i
1082 for %%i@tab@in (X)@tab@do@tab@echo %%i
1083 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
1084 for %%i in (`echo A B`) do echo %%i
1085 for %%i in ('echo A B') do echo %%i
1086 for %%i in ("echo A B") do echo %%i
1087 for %%i in ("A B" C) do echo %%i
1088 goto :endForTestFun1
1093 echo --- imbricated FORs
1100 for %%i in (A B) do (
1101 for %%j in (C D) do (
1103 for %%i in (A B) do (
1104 for %%j in (C D) do (
1105 call :forTestFun2 %%i %%j ))
1106 goto :endForTestFun2
1111 mkdir foobar & cd foobar
1116 echo --- basic wildcards
1117 for %%i in (ba*) do echo %%i
1119 for /d %%i in (baz foo bar) do echo %%i 2>&1
1120 rem Confirm we don't match files:
1121 for /d %%i in (bazb*) do echo %%i 2>&1
1122 for /d %%i in (bazb2*) do echo %%i 2>&1
1123 rem Show we pass through non wildcards
1124 for /d %%i in (PASSED) do echo %%i
1125 for /d %%i in (xxx) do (
1126 echo %%i - Should be xxx
1127 echo Expected second line
1129 rem Show we issue no messages on failures
1130 for /d %%i in (FAILED?) do echo %%i 2>&1
1131 for /d %%i in (FAILED?) do (
1132 echo %%i - Unexpected!
1133 echo FAILED Unexpected second line
1135 for /d %%i in (FAILED*) do echo %%i 2>&1
1136 for /d %%i in (FAILED*) do (
1137 echo %%i - Unexpected!
1138 echo FAILED Unexpected second line
1140 rem FIXME can't test wildcard expansion here since it's listed in directory
1141 rem order, and not in alphabetic order.
1142 rem Proper testing would need a currently missing "sort" program implementation.
1143 rem for /d %%i in (ba*) do echo %%i>> tmp
1146 rem for /d %%i in (?a*) do echo %%i>> tmp
1149 rem for /d %%i in (*) do echo %%i>> tmp
1157 call :WriteLine set WINE_found=N
1158 for /l %%i in (1,1,%WINE_expectedresults%) do (
1159 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%~1" set WINE_found=Y
1160 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
1161 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
1163 call :WriteLine echo Got unexpected result: "%%%%~1"
1172 for /l %%i in (1,1,%WINE_expectedresults%) do (
1173 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
1180 rem %CD% does not work on NT4 so use the following workaround
1181 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
1184 echo Plain directory enumeration
1185 set WINE_expectedresults=4
1186 set WINE_expectedresults.1=%WINE_CURDIR%\.
1187 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1188 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1189 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1191 for /R %%i in (.) do call temp.bat "%%i"
1192 call :ValidateExpected
1194 echo Plain directory enumeration from provided root
1195 set WINE_expectedresults=4
1196 set WINE_expectedresults.1=%WINE_CURDIR%\.
1197 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1198 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1199 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1200 if "%CD%"=="" goto :SkipBrokenNT4
1202 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat "%%i"
1203 call :ValidateExpected
1206 echo File enumeration
1207 set WINE_expectedresults=2
1208 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1209 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1211 for /R %%i in (baz*) do call temp.bat "%%i"
1212 call :ValidateExpected
1214 echo File enumeration from provided root
1215 set WINE_expectedresults=2
1216 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1217 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1219 for /R %%i in (baz*) do call temp.bat "%%i"
1220 call :ValidateExpected
1222 echo Mixed enumeration
1223 set WINE_expectedresults=6
1224 set WINE_expectedresults.1=%WINE_CURDIR%\.
1225 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1226 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1227 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1228 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1229 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1231 for /R %%i in (. baz*) do call temp.bat "%%i"
1232 call :ValidateExpected
1234 echo Mixed enumeration from provided root
1235 set WINE_expectedresults=6
1236 set WINE_expectedresults.1=%WINE_CURDIR%\.
1237 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1238 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1239 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1240 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1241 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1243 for /R %%i in (. baz*) do call temp.bat "%%i"
1244 call :ValidateExpected
1246 echo With duplicates enumeration
1247 set WINE_expectedresults=12
1248 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
1249 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
1250 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
1251 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1252 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
1253 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
1254 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
1255 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
1256 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1257 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1258 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1259 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1261 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat "%%i"
1262 call :ValidateExpected
1264 echo Strip missing wildcards, keep unwildcarded names
1265 set WINE_expectedresults=6
1266 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1267 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1268 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1269 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1270 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1271 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1273 for /R %%i in (baz* fred* jim) do call temp.bat "%%i"
1274 call :ValidateExpected
1277 echo --- Complex wildcards unix and windows slash
1279 echo Windows slashes, valid path
1280 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1281 for %%f in (foobar\baz\*) do echo WC : %%f
1282 echo Windows slashes, invalid path
1283 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1284 for %%f in (foobar\jim\*) do echo WC : %%f
1285 echo Unix slashes, valid path
1286 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1287 for %%f in (foobar/baz/*) do echo WC : %%f
1288 echo Unix slashes, invalid path
1289 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1290 for %%f in (foobar/jim/*) do echo WC : %%f
1294 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
1295 for /L %%i in (1,2,0) do echo %%i
1296 for@tab@/L %%i in (1,2,0) do echo %%i
1297 for /L %%i in (1,2,6) do echo %%i
1298 for /l %%i in (1 ,2,6) do echo %%i
1299 for /L %%i in (a,2,3) do echo %%i
1300 for /L %%i in (1,2,-1) do echo %%i
1301 for /L %%i in (-4,-1,-1) do echo %%i
1302 for /L %%i in (1,-2,-2) do echo %%i
1303 for /L %%i in (1,2,a) do echo %%i
1304 echo ErrorLevel %ErrorLevel%
1305 for /L %%i in (1,a,b) do echo %%i
1306 echo ErrorLevel %ErrorLevel%
1308 for /l %%i in (1,1,4) do echo %%i
1309 for /l %%i in (1,2,4) do echo %%i
1310 for /l %%i in (4,-1,1) do echo %%i
1311 for /l %%i in (4,-2,1) do echo %%i
1312 for /l %%i in (1,-1,4) do echo %%i
1313 for /l %%i in (4,1,1) do echo %%i
1314 for /L %%i in (a,2,b) do echo %%i
1315 for /L %%i in (1,1,1) do echo %%i
1316 for /L %%i in (1,-2,-1) do echo %%i
1317 for /L %%i in (-1,-1,-1) do echo %%i
1318 for /L %%i in (1,2, 3) do echo %%i
1319 rem Test zero iteration skips the body of the for
1320 for /L %%i in (2,2,1) do (
1327 Rem Ideally for /f can be used rather than building a command to execute
1328 rem but that does not work on NT4
1330 if "%1"=="" goto :eof
1331 call :executecmd set wine_result=%%%1%%
1332 if "%wine_result%"=="%2" (
1333 echo %1 correctly %2
1334 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1345 rem No output when using "set expr" syntax, unless in interactive mode
1346 rem Need to use "set envvar=expr" to use in a batch script
1347 echo ------ individual operations
1349 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1350 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1351 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1352 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1353 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1354 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1355 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1356 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1357 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1358 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1359 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1360 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1361 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1362 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1363 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1364 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1365 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1366 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1367 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1368 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1369 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1370 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1371 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1372 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1373 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1374 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1375 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1376 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1377 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1378 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1379 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1380 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1381 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1382 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1383 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1384 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1385 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1386 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1387 echo ------ precedence and grouping
1388 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1389 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1390 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1391 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1392 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1393 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1394 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1395 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1396 echo ------ octal and hexadecimal
1397 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1398 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1399 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1400 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1401 echo ------ variables
1402 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1403 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1404 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
1406 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1407 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1409 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1411 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1413 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1414 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1416 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1418 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1420 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1421 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1422 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1424 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1427 call :checkenvvars WINE_foo 1
1429 call :checkenvvars WINE_foo 1
1430 set /a WINE_foo=1,WINE_bar=2
1431 call :checkenvvars WINE_foo 1 WINE_bar 2
1432 set /a "WINE_foo=1,WINE_bar=2"
1433 call :checkenvvars WINE_foo 1 WINE_bar 2
1434 set /a "WINE_foo=1","WINE_bar=2"
1435 call :checkenvvars WINE_foo 1 WINE_bar 2
1436 set /a ""WINE_foo=1","WINE_bar=2""
1437 call :checkenvvars WINE_foo 1 WINE_bar 2
1438 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1439 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1440 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
1441 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1442 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
1443 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1444 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1445 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1446 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
1447 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1448 set /a """"""WINE_foo=1""""""
1449 call :checkenvvars WINE_foo 1
1450 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1451 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1452 set /a WINE_foo="3"+"4"+"5+6"
1453 call :checkenvvars WINE_foo 18
1455 set /a WINE_bar="WINE_""foo"+4
1456 call :checkenvvars WINE_foo 3 WINE_bar 7
1457 echo --- whitespace are ignored between double char operators
1460 set /a WINE_foo + = 6
1461 set /a WINE_bar * = WINE_foo
1462 call :checkenvvars WINE_foo 10 WINE_bar 50
1465 set /a WINE_foo + = "6 < < 7"
1466 set /a WINE_bar * = WINE_foo + WINE_foo
1467 call :checkenvvars WINE_foo 772 WINE_bar 7720
1471 echo --- invalid operator sequence
1477 set /a WINE_foo^>^<=4
1479 set /a WINE_foo^>^>^>=4
1481 echo ----- negative prefix
1483 call :checkenvvars WINE_foo -1
1485 call :checkenvvars WINE_foo 1
1486 set /a WINE_foo=3--3
1487 call :checkenvvars WINE_foo 6
1488 set /a WINE_foo=3---3
1489 call :checkenvvars WINE_foo 0
1490 set /a WINE_foo=3----3
1491 call :checkenvvars WINE_foo 6
1493 call :checkenvvars WINE_foo 2
1495 call :checkenvvars WINE_foo 0
1496 set /a WINE_foo=3+-~1
1497 call :checkenvvars WINE_foo 5
1498 set /a WINE_foo=3+~-1
1499 call :checkenvvars WINE_foo 3
1500 echo ----- assignment tests involving the end destination
1502 set /a WINE_foo+=3+(WINE_foo=4)
1503 call :checkenvvars WINE_foo 11
1505 set /a WINE_bar=3+(WINE_foo=6)
1506 call :checkenvvars WINE_foo 6 WINE_bar 9
1508 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1509 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1511 set /a WINE_bar=WINE_foo=7
1512 call :checkenvvars WINE_foo 7 WINE_bar 7
1513 echo ----- equal precedence on stack
1514 rem Unary - don't reduce if precedence is equal
1516 call :checkenvvars WINE_foo 1
1518 call :checkenvvars WINE_foo 0
1520 call :checkenvvars WINE_foo 1
1522 call :checkenvvars WINE_foo 0
1524 call :checkenvvars WINE_foo 1
1526 call :checkenvvars WINE_foo -1
1528 call :checkenvvars WINE_foo -1
1530 call :checkenvvars WINE_foo 1
1532 call :checkenvvars WINE_foo 0
1534 call :checkenvvars WINE_foo -1
1536 call :checkenvvars WINE_foo 0
1538 call :checkenvvars WINE_foo 0
1540 call :checkenvvars WINE_foo 1
1542 call :checkenvvars WINE_foo -1
1543 rem Aritmatic - Reduce if precedence is equal
1544 set /a WINE_foo=10*5/2
1545 call :checkenvvars WINE_foo 25
1546 set /a WINE_foo=5/2*10
1547 call :checkenvvars WINE_foo 20
1548 set /a WINE_foo=10/5/2
1549 call :checkenvvars WINE_foo 1
1550 set /a WINE_foo=5%%2*4
1551 call :checkenvvars WINE_foo 4
1552 set /a WINE_foo=10-5+2
1553 call :checkenvvars WINE_foo 7
1554 set /a WINE_foo=1^<^<4^>^>1
1555 call :checkenvvars WINE_foo 8
1556 rem Assignment - don't reduce if precedence is equal
1558 set /a WINE_bar=WINE_foo=6
1559 call :checkenvvars WINE_foo 6 WINE_bar 6
1562 mkdir foobar & cd foobar
1563 echo ------ string argument
1564 rem NT4 does not support usebackq
1565 for /F %%i in ("a b c") do echo %%i
1566 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1567 if not exist output_file (echo no output) else (type output_file & del output_file)
1568 for /f %%i in ("a ") do echo %%i
1569 for /f usebackq %%i in ('a ') do echo %%i>output_file
1570 if not exist output_file (echo no output) else (type output_file & del output_file)
1571 for /f %%i in ("a") do echo %%i
1572 for /f usebackq %%i in ('a') do echo %%i>output_file
1573 if not exist output_file (echo no output) else (type output_file & del output_file)
1574 fOr /f %%i in (" a") do echo %%i
1575 for /f usebackq %%i in (' a') do echo %%i>output_file
1576 if not exist output_file (echo no output) else (type output_file & del output_file)
1577 for /f %%i in (" a ") do echo %%i
1578 for /f usebackq %%i in (' a ') do echo %%i>output_file
1579 if not exist output_file (echo no output) else (type output_file & del output_file)
1580 echo ------ fileset argument
1581 echo --------- basic blank handling
1583 for /f %%i in (foo) do echo %%i
1585 for /f %%i in (foo) do echo %%i
1587 for /f %%i in (foo) do echo %%i
1589 for /f %%i in (foo) do echo %%i
1591 for /f %%i in (foo) do echo %%i
1593 for /f %%i in (foo) do echo %%i
1596 for /f %%i in (foo) do echo %%i
1597 echo --------- multi-line with empty lines
1604 for /f %%b in (foo) do echo %%b
1605 echo --------- multiple files
1609 for /f %%k in (foo bar) do echo %%k
1610 for /f %%k in (bar foo) do echo %%k
1611 echo ------ command argument
1612 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1613 if "%CD%"=="" goto :SkipFORFcmdNT4
1614 for /f %%i in ('echo.Passed1') do echo %%i
1615 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
1616 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1619 for /l %%i in (1,1,3) do echo Missing functionality - Broken%%i
1621 rem FIXME: Rest not testable right now in wine: not implemented and would need
1622 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1623 rem for a simple todo_wine test
1624 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1625 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1626 echo ------ eol option
1627 if "%CD%"=="" goto :SkipFORFeolNT4
1629 echo and Line two>>foo
1630 echo Line three>>foo
1631 for /f "eol=L" %%i in (foo) do echo %%i
1632 for /f "eol=a" %%i in (foo) do echo %%i
1634 goto :ContinueFORFeol
1636 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1638 for /f "eol=@" %%i in (" ad") do echo %%i
1639 for /f "eol=@" %%i in (" z@y") do echo %%i
1640 for /f "eol=|" %%i in ("a|d") do echo %%i
1641 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
1642 if not exist output_file (echo no output) else (del output_file)
1643 for /f "eol==" %%i in ("=y") do echo %%i > output_file
1644 if not exist output_file (echo no output) else (del output_file)
1645 echo ------ delims option
1646 for /f "delims=|" %%i in ("a|d") do echo %%i
1647 for /f "delims=|" %%i in ("a |d") do echo %%i
1648 for /f "delims=|" %%i in ("a d|") do echo %%i
1649 for /f "delims=| " %%i in ("a d|") do echo %%i
1650 for /f "delims==" %%i in ("C r=d|") do echo %%i
1651 for /f "delims=" %%i in ("foo bar baz") do echo %%i
1652 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
1653 echo ------ skip option
1657 for /f "skip=2" %%i in (foo) do echo %%i
1658 for /f "skip=3" %%i in (foo) do echo %%i > output_file
1659 if not exist output_file (echo no output) else (del output_file)
1660 for /f "skip=4" %%i in (foo) do echo %%i > output_file
1661 if not exist output_file (echo no output) else (del output_file)
1662 for /f "skip=02" %%i in (foo) do echo %%i
1663 for /f "skip=0x2" %%i in (foo) do echo %%i
1664 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
1665 if not exist output_file (echo no output) else (del output_file)
1666 echo ------ tokens= option
1668 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
1669 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
1670 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
1671 rem Show * means the rest
1672 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
1673 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
1674 rem Show * means the rest (not tokenized and rebuilt)
1675 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
1676 rem Order is irrelevant
1677 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
1678 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
1679 rem Duplicates are ignored
1680 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
1681 rem Large tokens are allowed
1682 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
1683 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1684 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
1685 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
1686 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1687 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
1688 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
1689 rem Show negative ranges have no effect
1690 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
1691 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
1692 rem Show duplicates stop * from working
1693 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
1694 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
1695 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
1696 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
1699 echo ------ parameter splitting
1700 echo forFParameterSplittingFunc "myparam1=myvalue1 myparam2=myparam2" mytest> foo
1701 for /f "tokens=1 delims=;" %%i in (foo) do (call :%%i)
1703 for /f "tokens=1 delims=;" %%i in ("forFParameterSplittingFunc "myparam1^=myvalue1 myparam2^=myparam2" mytest") do (call :%%i)
1704 goto :forFParameterSplittingEnd
1705 :forFParameterSplittingFunc
1706 echo %~0 %~1 %~2 %~3 %~4 %~5
1708 :forFParameterSplittingEnd
1710 echo ------------ Testing del ------------
1712 echo deleting 'file'
1715 echo errorlevel is 0, good
1717 echo unexpected errorlevel, got %errorlevel%
1720 echo successfully deleted 'file'
1722 echo error deleting 'file'
1724 echo attempting to delete 'file', even though it is not present
1727 echo errorlevel is 0, good
1729 echo unexpected errorlevel, got %errorlevel%
1732 echo ------------ Testing del /a ------------
1733 del /f/q *.test > nul
1736 echo not-r > not-r.test
1738 if not exist not-r.test echo not-r.test not found before delete, bad
1740 if not exist not-r.test echo not-r.test not found after delete, good
1742 if not exist r.test echo r.test not found before delete, bad
1743 if exist r.test echo r.test found before delete, good
1745 if not exist r.test echo r.test not found after delete, good
1746 if exist r.test echo r.test found after delete, bad
1748 echo ------------ Testing del /q ------------
1752 echo abc > file2.dat
1753 rem If /q doesn't work, cmd will prompt and the test case should hang
1755 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1756 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1760 echo ------------ Testing del /s ------------
1765 echo there > file2.dat
1766 echo bub > file3.dat
1767 echo bye > "file with spaces.dat"
1769 del /s file1.dat > nul
1770 del file2.dat /s > nul
1771 del "file3.dat" /s > nul
1772 del "file with spaces.dat" /s > nul
1774 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1775 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1776 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
1777 if exist "file with spaces.dat" del "file with spaces.dat"
1782 echo ------------ Testing rename ------------
1783 mkdir foobar & cd foobar
1784 echo --- ren and rename are synonymous
1787 if exist foo echo foo should be renamed!
1788 if exist bar echo foo renamed to bar
1790 if exist bar echo bar should be renamed!
1791 if exist foo echo bar renamed to foo
1792 echo --- name collision
1802 echo --- rename read-only files
1806 if not exist file1 (
1808 echo read-only file renamed
1811 echo read-only file not renamed!
1813 echo --- rename directories
1825 echo read-only dir renamed
1828 echo --- rename in other directory
1829 if not exist baz\abc (
1830 echo rename impossible in other directory
1831 if exist foo echo original file still present
1833 echo shouldn't rename in other directory!
1834 if not exist foo echo original file not present anymore
1836 cd .. & rd /s/q foobar
1838 echo ------------ Testing move ------------
1839 mkdir foobar & cd foobar
1842 move foo bar > nul 2>&1
1845 echo file move succeeded
1850 move /Y bar baz > nul 2>&1
1853 echo file move with overwrite succeeded
1856 echo file overwrite impossible!
1862 move baz bazro > nul 2>&1
1865 echo read-only files are moveable
1866 move bazro baz > nul 2>&1
1869 echo read-only file not moved!
1873 move baz rep > nul 2>&1
1876 echo file moved in subdirectory
1880 move rep\baz . > nul 2>&1
1881 move /Y baz baz > nul 2>&1
1883 echo moving a file to itself should be a no-op!
1885 echo moving a file to itself is a no-op
1887 echo ErrorLevel: %ErrorLevel%
1890 echo --- directory move
1894 move baz foo\bar > nul 2>&1
1896 if exist foo\bar\baz\baz2 (
1897 echo simple directory move succeeded
1902 move baz baz > nul 2>&1
1903 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1904 echo ------ dir in dir move
1909 move foo bar > nul 2>&1
1917 cd .. & rd /s/q foobar
1919 echo ------------ Testing mkdir ------------
1921 echo --- md and mkdir are synonymous
1928 echo --- creating an already existing directory/file must fail
1937 echo --- multilevel path creation
1949 mkdir ..\..\..\foo\bar2
1952 mkdir ..\..\..\foo\bar2
1954 rmdir ..\..\..\foo\bar2
1962 echo --- trailing backslashes
1965 if exist foo (rmdir foo & echo dir created
1966 ) else ( echo dir not created )
1968 echo --- invalid chars
1970 echo mkdir ? gives errorlevel %ErrorLevel%
1973 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1976 echo mkdir foo\? gives errorlevel %ErrorLevel%
1977 if exist foo (rmdir foo & echo ok, foo created
1978 ) else ( echo foo not created )
1981 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1984 echo bad, foo not created
1988 echo ok, foo\bar created
1994 echo --- multiple directories at once
1995 mkdir foobaz & cd foobaz
1996 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
1997 if exist foo (echo foo created) else echo foo not created!
1998 if exist bar (echo bar created) else echo bar not created!
1999 if exist foobar (echo foobar created) else echo foobar not created!
2000 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
2001 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
2002 if exist zabzab (echo zabzab created) else echo zabzab not created!
2003 cd .. & rd /s/q foobaz
2006 echo mkdir foo\* errorlevel %ErrorLevel%
2007 if exist foo (rmdir foo & echo ok, foo created
2008 ) else ( echo bad, foo not created )
2010 echo ------------ Testing rmdir ------------
2012 rem rd and rmdir are synonymous
2016 if not exist foobar echo dir removed
2020 if not exist foobar echo dir removed
2021 rem Removing nonexistent directory
2024 rem Removing single-level directories
2028 if exist foo echo file not removed
2034 if exist foo echo non-empty dir not removed
2039 if exist foo echo non-empty dir not removed
2046 echo recursive rmdir succeeded
2053 echo foo > foo\bar\brol
2054 rmdir /s /Q foo 2>&1
2056 echo recursive rmdir succeeded
2063 rem multiples directories at once
2064 mkdir foobaz & cd foobaz
2068 rd /s/q foo bar foobar
2069 if not exist foo (echo foo removed) else echo foo not removed!
2070 if not exist bar (echo bar removed) else echo bar not removed!
2071 if not exist foobar (echo foobar removed) else echo foobar not removed!
2072 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
2073 cd .. & rd /s/q foobaz
2075 echo ------------ Testing pushd/popd ------------
2077 echo --- popd is no-op when dir stack is empty
2080 echo --- pushing non-existing dir
2083 echo --- basic behaviour
2108 echo ------------ Testing attrib ------------
2109 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
2110 mkdir foobar & cd foobar
2111 echo foo original contents> foo
2114 echo --- read-only attribute
2115 rem Read-only files cannot be altered or deleted, unless forced
2123 echo Read-only file not deleted
2125 echo Should not delete read-only file!
2129 echo Read-only file forcibly deleted
2131 echo Should delete read-only file with del /F!
2135 cd .. & rd /s/q foobar
2136 echo --- recursive behaviour
2137 mkdir foobar\baz & cd foobar
2143 attrib +R l*vel? /S > nul 2>&1
2149 cd .. & rd /s/q foobar
2150 echo --- folders processing
2156 attrib +r baz /s /d > nul 2>&1
2162 rem Oddly windows allows file creation in a read-only directory...
2163 if exist baz\lala (echo file created in read-only dir) else echo file not created
2164 cd .. & rd /s/q foobar
2166 echo ------------ Testing assoc ------------
2167 rem Modifying associations requires some privileges...
2168 net session >nul 2>&1
2169 if errorlevel 1 goto :SkipAssoc
2171 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2172 rem FIXME Revise once || conditional execution is fixed
2173 mkdir foobar & cd foobar
2174 echo --- setting association
2182 rem association set system-wide
2183 echo @echo off> tmp.cmd
2184 echo echo +++>> tmp.cmd
2185 echo assoc .foo>> tmp.cmd
2188 echo --- resetting association
2194 rem association removal set system-wide
2195 cmd /c tmp.cmd > baz
2198 cd .. & rd /s/q foobar
2201 echo --- setting association
2207 echo --- resetting association
2214 echo ------------ Testing ftype ------------
2215 rem Modifying associations requires some privileges...
2216 net session >nul 2>&1
2217 if errorlevel 1 goto :SkipFType
2218 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2219 rem FIXME Revise once || conditional execution is fixed
2220 mkdir foobar & cd foobar
2221 echo --- setting association
2226 ftype footype=foo_opencmd
2230 rem association set system-wide
2231 echo @echo off> tmp.cmd
2232 echo echo +++>> tmp.cmd
2233 echo ftype footype>> tmp.cmd
2236 echo --- resetting association
2239 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2240 setlocal EnableDelayedExpansion
2241 set WINE_FOO=original value
2244 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
2245 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2246 rem FIXME Revisit once a grep-like program like ftype is implemented
2247 rem (e.g. to check baz's size using dir /b instead)
2250 rem cleanup registry
2251 echo REGEDIT4> regCleanup.reg
2252 echo.>> regCleanup.reg
2253 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
2254 regedit /s regCleanup.reg
2257 cd .. & rd /s/q foobar
2260 echo --- setting association
2262 echo footype=foo_opencmd
2264 echo footype=foo_opencmd
2266 echo footype=foo_opencmd
2267 echo --- resetting association
2271 echo ------------ Testing CALL ------------
2272 mkdir foobar & cd foobar
2273 echo --- external script
2274 echo echo foo %%1> foo.cmd
2277 echo echo %%1 %%2 > foo.cmd
2279 call foo.cmd foo bar
2286 echo --- internal routines
2287 call :testRoutine :testRoutine
2288 goto :endTestRoutine
2294 call :testRoutineArgs foo
2295 call :testRoutineArgs foo bar
2296 call :testRoutineArgs foo ""
2297 call :testRoutineArgs "" bar
2298 call :testRoutineArgs foo ''
2299 call :testRoutineArgs '' bar
2300 goto :endTestRoutineArgs
2306 echo --- with builtins
2309 if exist foo (echo foo created) else echo foo should exist!
2311 set WINE_FOOBAZ_VAR=foobaz
2312 call echo Should expand %WINE_FOOBAZ_VAR%
2313 set WINE_FOOBAZ_VAR=
2317 if 1==1 call del batfile
2319 if exist batfile echo batfile shouldn't exist
2320 rem ... but not for 'if' or 'for'
2321 call if 1==1 echo bar 2> nul
2324 call for %%i in (foo bar baz) do echo %%i 2> nul
2326 rem First look for programs in the path before trying a builtin
2327 echo echo non-builtin dir> dir.cmd
2330 rem The below line equates to call (, which does nothing, then the
2331 rem subsequent lines are executed.
2336 rem The below line equates to call if, which always fails, then the
2337 rem subsequent lines are executed. Note cmd.exe swallows all lines
2344 call call call echo passed
2345 cd .. & rd /s/q foobar
2347 echo ------------ Testing SHIFT ------------
2349 call :shiftFun p1 p2 p3 p4 p5
2353 echo '%1' '%2' '%3' '%4' '%5'
2355 echo '%1' '%2' '%3' '%4' '%5'
2357 echo '%1' '%2' '%3' '%4' '%5'
2359 echo '%1' '%2' '%3' '%4' '%5'
2361 echo '%1' '%2' '%3' '%4' '%5'
2363 echo '%1' '%2' '%3' '%4' '%5'
2367 echo ------------ Testing cmd invocation ------------
2368 rem FIXME: only a stub ATM
2369 echo --- a batch file can delete itself
2370 echo del foo.cmd>foo.cmd
2372 if not exist foo.cmd (
2373 echo file correctly deleted
2375 echo file should be deleted!
2378 echo --- a batch file can alter itself
2379 echo echo bar^>foo.cmd>foo.cmd
2380 cmd /q /c foo.cmd > NUL 2>&1
2385 echo file not created!
2388 echo ---------- Testing copy
2391 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2394 echo CCCCCCCCC> file3
2400 echo Passed: Found expected %1
2402 echo Failed: Did not find expected %1
2404 del /q "%1" >nul 2>&1
2406 if not "%1"=="" goto :CheckExist
2411 echo Passed: Did not find %1
2413 echo Failed: Unexpectedly found %1
2414 del /q "%1" >nul 2>&1
2417 if not "%1"=="" goto :CheckNotExist
2420 rem Note: No way to check file size on NT4 so skip the test
2423 echo Failed: File missing when requested filesize check [%2]
2424 goto :ContinueFileSizeChecks
2426 for %%i in (%1) do set WINE_filesize=%%~zi
2427 if "%WINE_filesize%"=="%2" (
2428 echo Passed: file size check on %1 [%WINE_filesize%]
2430 if "%WINE_filesize%"=="%%~zi" (
2431 echo Skipping file size check on NT4
2433 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2436 :ContinueFileSizeChecks
2439 if not "%1"=="" goto :CheckFileSize
2444 rem -----------------------
2445 rem Simple single file copy
2446 rem -----------------------
2447 rem Simple single file copy, normally used syntax
2448 copy file1 dummy.file >nul 2>&1
2449 if errorlevel 1 echo Incorrect errorlevel
2450 call :CheckExist dummy.file
2452 rem Simple single file copy, destination supplied as two forms of directory
2453 copy file1 dir1 >nul 2>&1
2454 if errorlevel 1 echo Incorrect errorlevel
2455 call :CheckExist dir1\file1
2457 copy file1 dir1\ >nul 2>&1
2458 if errorlevel 1 echo Incorrect errorlevel
2459 call :CheckExist dir1\file1
2461 rem Simple single file copy, destination supplied as fully qualified destination
2462 copy file1 dir1\file99 >nul 2>&1
2463 if errorlevel 1 echo Incorrect errorlevel
2464 call :CheckExist dir1\file99
2466 rem Simple single file copy, destination not supplied
2468 copy ..\file1 >nul 2>&1
2469 if errorlevel 1 echo Incorrect errorlevel
2470 call :CheckExist file1
2473 rem Simple single file copy, destination supplied as nonexistent directory
2474 copy file1 dir2\ >nul 2>&1
2475 if not errorlevel 1 echo Incorrect errorlevel
2476 call :CheckNotExist dir2 dir2\file1
2478 rem -----------------------
2480 rem -----------------------
2481 rem Simple single file copy, destination supplied as two forms of directory
2482 copy file? dir1 >nul 2>&1
2483 if errorlevel 1 echo Incorrect errorlevel
2484 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2486 copy file* dir1\ >nul 2>&1
2487 if errorlevel 1 echo Incorrect errorlevel
2488 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2490 rem Simple single file copy, destination not supplied
2492 copy ..\file*.* >nul 2>&1
2493 if errorlevel 1 echo Incorrect errorlevel
2494 call :CheckExist file1 file2 file3
2497 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2498 copy file? dir2\ >nul 2>&1
2499 if not errorlevel 1 echo Incorrect errorlevel
2500 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2502 rem ------------------------------------------------
2503 rem Confirm overwrite works (cannot test prompting!)
2504 rem ------------------------------------------------
2505 copy file1 testfile >nul 2>&1
2506 copy /y file2 testfile >nul 2>&1
2507 call :CheckExist testfile
2509 rem ------------------------------------------------
2510 rem Test concatenation
2511 rem ------------------------------------------------
2512 rem simple case, no wildcards
2513 copy file1+file2 testfile >nul 2>&1
2514 if errorlevel 1 echo Incorrect errorlevel
2515 call :CheckExist testfile
2517 rem simple case, wildcards, no concatenation
2518 copy file* testfile >nul 2>&1
2519 if errorlevel 1 echo Incorrect errorlevel
2520 call :CheckExist testfile
2522 rem simple case, wildcards, and concatenation
2524 copy file*+fred testfile >nul 2>&1
2525 if errorlevel 1 echo Incorrect errorlevel
2526 call :CheckExist testfile
2528 rem simple case, wildcards, and concatenation
2529 copy fred+file* testfile >nul 2>&1
2530 if errorlevel 1 echo Incorrect errorlevel
2531 call :CheckExist testfile
2533 rem Calculate destination name
2534 copy fred+file* dir1 >nul 2>&1
2535 if errorlevel 1 echo Incorrect errorlevel
2536 call :CheckExist dir1\fred
2538 rem Calculate destination name
2539 copy fred+file* dir1\ >nul 2>&1
2540 if errorlevel 1 echo Incorrect errorlevel
2541 call :CheckExist dir1\fred
2543 rem Calculate destination name (none supplied)
2545 copy ..\fred+..\file* >nul 2>&1
2546 if errorlevel 1 echo Incorrect errorlevel
2547 call :CheckExist fred
2549 copy ..\fr*+..\file1 >nul 2>&1
2550 if errorlevel 1 echo Incorrect errorlevel
2551 call :CheckExist fred
2554 rem ******************************************************************
2555 rem ASCII and BINARY tests
2556 rem Note: hard coded numbers deliberate because need to ensure whether
2557 rem an additional EOF has been added or not. There is no way to handle
2558 rem EOFs in batch, so assume if a single byte appears, it's an EOF!
2559 rem ******************************************************************
2561 rem Confirm original sizes of file1,2,3
2562 call :CheckFileSize file1 5 file2 8 file3 11
2566 rem ----------------------------------------------
2567 rem Show concatenation defaults copy to ascii mode
2568 rem ----------------------------------------------
2569 rem Simple default copy source to destination (should not append EOF 5)
2570 copy ..\file1 file1_default >nul 2>&1
2571 call :CheckFileSize file1_default 5
2573 rem Simple binary copy source to destination (should not append EOF 5)
2574 copy /b ..\file1 file1_default2 >nul 2>&1
2575 call :CheckFileSize file1_default2 5
2577 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2578 copy /a ..\file1 file1_plus_eof >nul 2>&1
2579 call :CheckFileSize file1_plus_eof 6
2580 copy /a ..\file2 file2_plus_eof >nul 2>&1
2581 call :CheckFileSize file2_plus_eof 9
2582 copy /a ..\file3 file3_plus_eof >nul 2>&1
2583 call :CheckFileSize file3_plus_eof 12
2585 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2586 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2587 call :CheckFileSize file12_plus_eof 14
2589 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2590 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2591 call :CheckFileSize file12_no_eof 13
2593 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2594 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2595 call :CheckFileSize file12_eof2 14
2597 rem Test copying when destination is one of the sources.
2598 rem Concat file1+file2+file3 into file1, should produce file1+file2+file3 = 24
2599 copy /y ..\file? .\ >nul 2>&1
2600 copy /y /b file1+file2+file3 file1 >nul 2>&1
2601 call :CheckFileSize file1 24
2603 rem Concat file1+file2+file3 into file2, should produce file1+file3 = 16
2604 copy /y ..\file? .\ >nul 2>&1
2605 copy /y /b file1+file2+file3 file2 >nul 2>&1
2606 call :CheckFileSize file2 16
2608 rem Concat file1+file2+file3 into file3, should produce file1+file2 = 13
2609 copy /y ..\file? .\ >nul 2>&1
2610 copy /y /b file1+file2+file3 file3 >nul 2>&1
2611 call :CheckFileSize file3 13
2613 rem --------------------------------------------------------------
2614 rem Show ascii source copy stops at first EOF, binary does the lot
2615 rem --------------------------------------------------------------
2616 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2617 call :CheckFileSize file1_binary_srccopy 6
2619 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2620 call :CheckFileSize file1_ascii_srccopy 5
2622 rem --------------------------------------------------------------
2623 rem Show results of concatenating files (ending in EOFs) and /a /b
2624 rem --------------------------------------------------------------
2626 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2627 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2628 call :CheckFileSize file123_default_copy 25
2629 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2630 call :CheckFileSize file123_ascii_copy 25
2632 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2633 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2634 call :CheckFileSize file123_binary_copy 27
2636 rem We can select which we want the eofs from by postfixing it with /a or /b
2637 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2638 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2639 call :CheckFileSize file123_mixed_copy1 26
2641 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2642 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2643 rem Note the delta between this and the previous one also shows that the destination
2644 rem ascii/binary is inherited from the last /a or /b on the line
2645 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2646 call :CheckFileSize file123_mixed_copy2 27
2648 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2649 rem Note the delta between the next two also shows that the destination ascii/binary is
2650 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2651 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2652 call :CheckFileSize file123_mixed_copy3 26
2653 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2654 call :CheckFileSize file123_mixed_copy4 25
2656 rem -------------------------------------------------------------------------------------------
2657 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2658 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2659 rem -------------------------------------------------------------------------------------------
2661 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2662 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2663 call :CheckFileSize file123_mixed_copy5 28
2665 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2666 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2667 call :CheckFileSize file123_mixed_copy6 19
2669 rem One file has EOF, but doesn't get an extra one, i.e. 6
2670 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2671 call :CheckFileSize file123_mixed_copy7 6
2673 rem Syntax means concatenate so ascii destination kicks in
2674 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2675 call :CheckFileSize file123_mixed_copy8 7
2680 rem ---------------------------------------
2681 rem Error combinations
2682 rem ---------------------------------------
2683 rem Specify source directory but name is a file
2685 copy file1\ dir1\ >NUL 2>&1
2686 if errorlevel 1 echo Passed: errorlevel invalid check 1
2687 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2688 call :CheckNotExist dir1\file1
2690 rem Overwrite same file
2692 copy file1 file1 >NUL 2>&1
2693 if errorlevel 1 echo Passed: errorlevel invalid check 2
2694 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2696 rem Supply same file identified as a directory
2698 copy file1 file1\ >NUL 2>&1
2699 if errorlevel 1 echo Passed: errorlevel invalid check 3
2700 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2705 echo ------------ Testing setlocal/endlocal ------------
2707 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2708 mkdir foobar & cd foobar
2709 echo --- enable/disable extensions
2710 setlocal DisableEXTensions
2711 echo ErrLev: %ErrorLevel%
2713 echo ErrLev: %ErrorLevel%
2714 echo @echo off> tmp.cmd
2715 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2716 rem Enabled by default
2718 cmd /E:OfF /C tmp.cmd
2719 cmd /e:oN /C tmp.cmd
2721 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2722 echo --- setlocal with corresponding endlocal
2723 rem %CD% does not work on NT4 so use the following workaround
2724 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2725 echo @echo off> test.cmd
2726 echo echo %%WINE_VAR%%>> test.cmd
2727 echo setlocal>> test.cmd
2728 echo set WINE_VAR=localval>> test.cmd
2729 echo md foobar2>> test.cmd
2730 echo cd foobar2>> test.cmd
2731 echo echo %%WINE_VAR%%>> test.cmd
2732 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2733 echo endlocal>> test.cmd
2734 echo echo %%WINE_VAR%%>> test.cmd
2735 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2736 set WINE_VAR=globalval
2739 for /d %%i in (.) do echo %%~dpnxi
2743 echo --- setlocal with no corresponding endlocal
2744 echo @echo off> test.cmd
2745 echo echo %%WINE_VAR%%>> test.cmd
2746 echo setlocal>> test.cmd
2747 echo set WINE_VAR=localval>> test.cmd
2748 echo md foobar2>> test.cmd
2749 echo cd foobar2>> test.cmd
2750 echo echo %%WINE_VAR%%>> test.cmd
2751 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2752 set WINE_VAR=globalval
2753 rem %CD% does not work on NT4 so use the following workaround
2754 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2757 for /d %%i in (.) do echo %%~dpnxi
2761 echo --- setlocal within same batch program
2765 rem %CD% does not work on NT4 so use the following workaround
2766 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2773 if "%WINE_var1%"=="one" echo Var1 ok 1
2774 if "%WINE_var2%"=="two" echo Var2 ok 2
2775 if "%WINE_var3%"=="three" echo Var3 ok 3
2776 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2777 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
2779 if "%WINE_var1%"=="one" echo Var1 ok 1
2780 if "%WINE_var2%"=="two" echo Var2 ok 2
2781 if "%WINE_var3%"=="" echo Var3 ok 3
2782 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2783 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
2785 if "%WINE_var1%"=="one" echo Var1 ok 1
2786 if "%WINE_var2%"=="" echo Var2 ok 2
2787 if "%WINE_var3%"=="" echo Var3 ok 3
2788 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2789 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
2793 echo --- Mismatched set and end locals
2797 rem %CD% does not work on NT4 so use the following workaround
2798 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
2800 echo @echo off> 2set1end.cmd
2801 echo echo %%WINE_var%%>> 2set1end.cmd
2802 echo setlocal>> 2set1end.cmd
2803 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
2804 echo cd ..\foodir3>> 2set1end.cmd
2805 echo setlocal>> 2set1end.cmd
2806 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
2807 echo cd ..\foodir4>> 2set1end.cmd
2808 echo endlocal>> 2set1end.cmd
2809 echo echo %%WINE_var%%>> 2set1end.cmd
2810 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
2812 echo @echo off> 1set2end.cmd
2813 echo echo %%WINE_var%%>> 1set2end.cmd
2814 echo setlocal>> 1set2end.cmd
2815 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
2816 echo cd ..\foodir3>> 1set2end.cmd
2817 echo endlocal>> 1set2end.cmd
2818 echo echo %%WINE_var%%>> 1set2end.cmd
2819 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2820 echo endlocal>> 1set2end.cmd
2821 echo echo %%WINE_var%%>> 1set2end.cmd
2822 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2824 echo --- Extra setlocal in called batch
2826 rem -- setlocal1 == this batch, should never be used inside a called routine
2830 call "%WINE_CURDIR%\2set1end.cmd"
2833 for /d %%i in (.) do echo %%~dpnxi
2836 for /d %%i in (.) do echo %%~dpnxi
2839 echo --- Extra endlocal in called batch
2841 rem -- setlocal1 == this batch, should never be used inside a called routine
2845 call "%WINE_CURDIR%\1set2end.cmd"
2848 for /d %%i in (.) do echo %%~dpnxi
2851 for /d %%i in (.) do echo %%~dpnxi
2854 echo --- endlocal in called function rather than batch pgm is ineffective
2860 call :endlocalroutine
2864 goto :endlocalfinished
2882 cd .. & rd /q/s foobar
2884 echo ------------ Testing Errorlevel ------------
2885 rem WARNING: Do *not* add tests using ErrorLevel after this section
2886 should_not_exist 2> nul > nul
2888 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2889 rem See http://www.robvanderwoude.com/exit.php
2892 if errorlevel 2 echo errorlevel too high, bad
2893 if errorlevel 1 echo errorlevel just right, good
2894 if errorlevel 01 echo errorlevel with leading zero just right, good
2895 if errorlevel -1 echo errorlevel with negative number OK
2896 if errorlevel 0x1 echo hexa should not be recognized!
2897 if errorlevel 1a echo invalid error level recognized!
2899 echo abc%ErrorLevel%def
2900 if errorlevel 1 echo errorlevel nonzero, bad
2901 if not errorlevel 1 echo errorlevel zero, good
2902 if not errorlevel 0x1 echo hexa should not be recognized!
2903 if not errorlevel 1a echo invalid error level recognized!
2904 rem Now verify that setting a real variable hides its magic variable
2906 echo %ErrorLevel% should be 7
2907 if errorlevel 7 echo setting var worked too well, bad
2909 echo %ErrorLevel% should still be 7
2911 echo ------------ Testing GOTO ------------
2913 echo FAILURE at dest 1
2915 echo goto with no leading space worked
2916 if a==a goto :dest1b
2917 echo FAILURE at dest 1b
2919 echo goto with colon and no leading space worked
2921 echo FAILURE at dest 2
2923 echo goto with a leading space worked
2925 echo FAILURE at dest 3
2927 echo goto with a leading tab worked
2929 echo FAILURE at dest 4
2931 echo goto with a following space worked
2933 echo FAILURE at dest 5
2934 :dest5&& echo FAILURE
2935 echo goto with following amphersands worked
2937 del failure.txt >nul 2>&1
2939 echo FAILURE at dest 6
2941 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
2942 echo goto with redirections worked
2943 del FAILURE.TXT >nul 2>&1
2945 :: some text that is ignored | dir >cmd_output | another test
2946 if exist cmd_output echo FAILURE at dest 6 as file exists
2947 echo Ignoring double colons worked
2948 del cmd_output >nul 2>&1
2950 rem goto a label which does not exist issues an error message and
2951 rem acts the same as goto :EOF, and ensure ::label is never matched
2952 del testgoto.bat >nul 2>&1
2953 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
2954 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2955 echo ::dest7>> testgoto.bat
2956 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
2958 del testgoto.bat >nul 2>&1
2960 del testgoto.bat >nul 2>&1
2961 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
2962 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2963 echo ::dest8>> testgoto.bat
2964 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
2966 del testgoto.bat >nul 2>&1
2969 echo FAILURE at dest 9
2971 echo FAILURE at dest 91
2973 echo label with mixed whitespace and no echo worked
2975 if h==h goto :dest10:this is ignored
2976 echo FAILURE at dest 10
2977 :dest10:this is also ignored
2978 echo Correctly ignored trailing information
2980 echo ------------ Testing PATH ------------
2981 set WINE_backup_path=%path%
2988 set path=%WINE_backup_path%
2989 set WINE_backup_path=
2991 echo ------------ Testing combined CALLs/GOTOs ------------
2992 echo @echo off>foo.cmd
2993 echo goto :eof>>foot.cmd
2995 echo echo world>>foo.cmd
2997 echo @echo off>foot.cmd
2998 echo echo cheball>>foot.cmd
3000 echo call :bar>>foot.cmd
3001 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
3002 echo goto :eof>>foot.cmd
3005 echo echo barbare>>foot.cmd
3006 echo goto :eof>>foot.cmd
3012 rem Script execution stops after the following line
3035 echo Final message is not output since earlier 'foot' processing stops script execution
3036 echo Do NOT add any tests below this line
3038 echo ------------ Done, jumping to EOF -----------
3040 rem Subroutine to set errorlevel and return
3041 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
3044 rem This line runs under cmd in windows NT 4, but not in more modern versions.