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@
40 echo ------------ Testing 'echo' [OFF] ------------
42 echo 'singlequotedword'
43 echo "doublequotedword"
60 echo word@space@@space@
64 echo@tab@word@tab@@space@
70 echo ------------ Testing mixed echo modes ------------
71 echo @echo on> mixedEchoModes.cmd
72 echo if 1==1 echo foo>> mixedEchoModes.cmd
73 echo if 1==1 @echo bar>> mixedEchoModes.cmd
74 echo @echo off>> mixedEchoModes.cmd
75 echo if 1==1 echo foo2>> mixedEchoModes.cmd
76 echo if 1==1 @echo bar2>> mixedEchoModes.cmd
77 type mixedEchoModes.cmd
78 cmd /c mixedEchoModes.cmd
79 del mixedEchoModes.cmd
81 echo ------------ Testing parameterization ------------
83 call :TestParm "a b c"
84 call :TestParm "a b"\c
85 call :TestParm a=~`+,.{}!+b
89 call :TestParm a[b]{c}(d)e
90 call :TestParm a&echo second line
91 call :TestParm a b,,,c
92 call :TestParm a==b;;c
101 echo ------------ Testing rem ------------
106 rem echo foo & echo bar
109 rem@tab@echo foo & echo bar
115 rem echo foo & echo bar
118 rem@tab@echo foo & echo bar
121 echo ------------ Testing redirection operators ------------
122 mkdir foobar & cd foobar
123 echo --- stdout redirection
132 echo foo@tab@1>@tab@foo
153 echo --- stdout appending
171 echo foo7 7>> foo || (echo not supported & del foo)
172 if exist foo (type foo) else echo not supported
173 echo --- redirections within IF statements
174 if 1==1 echo foo1>bar
177 if 1==1 (echo foo2>bar) else echo baz2>bar
179 if 1==1 (echo foo3) else echo baz3>bar
180 type bar || echo file does not exist, ok
181 if 1==1 (echo foo4>bar) else echo baz4>bar
183 if 1==0 (echo foo5>bar) else echo baz5>bar
185 if 1==0 (echo foo6) else echo baz6 1>bar
187 if 1==0 (echo foo7 1>bar) else echo baz7>bar
189 if 1==0 (echo foo8 1>bar) else echo baz8>bak
191 if 1==1 (echo foo>bar & echo baz)
198 (if 1==1 (echo A) else echo B) > C
200 (if 1==0 (echo A) else echo B) > C
202 (if 1==0 (echo A > B) else echo C)
203 cd .. & rd /s/q foobar
205 echo ------------ Testing circumflex escape character ------------
206 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
228 echo bak ^&& echo baz 2> nul
236 set WINE_FOO=bar ^| baz
238 rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
239 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
242 set WINE_FOO=bar ^^^| baz
248 echo ------------ Testing 'set' ------------
250 rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
251 for /f "delims==" %%i in ('set WINE_ba') do set %%i=
252 for /f "delims==" %%i in ('set WINE_foo') do set %%i=
253 set WINE_FOOBAR 2> nul > nul
255 set WINE_FOOBAR = baz
257 echo %WINE_FOOBAR%WINE_FOOBAR not defined
259 set WINE_FOOBAR 2> nul
260 set WINE_FOOBAR = baz2
269 echo %WINE_FOOBAR%WINE_FOOBAR not defined
271 set WINE_FOOBA 2> nul > nul
277 echo %WINE_FOO%%WINE_BAR%
280 set WINE_FOO=%WINE_FOO%
281 echo %WINE_FOO%WINE_FOO not defined
286 echo set "WINE_FOO=bar" should not include the quotes in the variable value
293 set WINE_FOO=foo@space@
295 set WINE_FOO=foo@tab@
297 rem Space symbol must appear in `var`
298 set WINE_FOO=value@space@
300 rem Space symbol must NOT appear in `var`
301 set "WINE_FOO=value"@space@
304 set WINE_FOO=jim fred
306 set WINE_FOO="jim" fred
308 set "WINE_FOO=jim fred"
310 set "WINE_FOO=jim" fred
312 rem Only the final quote ends the string
313 set "WINE_FOO=apple"banana"grape"orange
317 echo ------------ Testing variable expansion ------------
319 echo ~p0 should be path containing batch file
326 echo ~dp0 should be directory containing batch file
339 echo P%WINE_UNKNOWN%S
342 echo %ERRORLEVEL%%ERRORLEVEL%
343 echo %ERRORLEVEL%ERRORLEVEL%
350 echo ------------ Testing variable substrings ------------
355 echo '%WINE_VAR:~-2,3%'
356 echo '%WINE_VAR:~-2,1%'
357 echo %WINE_VAR:~2,-1%
358 echo %WINE_VAR:~2,-3%
359 echo '%WINE_VAR:~-2,-4%'
360 echo %WINE_VAR:~-3,-2%
363 echo ------------ Testing variable substitution ------------
364 echo --- in FOR variables
365 for %%i in ("A B" C) do echo %%i
366 rem check works when prefix with @
367 @for %%i in ("A B" C) do echo %%i
369 for %%i in ("A B" C) do echo '%%~i'
370 rem fully qualified path
371 for %%f in ("C D" E) do echo %%~ff
373 for %%i in ("F G" H) do echo %%~di
375 for %%d in ("I J" K) do echo %%~pd
377 for %%i in ("L M" N) do echo %%~ni
379 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
380 rem path with short path names
381 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
383 for %%i in ("U V" W) do echo '%%~ai'
385 for %%i in (foo) do echo '%%~ai'
386 for %%i in (foo) do echo '%%~zi'
389 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
390 for %%i in ("a b" c) do echo '%%~ti'
392 rem Similar issues as above
393 for %%i in ("a b" c) do echo '%%~zi'
395 for %%i in ("d e" f) do echo %%~dpi
396 for %%i in ("g h" i) do echo %%~sdi
397 for %%i in ("g h" i) do echo %%~dsi
398 for %%i in ("j k" l.eh) do echo '%%~xsi'
399 for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
401 echo --- in parameters
402 for %%i in ("A B" C) do call :echoFun %%i
404 for %%i in ("A B" C) do call :echoFunQ %%i
405 rem fully qualified path
406 for %%f in ("C D" E) do call :echoFunF %%f
408 for %%i in ("F G" H) do call :echoFunD %%i
410 for %%d in ("I J" K) do call :echoFunP %%d
412 for %%i in ("L M" N) do call :echoFunN %%i
414 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
415 rem path with short path names
416 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
417 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
419 for %%i in ("d e" f) do call :echoFunDP %%i
420 for %%i in ("g h" i) do call :echoFunSD %%i
421 for %%i in ("g h" i) do call :echoFunDS %%i
422 for %%i in ("j k" l.eh) do call :echoFunXS %%i
454 rem some NT4 workaround
477 echo ------------ Testing variable delayed expansion ------------
478 rem NT4 doesn't support this
479 echo --- default mode (load-time expansion)
483 if %WINE_FOO% == foo (
485 if %WINE_FOO% == bar (echo bar) else echo foo
489 if %WINE_FOO% == foo (
491 if !WINE_FOO! == bar (echo bar) else echo foo
494 echo --- runtime (delayed) expansion mode
495 setlocal EnableDelayedExpansion
499 if %WINE_FOO% == foo (
501 if %WINE_FOO% == bar (echo bar) else echo foo
505 if %WINE_FOO% == foo (
507 if !WINE_FOO! == bar (echo bar) else echo foo
510 setlocal DisableDelayedExpansion
516 echo --- using /V cmd flag
517 echo @echo off> tmp.cmd
518 echo set WINE_FOO=foo>> tmp.cmd
519 echo echo %%WINE_FOO%%>> tmp.cmd
520 echo echo !WINE_FOO!>> tmp.cmd
521 echo set WINE_FOO=>> tmp.cmd
523 cmd /V:OfF /C tmp.cmd
526 echo ------------ Testing conditional execution ------------
527 echo --- unconditional ampersand
528 call :setError 123 & echo foo1
529 echo bar2 & echo foo2
530 mkdir foobar & cd foobar
532 cd .. & rd /s/q foobar
534 echo foobar not deleted!
537 ) else echo foobar deleted
538 echo --- on success conditional and
539 call :setError 456 && echo foo3 > foo3
543 ) else echo foo3 not created
544 echo bar4 && echo foo4
545 echo --- on failure conditional or
546 call :setError 789 || echo foo5
547 echo foo6 || echo bar6 > bar6
553 echo ------------ Testing cd ------------
556 echo blabla > singleFile
558 echo Current dir: %CD%
573 if not exist foobar (cd ..)
575 cd@tab@..@tab@@space@@tab@
577 if not exist foobar (cd ..)
591 cd "bar bak@space@"@tab@@space@
602 echo ------------ Testing type ------------
616 echo ------------ Testing NUL ------------
617 md foobar & cd foobar
618 rem NUL file (non) creation + case insensitivity
619 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
628 rem NUL not special everywhere
631 if not exist foo (echo foo should have been created) else (
635 rem Empty file creation
645 copy a.a+NUL b.b >nul
646 call :CheckFileSize a.a 7 b.b 8
647 copy NUL+a.a b.b >nul
648 call :CheckFileSize a.a 7 b.b 8
650 copy a.a+NUL subdir\ >nul
651 call :CheckFileSize a.a 7 subdir\a.a 8
655 if exist a.a echo Failed
659 cd .. & rd foobar /s /q
661 echo ------------ Testing if/else ------------
662 echo --- if/else should work with blocks
664 echo if seems to work
666 echo if seems to be broken
669 echo else seems to be broken
671 echo else seems to work
674 echo if seems not to detect /c as parameter
676 echo parameter detection seems to be broken
680 SET /a elseIF=%elseIF%+1
682 SET /a elseIF=%elseIF%+2
684 SET /a elseIF=%elseIF%+2
687 echo else if seems to work
689 echo else if seems to be broken
693 SET /a elseIF=%elseIF%+2
695 SET /a elseIF=%elseIF%+1
697 SET /a elseIF=%elseIF%+2
700 echo else if seems to work
702 echo else if seems to be broken
706 SET /a elseIF=%elseIF%+2
708 SET /a elseIF=%elseIF%+2
710 SET /a elseIF=%elseIF%+1
713 echo else if seems to work
715 echo else if seems to be broken
717 echo --- case sensitivity with and without /i option
718 if bar==BAR echo if does not default to case sensitivity
719 if not bar==BAR echo if seems to default to case sensitivity
720 if /i foo==FOO echo if /i seems to work
721 if /i not foo==FOO echo if /i seems to be broken
722 if /I foo==FOO echo if /I seems to work
723 if /I not foo==FOO echo if /I seems to be broken
725 echo --- string comparisons
726 if abc == abc (echo equal) else echo non equal
727 if abc =="abc" (echo equal) else echo non equal
728 if "abc"== abc (echo equal) else echo non equal
729 if "abc"== "abc" (echo equal) else echo non equal
731 echo --- tabs handling
732 if@tab@1==1 echo doom
733 if @tab@1==1 echo doom
734 if 1==1 (echo doom) else@tab@echo quake
735 if@tab@not @tab@1==@tab@0 @tab@echo lol
736 if 1==0@tab@(echo doom) else echo quake
737 if 1==0 (echo doom)@tab@else echo quake
738 if 1==0 (echo doom) else@tab@echo quake
740 echo --- comparison operators
741 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
742 echo ------ for strings
743 rem NT4 stops processing of the whole batch file as soon as it finds a
744 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
745 rem can't test those here.
746 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
747 if LSS LSS LSS (echo bar)
748 if 1.1 LSS 1.10 (echo floats are handled as strings)
749 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
750 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
751 if /i foo LSS FoOc echo if /i seems to work for LSS
752 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
753 set WINE_STR_PARMS=A B AB BA AA
754 for %%i in (%WINE_STR_PARMS%) do (
755 for %%j in (%WINE_STR_PARMS%) do (
756 call :LSStest %%i %%j))
757 if b LSS B (echo b LSS B) else echo NT4
758 if /I b LSS B echo b LSS B insensitive
759 if b LSS A echo b LSS A
760 if /I b LSS A echo b LSS A insensitive
761 if a LSS B (echo a LSS B) else echo NT4
762 if /I a LSS B echo a LSS B insensitive
763 if A LSS b echo A LSS b
764 if /I A LSS b echo A LSS b insensitive
765 for %%i in (%WINE_STR_PARMS%) do (
766 for %%j in (%WINE_STR_PARMS%) do (
767 call :LEQtest %%i %%j))
768 if b LEQ B (echo b LEQ B) else echo NT4
769 if /I b LEQ B echo b LEQ B insensitive
770 if b LEQ A echo b LEQ A
771 if /I b LEQ A echo b LEQ A insensitive
772 if a LEQ B (echo a LEQ B) else echo NT4
773 if /I a LEQ B echo a LEQ B insensitive
774 if A LEQ b echo A LEQ b
775 if /I A LEQ b echo A LEQ b insensitive
776 for %%i in (%WINE_STR_PARMS%) do (
777 for %%j in (%WINE_STR_PARMS%) do (
778 call :EQUtest %%i %%j))
779 if /I A EQU a echo A EQU a insensitive
780 for %%i in (%WINE_STR_PARMS%) do (
781 for %%j in (%WINE_STR_PARMS%) do (
782 call :NEQtest %%i %%j))
783 for %%i in (%WINE_STR_PARMS%) do (
784 for %%j in (%WINE_STR_PARMS%) do (
785 call :GEQtest %%i %%j))
786 for %%i in (%WINE_STR_PARMS%) do (
787 for %%j in (%WINE_STR_PARMS%) do (
788 call :GTRtest %%i %%j))
789 echo ------ for numbers
790 if -1 LSS 1 (echo negative numbers handled)
791 if not -1 LSS -10 (echo negative numbers handled)
792 if not 9 LSS 010 (echo octal handled)
793 if not -010 LSS -8 (echo also in negative form)
794 if 4 LSS 0x5 (echo hexa handled)
795 if not -1 LSS -0x1A (echo also in negative form)
796 if 11 LSS 101 (echo 11 LSS 101)
797 set WINE_INT_PARMS=0 1 10 9
798 for %%i in (%WINE_INT_PARMS%) do (
799 for %%j in (%WINE_INT_PARMS%) do (
800 call :LSStest %%i %%j))
801 for %%i in (%WINE_INT_PARMS%) do (
802 for %%j in (%WINE_INT_PARMS%) do (
803 call :LEQtest %%i %%j))
804 for %%i in (%WINE_INT_PARMS%) do (
805 for %%j in (%WINE_INT_PARMS%) do (
806 call :EQUtest %%i %%j))
807 if 011 EQU 9 (echo octal ok)
808 if 0xA1 EQU 161 (echo hexa ok)
809 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
810 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
811 for %%i in (%WINE_INT_PARMS%) do (
812 for %%j in (%WINE_INT_PARMS%) do (
813 call :NEQtest %%i %%j))
814 for %%i in (%WINE_INT_PARMS%) do (
815 for %%j in (%WINE_INT_PARMS%) do (
816 call :GEQtest %%i %%j))
817 for %%i in (%WINE_INT_PARMS%) do (
818 for %%j in (%WINE_INT_PARMS%) do (
819 call :GTRtest %%i %%j))
820 echo ------ for numbers and stringified numbers
821 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
822 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
823 if '1' EQU 1 echo '1' EQU 1
824 if 1 EQU '1' echo 1 EQU '1'
825 if not "1" GEQ 1 (echo foo) else echo bar
826 if "10" GEQ "1" echo "10" GEQ "1"
827 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
828 if 1 GEQ "1" echo 1 GEQ "1"
829 if "1" GEQ "1" echo "1" GEQ "1"
830 if '1' GEQ "1" echo '1' GEQ "1"
831 if "10" GEQ "1" echo "10" GEQ "1"
832 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
833 for %%i in ("1" '1') do call :GEQtest %%i '1'
834 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
835 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
836 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
837 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
838 if "10" GEQ "10" (echo "10" GEQ "10")
839 echo --- unconditional ampersand after if one line
840 if "0"=="0" echo 1 & echo 2 & echo 3 else echo 4
842 echo x & if "0"=="1" echo 1 & echo 2
844 echo x & if "0"=="1" echo 1 & echo 2 & echo 3
846 echo x & if "0"=="1" (echo 1 & echo 2 & echo 3)
848 echo x & if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
850 goto :endIfCompOpsSubroutines
852 rem IF subroutines helpers
854 if %1 LSS %2 echo %1 LSS %2
857 if %1 LEQ %2 echo %1 LEQ %2
860 if %1 EQU %2 echo %1 EQU %2
863 if %1 NEQ %2 echo %1 NEQ %2
866 if %1 GEQ %2 echo %1 GEQ %2
869 if %1 GTR %2 echo %1 GTR %2
872 :endIfCompOpsSubroutines
876 echo ------------ Testing for ------------
878 for %%i in (A B C) do echo %%i
879 for %%i in (A B C) do echo %%I
880 for %%i in (A B C) do echo %%j
881 for %%i in (A B C) do call :forTestFun1 %%i
882 for %%i in (1,4,1) do echo %%i
883 for %%i in (A, B,C) do echo %%i
884 for %%i in (X) do echo %%i
885 for@tab@%%i in (X2) do echo %%i
886 for %%i in@tab@(X3) do echo %%i
887 for %%i in (@tab@ foo@tab@) do echo %%i
888 for@tab@ %%i in@tab@(@tab@M) do echo %%i
889 for %%i@tab@in (X)@tab@do@tab@echo %%i
890 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
891 for %%i in (`echo A B`) do echo %%i
892 for %%i in ('echo A B') do echo %%i
893 for %%i in ("echo A B") do echo %%i
894 for %%i in ("A B" C) do echo %%i
900 echo --- imbricated FORs
907 for %%i in (A B) do (
908 for %%j in (C D) do (
910 for %%i in (A B) do (
911 for %%j in (C D) do (
912 call :forTestFun2 %%i %%j ))
918 mkdir foobar & cd foobar
923 echo --- basic wildcards
924 for %%i in (ba*) do echo %%i
926 for /d %%i in (baz foo bar) do echo %%i 2>&1
927 rem Confirm we don't match files:
928 for /d %%i in (bazb*) do echo %%i 2>&1
929 for /d %%i in (bazb2*) do echo %%i 2>&1
930 rem Show we pass through non wildcards
931 for /d %%i in (PASSED) do echo %%i
932 for /d %%i in (xxx) do (
933 echo %%i - Should be xxx
934 echo Expected second line
936 rem Show we issue no messages on failures
937 for /d %%i in (FAILED?) do echo %%i 2>&1
938 for /d %%i in (FAILED?) do (
939 echo %%i - Unexpected!
940 echo FAILED Unexpected second line
942 for /d %%i in (FAILED*) do echo %%i 2>&1
943 for /d %%i in (FAILED*) do (
944 echo %%i - Unexpected!
945 echo FAILED Unexpected second line
947 rem FIXME can't test wildcard expansion here since it's listed in directory
948 rem order, and not in alphabetic order.
949 rem Proper testing would need a currently missing "sort" program implementation.
950 rem for /d %%i in (ba*) do echo %%i>> tmp
953 rem for /d %%i in (?a*) do echo %%i>> tmp
956 rem for /d %%i in (*) do echo %%i>> tmp
964 call :WriteLine set WINE_found=N
965 for /l %%i in (1,1,%WINE_expectedresults%) do (
966 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%~1" set WINE_found=Y
967 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
968 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
970 call :WriteLine echo Got unexpected result: "%%%%~1"
979 for /l %%i in (1,1,%WINE_expectedresults%) do (
980 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
987 rem %CD% does not work on NT4 so use the following workaround
988 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
991 echo Plain directory enumeration
992 set WINE_expectedresults=4
993 set WINE_expectedresults.1=%WINE_CURDIR%\.
994 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
995 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
996 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
998 for /R %%i in (.) do call temp.bat "%%i"
999 call :ValidateExpected
1001 echo Plain directory enumeration from provided root
1002 set WINE_expectedresults=4
1003 set WINE_expectedresults.1=%WINE_CURDIR%\.
1004 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1005 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1006 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1007 if "%CD%"=="" goto :SkipBrokenNT4
1009 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat "%%i"
1010 call :ValidateExpected
1013 echo File enumeration
1014 set WINE_expectedresults=2
1015 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1016 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1018 for /R %%i in (baz*) do call temp.bat "%%i"
1019 call :ValidateExpected
1021 echo File enumeration from provided root
1022 set WINE_expectedresults=2
1023 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1024 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1026 for /R %%i in (baz*) do call temp.bat "%%i"
1027 call :ValidateExpected
1029 echo Mixed enumeration
1030 set WINE_expectedresults=6
1031 set WINE_expectedresults.1=%WINE_CURDIR%\.
1032 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1033 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1034 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1035 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1036 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1038 for /R %%i in (. baz*) do call temp.bat "%%i"
1039 call :ValidateExpected
1041 echo Mixed enumeration from provided root
1042 set WINE_expectedresults=6
1043 set WINE_expectedresults.1=%WINE_CURDIR%\.
1044 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1045 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1046 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1047 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1048 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1050 for /R %%i in (. baz*) do call temp.bat "%%i"
1051 call :ValidateExpected
1053 echo With duplicates enumeration
1054 set WINE_expectedresults=12
1055 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
1056 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
1057 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
1058 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1059 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
1060 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
1061 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
1062 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
1063 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1064 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1065 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1066 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1068 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat "%%i"
1069 call :ValidateExpected
1071 echo Strip missing wildcards, keep unwildcarded names
1072 set WINE_expectedresults=6
1073 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1074 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1075 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1076 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1077 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1078 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1080 for /R %%i in (baz* fred* jim) do call temp.bat "%%i"
1081 call :ValidateExpected
1084 echo --- Complex wildcards unix and windows slash
1086 echo Windows slashes, valid path
1087 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1088 for %%f in (foobar\baz\*) do echo WC : %%f
1089 echo Windows slashes, invalid path
1090 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1091 for %%f in (foobar\jim\*) do echo WC : %%f
1092 echo Unix slashes, valid path
1093 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1094 for %%f in (foobar/baz/*) do echo WC : %%f
1095 echo Unix slashes, invalid path
1096 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1097 for %%f in (foobar/jim/*) do echo WC : %%f
1101 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
1102 for /L %%i in (1,2,0) do echo %%i
1103 for@tab@/L %%i in (1,2,0) do echo %%i
1104 for /L %%i in (1,2,6) do echo %%i
1105 for /l %%i in (1 ,2,6) do echo %%i
1106 for /L %%i in (a,2,3) do echo %%i
1107 for /L %%i in (1,2,-1) do echo %%i
1108 for /L %%i in (-4,-1,-1) do echo %%i
1109 for /L %%i in (1,-2,-2) do echo %%i
1110 for /L %%i in (1,2,a) do echo %%i
1111 echo ErrorLevel %ErrorLevel%
1112 for /L %%i in (1,a,b) do echo %%i
1113 echo ErrorLevel %ErrorLevel%
1115 for /l %%i in (1,1,4) do echo %%i
1116 for /l %%i in (1,2,4) do echo %%i
1117 for /l %%i in (4,-1,1) do echo %%i
1118 for /l %%i in (4,-2,1) do echo %%i
1119 for /l %%i in (1,-1,4) do echo %%i
1120 for /l %%i in (4,1,1) do echo %%i
1121 for /L %%i in (a,2,b) do echo %%i
1122 for /L %%i in (1,1,1) do echo %%i
1123 for /L %%i in (1,-2,-1) do echo %%i
1124 for /L %%i in (-1,-1,-1) do echo %%i
1125 for /L %%i in (1,2, 3) do echo %%i
1126 rem Test zero iteration skips the body of the for
1127 for /L %%i in (2,2,1) do (
1134 Rem Ideally for /f can be used rather than building a command to execute
1135 rem but that does not work on NT4
1137 if "%1"=="" goto :eof
1138 call :executecmd set wine_result=%%%1%%
1139 if "%wine_result%"=="%2" (
1140 echo %1 correctly %2
1141 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1152 rem No output when using "set expr" syntax, unless in interactive mode
1153 rem Need to use "set envvar=expr" to use in a batch script
1154 echo ------ individual operations
1156 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1157 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1158 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1159 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1160 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1161 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1162 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1163 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1164 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1165 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1166 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1167 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1168 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1169 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1170 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1171 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1172 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1173 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1174 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1175 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1176 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1177 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1178 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1179 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1180 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1181 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1182 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1183 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1184 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1185 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1186 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1187 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1188 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1189 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1190 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1191 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1192 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1193 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1194 echo ------ precedence and grouping
1195 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1196 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1197 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1198 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1199 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1200 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1201 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1202 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1203 echo ------ octal and hexadecimal
1204 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1205 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1206 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1207 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1208 echo ------ variables
1209 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1210 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1211 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
1213 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1214 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1216 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1218 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1220 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1221 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1223 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1225 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1227 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1228 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1229 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1231 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1234 call :checkenvvars WINE_foo 1
1236 call :checkenvvars WINE_foo 1
1237 set /a WINE_foo=1,WINE_bar=2
1238 call :checkenvvars WINE_foo 1 WINE_bar 2
1239 set /a "WINE_foo=1,WINE_bar=2"
1240 call :checkenvvars WINE_foo 1 WINE_bar 2
1241 set /a "WINE_foo=1","WINE_bar=2"
1242 call :checkenvvars WINE_foo 1 WINE_bar 2
1243 set /a ""WINE_foo=1","WINE_bar=2""
1244 call :checkenvvars WINE_foo 1 WINE_bar 2
1245 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1246 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1247 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
1248 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1249 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
1250 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1251 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1252 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1253 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
1254 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1255 set /a """"""WINE_foo=1""""""
1256 call :checkenvvars WINE_foo 1
1257 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1258 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1259 set /a WINE_foo="3"+"4"+"5+6"
1260 call :checkenvvars WINE_foo 18
1262 set /a WINE_bar="WINE_""foo"+4
1263 call :checkenvvars WINE_foo 3 WINE_bar 7
1264 echo --- whitespace are ignored between double char operators
1267 set /a WINE_foo + = 6
1268 set /a WINE_bar * = WINE_foo
1269 call :checkenvvars WINE_foo 10 WINE_bar 50
1272 set /a WINE_foo + = "6 < < 7"
1273 set /a WINE_bar * = WINE_foo + WINE_foo
1274 call :checkenvvars WINE_foo 772 WINE_bar 7720
1278 echo --- invalid operator sequence
1284 set /a WINE_foo^>^<=4
1286 set /a WINE_foo^>^>^>=4
1288 echo ----- negative prefix
1290 call :checkenvvars WINE_foo -1
1292 call :checkenvvars WINE_foo 1
1293 set /a WINE_foo=3--3
1294 call :checkenvvars WINE_foo 6
1295 set /a WINE_foo=3---3
1296 call :checkenvvars WINE_foo 0
1297 set /a WINE_foo=3----3
1298 call :checkenvvars WINE_foo 6
1300 call :checkenvvars WINE_foo 2
1302 call :checkenvvars WINE_foo 0
1303 set /a WINE_foo=3+-~1
1304 call :checkenvvars WINE_foo 5
1305 set /a WINE_foo=3+~-1
1306 call :checkenvvars WINE_foo 3
1307 echo ----- assignment tests involving the end destination
1309 set /a WINE_foo+=3+(WINE_foo=4)
1310 call :checkenvvars WINE_foo 11
1312 set /a WINE_bar=3+(WINE_foo=6)
1313 call :checkenvvars WINE_foo 6 WINE_bar 9
1315 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1316 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1318 set /a WINE_bar=WINE_foo=7
1319 call :checkenvvars WINE_foo 7 WINE_bar 7
1320 echo ----- equal precedence on stack
1321 rem Unary - don't reduce if precedence is equal
1323 call :checkenvvars WINE_foo 1
1325 call :checkenvvars WINE_foo 0
1327 call :checkenvvars WINE_foo 1
1329 call :checkenvvars WINE_foo 0
1331 call :checkenvvars WINE_foo 1
1333 call :checkenvvars WINE_foo -1
1335 call :checkenvvars WINE_foo -1
1337 call :checkenvvars WINE_foo 1
1339 call :checkenvvars WINE_foo 0
1341 call :checkenvvars WINE_foo -1
1343 call :checkenvvars WINE_foo 0
1345 call :checkenvvars WINE_foo 0
1347 call :checkenvvars WINE_foo 1
1349 call :checkenvvars WINE_foo -1
1350 rem Aritmatic - Reduce if precedence is equal
1351 set /a WINE_foo=10*5/2
1352 call :checkenvvars WINE_foo 25
1353 set /a WINE_foo=5/2*10
1354 call :checkenvvars WINE_foo 20
1355 set /a WINE_foo=10/5/2
1356 call :checkenvvars WINE_foo 1
1357 set /a WINE_foo=5%%2*4
1358 call :checkenvvars WINE_foo 4
1359 set /a WINE_foo=10-5+2
1360 call :checkenvvars WINE_foo 7
1361 set /a WINE_foo=1^<^<4^>^>1
1362 call :checkenvvars WINE_foo 8
1363 rem Assignment - don't reduce if precedence is equal
1365 set /a WINE_bar=WINE_foo=6
1366 call :checkenvvars WINE_foo 6 WINE_bar 6
1369 mkdir foobar & cd foobar
1370 echo ------ string argument
1371 rem NT4 does not support usebackq
1372 for /F %%i in ("a b c") do echo %%i
1373 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1374 if not exist output_file (echo no output) else (type output_file & del output_file)
1375 for /f %%i in ("a ") do echo %%i
1376 for /f usebackq %%i in ('a ') do echo %%i>output_file
1377 if not exist output_file (echo no output) else (type output_file & del output_file)
1378 for /f %%i in ("a") do echo %%i
1379 for /f usebackq %%i in ('a') do echo %%i>output_file
1380 if not exist output_file (echo no output) else (type output_file & del output_file)
1381 fOr /f %%i in (" a") do echo %%i
1382 for /f usebackq %%i in (' a') do echo %%i>output_file
1383 if not exist output_file (echo no output) else (type output_file & del output_file)
1384 for /f %%i in (" a ") do echo %%i
1385 for /f usebackq %%i in (' a ') do echo %%i>output_file
1386 if not exist output_file (echo no output) else (type output_file & del output_file)
1387 echo ------ fileset argument
1388 echo --------- basic blank handling
1390 for /f %%i in (foo) do echo %%i
1392 for /f %%i in (foo) do echo %%i
1394 for /f %%i in (foo) do echo %%i
1396 for /f %%i in (foo) do echo %%i
1398 for /f %%i in (foo) do echo %%i
1400 for /f %%i in (foo) do echo %%i
1403 for /f %%i in (foo) do echo %%i
1404 echo --------- multi-line with empty lines
1411 for /f %%b in (foo) do echo %%b
1412 echo --------- multiple files
1416 for /f %%k in (foo bar) do echo %%k
1417 for /f %%k in (bar foo) do echo %%k
1418 echo ------ command argument
1419 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1420 if "%CD%"=="" goto :SkipFORFcmdNT4
1421 for /f %%i in ('echo.Passed1') do echo %%i
1422 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
1423 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1426 for /l %%i in (1,1,3) do echo Missing functionality - Broken%%i
1428 rem FIXME: Rest not testable right now in wine: not implemented and would need
1429 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1430 rem for a simple todo_wine test
1431 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1432 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1433 echo ------ eol option
1434 if "%CD%"=="" goto :SkipFORFeolNT4
1436 echo and Line two>>foo
1437 echo Line three>>foo
1438 for /f "eol=L" %%i in (foo) do echo %%i
1439 for /f "eol=a" %%i in (foo) do echo %%i
1441 goto :ContinueFORFeol
1443 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1445 for /f "eol=@" %%i in (" ad") do echo %%i
1446 for /f "eol=@" %%i in (" z@y") do echo %%i
1447 for /f "eol=|" %%i in ("a|d") do echo %%i
1448 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
1449 if not exist output_file (echo no output) else (del output_file)
1450 for /f "eol==" %%i in ("=y") do echo %%i > output_file
1451 if not exist output_file (echo no output) else (del output_file)
1452 echo ------ delims option
1453 for /f "delims=|" %%i in ("a|d") do echo %%i
1454 for /f "delims=|" %%i in ("a |d") do echo %%i
1455 for /f "delims=|" %%i in ("a d|") do echo %%i
1456 for /f "delims=| " %%i in ("a d|") do echo %%i
1457 for /f "delims==" %%i in ("C r=d|") do echo %%i
1458 for /f "delims=" %%i in ("foo bar baz") do echo %%i
1459 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
1460 echo ------ skip option
1464 for /f "skip=2" %%i in (foo) do echo %%i
1465 for /f "skip=3" %%i in (foo) do echo %%i > output_file
1466 if not exist output_file (echo no output) else (del output_file)
1467 for /f "skip=4" %%i in (foo) do echo %%i > output_file
1468 if not exist output_file (echo no output) else (del output_file)
1469 for /f "skip=02" %%i in (foo) do echo %%i
1470 for /f "skip=0x2" %%i in (foo) do echo %%i
1471 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
1472 if not exist output_file (echo no output) else (del output_file)
1473 echo ------ tokens= option
1475 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
1476 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
1477 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
1478 rem Show * means the rest
1479 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
1480 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
1481 rem Show * means the rest (not tokenized and rebuilt)
1482 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
1483 rem Order is irrelevant
1484 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
1485 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
1486 rem Duplicates are ignored
1487 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
1488 rem Large tokens are allowed
1489 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
1490 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1491 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
1492 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
1493 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1494 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
1495 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
1496 rem Show negative ranges have no effect
1497 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
1498 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
1499 rem Show duplicates stop * from working
1500 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
1501 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
1502 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
1503 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
1507 echo ------------ Testing del ------------
1509 echo deleting 'file'
1512 echo errorlevel is 0, good
1514 echo unexpected errorlevel, got %errorlevel%
1517 echo successfully deleted 'file'
1519 echo error deleting 'file'
1521 echo attempting to delete 'file', even though it is not present
1524 echo errorlevel is 0, good
1526 echo unexpected errorlevel, got %errorlevel%
1529 echo ------------ Testing del /a ------------
1530 del /f/q *.test > nul
1533 echo not-r > not-r.test
1535 if not exist not-r.test echo not-r.test not found before delete, bad
1537 if not exist not-r.test echo not-r.test not found after delete, good
1539 if not exist r.test echo r.test not found before delete, bad
1540 if exist r.test echo r.test found before delete, good
1542 if not exist r.test echo r.test not found after delete, good
1543 if exist r.test echo r.test found after delete, bad
1545 echo ------------ Testing del /q ------------
1549 echo abc > file2.dat
1550 rem If /q doesn't work, cmd will prompt and the test case should hang
1552 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1553 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1557 echo ------------ Testing del /s ------------
1562 echo there > file2.dat
1563 echo bub > file3.dat
1564 echo bye > "file with spaces.dat"
1566 del /s file1.dat > nul
1567 del file2.dat /s > nul
1568 del "file3.dat" /s > nul
1569 del "file with spaces.dat" /s > nul
1571 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1572 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1573 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
1574 if exist "file with spaces.dat" del "file with spaces.dat"
1579 echo ------------ Testing rename ------------
1580 mkdir foobar & cd foobar
1581 echo --- ren and rename are synonymous
1584 if exist foo echo foo should be renamed!
1585 if exist bar echo foo renamed to bar
1587 if exist bar echo bar should be renamed!
1588 if exist foo echo bar renamed to foo
1589 echo --- name collision
1599 echo --- rename read-only files
1603 if not exist file1 (
1605 echo read-only file renamed
1608 echo read-only file not renamed!
1610 echo --- rename directories
1622 echo read-only dir renamed
1625 echo --- rename in other directory
1626 if not exist baz\abc (
1627 echo rename impossible in other directory
1628 if exist foo echo original file still present
1630 echo shouldn't rename in other directory!
1631 if not exist foo echo original file not present anymore
1633 cd .. & rd /s/q foobar
1635 echo ------------ Testing move ------------
1636 mkdir foobar & cd foobar
1639 move foo bar > nul 2>&1
1642 echo file move succeeded
1647 move /Y bar baz > nul 2>&1
1650 echo file move with overwrite succeeded
1653 echo file overwrite impossible!
1659 move baz bazro > nul 2>&1
1662 echo read-only files are moveable
1663 move bazro baz > nul 2>&1
1666 echo read-only file not moved!
1670 move baz rep > nul 2>&1
1673 echo file moved in subdirectory
1677 move rep\baz . > nul 2>&1
1678 move /Y baz baz > nul 2>&1
1680 echo moving a file to itself should be a no-op!
1682 echo moving a file to itself is a no-op
1684 echo ErrorLevel: %ErrorLevel%
1687 echo --- directory move
1691 move baz foo\bar > nul 2>&1
1693 if exist foo\bar\baz\baz2 (
1694 echo simple directory move succeeded
1699 move baz baz > nul 2>&1
1700 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1701 echo ------ dir in dir move
1706 move foo bar > nul 2>&1
1714 cd .. & rd /s/q foobar
1716 echo ------------ Testing mkdir ------------
1718 echo --- md and mkdir are synonymous
1725 echo --- creating an already existing directory/file must fail
1734 echo --- multilevel path creation
1746 mkdir ..\..\..\foo\bar2
1749 mkdir ..\..\..\foo\bar2
1751 rmdir ..\..\..\foo\bar2
1759 echo --- trailing backslashes
1762 if exist foo (rmdir foo & echo dir created
1763 ) else ( echo dir not created )
1765 echo --- invalid chars
1767 echo mkdir ? gives errorlevel %ErrorLevel%
1770 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1773 echo mkdir foo\? gives errorlevel %ErrorLevel%
1774 if exist foo (rmdir foo & echo ok, foo created
1775 ) else ( echo foo not created )
1778 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1781 echo bad, foo not created
1785 echo ok, foo\bar created
1791 echo --- multiple directories at once
1792 mkdir foobaz & cd foobaz
1793 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
1794 if exist foo (echo foo created) else echo foo not created!
1795 if exist bar (echo bar created) else echo bar not created!
1796 if exist foobar (echo foobar created) else echo foobar not created!
1797 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
1798 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
1799 if exist zabzab (echo zabzab created) else echo zabzab not created!
1800 cd .. & rd /s/q foobaz
1803 echo mkdir foo\* errorlevel %ErrorLevel%
1804 if exist foo (rmdir foo & echo ok, foo created
1805 ) else ( echo bad, foo not created )
1807 echo ------------ Testing rmdir ------------
1809 rem rd and rmdir are synonymous
1813 if not exist foobar echo dir removed
1817 if not exist foobar echo dir removed
1818 rem Removing nonexistent directory
1821 rem Removing single-level directories
1825 if exist foo echo file not removed
1831 if exist foo echo non-empty dir not removed
1836 if exist foo echo non-empty dir not removed
1843 echo recursive rmdir succeeded
1850 echo foo > foo\bar\brol
1851 rmdir /s /Q foo 2>&1
1853 echo recursive rmdir succeeded
1860 rem multiples directories at once
1861 mkdir foobaz & cd foobaz
1865 rd /s/q foo bar foobar
1866 if not exist foo (echo foo removed) else echo foo not removed!
1867 if not exist bar (echo bar removed) else echo bar not removed!
1868 if not exist foobar (echo foobar removed) else echo foobar not removed!
1869 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
1870 cd .. & rd /s/q foobaz
1872 echo ------------ Testing pushd/popd ------------
1874 echo --- popd is no-op when dir stack is empty
1877 echo --- pushing non-existing dir
1880 echo --- basic behaviour
1905 echo ------------ Testing attrib ------------
1906 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
1907 mkdir foobar & cd foobar
1908 echo foo original contents> foo
1911 echo --- read-only attribute
1912 rem Read-only files cannot be altered or deleted, unless forced
1920 echo Read-only file not deleted
1922 echo Should not delete read-only file!
1926 echo Read-only file forcibly deleted
1928 echo Should delete read-only file with del /F!
1932 cd .. & rd /s/q foobar
1933 echo --- recursive behaviour
1934 mkdir foobar\baz & cd foobar
1940 attrib +R l*vel? /S > nul 2>&1
1946 cd .. & rd /s/q foobar
1947 echo --- folders processing
1953 attrib +r baz /s /d > nul 2>&1
1959 rem Oddly windows allows file creation in a read-only directory...
1960 if exist baz\lala (echo file created in read-only dir) else echo file not created
1961 cd .. & rd /s/q foobar
1963 echo ------------ Testing assoc ------------
1964 rem Modifying associations requires some privileges...
1965 net session >nul 2>&1
1966 if errorlevel 1 goto :SkipAssoc
1968 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1969 rem FIXME Revise once || conditional execution is fixed
1970 mkdir foobar & cd foobar
1971 echo --- setting association
1979 rem association set system-wide
1980 echo @echo off> tmp.cmd
1981 echo echo +++>> tmp.cmd
1982 echo assoc .foo>> tmp.cmd
1985 echo --- resetting association
1991 rem association removal set system-wide
1992 cmd /c tmp.cmd > baz
1995 cd .. & rd /s/q foobar
1998 echo --- setting association
2004 echo --- resetting association
2011 echo ------------ Testing ftype ------------
2012 rem Modifying associations requires some privileges...
2013 net session >nul 2>&1
2014 if errorlevel 1 goto :SkipFType
2015 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2016 rem FIXME Revise once || conditional execution is fixed
2017 mkdir foobar & cd foobar
2018 echo --- setting association
2023 ftype footype=foo_opencmd
2027 rem association set system-wide
2028 echo @echo off> tmp.cmd
2029 echo echo +++>> tmp.cmd
2030 echo ftype footype>> tmp.cmd
2033 echo --- resetting association
2036 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2037 setlocal EnableDelayedExpansion
2038 set WINE_FOO=original value
2041 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
2042 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2043 rem FIXME Revisit once a grep-like program like ftype is implemented
2044 rem (e.g. to check baz's size using dir /b instead)
2047 rem cleanup registry
2048 echo REGEDIT4> regCleanup.reg
2049 echo.>> regCleanup.reg
2050 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
2051 regedit /s regCleanup.reg
2054 cd .. & rd /s/q foobar
2057 echo --- setting association
2059 echo footype=foo_opencmd
2061 echo footype=foo_opencmd
2063 echo footype=foo_opencmd
2064 echo --- resetting association
2068 echo ------------ Testing CALL ------------
2069 mkdir foobar & cd foobar
2070 echo --- external script
2071 echo echo foo %%1> foo.cmd
2074 echo echo %%1 %%2 > foo.cmd
2076 call foo.cmd foo bar
2083 echo --- internal routines
2084 call :testRoutine :testRoutine
2085 goto :endTestRoutine
2091 call :testRoutineArgs foo
2092 call :testRoutineArgs foo bar
2093 call :testRoutineArgs foo ""
2094 call :testRoutineArgs "" bar
2095 call :testRoutineArgs foo ''
2096 call :testRoutineArgs '' bar
2097 goto :endTestRoutineArgs
2103 echo --- with builtins
2106 if exist foo (echo foo created) else echo foo should exist!
2108 set WINE_FOOBAZ_VAR=foobaz
2109 call echo Should expand %WINE_FOOBAZ_VAR%
2110 set WINE_FOOBAZ_VAR=
2114 if 1==1 call del batfile
2116 if exist batfile echo batfile shouldn't exist
2117 rem ... but not for 'if' or 'for'
2118 call if 1==1 echo bar 2> nul
2121 call for %%i in (foo bar baz) do echo %%i 2> nul
2123 rem First look for programs in the path before trying a builtin
2124 echo echo non-builtin dir> dir.cmd
2127 rem The below line equates to call (, which does nothing, then the
2128 rem subsequent lines are executed.
2133 rem The below line equates to call if, which always fails, then the
2134 rem subsequent lines are executed. Note cmd.exe swallows all lines
2141 call call call echo passed
2142 cd .. & rd /s/q foobar
2144 echo ------------ Testing SHIFT ------------
2146 call :shiftFun p1 p2 p3 p4 p5
2150 echo '%1' '%2' '%3' '%4' '%5'
2152 echo '%1' '%2' '%3' '%4' '%5'
2154 echo '%1' '%2' '%3' '%4' '%5'
2156 echo '%1' '%2' '%3' '%4' '%5'
2158 echo '%1' '%2' '%3' '%4' '%5'
2160 echo '%1' '%2' '%3' '%4' '%5'
2164 echo ------------ Testing cmd invocation ------------
2165 rem FIXME: only a stub ATM
2166 echo --- a batch file can delete itself
2167 echo del foo.cmd>foo.cmd
2169 if not exist foo.cmd (
2170 echo file correctly deleted
2172 echo file should be deleted!
2175 echo --- a batch file can alter itself
2176 echo echo bar^>foo.cmd>foo.cmd
2177 cmd /q /c foo.cmd > NUL 2>&1
2182 echo file not created!
2185 echo ---------- Testing copy
2188 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2191 echo CCCCCCCCC> file3
2197 echo Passed: Found expected %1
2199 echo Failed: Did not find expected %1
2201 del /q "%1" >nul 2>&1
2203 if not "%1"=="" goto :CheckExist
2208 echo Passed: Did not find %1
2210 echo Failed: Unexpectedly found %1
2211 del /q "%1" >nul 2>&1
2214 if not "%1"=="" goto :CheckNotExist
2217 rem Note: No way to check file size on NT4 so skip the test
2220 echo Failed: File missing when requested filesize check [%2]
2221 goto :ContinueFileSizeChecks
2223 for %%i in (%1) do set WINE_filesize=%%~zi
2224 if "%WINE_filesize%"=="%2" (
2225 echo Passed: file size check on %1 [%WINE_filesize%]
2227 if "%WINE_filesize%"=="%%~zi" (
2228 echo Skipping file size check on NT4
2230 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2233 :ContinueFileSizeChecks
2236 if not "%1"=="" goto :CheckFileSize
2241 rem -----------------------
2242 rem Simple single file copy
2243 rem -----------------------
2244 rem Simple single file copy, normally used syntax
2245 copy file1 dummy.file >nul 2>&1
2246 if errorlevel 1 echo Incorrect errorlevel
2247 call :CheckExist dummy.file
2249 rem Simple single file copy, destination supplied as two forms of directory
2250 copy file1 dir1 >nul 2>&1
2251 if errorlevel 1 echo Incorrect errorlevel
2252 call :CheckExist dir1\file1
2254 copy file1 dir1\ >nul 2>&1
2255 if errorlevel 1 echo Incorrect errorlevel
2256 call :CheckExist dir1\file1
2258 rem Simple single file copy, destination supplied as fully qualified destination
2259 copy file1 dir1\file99 >nul 2>&1
2260 if errorlevel 1 echo Incorrect errorlevel
2261 call :CheckExist dir1\file99
2263 rem Simple single file copy, destination not supplied
2265 copy ..\file1 >nul 2>&1
2266 if errorlevel 1 echo Incorrect errorlevel
2267 call :CheckExist file1
2270 rem Simple single file copy, destination supplied as nonexistent directory
2271 copy file1 dir2\ >nul 2>&1
2272 if not errorlevel 1 echo Incorrect errorlevel
2273 call :CheckNotExist dir2 dir2\file1
2275 rem -----------------------
2277 rem -----------------------
2278 rem Simple single file copy, destination supplied as two forms of directory
2279 copy file? dir1 >nul 2>&1
2280 if errorlevel 1 echo Incorrect errorlevel
2281 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2283 copy file* dir1\ >nul 2>&1
2284 if errorlevel 1 echo Incorrect errorlevel
2285 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2287 rem Simple single file copy, destination not supplied
2289 copy ..\file*.* >nul 2>&1
2290 if errorlevel 1 echo Incorrect errorlevel
2291 call :CheckExist file1 file2 file3
2294 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2295 copy file? dir2\ >nul 2>&1
2296 if not errorlevel 1 echo Incorrect errorlevel
2297 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2299 rem ------------------------------------------------
2300 rem Confirm overwrite works (cannot test prompting!)
2301 rem ------------------------------------------------
2302 copy file1 testfile >nul 2>&1
2303 copy /y file2 testfile >nul 2>&1
2304 call :CheckExist testfile
2306 rem ------------------------------------------------
2307 rem Test concatenation
2308 rem ------------------------------------------------
2309 rem simple case, no wildcards
2310 copy file1+file2 testfile >nul 2>&1
2311 if errorlevel 1 echo Incorrect errorlevel
2312 call :CheckExist testfile
2314 rem simple case, wildcards, no concatenation
2315 copy file* testfile >nul 2>&1
2316 if errorlevel 1 echo Incorrect errorlevel
2317 call :CheckExist testfile
2319 rem simple case, wildcards, and concatenation
2321 copy file*+fred testfile >nul 2>&1
2322 if errorlevel 1 echo Incorrect errorlevel
2323 call :CheckExist testfile
2325 rem simple case, wildcards, and concatenation
2326 copy fred+file* testfile >nul 2>&1
2327 if errorlevel 1 echo Incorrect errorlevel
2328 call :CheckExist testfile
2330 rem Calculate destination name
2331 copy fred+file* dir1 >nul 2>&1
2332 if errorlevel 1 echo Incorrect errorlevel
2333 call :CheckExist dir1\fred
2335 rem Calculate destination name
2336 copy fred+file* dir1\ >nul 2>&1
2337 if errorlevel 1 echo Incorrect errorlevel
2338 call :CheckExist dir1\fred
2340 rem Calculate destination name (none supplied)
2342 copy ..\fred+..\file* >nul 2>&1
2343 if errorlevel 1 echo Incorrect errorlevel
2344 call :CheckExist fred
2346 copy ..\fr*+..\file1 >nul 2>&1
2347 if errorlevel 1 echo Incorrect errorlevel
2348 call :CheckExist fred
2351 rem ******************************************************************
2352 rem ASCII and BINARY tests
2353 rem Note: hard coded numbers deliberate because need to ensure whether
2354 rem an additional EOF has been added or not. There is no way to handle
2355 rem EOFs in batch, so assume if a single byte appears, it's an EOF!
2356 rem ******************************************************************
2358 rem Confirm original sizes of file1,2,3
2359 call :CheckFileSize file1 5 file2 8 file3 11
2363 rem ----------------------------------------------
2364 rem Show concatenation defaults copy to ascii mode
2365 rem ----------------------------------------------
2366 rem Simple default copy source to destination (should not append EOF 5)
2367 copy ..\file1 file1_default >nul 2>&1
2368 call :CheckFileSize file1_default 5
2370 rem Simple binary copy source to destination (should not append EOF 5)
2371 copy /b ..\file1 file1_default2 >nul 2>&1
2372 call :CheckFileSize file1_default2 5
2374 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2375 copy /a ..\file1 file1_plus_eof >nul 2>&1
2376 call :CheckFileSize file1_plus_eof 6
2377 copy /a ..\file2 file2_plus_eof >nul 2>&1
2378 call :CheckFileSize file2_plus_eof 9
2379 copy /a ..\file3 file3_plus_eof >nul 2>&1
2380 call :CheckFileSize file3_plus_eof 12
2382 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2383 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2384 call :CheckFileSize file12_plus_eof 14
2386 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2387 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2388 call :CheckFileSize file12_no_eof 13
2390 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2391 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2392 call :CheckFileSize file12_eof2 14
2394 rem --------------------------------------------------------------
2395 rem Show ascii source copy stops at first EOF, binary does the lot
2396 rem --------------------------------------------------------------
2397 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2398 call :CheckFileSize file1_binary_srccopy 6
2400 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2401 call :CheckFileSize file1_ascii_srccopy 5
2403 rem --------------------------------------------------------------
2404 rem Show results of concatenating files (ending in EOFs) and /a /b
2405 rem --------------------------------------------------------------
2407 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2408 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2409 call :CheckFileSize file123_default_copy 25
2410 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2411 call :CheckFileSize file123_ascii_copy 25
2413 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2414 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2415 call :CheckFileSize file123_binary_copy 27
2417 rem We can select which we want the eofs from by postfixing it with /a or /b
2418 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2419 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2420 call :CheckFileSize file123_mixed_copy1 26
2422 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2423 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2424 rem Note the delta between this and the previous one also shows that the destination
2425 rem ascii/binary is inherited from the last /a or /b on the line
2426 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2427 call :CheckFileSize file123_mixed_copy2 27
2429 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2430 rem Note the delta between the next two also shows that the destination ascii/binary is
2431 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2432 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2433 call :CheckFileSize file123_mixed_copy3 26
2434 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2435 call :CheckFileSize file123_mixed_copy4 25
2437 rem -------------------------------------------------------------------------------------------
2438 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2439 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2440 rem -------------------------------------------------------------------------------------------
2442 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2443 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2444 call :CheckFileSize file123_mixed_copy5 28
2446 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2447 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2448 call :CheckFileSize file123_mixed_copy6 19
2450 rem One file has EOF, but doesn't get an extra one, i.e. 6
2451 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2452 call :CheckFileSize file123_mixed_copy7 6
2454 rem Syntax means concatenate so ascii destination kicks in
2455 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2456 call :CheckFileSize file123_mixed_copy8 7
2461 rem ---------------------------------------
2462 rem Error combinations
2463 rem ---------------------------------------
2464 rem Specify source directory but name is a file
2466 copy file1\ dir1\ >NUL 2>&1
2467 if errorlevel 1 echo Passed: errorlevel invalid check 1
2468 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2469 call :CheckNotExist dir1\file1
2471 rem Overwrite same file
2473 copy file1 file1 >NUL 2>&1
2474 if errorlevel 1 echo Passed: errorlevel invalid check 2
2475 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2477 rem Supply same file identified as a directory
2479 copy file1 file1\ >NUL 2>&1
2480 if errorlevel 1 echo Passed: errorlevel invalid check 3
2481 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2486 echo ------------ Testing setlocal/endlocal ------------
2488 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2489 mkdir foobar & cd foobar
2490 echo --- enable/disable extensions
2491 setlocal DisableEXTensions
2492 echo ErrLev: %ErrorLevel%
2494 echo ErrLev: %ErrorLevel%
2495 echo @echo off> tmp.cmd
2496 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2497 rem Enabled by default
2499 cmd /E:OfF /C tmp.cmd
2500 cmd /e:oN /C tmp.cmd
2502 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2503 echo --- setlocal with corresponding endlocal
2504 rem %CD% does not work on NT4 so use the following workaround
2505 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2506 echo @echo off> test.cmd
2507 echo echo %%WINE_VAR%%>> test.cmd
2508 echo setlocal>> test.cmd
2509 echo set WINE_VAR=localval>> test.cmd
2510 echo md foobar2>> test.cmd
2511 echo cd foobar2>> test.cmd
2512 echo echo %%WINE_VAR%%>> test.cmd
2513 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2514 echo endlocal>> test.cmd
2515 echo echo %%WINE_VAR%%>> test.cmd
2516 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2517 set WINE_VAR=globalval
2520 for /d %%i in (.) do echo %%~dpnxi
2524 echo --- setlocal with no corresponding endlocal
2525 echo @echo off> test.cmd
2526 echo echo %%WINE_VAR%%>> test.cmd
2527 echo setlocal>> test.cmd
2528 echo set WINE_VAR=localval>> test.cmd
2529 echo md foobar2>> test.cmd
2530 echo cd foobar2>> test.cmd
2531 echo echo %%WINE_VAR%%>> test.cmd
2532 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2533 set WINE_VAR=globalval
2534 rem %CD% does not work on NT4 so use the following workaround
2535 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2538 for /d %%i in (.) do echo %%~dpnxi
2542 echo --- setlocal within same batch program
2546 rem %CD% does not work on NT4 so use the following workaround
2547 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2554 if "%WINE_var1%"=="one" echo Var1 ok 1
2555 if "%WINE_var2%"=="two" echo Var2 ok 2
2556 if "%WINE_var3%"=="three" echo Var3 ok 3
2557 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2558 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
2560 if "%WINE_var1%"=="one" echo Var1 ok 1
2561 if "%WINE_var2%"=="two" echo Var2 ok 2
2562 if "%WINE_var3%"=="" echo Var3 ok 3
2563 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2564 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
2566 if "%WINE_var1%"=="one" echo Var1 ok 1
2567 if "%WINE_var2%"=="" echo Var2 ok 2
2568 if "%WINE_var3%"=="" echo Var3 ok 3
2569 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2570 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
2574 echo --- Mismatched set and end locals
2578 rem %CD% does not work on NT4 so use the following workaround
2579 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
2581 echo @echo off> 2set1end.cmd
2582 echo echo %%WINE_var%%>> 2set1end.cmd
2583 echo setlocal>> 2set1end.cmd
2584 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
2585 echo cd ..\foodir3>> 2set1end.cmd
2586 echo setlocal>> 2set1end.cmd
2587 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
2588 echo cd ..\foodir4>> 2set1end.cmd
2589 echo endlocal>> 2set1end.cmd
2590 echo echo %%WINE_var%%>> 2set1end.cmd
2591 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
2593 echo @echo off> 1set2end.cmd
2594 echo echo %%WINE_var%%>> 1set2end.cmd
2595 echo setlocal>> 1set2end.cmd
2596 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
2597 echo cd ..\foodir3>> 1set2end.cmd
2598 echo endlocal>> 1set2end.cmd
2599 echo echo %%WINE_var%%>> 1set2end.cmd
2600 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2601 echo endlocal>> 1set2end.cmd
2602 echo echo %%WINE_var%%>> 1set2end.cmd
2603 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2605 echo --- Extra setlocal in called batch
2607 rem -- setlocal1 == this batch, should never be used inside a called routine
2611 call "%WINE_CURDIR%\2set1end.cmd"
2614 for /d %%i in (.) do echo %%~dpnxi
2617 for /d %%i in (.) do echo %%~dpnxi
2620 echo --- Extra endlocal in called batch
2622 rem -- setlocal1 == this batch, should never be used inside a called routine
2626 call "%WINE_CURDIR%\1set2end.cmd"
2629 for /d %%i in (.) do echo %%~dpnxi
2632 for /d %%i in (.) do echo %%~dpnxi
2635 echo --- endlocal in called function rather than batch pgm is ineffective
2641 call :endlocalroutine
2645 goto :endlocalfinished
2663 cd .. & rd /q/s foobar
2665 echo ------------ Testing Errorlevel ------------
2666 rem WARNING: Do *not* add tests using ErrorLevel after this section
2667 should_not_exist 2> nul > nul
2669 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2670 rem See http://www.robvanderwoude.com/exit.php
2673 if errorlevel 2 echo errorlevel too high, bad
2674 if errorlevel 1 echo errorlevel just right, good
2675 if errorlevel 01 echo errorlevel with leading zero just right, good
2676 if errorlevel -1 echo errorlevel with negative number OK
2677 if errorlevel 0x1 echo hexa should not be recognized!
2678 if errorlevel 1a echo invalid error level recognized!
2680 echo abc%ErrorLevel%def
2681 if errorlevel 1 echo errorlevel nonzero, bad
2682 if not errorlevel 1 echo errorlevel zero, good
2683 if not errorlevel 0x1 echo hexa should not be recognized!
2684 if not errorlevel 1a echo invalid error level recognized!
2685 rem Now verify that setting a real variable hides its magic variable
2687 echo %ErrorLevel% should be 7
2688 if errorlevel 7 echo setting var worked too well, bad
2690 echo %ErrorLevel% should still be 7
2692 echo ------------ Testing GOTO ------------
2694 echo FAILURE at dest 1
2696 echo goto with no leading space worked
2697 if a==a goto :dest1b
2698 echo FAILURE at dest 1b
2700 echo goto with colon and no leading space worked
2702 echo FAILURE at dest 2
2704 echo goto with a leading space worked
2706 echo FAILURE at dest 3
2708 echo goto with a leading tab worked
2710 echo FAILURE at dest 4
2712 echo goto with a following space worked
2714 echo FAILURE at dest 5
2715 :dest5&& echo FAILURE
2716 echo goto with following amphersands worked
2718 del failure.txt >nul 2>&1
2720 echo FAILURE at dest 6
2722 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
2723 echo goto with redirections worked
2724 del FAILURE.TXT >nul 2>&1
2726 :: some text that is ignored | dir >cmd_output | another test
2727 if exist cmd_output echo FAILURE at dest 6 as file exists
2728 echo Ignoring double colons worked
2729 del cmd_output >nul 2>&1
2731 rem goto a label which does not exist issues an error message and
2732 rem acts the same as goto :EOF, and ensure ::label is never matched
2733 del testgoto.bat >nul 2>&1
2734 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
2735 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2736 echo ::dest7>> testgoto.bat
2737 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
2739 del testgoto.bat >nul 2>&1
2741 del testgoto.bat >nul 2>&1
2742 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
2743 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2744 echo ::dest8>> testgoto.bat
2745 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
2747 del testgoto.bat >nul 2>&1
2750 echo FAILURE at dest 9
2752 echo FAILURE at dest 91
2754 echo label with mixed whitespace and no echo worked
2756 if h==h goto :dest10:this is ignored
2757 echo FAILURE at dest 10
2758 :dest10:this is also ignored
2759 echo Correctly ignored trailing information
2761 echo ------------ Testing PATH ------------
2762 set WINE_backup_path=%path%
2769 set path=%WINE_backup_path%
2770 set WINE_backup_path=
2772 echo ------------ Testing combined CALLs/GOTOs ------------
2773 echo @echo off>foo.cmd
2774 echo goto :eof>>foot.cmd
2776 echo echo world>>foo.cmd
2778 echo @echo off>foot.cmd
2779 echo echo cheball>>foot.cmd
2781 echo call :bar>>foot.cmd
2782 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
2783 echo goto :eof>>foot.cmd
2786 echo echo barbare>>foot.cmd
2787 echo goto :eof>>foot.cmd
2793 rem Script execution stops after the following line
2816 echo Final message is not output since earlier 'foot' processing stops script execution
2817 echo Do NOT add any tests below this line
2819 echo ------------ Done, jumping to EOF -----------
2821 rem Subroutine to set errorlevel and return
2822 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
2825 rem This line runs under cmd in windows NT 4, but not in more modern versions.