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 goto :endIfCompOpsSubroutines
841 rem IF subroutines helpers
843 if %1 LSS %2 echo %1 LSS %2
846 if %1 LEQ %2 echo %1 LEQ %2
849 if %1 EQU %2 echo %1 EQU %2
852 if %1 NEQ %2 echo %1 NEQ %2
855 if %1 GEQ %2 echo %1 GEQ %2
858 if %1 GTR %2 echo %1 GTR %2
861 :endIfCompOpsSubroutines
865 echo ------------ Testing for ------------
867 for %%i in (A B C) do echo %%i
868 for %%i in (A B C) do echo %%I
869 for %%i in (A B C) do echo %%j
870 for %%i in (A B C) do call :forTestFun1 %%i
871 for %%i in (1,4,1) do echo %%i
872 for %%i in (A, B,C) do echo %%i
873 for %%i in (X) do echo %%i
874 for@tab@%%i in (X2) do echo %%i
875 for %%i in@tab@(X3) do echo %%i
876 for %%i in (@tab@ foo@tab@) do echo %%i
877 for@tab@ %%i in@tab@(@tab@M) do echo %%i
878 for %%i@tab@in (X)@tab@do@tab@echo %%i
879 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
880 for %%i in (`echo A B`) do echo %%i
881 for %%i in ('echo A B') do echo %%i
882 for %%i in ("echo A B
") do echo %%i
883 for %%i in ("A B
" C) do echo %%i
889 echo --- imbricated FORs
896 for %%i in (A B) do (
897 for %%j in (C D) do (
899 for %%i in (A B) do (
900 for %%j in (C D) do (
901 call :forTestFun2 %%i %%j ))
907 mkdir foobar & cd foobar
912 echo --- basic wildcards
913 for %%i in (ba*) do echo %%i
915 for /d %%i in (baz foo bar) do echo %%i 2>&1
916 rem Confirm we don't match files:
917 for /d %%i in (bazb*) do echo %%i 2>&1
918 for /d %%i in (bazb2*) do echo %%i 2>&1
919 rem Show we pass through non wildcards
920 for /d %%i in (PASSED) do echo %%i
921 for /d %%i in (xxx) do (
922 echo %%i - Should be xxx
923 echo Expected second line
925 rem Show we issue no messages on failures
926 for /d %%i in (FAILED?) do echo %%i 2>&1
927 for /d %%i in (FAILED?) do (
928 echo %%i - Unexpected!
929 echo FAILED Unexpected second line
931 for /d %%i in (FAILED*) do echo %%i 2>&1
932 for /d %%i in (FAILED*) do (
933 echo %%i - Unexpected!
934 echo FAILED Unexpected second line
936 rem FIXME can't test wildcard expansion here since it's listed in directory
937 rem order, and not in alphabetic order.
938 rem Proper testing would need a currently missing "sort" program implementation.
939 rem for /d %%i in (ba*) do echo %%i>> tmp
942 rem for /d %%i in (?a*) do echo %%i>> tmp
945 rem for /d %%i in (*) do echo %%i>> tmp
953 call :WriteLine set WINE_found=N
954 for /l %%i in (1,1,%WINE_expectedresults%) do (
955 call :WriteLine if "%%%%WINE_expectedresults.
%%i%%%%"=="%%%%1" set WINE_found=Y
956 call :WriteLine if "%%%%WINE_found%%%%"=="Y
" set WINE_expectedresults.%%i=
957 call :WriteLine if "%%%%WINE_found%%%%"=="Y
" goto :eof
959 call :WriteLine echo Got unexpected result: "%%%%1"
968 for /l %%i in (1,1,%WINE_expectedresults%) do (
969 call :WriteLine if not "%%%%WINE_expectedresults.
%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.
%%i%%%%"
976 rem %CD% does not tork on NT4 so use the following workaround
977 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
980 echo Plain directory enumeration
981 set WINE_expectedresults=4
982 set WINE_expectedresults.1=%WINE_CURDIR%\.
983 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
984 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
985 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
987 for /R %%i in (.) do call temp.bat %%i
988 call :ValidateExpected
990 echo Plain directory enumeration from provided root
991 set WINE_expectedresults=4
992 set WINE_expectedresults.1=%WINE_CURDIR%\.
993 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
994 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
995 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
996 if "%CD%"=="" goto :SkipBrokenNT4
998 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat %%i
999 call :ValidateExpected
1002 echo File enumeration
1003 set WINE_expectedresults=2
1004 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1005 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1007 for /R %%i in (baz*) do call temp.bat %%i
1008 call :ValidateExpected
1010 echo File enumeration from provided root
1011 set WINE_expectedresults=2
1012 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1013 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1015 for /R %%i in (baz*) do call temp.bat %%i
1016 call :ValidateExpected
1018 echo Mixed enumeration
1019 set WINE_expectedresults=6
1020 set WINE_expectedresults.1=%WINE_CURDIR%\.
1021 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1022 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1023 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1024 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1025 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1027 for /R %%i in (. baz*) do call temp.bat %%i
1028 call :ValidateExpected
1030 echo Mixed enumeration from provided root
1031 set WINE_expectedresults=6
1032 set WINE_expectedresults.1=%WINE_CURDIR%\.
1033 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1034 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1035 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1036 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1037 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1039 for /R %%i in (. baz*) do call temp.bat %%i
1040 call :ValidateExpected
1042 echo With duplicates enumeration
1043 set WINE_expectedresults=12
1044 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
1045 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
1046 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
1047 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1048 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
1049 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
1050 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
1051 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
1052 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1053 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1054 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1055 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1057 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat %%i
1058 call :ValidateExpected
1060 echo Strip missing wildcards, keep unwildcarded names
1061 set WINE_expectedresults=6
1062 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1063 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1064 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1065 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1066 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1067 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1069 for /R %%i in (baz* fred* jim) do call temp.bat %%i
1070 call :ValidateExpected
1073 echo --- Complex wildcards unix and windows slash
1075 echo Windows slashs, valid path
1076 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1077 for %%f in (foobar\baz\*) do echo WC : %%f
1078 echo Windows slashs, invalid path
1079 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1080 for %%f in (foobar\jim\*) do echo WC : %%f
1081 echo Unix slashs, valid path
1082 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1083 for %%f in (foobar/baz/*) do echo WC : %%f
1084 echo Unix slashs, invalid path
1085 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1086 for %%f in (foobar/jim/*) do echo WC : %%f
1090 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
1091 for /L %%i in (1,2,0) do echo %%i
1092 for@tab@/L %%i in (1,2,0) do echo %%i
1093 for /L %%i in (1,2,6) do echo %%i
1094 for /l %%i in (1 ,2,6) do echo %%i
1095 for /L %%i in (a,2,3) do echo %%i
1096 for /L %%i in (1,2,-1) do echo %%i
1097 for /L %%i in (-4,-1,-1) do echo %%i
1098 for /L %%i in (1,-2,-2) do echo %%i
1099 for /L %%i in (1,2,a) do echo %%i
1100 echo ErrorLevel %ErrorLevel%
1101 for /L %%i in (1,a,b) do echo %%i
1102 echo ErrorLevel %ErrorLevel%
1104 for /l %%i in (1,1,4) do echo %%i
1105 for /l %%i in (1,2,4) do echo %%i
1106 for /l %%i in (4,-1,1) do echo %%i
1107 for /l %%i in (4,-2,1) do echo %%i
1108 for /l %%i in (1,-1,4) do echo %%i
1109 for /l %%i in (4,1,1) do echo %%i
1110 for /L %%i in (a,2,b) do echo %%i
1111 for /L %%i in (1,1,1) do echo %%i
1112 for /L %%i in (1,-2,-1) do echo %%i
1113 for /L %%i in (-1,-1,-1) do echo %%i
1114 for /L %%i in (1,2, 3) do echo %%i
1115 rem Test zero iteration skips the body of the for
1116 for /L %%i in (2,2,1) do (
1123 Rem Ideally for /f can be used rather than building a command to execute
1124 rem but that does not work on NT4
1126 if "%1"=="" goto :eof
1127 call :executecmd set wine_result=%%%1%%
1128 if "%wine_result%"=="%2" (
1129 echo %1 correctly %2
1130 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1141 rem No output when using "set expr
" syntax, unless in interactive mode
1142 rem Need to use "set envvar
=expr
" to use in a batch script
1143 echo ------ individual operations
1145 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1146 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1147 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1148 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1149 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1150 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1151 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1152 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1153 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1154 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1155 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1156 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1157 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1158 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1159 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1160 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1161 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1162 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1163 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1164 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1165 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1166 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1167 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1168 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1169 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1170 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1171 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1172 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1173 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1174 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1175 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1176 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1177 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1178 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1179 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1180 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1181 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1182 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1183 echo ------ precedence and grouping
1184 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1185 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1186 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1187 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1188 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1189 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1190 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1191 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1192 echo ------ octal and hexadecimal
1193 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1194 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1195 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1196 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1197 echo ------ variables
1198 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1199 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1200 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
1202 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1203 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1205 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1207 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1209 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1210 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1212 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1214 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1216 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1217 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1218 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1220 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1223 call :checkenvvars WINE_foo 1
1225 call :checkenvvars WINE_foo 1
1226 set /a WINE_foo=1,WINE_bar=2
1227 call :checkenvvars WINE_foo 1 WINE_bar 2
1228 set /a "WINE_foo
=1,WINE_bar
=2"
1229 call :checkenvvars WINE_foo 1 WINE_bar 2
1230 set /a "WINE_foo
=1","WINE_bar
=2"
1231 call :checkenvvars WINE_foo 1 WINE_bar 2
1232 set /a ""WINE_foo=1","WINE_bar=2""
1233 call :checkenvvars WINE_foo 1 WINE_bar 2
1234 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1235 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1236 set /a "WINE_foo
=1,WINE_bar
=2,WINE_baz
=3"
1237 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1238 set /a "WINE_foo
=1","WINE_bar
=2","WINE_baz
=3"
1239 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1240 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1241 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1242 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz
=3"
1243 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1244 set /a """"""WINE_foo=1""""""
1245 call :checkenvvars WINE_foo 1
1246 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1247 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1248 set /a WINE_foo="3"+"4"+"5+6"
1249 call :checkenvvars WINE_foo 18
1251 set /a WINE_bar="WINE_
""foo
"+4
1252 call :checkenvvars WINE_foo 3 WINE_bar 7
1253 echo --- whitespace are ignored between double char operators
1256 set /a WINE_foo + = 6
1257 set /a WINE_bar * = WINE_foo
1258 call :checkenvvars WINE_foo 10 WINE_bar 50
1261 set /a WINE_foo + = "6 < < 7"
1262 set /a WINE_bar * = WINE_foo + WINE_foo
1263 call :checkenvvars WINE_foo 772 WINE_bar 7720
1267 echo --- invalid operator sequence
1273 set /a WINE_foo^>^<=4
1275 set /a WINE_foo^>^>^>=4
1277 echo ----- negative prefix
1279 call :checkenvvars WINE_foo -1
1281 call :checkenvvars WINE_foo 1
1282 set /a WINE_foo=3--3
1283 call :checkenvvars WINE_foo 6
1284 set /a WINE_foo=3---3
1285 call :checkenvvars WINE_foo 0
1286 set /a WINE_foo=3----3
1287 call :checkenvvars WINE_foo 6
1289 call :checkenvvars WINE_foo 2
1291 call :checkenvvars WINE_foo 0
1292 set /a WINE_foo=3+-~1
1293 call :checkenvvars WINE_foo 5
1294 set /a WINE_foo=3+~-1
1295 call :checkenvvars WINE_foo 3
1296 echo ----- assignment tests involving the end destination
1298 set /a WINE_foo+=3+(WINE_foo=4)
1299 call :checkenvvars WINE_foo 11
1301 set /a WINE_bar=3+(WINE_foo=6)
1302 call :checkenvvars WINE_foo 6 WINE_bar 9
1304 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1305 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1307 set /a WINE_bar=WINE_foo=7
1308 call :checkenvvars WINE_foo 7 WINE_bar 7
1309 echo ----- equal precedence on stack
1310 rem Unary - don't reduce if precedence is equal
1312 call :checkenvvars WINE_foo 1
1314 call :checkenvvars WINE_foo 0
1316 call :checkenvvars WINE_foo 1
1318 call :checkenvvars WINE_foo 0
1320 call :checkenvvars WINE_foo 1
1322 call :checkenvvars WINE_foo -1
1324 call :checkenvvars WINE_foo -1
1326 call :checkenvvars WINE_foo 1
1328 call :checkenvvars WINE_foo 0
1330 call :checkenvvars WINE_foo -1
1332 call :checkenvvars WINE_foo 0
1334 call :checkenvvars WINE_foo 0
1336 call :checkenvvars WINE_foo 1
1338 call :checkenvvars WINE_foo -1
1339 rem Aritmatic - Reduce if precedence is equal
1340 set /a WINE_foo=10*5/2
1341 call :checkenvvars WINE_foo 25
1342 set /a WINE_foo=5/2*10
1343 call :checkenvvars WINE_foo 20
1344 set /a WINE_foo=10/5/2
1345 call :checkenvvars WINE_foo 1
1346 set /a WINE_foo=5%%2*4
1347 call :checkenvvars WINE_foo 4
1348 set /a WINE_foo=10-5+2
1349 call :checkenvvars WINE_foo 7
1350 set /a WINE_foo=1^<^<4^>^>1
1351 call :checkenvvars WINE_foo 8
1352 rem Assignment - don't reduce if precedence is equal
1354 set /a WINE_bar=WINE_foo=6
1355 call :checkenvvars WINE_foo 6 WINE_bar 6
1358 mkdir foobar & cd foobar
1359 echo ------ string argument
1360 rem NT4 does not support usebackq
1361 for /F %%i in ("a b c
") do echo %%i
1362 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1363 if not exist output_file (echo no output) else (type output_file & del output_file)
1364 for /f %%i in ("a
") do echo %%i
1365 for /f usebackq %%i in ('a ') do echo %%i>output_file
1366 if not exist output_file (echo no output) else (type output_file & del output_file)
1367 for /f %%i in ("a
") do echo %%i
1368 for /f usebackq %%i in ('a') do echo %%i>output_file
1369 if not exist output_file (echo no output) else (type output_file & del output_file)
1370 fOr /f %%i in (" a
") do echo %%i
1371 for /f usebackq %%i in (' a') do echo %%i>output_file
1372 if not exist output_file (echo no output) else (type output_file & del output_file)
1373 for /f %%i in (" a
") do echo %%i
1374 for /f usebackq %%i in (' a ') do echo %%i>output_file
1375 if not exist output_file (echo no output) else (type output_file & del output_file)
1376 echo ------ fileset argument
1377 echo --------- basic blank handling
1379 for /f %%i in (foo) do echo %%i
1381 for /f %%i in (foo) do echo %%i
1383 for /f %%i in (foo) do echo %%i
1385 for /f %%i in (foo) do echo %%i
1387 for /f %%i in (foo) do echo %%i
1389 for /f %%i in (foo) do echo %%i
1392 for /f %%i in (foo) do echo %%i
1393 echo --------- multi-line with empty lines
1400 for /f %%b in (foo) do echo %%b
1401 echo --------- multiple files
1405 for /f %%k in (foo bar) do echo %%k
1406 for /f %%k in (bar foo) do echo %%k
1407 echo ------ command argument
1408 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1409 if "%CD%"=="" goto :SkipFORFcmdNT4
1410 for /f %%i in ('echo.Passed1') do echo %%i
1411 for /f "usebackq
" %%i in (`echo.Passed2`) do echo %%i
1412 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1415 for /l %%i in (1,1,3) do echo Missing functionality - Broken%%i
1417 rem FIXME: Rest not testable right now in wine: not implemented and would need
1418 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1419 rem for a simple todo_wine test
1420 rem (for /f "usebackq
" %%i in (`echo z a b`) do echo %%i) || echo not supported
1421 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1422 echo ------ eol option
1423 if "%CD%"=="" goto :SkipFORFeolNT4
1425 echo and Line two>>foo
1426 echo Line three>>foo
1427 for /f "eol
=L
" %%i in (foo) do echo %%i
1428 for /f "eol
=a
" %%i in (foo) do echo %%i
1430 goto :ContinueFORFeol
1432 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1434 for /f "eol
=@
" %%i in (" ad
") do echo %%i
1435 for /f "eol
=@
" %%i in (" z@y
") do echo %%i
1436 for /f "eol
=|
" %%i in ("a|d
") do echo %%i
1437 for /f "eol
=@
" %%i in ("@y
") do echo %%i > output_file
1438 if not exist output_file (echo no output) else (del output_file)
1439 for /f "eol
==" %%i in ("=y
") do echo %%i > output_file
1440 if not exist output_file (echo no output) else (del output_file)
1441 echo ------ delims option
1442 for /f "delims
=|
" %%i in ("a|d
") do echo %%i
1443 for /f "delims
=|
" %%i in ("a |d
") do echo %%i
1444 for /f "delims
=|
" %%i in ("a d|
") do echo %%i
1445 for /f "delims
=|
" %%i in ("a d|
") do echo %%i
1446 for /f "delims
==" %%i in ("C r
=d|
") do echo %%i
1447 for /f "delims
=" %%i in ("foo bar baz
") do echo %%i
1448 for /f "delims
=" %%i in ("c
:\foo bar baz\..
") do echo %%~fi
1449 echo ------ skip option
1453 for /f "skip
=2" %%i in (foo) do echo %%i
1454 for /f "skip
=3" %%i in (foo) do echo %%i > output_file
1455 if not exist output_file (echo no output) else (del output_file)
1456 for /f "skip
=4" %%i in (foo) do echo %%i > output_file
1457 if not exist output_file (echo no output) else (del output_file)
1458 for /f "skip
=02" %%i in (foo) do echo %%i
1459 for /f "skip
=0x2" %%i in (foo) do echo %%i
1460 for /f "skip
=1" %%i in ("skipme
") do echo %%i > output_file
1461 if not exist output_file (echo no output) else (del output_file)
1462 echo ------ tokens= option
1464 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
1465 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
1466 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
1467 rem Show * means the rest
1468 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
1469 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
1470 rem Show * means the rest (not tokenized and rebuilt)
1471 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
1472 rem Order is irrelevant
1473 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
1474 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
1475 rem Duplicates are ignored
1476 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
1477 rem Large tokens are allowed
1478 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
1479 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1480 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
1481 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
1482 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1483 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
1484 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
1485 rem Show negative ranges have no effect
1486 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
1487 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
1488 rem Show duplicates stop * from working
1489 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
1490 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
1491 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
1492 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
1496 echo ------------ Testing del ------------
1498 echo deleting 'file'
1501 echo errorlevel is 0, good
1503 echo unexpected errorlevel, got %errorlevel%
1506 echo successfully deleted 'file'
1508 echo error deleting 'file'
1510 echo attempting to delete 'file', even though it is not present
1513 echo errorlevel is 0, good
1515 echo unexpected errorlevel, got %errorlevel%
1518 echo ------------ Testing del /a ------------
1519 del /f/q *.test > nul
1522 echo not-r > not-r.test
1524 if not exist not-r.test echo not-r.test not found before delete, bad
1526 if not exist not-r.test echo not-r.test not found after delete, good
1528 if not exist r.test echo r.test not found before delete, bad
1529 if exist r.test echo r.test found before delete, good
1531 if not exist r.test echo r.test not found after delete, good
1532 if exist r.test echo r.test found after delete, bad
1534 echo ------------ Testing del /q ------------
1538 echo abc > file2.dat
1539 rem If /q doesn't work, cmd will prompt and the test case should hang
1541 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1542 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1546 echo ------------ Testing del /s ------------
1551 echo there > file2.dat
1552 echo bub > file3.dat
1553 echo bye > "file with spaces.dat
"
1555 del /s file1.dat > nul
1556 del file2.dat /s > nul
1557 del "file3.dat
" /s > nul
1558 del "file with spaces.dat
" /s > nul
1560 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1561 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1562 if exist "file with spaces.dat
" echo Del /s failed on "file with spaces.dat
"
1563 if exist "file with spaces.dat
" del "file with spaces.dat
"
1568 echo ------------ Testing rename ------------
1569 mkdir foobar & cd foobar
1570 echo --- ren and rename are synonymous
1573 if exist foo echo foo should be renamed!
1574 if exist bar echo foo renamed to bar
1576 if exist bar echo bar should be renamed!
1577 if exist foo echo bar renamed to foo
1578 echo --- name collision
1588 echo --- rename read-only files
1592 if not exist file1 (
1594 echo read-only file renamed
1597 echo read-only file not renamed!
1599 echo --- rename directories
1611 echo read-only dir renamed
1614 echo --- rename in other directory
1615 if not exist baz\abc (
1616 echo rename impossible in other directory
1617 if exist foo echo original file still present
1619 echo shouldn't rename in other directory!
1620 if not exist foo echo original file not present anymore
1622 cd .. & rd /s/q foobar
1624 echo ------------ Testing move ------------
1625 mkdir foobar & cd foobar
1628 move foo bar > nul 2>&1
1631 echo file move succeeded
1636 move /Y bar baz > nul 2>&1
1639 echo file move with overwrite succeeded
1642 echo file overwrite impossible!
1648 move baz bazro > nul 2>&1
1651 echo read-only files are moveable
1652 move bazro baz > nul 2>&1
1655 echo read-only file not moved!
1659 move baz rep > nul 2>&1
1662 echo file moved in subdirectory
1666 move rep\baz . > nul 2>&1
1667 move /Y baz baz > nul 2>&1
1669 echo moving a file to itself should be a no-op!
1671 echo moving a file to itself is a no-op
1673 echo ErrorLevel: %ErrorLevel%
1676 echo --- directory move
1680 move baz foo\bar > nul 2>&1
1682 if exist foo\bar\baz\baz2 (
1683 echo simple directory move succeeded
1688 move baz baz > nul 2>&1
1689 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1690 echo ------ dir in dir move
1695 move foo bar > nul 2>&1
1703 cd .. & rd /s/q foobar
1705 echo ------------ Testing mkdir ------------
1707 echo --- md and mkdir are synonymous
1714 echo --- creating an already existing directory/file must fail
1723 echo --- multilevel path creation
1735 mkdir ..\..\..\foo\bar2
1738 mkdir ..\..\..\foo\bar2
1740 rmdir ..\..\..\foo\bar2
1748 echo --- trailing backslashes
1751 if exist foo (rmdir foo & echo dir created
1752 ) else ( echo dir not created )
1754 echo --- invalid chars
1756 echo mkdir ? gives errorlevel %ErrorLevel%
1759 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1762 echo mkdir foo\? gives errorlevel %ErrorLevel%
1763 if exist foo (rmdir foo & echo ok, foo created
1764 ) else ( echo foo not created )
1767 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1770 echo bad, foo not created
1774 echo ok, foo\bar created
1780 echo --- multiple directories at once
1781 mkdir foobaz & cd foobaz
1782 mkdir foo bar\baz foobar "bazbaz
" .\"zabzab"
1783 if exist foo
(echo foo created
) else echo foo
not created
!
1784 if exist bar
(echo bar created
) else echo bar
not created
!
1785 if exist foobar
(echo foobar created
) else echo foobar
not created
!
1786 if exist bar
\baz
(echo bar
\baz created
) else echo bar
\baz
not created
!
1787 if exist bazbaz
(echo bazbaz created
) else echo bazbaz
not created
!
1788 if exist zabzab
(echo zabzab created
) else echo zabzab
not created
!
1789 cd ..
& rd /s
/q foobaz
1792 echo mkdir foo\
* errorlevel %ErrorLevel%
1793 if exist foo
(rmdir foo
& echo ok
, foo created
1794 ) else ( echo bad
, foo
not created
)
1796 echo ------------ Testing
rmdir ------------
1798 rem rd and rmdir are synonymous
1802 if not exist foobar
echo dir removed
1806 if not exist foobar
echo dir removed
1807 rem Removing nonexistent directory
1810 rem Removing single-level directories
1814 if exist foo
echo file
not removed
1820 if exist foo
echo non
-empty
dir not removed
1825 if exist foo
echo non
-empty
dir not removed
1832 echo recursive
rmdir succeeded
1839 echo foo
> foo
\bar
\brol
1840 rmdir /s
/Q foo
2>&1
1842 echo recursive
rmdir succeeded
1849 rem multiples directories at once
1850 mkdir foobaz
& cd foobaz
1854 rd /s
/q foo bar foobar
1855 if not exist foo
(echo foo removed
) else echo foo
not removed
!
1856 if not exist bar
(echo bar removed
) else echo bar
not removed
!
1857 if not exist foobar
(echo foobar removed
) else echo foobar
not removed
!
1858 if not exist bar
\baz
(echo bar
\baz removed
) else echo bar
\baz
not removed
!
1859 cd ..
& rd /s
/q foobaz
1861 echo ------------ Testing pushd
/popd
------------
1863 echo --- popd is no
-op
when dir stack is empty
1866 echo --- pushing non
-existing
dir
1869 echo --- basic behaviour
1894 echo ------------ Testing
attrib ------------
1895 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
1896 mkdir foobar
& cd foobar
1897 echo foo original contents
> foo
1900 echo --- read
-only attribute
1901 rem Read-only files cannot be altered or deleted, unless forced
1909 echo Read
-only file
not deleted
1911 echo Should
not delete read
-only file
!
1915 echo Read
-only file forcibly deleted
1917 echo Should delete read
-only file with
del /F
!
1921 cd ..
& rd /s
/q foobar
1922 echo --- recursive behaviour
1923 mkdir foobar
\baz
& cd foobar
1929 attrib +R l
*vel?
/S
> nul
2>&1
1935 cd ..
& rd /s
/q foobar
1936 echo --- folders processing
1942 attrib +r baz
/s
/d
> nul
2>&1
1948 rem Oddly windows allows file creation in a read-only directory...
1949 if exist baz\lala
(echo file created in read
-only
dir) else echo file
not created
1950 cd ..
& rd /s
/q foobar
1952 echo ------------ Testing assoc
------------
1953 rem Modifying associations requires some privileges...
1954 net session
>nul
2>&1
1955 if errorlevel 1 goto :SkipAssoc
1957 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1958 rem FIXME Revise once || conditional execution is fixed
1959 mkdir foobar
& cd foobar
1960 echo --- setting association
1968 rem association set system-wide
1969 echo @
echo off
> tmp.
cmd
1970 echo echo +++>> tmp.
cmd
1971 echo assoc .foo
>> tmp.
cmd
1974 echo --- resetting association
1980 rem association removal set system-wide
1981 cmd /c tmp.
cmd > baz
1984 cd ..
& rd /s
/q foobar
1987 echo --- setting association
1993 echo --- resetting association
2000 echo ------------ Testing ftype
------------
2001 rem Modifying associations requires some privileges...
2002 net session
>nul
2>&1
2003 if errorlevel 1 goto :SkipFType
2004 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2005 rem FIXME Revise once || conditional execution is fixed
2006 mkdir foobar
& cd foobar
2007 echo --- setting association
2012 ftype footype
=foo_opencmd
2016 rem association set system-wide
2017 echo @
echo off
> tmp.
cmd
2018 echo echo +++>> tmp.
cmd
2019 echo ftype footype
>> tmp.
cmd
2022 echo --- resetting association
2025 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2026 setlocal EnableDelayedExpansion
2027 set WINE_FOO
=original value
2030 for /F
%%i in
('type baz') do (set WINE_FOO
=buggyXP
)
2031 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2032 rem FIXME Revisit once a grep-like program like ftype is implemented
2033 rem (e.g. to check baz's size using dir /b instead)
2036 rem cleanup registry
2037 echo REGEDIT4
> regCleanup.reg
2038 echo.
>> regCleanup.reg
2039 echo [-HKEY_CLASSES_ROOT
\footype
]>> regCleanup.reg
2040 regedit
/s regCleanup.reg
2043 cd ..
& rd /s
/q foobar
2046 echo --- setting association
2048 echo footype
=foo_opencmd
2050 echo footype
=foo_opencmd
2052 echo footype
=foo_opencmd
2053 echo --- resetting association
2057 echo ------------ Testing
CALL ------------
2058 mkdir foobar
& cd foobar
2059 echo --- external script
2060 echo echo foo
%%1> foo.
cmd
2063 echo echo %%1 %%2 > foo.
cmd
2065 call foo.
cmd foo bar
2072 echo --- internal routines
2073 call :testRoutine :testRoutine
2074 goto :endTestRoutine
2080 call :testRoutineArgs foo
2081 call :testRoutineArgs foo bar
2082 call :testRoutineArgs foo
""
2083 call :testRoutineArgs "" bar
2084 call :testRoutineArgs foo
''
2085 call :testRoutineArgs '' bar
2086 goto :endTestRoutineArgs
2092 echo --- with builtins
2095 if exist foo
(echo foo created
) else echo foo should
exist!
2097 set WINE_FOOBAZ_VAR
=foobaz
2098 call echo Should expand
%WINE_FOOBAZ_VAR%
2099 set WINE_FOOBAZ_VAR
=
2103 if 1==1 call del batfile
2105 if exist batfile
echo batfile shouldn
't exist
2106 rem ... but not for 'if' or 'for'
2107 call if 1==1 echo bar 2> nul
2110 call for %%i in (foo bar baz) do echo %%i 2> nul
2112 rem First look for programs in the path before trying a builtin
2113 echo echo non-builtin dir> dir.cmd
2116 rem The below line equates to call (, which does nothing, then the
2117 rem subsequent lines are executed.
2122 rem The below line equates to call if, which always fails, then the
2123 rem subsequent lines are executed. Note cmd.exe swallows all lines
2130 call call call echo passed
2131 cd .. & rd /s/q foobar
2133 echo ------------ Testing SHIFT ------------
2135 call :shiftFun p1 p2 p3 p4 p5
2139 echo '%1' '%2' '%3' '%4' '%5'
2141 echo '%1' '%2' '%3' '%4' '%5'
2143 echo '%1' '%2' '%3' '%4' '%5'
2145 echo '%1' '%2' '%3' '%4' '%5'
2147 echo '%1' '%2' '%3' '%4' '%5'
2149 echo '%1' '%2' '%3' '%4' '%5'
2153 echo ------------ Testing cmd invocation ------------
2154 rem FIXME: only a stub ATM
2155 echo --- a batch file can delete itself
2156 echo del foo.cmd>foo.cmd
2158 if not exist foo.cmd (
2159 echo file correctly deleted
2161 echo file should be deleted!
2164 echo --- a batch file can alter itself
2165 echo echo bar^>foo.cmd>foo.cmd
2166 cmd /q /c foo.cmd > NUL 2>&1
2171 echo file not created!
2174 echo ---------- Testing copy
2177 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2180 echo CCCCCCCCC> file3
2186 echo Passed: Found expected %1
2188 echo Failed: Did not find expected %1
2190 del /q "%1" >nul 2>&1
2192 if not "%1"=="" goto :CheckExist
2197 echo Passed: Did not find %1
2199 echo Failed: Unexpectedly found %1
2200 del /q "%1" >nul 2>&1
2203 if not "%1"=="" goto :CheckNotExist
2206 rem Note: No way to check file size on NT4 so skip the test
2209 echo Failed: File missing when requested filesize check [%2]
2210 goto :ContinueFileSizeChecks
2212 for %%i in (%1) do set WINE_filesize=%%~zi
2213 if "%WINE_filesize%"=="%2" (
2214 echo Passed: file size check on %1 [%WINE_filesize%]
2216 if "%WINE_filesize%"=="%%~zi" (
2217 echo Skipping file size check on NT4
2219 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2222 :ContinueFileSizeChecks
2225 if not "%1"=="" goto :CheckFileSize
2230 rem -----------------------
2231 rem Simple single file copy
2232 rem -----------------------
2233 rem Simple single file copy, normally used syntax
2234 copy file1 dummy.file >nul 2>&1
2235 if errorlevel 1 echo Incorrect errorlevel
2236 call :CheckExist dummy.file
2238 rem Simple single file copy, destination supplied as two forms of directory
2239 copy file1 dir1 >nul 2>&1
2240 if errorlevel 1 echo Incorrect errorlevel
2241 call :CheckExist dir1\file1
2243 copy file1 dir1\ >nul 2>&1
2244 if errorlevel 1 echo Incorrect errorlevel
2245 call :CheckExist dir1\file1
2247 rem Simple single file copy, destination supplied as fully qualified destination
2248 copy file1 dir1\file99 >nul 2>&1
2249 if errorlevel 1 echo Incorrect errorlevel
2250 call :CheckExist dir1\file99
2252 rem Simple single file copy, destination not supplied
2254 copy ..\file1 >nul 2>&1
2255 if errorlevel 1 echo Incorrect errorlevel
2256 call :CheckExist file1
2259 rem Simple single file copy, destination supplied as nonexistent directory
2260 copy file1 dir2\ >nul 2>&1
2261 if not errorlevel 1 echo Incorrect errorlevel
2262 call :CheckNotExist dir2 dir2\file1
2264 rem -----------------------
2266 rem -----------------------
2267 rem Simple single file copy, destination supplied as two forms of directory
2268 copy file? dir1 >nul 2>&1
2269 if errorlevel 1 echo Incorrect errorlevel
2270 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2272 copy file* dir1\ >nul 2>&1
2273 if errorlevel 1 echo Incorrect errorlevel
2274 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2276 rem Simple single file copy, destination not supplied
2278 copy ..\file*.* >nul 2>&1
2279 if errorlevel 1 echo Incorrect errorlevel
2280 call :CheckExist file1 file2 file3
2283 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2284 copy file? dir2\ >nul 2>&1
2285 if not errorlevel 1 echo Incorrect errorlevel
2286 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2288 rem ------------------------------------------------
2289 rem Confirm overwrite works (cannot test prompting!)
2290 rem ------------------------------------------------
2291 copy file1 testfile >nul 2>&1
2292 copy /y file2 testfile >nul 2>&1
2293 call :CheckExist testfile
2295 rem ------------------------------------------------
2296 rem Test concatenation
2297 rem ------------------------------------------------
2298 rem simple case, no wildcards
2299 copy file1+file2 testfile >nul 2>&1
2300 if errorlevel 1 echo Incorrect errorlevel
2301 call :CheckExist testfile
2303 rem simple case, wildcards, no concatenation
2304 copy file* testfile >nul 2>&1
2305 if errorlevel 1 echo Incorrect errorlevel
2306 call :CheckExist testfile
2308 rem simple case, wildcards, and concatenation
2310 copy file*+fred testfile >nul 2>&1
2311 if errorlevel 1 echo Incorrect errorlevel
2312 call :CheckExist testfile
2314 rem simple case, wildcards, and concatenation
2315 copy fred+file* testfile >nul 2>&1
2316 if errorlevel 1 echo Incorrect errorlevel
2317 call :CheckExist testfile
2319 rem Calculate destination name
2320 copy fred+file* dir1 >nul 2>&1
2321 if errorlevel 1 echo Incorrect errorlevel
2322 call :CheckExist dir1\fred
2324 rem Calculate destination name
2325 copy fred+file* dir1\ >nul 2>&1
2326 if errorlevel 1 echo Incorrect errorlevel
2327 call :CheckExist dir1\fred
2329 rem Calculate destination name (none supplied)
2331 copy ..\fred+..\file* >nul 2>&1
2332 if errorlevel 1 echo Incorrect errorlevel
2333 call :CheckExist fred
2335 copy ..\fr*+..\file1 >nul 2>&1
2336 if errorlevel 1 echo Incorrect errorlevel
2337 call :CheckExist fred
2340 rem ******************************************************************
2341 rem ASCII and BINARY tests
2342 rem Note: hard coded numbers deliberate because need to ensure whether
2343 rem an additional EOF has been added or not. There is no way to handle
2344 rem EOFs in batch, so assume if a single byte appears, it's an EOF
!
2345 rem ******************************************************************
2347 rem Confirm original sizes of file1,2,3
2348 call :CheckFileSize file1
5 file2
8 file3
11
2352 rem ----------------------------------------------
2353 rem Show concatenation defaults copy to ascii mode
2354 rem ----------------------------------------------
2355 rem Simple default copy source to destination (should not append EOF 5)
2356 copy ..
\file
1 file1_default
>nul
2>&1
2357 call :CheckFileSize file1_default
5
2359 rem Simple binary copy source to destination (should not append EOF 5)
2360 copy /b ..
\file
1 file1_default2
>nul
2>&1
2361 call :CheckFileSize file1_default2
5
2363 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2364 copy /a ..
\file
1 file1_plus_eof
>nul
2>&1
2365 call :CheckFileSize file1_plus_eof
6
2366 copy /a ..
\file
2 file2_plus_eof
>nul
2>&1
2367 call :CheckFileSize file2_plus_eof
9
2368 copy /a ..
\file
3 file3_plus_eof
>nul
2>&1
2369 call :CheckFileSize file3_plus_eof
12
2371 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2372 copy /a ..
\file
1+..
\file
2 file12_plus_eof
>nul
2>&1
2373 call :CheckFileSize file12_plus_eof
14
2375 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2376 copy /b ..
\file
1+..
\file
2 file12_no_eof
>nul
2>&1
2377 call :CheckFileSize file12_no_eof
13
2379 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2380 copy ..
\file
1+..
\file
2 file12_eof2
>nul
2>&1
2381 call :CheckFileSize file12_eof2
14
2383 rem --------------------------------------------------------------
2384 rem Show ascii source copy stops at first EOF, binary does the lot
2385 rem --------------------------------------------------------------
2386 copy file1_plus_eof
/b file1_binary_srccopy
/b
>nul
2>&1
2387 call :CheckFileSize file1_binary_srccopy
6
2389 copy file1_plus_eof
/a file1_ascii_srccopy
/b
>nul
2>&1
2390 call :CheckFileSize file1_ascii_srccopy
5
2392 rem --------------------------------------------------------------
2393 rem Show results of concatenating files (ending in EOFs) and /a /b
2394 rem --------------------------------------------------------------
2396 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2397 copy file1_plus_eof
+file2_plus_eof
+file3_plus_eof file123_default_copy
>nul
2>&1
2398 call :CheckFileSize file123_default_copy
25
2399 copy /a file1_plus_eof
+file2_plus_eof
+file3_plus_eof file123_ascii_copy
>nul
2>&1
2400 call :CheckFileSize file123_ascii_copy
25
2402 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2403 copy /b file1_plus_eof
+ file2_plus_eof
+ file3_plus_eof file123_binary_copy
>nul
2>&1
2404 call :CheckFileSize file123_binary_copy
27
2406 rem We can select which we want the eofs from by postfixing it with /a or /b
2407 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2408 copy file1_plus_eof
/b
+ file2_plus_eof
/a
+ file3_plus_eof
/b file123_mixed_copy1
>nul
2>&1
2409 call :CheckFileSize file123_mixed_copy1
26
2411 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2412 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2413 rem Note the delta between this and the previous one also shows that the destination
2414 rem ascii/binary is inherited from the last /a or /b on the line
2415 copy file1_plus_eof
/b
+ file2_plus_eof
/a
+ file3_plus_eof
/b file123_mixed_copy2
/a
>nul
2>&1
2416 call :CheckFileSize file123_mixed_copy2
27
2418 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2419 rem Note the delta between the next two also shows that the destination ascii/binary is
2420 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2421 copy file1_plus_eof
/a
+ file2_plus_eof
/b
+ file3_plus_eof
/a file123_mixed_copy3
>nul
2>&1
2422 call :CheckFileSize file123_mixed_copy3
26
2423 copy file1_plus_eof
/a
+ file2_plus_eof
/b
+ file3_plus_eof
/a file123_mixed_copy4
/b
>nul
2>&1
2424 call :CheckFileSize file123_mixed_copy4
25
2426 rem -------------------------------------------------------------------------------------------
2427 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2428 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2429 rem -------------------------------------------------------------------------------------------
2431 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2432 copy /b file1_plus_eof
+ file2_plus_eof
+ file3_plus_eof file123_mixed_copy5
/a
>nul
2>&1
2433 call :CheckFileSize file123_mixed_copy5
28
2435 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2436 copy /b file1_plus_eof
+ file3_plus_eof file123_mixed_copy6
/a
>nul
2>&1
2437 call :CheckFileSize file123_mixed_copy6
19
2439 rem One file has EOF, but doesn't get an extra one, i.e. 6
2440 copy /b file1_plus_eof file123_mixed_copy7
/a
>nul
2>&1
2441 call :CheckFileSize file123_mixed_copy7
6
2443 rem Syntax means concatenate so ascii destination kicks in
2444 copy /b file1_plus_eof
* file123_mixed_copy8
/a
>nul
2>&1
2445 call :CheckFileSize file123_mixed_copy8
7
2450 rem ---------------------------------------
2451 rem Error combinations
2452 rem ---------------------------------------
2453 rem Specify source directory but name is a file
2455 copy file1\ dir1\
>NUL
2>&1
2456 if errorlevel 1 echo Passed
: errorlevel invalid check
1
2457 if not errorlevel 1 echo Failed
: errorlevel invalid check
1
2458 call :CheckNotExist dir1
\file
1
2460 rem Overwrite same file
2462 copy file1 file1
>NUL
2>&1
2463 if errorlevel 1 echo Passed
: errorlevel invalid check
2
2464 if not errorlevel 1 echo Failed
: errorlevel invalid check
2
2466 rem Supply same file identified as a directory
2468 copy file1 file1\
>NUL
2>&1
2469 if errorlevel 1 echo Passed
: errorlevel invalid check
3
2470 if not errorlevel 1 echo Failed
: errorlevel invalid check
3
2475 echo ------------ Testing
setlocal/endlocal ------------
2477 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2478 mkdir foobar
& cd foobar
2479 echo --- enable
/disable extensions
2480 setlocal DisableEXTensions
2481 echo ErrLev
: %ErrorLevel%
2483 echo ErrLev
: %ErrorLevel%
2484 echo @
echo off
> tmp.
cmd
2485 echo echo ErrLev
: %%ErrorLevel%%>> tmp.
cmd
2486 rem Enabled by default
2488 cmd /E
:OfF /C tmp.
cmd
2489 cmd /e
:oN /C tmp.
cmd
2491 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2492 echo --- setlocal with corresponding
endlocal
2493 rem %CD% does not tork on NT4 so use the following workaround
2494 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2495 echo @
echo off
> test.
cmd
2496 echo echo %%WINE_VAR%%>> test.
cmd
2497 echo setlocal>> test.
cmd
2498 echo set WINE_VAR
=localval
>> test.
cmd
2499 echo md foobar2
>> test.
cmd
2500 echo cd foobar2
>> test.
cmd
2501 echo echo %%WINE_VAR%%>> test.
cmd
2502 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2503 echo endlocal>> test.
cmd
2504 echo echo %%WINE_VAR%%>> test.
cmd
2505 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2506 set WINE_VAR
=globalval
2509 for /d
%%i in
(.
) do echo %%~dpnxi
2513 echo --- setlocal with no corresponding
endlocal
2514 echo @
echo off
> test.
cmd
2515 echo echo %%WINE_VAR%%>> test.
cmd
2516 echo setlocal>> test.
cmd
2517 echo set WINE_VAR
=localval
>> test.
cmd
2518 echo md foobar2
>> test.
cmd
2519 echo cd foobar2
>> test.
cmd
2520 echo echo %%WINE_VAR%%>> test.
cmd
2521 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2522 set WINE_VAR
=globalval
2523 rem %CD% does not tork on NT4 so use the following workaround
2524 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2527 for /d
%%i in
(.
) do echo %%~dpnxi
2531 echo --- setlocal within same batch program
2535 rem %CD% does not tork on NT4 so use the following workaround
2536 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2543 if "%WINE_var1%"=="one" echo Var1 ok
1
2544 if "%WINE_var2%"=="two" echo Var2 ok
2
2545 if "%WINE_var3%"=="three" echo Var3 ok
3
2546 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2547 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok
1
2549 if "%WINE_var1%"=="one" echo Var1 ok
1
2550 if "%WINE_var2%"=="two" echo Var2 ok
2
2551 if "%WINE_var3%"=="" echo Var3 ok
3
2552 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2553 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok
2
2555 if "%WINE_var1%"=="one" echo Var1 ok
1
2556 if "%WINE_var2%"=="" echo Var2 ok
2
2557 if "%WINE_var3%"=="" echo Var3 ok
3
2558 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2559 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok
3
2563 echo --- Mismatched
set and
end locals
2567 rem %CD% does not tork on NT4 so use the following workaround
2568 for /d
%%i in
(.
) do set WINE_curdir
=%%~dpnxi
2570 echo @
echo off
> 2set1end.
cmd
2571 echo echo %%WINE_var%%>> 2set1end.
cmd
2572 echo setlocal>> 2set1end.
cmd
2573 echo set WINE_VAR
=2set1endvalue1
>> 2set1end.
cmd
2574 echo cd ..
\foodir
3>> 2set1end.
cmd
2575 echo setlocal>> 2set1end.
cmd
2576 echo set WINE_VAR
=2set1endvalue2
>> 2set1end.
cmd
2577 echo cd ..
\foodir
4>> 2set1end.
cmd
2578 echo endlocal>> 2set1end.
cmd
2579 echo echo %%WINE_var%%>> 2set1end.
cmd
2580 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 2set1end.
cmd
2582 echo @
echo off
> 1set2end.
cmd
2583 echo echo %%WINE_var%%>> 1set2end.
cmd
2584 echo setlocal>> 1set2end.
cmd
2585 echo set WINE_VAR
=1set2endvalue1
>> 1set2end.
cmd
2586 echo cd ..
\foodir
3>> 1set2end.
cmd
2587 echo endlocal>> 1set2end.
cmd
2588 echo echo %%WINE_var%%>> 1set2end.
cmd
2589 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 1set2end.
cmd
2590 echo endlocal>> 1set2end.
cmd
2591 echo echo %%WINE_var%%>> 1set2end.
cmd
2592 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 1set2end.
cmd
2594 echo --- Extra
setlocal in called batch
2596 rem -- setlocal1 == this batch, should never be used inside a called routine
2600 call %WINE_CURDIR%\
2set1end.
cmd
2603 for /d
%%i in
(.
) do echo %%~dpnxi
2606 for /d
%%i in
(.
) do echo %%~dpnxi
2609 echo --- Extra
endlocal in called batch
2611 rem -- setlocal1 == this batch, should never be used inside a called routine
2615 call %WINE_CURDIR%\
1set2end.
cmd
2618 for /d
%%i in
(.
) do echo %%~dpnxi
2621 for /d
%%i in
(.
) do echo %%~dpnxi
2624 echo --- endlocal in called function rather than batch pgm is ineffective
2630 call :endlocalroutine
2634 goto :endlocalfinished
2652 cd ..
& rd /q
/s foobar
2654 echo ------------ Testing
Errorlevel ------------
2655 rem WARNING: Do *not* add tests using ErrorLevel after this section
2656 should_not_exist
2> nul
> nul
2658 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2659 rem See http://www.robvanderwoude.com/exit.php
2662 if errorlevel 2 echo errorlevel too high
, bad
2663 if errorlevel 1 echo errorlevel just right
, good
2664 if errorlevel 01 echo errorlevel with leading zero just right
, good
2665 if errorlevel -1 echo errorlevel with negative number OK
2666 if errorlevel 0x1 echo hexa should
not be recognized
!
2667 if errorlevel 1a
echo invalid error level recognized
!
2669 echo abc
%ErrorLevel%def
2670 if errorlevel 1 echo errorlevel nonzero
, bad
2671 if not errorlevel 1 echo errorlevel zero
, good
2672 if not errorlevel 0x1 echo hexa should
not be recognized
!
2673 if not errorlevel 1a
echo invalid error level recognized
!
2674 rem Now verify that setting a real variable hides its magic variable
2676 echo %ErrorLevel% should be
7
2677 if errorlevel 7 echo setting var worked too well
, bad
2679 echo %ErrorLevel% should still be
7
2681 echo ------------ Testing
GOTO ------------
2683 echo FAILURE at dest
1
2685 echo goto with no leading space worked
2686 if a
==a
goto :dest1b
2687 echo FAILURE at dest
1b
2689 echo goto with colon and no leading space worked
2691 echo FAILURE at dest
2
2693 echo goto with a leading space worked
2695 echo FAILURE at dest
3
2697 echo goto with a leading tab worked
2699 echo FAILURE at dest
4
2701 echo goto with a following space worked
2703 echo FAILURE at dest
5
2704 :dest5&& echo FAILURE
2705 echo goto with following amphersands worked
2707 del failure.txt
>nul
2>&1
2709 echo FAILURE at dest
6
2711 if exist FAILURE.TXT
echo FAILURE at dest
6 as file exists
2712 echo goto with redirections worked
2713 del FAILURE.TXT
>nul
2>&1
2715 :: some text that is ignored |
dir >cmd_output | another test
2716 if exist cmd_output
echo FAILURE at dest
6 as file exists
2717 echo Ignoring double colons worked
2718 del cmd_output
>nul
2>&1
2720 rem goto a label which does not exist issues an error message and
2721 rem acts the same as goto :EOF, and ensure ::label is never matched
2722 del testgoto.bat
>nul
2>&1
2723 echo goto :dest7 ^
>nul
2^
>^
&1 >> testgoto.bat
2724 echo echo FAILURE at dest
7 - Should have
not found
label and issued an error plus ended the batch
>> testgoto.bat
2725 echo ::dest7>> testgoto.bat
2726 echo echo FAILURE at dest
7 - Incorrectly went to
label >> testgoto.bat
2728 del testgoto.bat
>nul
2>&1
2730 del testgoto.bat
>nul
2>&1
2731 echo goto ::dest8 ^
>nul
2^
>^
&1 >> testgoto.bat
2732 echo echo FAILURE at dest
8 - Should have
not found
label and issued an error plus ended the batch
>> testgoto.bat
2733 echo ::dest8>> testgoto.bat
2734 echo echo FAILURE at dest
8 - Incorrectly went to
label >> testgoto.bat
2736 del testgoto.bat
>nul
2>&1
2739 echo FAILURE at dest
9
2741 echo FAILURE at dest
91
2743 echo label with mixed whitespace and no
echo worked
2745 if h
==h
goto :dest10:this is ignored
2746 echo FAILURE at dest
10
2747 :dest10:this is also ignored
2748 echo Correctly ignored trailing information
2750 echo ------------ Testing
PATH ------------
2751 set WINE_backup_path
=%path%
2758 set path=%WINE_backup_path%
2759 set WINE_backup_path
=
2761 echo ------------ Testing combined CALLs
/GOTOs
------------
2762 echo @
echo off
>foo.
cmd
2763 echo goto :eof>>foot.
cmd
2765 echo echo world
>>foo.
cmd
2767 echo @
echo off
>foot.
cmd
2768 echo echo cheball
>>foot.
cmd
2770 echo call :bar>>foot.
cmd
2771 echo if "%%1"=="deleteMe" (del foot.
cmd)>>foot.
cmd
2772 echo goto :eof>>foot.
cmd
2775 echo echo barbare
>>foot.
cmd
2776 echo goto :eof>>foot.
cmd
2782 rem Script execution stops after the following line
2805 echo Final message is
not output since earlier
'foot' processing stops script execution
2806 echo Do NOT add any tests below this line
2808 echo ------------ Done
, jumping to EOF
-----------
2810 rem Subroutine to set errorlevel and return
2811 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
2814 rem This line runs under cmd in windows NT 4, but not in more modern versions.