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
1700 echo ------------ Testing del ------------
1702 echo deleting 'file'
1705 echo errorlevel is 0, good
1707 echo unexpected errorlevel, got %errorlevel%
1710 echo successfully deleted 'file'
1712 echo error deleting 'file'
1714 echo attempting to delete 'file', even though it is not present
1717 echo errorlevel is 0, good
1719 echo unexpected errorlevel, got %errorlevel%
1722 echo ------------ Testing del /a ------------
1723 del /f/q *.test > nul
1726 echo not-r > not-r.test
1728 if not exist not-r.test echo not-r.test not found before delete, bad
1730 if not exist not-r.test echo not-r.test not found after delete, good
1732 if not exist r.test echo r.test not found before delete, bad
1733 if exist r.test echo r.test found before delete, good
1735 if not exist r.test echo r.test not found after delete, good
1736 if exist r.test echo r.test found after delete, bad
1738 echo ------------ Testing del /q ------------
1742 echo abc > file2.dat
1743 rem If /q doesn't work, cmd will prompt and the test case should hang
1745 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1746 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1750 echo ------------ Testing del /s ------------
1755 echo there > file2.dat
1756 echo bub > file3.dat
1757 echo bye > "file with spaces.dat"
1759 del /s file1.dat > nul
1760 del file2.dat /s > nul
1761 del "file3.dat" /s > nul
1762 del "file with spaces.dat" /s > nul
1764 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1765 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1766 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
1767 if exist "file with spaces.dat" del "file with spaces.dat"
1772 echo ------------ Testing rename ------------
1773 mkdir foobar & cd foobar
1774 echo --- ren and rename are synonymous
1777 if exist foo echo foo should be renamed!
1778 if exist bar echo foo renamed to bar
1780 if exist bar echo bar should be renamed!
1781 if exist foo echo bar renamed to foo
1782 echo --- name collision
1792 echo --- rename read-only files
1796 if not exist file1 (
1798 echo read-only file renamed
1801 echo read-only file not renamed!
1803 echo --- rename directories
1815 echo read-only dir renamed
1818 echo --- rename in other directory
1819 if not exist baz\abc (
1820 echo rename impossible in other directory
1821 if exist foo echo original file still present
1823 echo shouldn't rename in other directory!
1824 if not exist foo echo original file not present anymore
1826 cd .. & rd /s/q foobar
1828 echo ------------ Testing move ------------
1829 mkdir foobar & cd foobar
1832 move foo bar > nul 2>&1
1835 echo file move succeeded
1840 move /Y bar baz > nul 2>&1
1843 echo file move with overwrite succeeded
1846 echo file overwrite impossible!
1852 move baz bazro > nul 2>&1
1855 echo read-only files are moveable
1856 move bazro baz > nul 2>&1
1859 echo read-only file not moved!
1863 move baz rep > nul 2>&1
1866 echo file moved in subdirectory
1870 move rep\baz . > nul 2>&1
1871 move /Y baz baz > nul 2>&1
1873 echo moving a file to itself should be a no-op!
1875 echo moving a file to itself is a no-op
1877 echo ErrorLevel: %ErrorLevel%
1880 echo --- directory move
1884 move baz foo\bar > nul 2>&1
1886 if exist foo\bar\baz\baz2 (
1887 echo simple directory move succeeded
1892 move baz baz > nul 2>&1
1893 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1894 echo ------ dir in dir move
1899 move foo bar > nul 2>&1
1907 cd .. & rd /s/q foobar
1909 echo ------------ Testing mkdir ------------
1911 echo --- md and mkdir are synonymous
1918 echo --- creating an already existing directory/file must fail
1927 echo --- multilevel path creation
1939 mkdir ..\..\..\foo\bar2
1942 mkdir ..\..\..\foo\bar2
1944 rmdir ..\..\..\foo\bar2
1952 echo --- trailing backslashes
1955 if exist foo (rmdir foo & echo dir created
1956 ) else ( echo dir not created )
1958 echo --- invalid chars
1960 echo mkdir ? gives errorlevel %ErrorLevel%
1963 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1966 echo mkdir foo\? gives errorlevel %ErrorLevel%
1967 if exist foo (rmdir foo & echo ok, foo created
1968 ) else ( echo foo not created )
1971 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1974 echo bad, foo not created
1978 echo ok, foo\bar created
1984 echo --- multiple directories at once
1985 mkdir foobaz & cd foobaz
1986 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
1987 if exist foo (echo foo created) else echo foo not created!
1988 if exist bar (echo bar created) else echo bar not created!
1989 if exist foobar (echo foobar created) else echo foobar not created!
1990 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
1991 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
1992 if exist zabzab (echo zabzab created) else echo zabzab not created!
1993 cd .. & rd /s/q foobaz
1996 echo mkdir foo\* errorlevel %ErrorLevel%
1997 if exist foo (rmdir foo & echo ok, foo created
1998 ) else ( echo bad, foo not created )
2000 echo ------------ Testing rmdir ------------
2002 rem rd and rmdir are synonymous
2006 if not exist foobar echo dir removed
2010 if not exist foobar echo dir removed
2011 rem Removing nonexistent directory
2014 rem Removing single-level directories
2018 if exist foo echo file not removed
2024 if exist foo echo non-empty dir not removed
2029 if exist foo echo non-empty dir not removed
2036 echo recursive rmdir succeeded
2043 echo foo > foo\bar\brol
2044 rmdir /s /Q foo 2>&1
2046 echo recursive rmdir succeeded
2053 rem multiples directories at once
2054 mkdir foobaz & cd foobaz
2058 rd /s/q foo bar foobar
2059 if not exist foo (echo foo removed) else echo foo not removed!
2060 if not exist bar (echo bar removed) else echo bar not removed!
2061 if not exist foobar (echo foobar removed) else echo foobar not removed!
2062 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
2063 cd .. & rd /s/q foobaz
2065 echo ------------ Testing pushd/popd ------------
2067 echo --- popd is no-op when dir stack is empty
2070 echo --- pushing non-existing dir
2073 echo --- basic behaviour
2098 echo ------------ Testing attrib ------------
2099 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
2100 mkdir foobar & cd foobar
2101 echo foo original contents> foo
2104 echo --- read-only attribute
2105 rem Read-only files cannot be altered or deleted, unless forced
2113 echo Read-only file not deleted
2115 echo Should not delete read-only file!
2119 echo Read-only file forcibly deleted
2121 echo Should delete read-only file with del /F!
2125 cd .. & rd /s/q foobar
2126 echo --- recursive behaviour
2127 mkdir foobar\baz & cd foobar
2133 attrib +R l*vel? /S > nul 2>&1
2139 cd .. & rd /s/q foobar
2140 echo --- folders processing
2146 attrib +r baz /s /d > nul 2>&1
2152 rem Oddly windows allows file creation in a read-only directory...
2153 if exist baz\lala (echo file created in read-only dir) else echo file not created
2154 cd .. & rd /s/q foobar
2156 echo ------------ Testing assoc ------------
2157 rem Modifying associations requires some privileges...
2158 net session >nul 2>&1
2159 if errorlevel 1 goto :SkipAssoc
2161 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2162 rem FIXME Revise once || conditional execution is fixed
2163 mkdir foobar & cd foobar
2164 echo --- setting association
2172 rem association set system-wide
2173 echo @echo off> tmp.cmd
2174 echo echo +++>> tmp.cmd
2175 echo assoc .foo>> tmp.cmd
2178 echo --- resetting association
2184 rem association removal set system-wide
2185 cmd /c tmp.cmd > baz
2188 cd .. & rd /s/q foobar
2191 echo --- setting association
2197 echo --- resetting association
2204 echo ------------ Testing ftype ------------
2205 rem Modifying associations requires some privileges...
2206 net session >nul 2>&1
2207 if errorlevel 1 goto :SkipFType
2208 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2209 rem FIXME Revise once || conditional execution is fixed
2210 mkdir foobar & cd foobar
2211 echo --- setting association
2216 ftype footype=foo_opencmd
2220 rem association set system-wide
2221 echo @echo off> tmp.cmd
2222 echo echo +++>> tmp.cmd
2223 echo ftype footype>> tmp.cmd
2226 echo --- resetting association
2229 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2230 setlocal EnableDelayedExpansion
2231 set WINE_FOO=original value
2234 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
2235 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2236 rem FIXME Revisit once a grep-like program like ftype is implemented
2237 rem (e.g. to check baz's size using dir /b instead)
2240 rem cleanup registry
2241 echo REGEDIT4> regCleanup.reg
2242 echo.>> regCleanup.reg
2243 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
2244 regedit /s regCleanup.reg
2247 cd .. & rd /s/q foobar
2250 echo --- setting association
2252 echo footype=foo_opencmd
2254 echo footype=foo_opencmd
2256 echo footype=foo_opencmd
2257 echo --- resetting association
2261 echo ------------ Testing CALL ------------
2262 mkdir foobar & cd foobar
2263 echo --- external script
2264 echo echo foo %%1> foo.cmd
2267 echo echo %%1 %%2 > foo.cmd
2269 call foo.cmd foo bar
2276 echo --- internal routines
2277 call :testRoutine :testRoutine
2278 goto :endTestRoutine
2284 call :testRoutineArgs foo
2285 call :testRoutineArgs foo bar
2286 call :testRoutineArgs foo ""
2287 call :testRoutineArgs "" bar
2288 call :testRoutineArgs foo ''
2289 call :testRoutineArgs '' bar
2290 goto :endTestRoutineArgs
2296 echo --- with builtins
2299 if exist foo (echo foo created) else echo foo should exist!
2301 set WINE_FOOBAZ_VAR=foobaz
2302 call echo Should expand %WINE_FOOBAZ_VAR%
2303 set WINE_FOOBAZ_VAR=
2307 if 1==1 call del batfile
2309 if exist batfile echo batfile shouldn't exist
2310 rem ... but not for 'if' or 'for'
2311 call if 1==1 echo bar 2> nul
2314 call for %%i in (foo bar baz) do echo %%i 2> nul
2316 rem First look for programs in the path before trying a builtin
2317 echo echo non-builtin dir> dir.cmd
2320 rem The below line equates to call (, which does nothing, then the
2321 rem subsequent lines are executed.
2326 rem The below line equates to call if, which always fails, then the
2327 rem subsequent lines are executed. Note cmd.exe swallows all lines
2334 call call call echo passed
2335 cd .. & rd /s/q foobar
2337 echo ------------ Testing SHIFT ------------
2339 call :shiftFun p1 p2 p3 p4 p5
2343 echo '%1' '%2' '%3' '%4' '%5'
2345 echo '%1' '%2' '%3' '%4' '%5'
2347 echo '%1' '%2' '%3' '%4' '%5'
2349 echo '%1' '%2' '%3' '%4' '%5'
2351 echo '%1' '%2' '%3' '%4' '%5'
2353 echo '%1' '%2' '%3' '%4' '%5'
2357 echo ------------ Testing cmd invocation ------------
2358 rem FIXME: only a stub ATM
2359 echo --- a batch file can delete itself
2360 echo del foo.cmd>foo.cmd
2362 if not exist foo.cmd (
2363 echo file correctly deleted
2365 echo file should be deleted!
2368 echo --- a batch file can alter itself
2369 echo echo bar^>foo.cmd>foo.cmd
2370 cmd /q /c foo.cmd > NUL 2>&1
2375 echo file not created!
2378 echo ---------- Testing copy
2381 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2384 echo CCCCCCCCC> file3
2390 echo Passed: Found expected %1
2392 echo Failed: Did not find expected %1
2394 del /q "%1" >nul 2>&1
2396 if not "%1"=="" goto :CheckExist
2401 echo Passed: Did not find %1
2403 echo Failed: Unexpectedly found %1
2404 del /q "%1" >nul 2>&1
2407 if not "%1"=="" goto :CheckNotExist
2410 rem Note: No way to check file size on NT4 so skip the test
2413 echo Failed: File missing when requested filesize check [%2]
2414 goto :ContinueFileSizeChecks
2416 for %%i in (%1) do set WINE_filesize=%%~zi
2417 if "%WINE_filesize%"=="%2" (
2418 echo Passed: file size check on %1 [%WINE_filesize%]
2420 if "%WINE_filesize%"=="%%~zi" (
2421 echo Skipping file size check on NT4
2423 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2426 :ContinueFileSizeChecks
2429 if not "%1"=="" goto :CheckFileSize
2434 rem -----------------------
2435 rem Simple single file copy
2436 rem -----------------------
2437 rem Simple single file copy, normally used syntax
2438 copy file1 dummy.file >nul 2>&1
2439 if errorlevel 1 echo Incorrect errorlevel
2440 call :CheckExist dummy.file
2442 rem Simple single file copy, destination supplied as two forms of directory
2443 copy file1 dir1 >nul 2>&1
2444 if errorlevel 1 echo Incorrect errorlevel
2445 call :CheckExist dir1\file1
2447 copy file1 dir1\ >nul 2>&1
2448 if errorlevel 1 echo Incorrect errorlevel
2449 call :CheckExist dir1\file1
2451 rem Simple single file copy, destination supplied as fully qualified destination
2452 copy file1 dir1\file99 >nul 2>&1
2453 if errorlevel 1 echo Incorrect errorlevel
2454 call :CheckExist dir1\file99
2456 rem Simple single file copy, destination not supplied
2458 copy ..\file1 >nul 2>&1
2459 if errorlevel 1 echo Incorrect errorlevel
2460 call :CheckExist file1
2463 rem Simple single file copy, destination supplied as nonexistent directory
2464 copy file1 dir2\ >nul 2>&1
2465 if not errorlevel 1 echo Incorrect errorlevel
2466 call :CheckNotExist dir2 dir2\file1
2468 rem -----------------------
2470 rem -----------------------
2471 rem Simple single file copy, destination supplied as two forms of directory
2472 copy file? dir1 >nul 2>&1
2473 if errorlevel 1 echo Incorrect errorlevel
2474 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2476 copy file* dir1\ >nul 2>&1
2477 if errorlevel 1 echo Incorrect errorlevel
2478 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2480 rem Simple single file copy, destination not supplied
2482 copy ..\file*.* >nul 2>&1
2483 if errorlevel 1 echo Incorrect errorlevel
2484 call :CheckExist file1 file2 file3
2487 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2488 copy file? dir2\ >nul 2>&1
2489 if not errorlevel 1 echo Incorrect errorlevel
2490 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2492 rem ------------------------------------------------
2493 rem Confirm overwrite works (cannot test prompting!)
2494 rem ------------------------------------------------
2495 copy file1 testfile >nul 2>&1
2496 copy /y file2 testfile >nul 2>&1
2497 call :CheckExist testfile
2499 rem ------------------------------------------------
2500 rem Test concatenation
2501 rem ------------------------------------------------
2502 rem simple case, no wildcards
2503 copy file1+file2 testfile >nul 2>&1
2504 if errorlevel 1 echo Incorrect errorlevel
2505 call :CheckExist testfile
2507 rem simple case, wildcards, no concatenation
2508 copy file* testfile >nul 2>&1
2509 if errorlevel 1 echo Incorrect errorlevel
2510 call :CheckExist testfile
2512 rem simple case, wildcards, and concatenation
2514 copy file*+fred testfile >nul 2>&1
2515 if errorlevel 1 echo Incorrect errorlevel
2516 call :CheckExist testfile
2518 rem simple case, wildcards, and concatenation
2519 copy fred+file* testfile >nul 2>&1
2520 if errorlevel 1 echo Incorrect errorlevel
2521 call :CheckExist testfile
2523 rem Calculate destination name
2524 copy fred+file* dir1 >nul 2>&1
2525 if errorlevel 1 echo Incorrect errorlevel
2526 call :CheckExist dir1\fred
2528 rem Calculate destination name
2529 copy fred+file* dir1\ >nul 2>&1
2530 if errorlevel 1 echo Incorrect errorlevel
2531 call :CheckExist dir1\fred
2533 rem Calculate destination name (none supplied)
2535 copy ..\fred+..\file* >nul 2>&1
2536 if errorlevel 1 echo Incorrect errorlevel
2537 call :CheckExist fred
2539 copy ..\fr*+..\file1 >nul 2>&1
2540 if errorlevel 1 echo Incorrect errorlevel
2541 call :CheckExist fred
2544 rem ******************************************************************
2545 rem ASCII and BINARY tests
2546 rem Note: hard coded numbers deliberate because need to ensure whether
2547 rem an additional EOF has been added or not. There is no way to handle
2548 rem EOFs in batch, so assume if a single byte appears, it's an EOF!
2549 rem ******************************************************************
2551 rem Confirm original sizes of file1,2,3
2552 call :CheckFileSize file1 5 file2 8 file3 11
2556 rem ----------------------------------------------
2557 rem Show concatenation defaults copy to ascii mode
2558 rem ----------------------------------------------
2559 rem Simple default copy source to destination (should not append EOF 5)
2560 copy ..\file1 file1_default >nul 2>&1
2561 call :CheckFileSize file1_default 5
2563 rem Simple binary copy source to destination (should not append EOF 5)
2564 copy /b ..\file1 file1_default2 >nul 2>&1
2565 call :CheckFileSize file1_default2 5
2567 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2568 copy /a ..\file1 file1_plus_eof >nul 2>&1
2569 call :CheckFileSize file1_plus_eof 6
2570 copy /a ..\file2 file2_plus_eof >nul 2>&1
2571 call :CheckFileSize file2_plus_eof 9
2572 copy /a ..\file3 file3_plus_eof >nul 2>&1
2573 call :CheckFileSize file3_plus_eof 12
2575 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2576 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2577 call :CheckFileSize file12_plus_eof 14
2579 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2580 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2581 call :CheckFileSize file12_no_eof 13
2583 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2584 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2585 call :CheckFileSize file12_eof2 14
2587 rem Test copying when destination is one of the sources.
2588 rem Concat file1+file2+file3 into file1, should produce file1+file2+file3 = 24
2589 copy /y ..\file? .\ >nul 2>&1
2590 copy /y /b file1+file2+file3 file1 >nul 2>&1
2591 call :CheckFileSize file1 24
2593 rem Concat file1+file2+file3 into file2, should produce file1+file3 = 16
2594 copy /y ..\file? .\ >nul 2>&1
2595 copy /y /b file1+file2+file3 file2 >nul 2>&1
2596 call :CheckFileSize file2 16
2598 rem Concat file1+file2+file3 into file3, should produce file1+file2 = 13
2599 copy /y ..\file? .\ >nul 2>&1
2600 copy /y /b file1+file2+file3 file3 >nul 2>&1
2601 call :CheckFileSize file3 13
2603 rem --------------------------------------------------------------
2604 rem Show ascii source copy stops at first EOF, binary does the lot
2605 rem --------------------------------------------------------------
2606 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2607 call :CheckFileSize file1_binary_srccopy 6
2609 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2610 call :CheckFileSize file1_ascii_srccopy 5
2612 rem --------------------------------------------------------------
2613 rem Show results of concatenating files (ending in EOFs) and /a /b
2614 rem --------------------------------------------------------------
2616 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2617 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2618 call :CheckFileSize file123_default_copy 25
2619 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2620 call :CheckFileSize file123_ascii_copy 25
2622 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2623 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2624 call :CheckFileSize file123_binary_copy 27
2626 rem We can select which we want the eofs from by postfixing it with /a or /b
2627 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2628 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2629 call :CheckFileSize file123_mixed_copy1 26
2631 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2632 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2633 rem Note the delta between this and the previous one also shows that the destination
2634 rem ascii/binary is inherited from the last /a or /b on the line
2635 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2636 call :CheckFileSize file123_mixed_copy2 27
2638 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2639 rem Note the delta between the next two also shows that the destination ascii/binary is
2640 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2641 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2642 call :CheckFileSize file123_mixed_copy3 26
2643 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2644 call :CheckFileSize file123_mixed_copy4 25
2646 rem -------------------------------------------------------------------------------------------
2647 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2648 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2649 rem -------------------------------------------------------------------------------------------
2651 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2652 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2653 call :CheckFileSize file123_mixed_copy5 28
2655 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2656 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2657 call :CheckFileSize file123_mixed_copy6 19
2659 rem One file has EOF, but doesn't get an extra one, i.e. 6
2660 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2661 call :CheckFileSize file123_mixed_copy7 6
2663 rem Syntax means concatenate so ascii destination kicks in
2664 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2665 call :CheckFileSize file123_mixed_copy8 7
2670 rem ---------------------------------------
2671 rem Error combinations
2672 rem ---------------------------------------
2673 rem Specify source directory but name is a file
2675 copy file1\ dir1\ >NUL 2>&1
2676 if errorlevel 1 echo Passed: errorlevel invalid check 1
2677 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2678 call :CheckNotExist dir1\file1
2680 rem Overwrite same file
2682 copy file1 file1 >NUL 2>&1
2683 if errorlevel 1 echo Passed: errorlevel invalid check 2
2684 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2686 rem Supply same file identified as a directory
2688 copy file1 file1\ >NUL 2>&1
2689 if errorlevel 1 echo Passed: errorlevel invalid check 3
2690 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2695 echo ------------ Testing setlocal/endlocal ------------
2697 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2698 mkdir foobar & cd foobar
2699 echo --- enable/disable extensions
2700 setlocal DisableEXTensions
2701 echo ErrLev: %ErrorLevel%
2703 echo ErrLev: %ErrorLevel%
2704 echo @echo off> tmp.cmd
2705 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2706 rem Enabled by default
2708 cmd /E:OfF /C tmp.cmd
2709 cmd /e:oN /C tmp.cmd
2711 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2712 echo --- setlocal with corresponding endlocal
2713 rem %CD% does not work on NT4 so use the following workaround
2714 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2715 echo @echo off> test.cmd
2716 echo echo %%WINE_VAR%%>> test.cmd
2717 echo setlocal>> test.cmd
2718 echo set WINE_VAR=localval>> test.cmd
2719 echo md foobar2>> test.cmd
2720 echo cd foobar2>> test.cmd
2721 echo echo %%WINE_VAR%%>> test.cmd
2722 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2723 echo endlocal>> test.cmd
2724 echo echo %%WINE_VAR%%>> test.cmd
2725 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2726 set WINE_VAR=globalval
2729 for /d %%i in (.) do echo %%~dpnxi
2733 echo --- setlocal with no corresponding endlocal
2734 echo @echo off> test.cmd
2735 echo echo %%WINE_VAR%%>> test.cmd
2736 echo setlocal>> test.cmd
2737 echo set WINE_VAR=localval>> test.cmd
2738 echo md foobar2>> test.cmd
2739 echo cd foobar2>> test.cmd
2740 echo echo %%WINE_VAR%%>> test.cmd
2741 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2742 set WINE_VAR=globalval
2743 rem %CD% does not work on NT4 so use the following workaround
2744 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2747 for /d %%i in (.) do echo %%~dpnxi
2751 echo --- setlocal within same batch program
2755 rem %CD% does not work on NT4 so use the following workaround
2756 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2763 if "%WINE_var1%"=="one" echo Var1 ok 1
2764 if "%WINE_var2%"=="two" echo Var2 ok 2
2765 if "%WINE_var3%"=="three" echo Var3 ok 3
2766 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2767 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
2769 if "%WINE_var1%"=="one" echo Var1 ok 1
2770 if "%WINE_var2%"=="two" echo Var2 ok 2
2771 if "%WINE_var3%"=="" echo Var3 ok 3
2772 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2773 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
2775 if "%WINE_var1%"=="one" echo Var1 ok 1
2776 if "%WINE_var2%"=="" echo Var2 ok 2
2777 if "%WINE_var3%"=="" echo Var3 ok 3
2778 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2779 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
2783 echo --- Mismatched set and end locals
2787 rem %CD% does not work on NT4 so use the following workaround
2788 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
2790 echo @echo off> 2set1end.cmd
2791 echo echo %%WINE_var%%>> 2set1end.cmd
2792 echo setlocal>> 2set1end.cmd
2793 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
2794 echo cd ..\foodir3>> 2set1end.cmd
2795 echo setlocal>> 2set1end.cmd
2796 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
2797 echo cd ..\foodir4>> 2set1end.cmd
2798 echo endlocal>> 2set1end.cmd
2799 echo echo %%WINE_var%%>> 2set1end.cmd
2800 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
2802 echo @echo off> 1set2end.cmd
2803 echo echo %%WINE_var%%>> 1set2end.cmd
2804 echo setlocal>> 1set2end.cmd
2805 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
2806 echo cd ..\foodir3>> 1set2end.cmd
2807 echo endlocal>> 1set2end.cmd
2808 echo echo %%WINE_var%%>> 1set2end.cmd
2809 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2810 echo endlocal>> 1set2end.cmd
2811 echo echo %%WINE_var%%>> 1set2end.cmd
2812 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2814 echo --- Extra setlocal in called batch
2816 rem -- setlocal1 == this batch, should never be used inside a called routine
2820 call "%WINE_CURDIR%\2set1end.cmd"
2823 for /d %%i in (.) do echo %%~dpnxi
2826 for /d %%i in (.) do echo %%~dpnxi
2829 echo --- Extra endlocal in called batch
2831 rem -- setlocal1 == this batch, should never be used inside a called routine
2835 call "%WINE_CURDIR%\1set2end.cmd"
2838 for /d %%i in (.) do echo %%~dpnxi
2841 for /d %%i in (.) do echo %%~dpnxi
2844 echo --- endlocal in called function rather than batch pgm is ineffective
2850 call :endlocalroutine
2854 goto :endlocalfinished
2872 cd .. & rd /q/s foobar
2874 echo ------------ Testing Errorlevel ------------
2875 rem WARNING: Do *not* add tests using ErrorLevel after this section
2876 should_not_exist 2> nul > nul
2878 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2879 rem See http://www.robvanderwoude.com/exit.php
2882 if errorlevel 2 echo errorlevel too high, bad
2883 if errorlevel 1 echo errorlevel just right, good
2884 if errorlevel 01 echo errorlevel with leading zero just right, good
2885 if errorlevel -1 echo errorlevel with negative number OK
2886 if errorlevel 0x1 echo hexa should not be recognized!
2887 if errorlevel 1a echo invalid error level recognized!
2889 echo abc%ErrorLevel%def
2890 if errorlevel 1 echo errorlevel nonzero, bad
2891 if not errorlevel 1 echo errorlevel zero, good
2892 if not errorlevel 0x1 echo hexa should not be recognized!
2893 if not errorlevel 1a echo invalid error level recognized!
2894 rem Now verify that setting a real variable hides its magic variable
2896 echo %ErrorLevel% should be 7
2897 if errorlevel 7 echo setting var worked too well, bad
2899 echo %ErrorLevel% should still be 7
2901 echo ------------ Testing GOTO ------------
2903 echo FAILURE at dest 1
2905 echo goto with no leading space worked
2906 if a==a goto :dest1b
2907 echo FAILURE at dest 1b
2909 echo goto with colon and no leading space worked
2911 echo FAILURE at dest 2
2913 echo goto with a leading space worked
2915 echo FAILURE at dest 3
2917 echo goto with a leading tab worked
2919 echo FAILURE at dest 4
2921 echo goto with a following space worked
2923 echo FAILURE at dest 5
2924 :dest5&& echo FAILURE
2925 echo goto with following amphersands worked
2927 del failure.txt >nul 2>&1
2929 echo FAILURE at dest 6
2931 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
2932 echo goto with redirections worked
2933 del FAILURE.TXT >nul 2>&1
2935 :: some text that is ignored | dir >cmd_output | another test
2936 if exist cmd_output echo FAILURE at dest 6 as file exists
2937 echo Ignoring double colons worked
2938 del cmd_output >nul 2>&1
2940 rem goto a label which does not exist issues an error message and
2941 rem acts the same as goto :EOF, and ensure ::label is never matched
2942 del testgoto.bat >nul 2>&1
2943 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
2944 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2945 echo ::dest7>> testgoto.bat
2946 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
2948 del testgoto.bat >nul 2>&1
2950 del testgoto.bat >nul 2>&1
2951 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
2952 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2953 echo ::dest8>> testgoto.bat
2954 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
2956 del testgoto.bat >nul 2>&1
2959 echo FAILURE at dest 9
2961 echo FAILURE at dest 91
2963 echo label with mixed whitespace and no echo worked
2965 if h==h goto :dest10:this is ignored
2966 echo FAILURE at dest 10
2967 :dest10:this is also ignored
2968 echo Correctly ignored trailing information
2970 echo ------------ Testing PATH ------------
2971 set WINE_backup_path=%path%
2978 set path=%WINE_backup_path%
2979 set WINE_backup_path=
2981 echo ------------ Testing combined CALLs/GOTOs ------------
2982 echo @echo off>foo.cmd
2983 echo goto :eof>>foot.cmd
2985 echo echo world>>foo.cmd
2987 echo @echo off>foot.cmd
2988 echo echo cheball>>foot.cmd
2990 echo call :bar>>foot.cmd
2991 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
2992 echo goto :eof>>foot.cmd
2995 echo echo barbare>>foot.cmd
2996 echo goto :eof>>foot.cmd
3002 rem Script execution stops after the following line
3025 echo Final message is not output since earlier 'foot' processing stops script execution
3026 echo Do NOT add any tests below this line
3028 echo ------------ Done, jumping to EOF -----------
3030 rem Subroutine to set errorlevel and return
3031 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
3034 rem This line runs under cmd in windows NT 4, but not in more modern versions.