1 echo Tests
for cmd's builtin commands
4 echo ------------ Testing 'echo' [ON] ------------
6 echo 'singlequotedword
'
7 echo "doublequotedword"
20 echo word@space@@space@
24 echo@tab@word@tab@@space@
36 echo ------------ Testing 'echo' [OFF] ------------
38 echo 'singlequotedword
'
39 echo "doublequotedword"
52 echo word@space@@space@
56 echo@tab@word@tab@@space@
62 echo ------------ Testing mixed echo modes ------------
63 echo @echo on> mixedEchoModes.cmd
64 echo if 1==1 echo foo>> mixedEchoModes.cmd
65 echo if 1==1 @echo bar>> mixedEchoModes.cmd
66 echo @echo off>> mixedEchoModes.cmd
67 echo if 1==1 echo foo2>> mixedEchoModes.cmd
68 echo if 1==1 @echo bar2>> mixedEchoModes.cmd
69 type mixedEchoModes.cmd
70 cmd /c mixedEchoModes.cmd
71 del mixedEchoModes.cmd
73 echo ------------ Testing parameterization ------------
75 call :TestParm "a b c"
76 call :TestParm "a b"\c
77 call :TestParm a=~`+,.{}!+b
81 call :TestParm a[b]{c}(d)e
82 call :TestParm a&echo second line
83 call :TestParm a b,,,c
84 call :TestParm a==b;;c
93 echo ------------ Testing rem ------------
98 rem echo foo & echo bar
101 rem@tab@echo foo & echo bar
107 rem echo foo & echo bar
110 rem@tab@echo foo & echo bar
113 echo ------------ Testing redirection operators ------------
114 mkdir foobar & cd foobar
115 echo --- stdout redirection
124 echo foo@tab@1>@tab@foo
145 echo --- stdout appending
163 echo foo7 7>> foo || (echo not supported & del foo)
164 if exist foo (type foo) else echo not supported
165 echo --- redirections within IF statements
166 if 1==1 echo foo1>bar
169 if 1==1 (echo foo2>bar) else echo baz2>bar
171 if 1==1 (echo foo3) else echo baz3>bar
172 type bar || echo file does not exist, ok
173 if 1==1 (echo foo4>bar) else echo baz4>bar
175 if 1==0 (echo foo5>bar) else echo baz5>bar
177 if 1==0 (echo foo6) else echo baz6 1>bar
179 if 1==0 (echo foo7 1>bar) else echo baz7>bar
181 if 1==0 (echo foo8 1>bar) else echo baz8>bak
183 if 1==1 (echo foo>bar & echo baz)
190 (if 1==1 (echo A) else echo B) > C
192 (if 1==0 (echo A) else echo B) > C
194 (if 1==0 (echo A > B) else echo C)
195 cd .. & rd /s/q foobar
197 echo ------------ Testing circumflex escape character ------------
198 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
220 echo bak ^
&& echo baz
2> nul
228 set WINE_FOO
=bar ^| baz
230 rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
231 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
234 set WINE_FOO
=bar ^^^| baz
240 echo ------------ Testing
'set' ------------
242 rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
243 for /f
"delims==" %%i in
('set WINE_ba') do set %%i
=
244 for /f
"delims==" %%i in
('set WINE_foo') do set %%i
=
245 set WINE_FOOBAR
2> nul
> nul
247 set WINE_FOOBAR
= baz
249 echo %WINE_FOOBAR%WINE_FOOBAR
not defined
251 set WINE_FOOBAR
2> nul
252 set WINE_FOOBAR
= baz2
261 echo %WINE_FOOBAR%WINE_FOOBAR
not defined
263 set WINE_FOOBA
2> nul
> nul
269 echo %WINE_FOO%%WINE_BAR%
272 set WINE_FOO
=%WINE_FOO%
273 echo %WINE_FOO%WINE_FOO
not defined
278 echo set "WINE_FOO=bar" should
not include the quotes in the variable value
285 set WINE_FOO
=foo@space@
287 set WINE_FOO
=foo@tab@
289 rem Space symbol must appear in `var`
290 set WINE_FOO
=value@space@
292 rem Space symbol must NOT appear in `var`
293 set "WINE_FOO=value"@space@
296 set WINE_FOO
=jim fred
298 set WINE_FOO
="jim" fred
300 set "WINE_FOO=jim fred"
302 set "WINE_FOO=jim" fred
304 rem Only the final quote ends the string
305 set "WINE_FOO=apple"banana
"grape"orange
309 echo ------------ Testing variable expansion
------------
311 echo ~dp0 should be directory containing batch file
324 echo P
%WINE_UNKNOWN%S
327 echo %ERRORLEVEL%%ERRORLEVEL%
328 echo %ERRORLEVEL%ERRORLEVEL%
335 echo ------------ Testing variable substrings
------------
340 echo '%WINE_VAR:~-2,3%'
341 echo '%WINE_VAR:~-2,1%'
342 echo %WINE_VAR
:~
2,-1%
343 echo %WINE_VAR
:~
2,-3%
344 echo '%WINE_VAR:~-2,-4%'
345 echo %WINE_VAR
:~
-3,-2%
348 echo ------------ Testing variable substitution
------------
349 echo --- in
FOR variables
350 for %%i in
("A B" C
) do echo %%i
351 rem check works when prefix with @
352 @
for %%i in
("A B" C
) do echo %%i
354 for %%i in
("A B" C
) do echo '%%~i'
355 rem fully qualified path
356 for %%f in
("C D" E
) do echo %%~ff
358 for %%i in
("F G" H
) do echo %%~di
360 for %%d in
("I J" K
) do echo %%~pd
362 for %%i in
("L M" N
) do echo %%~ni
364 for %%i in
("O. P.OOL" Q.TABC hello
) do echo '%%~xi'
365 rem path with short path names
366 for %%I in
("R S" T ABCDEFGHIJK.LMNOP
) do echo '%%~sI'
368 for %%i in
("U V" W
) do echo '%%~ai'
370 for %%i in
(foo
) do echo '%%~ai'
371 for %%i in
(foo
) do echo '%%~zi'
374 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
375 for %%i in
("a b" c
) do echo '%%~ti'
377 rem Similar issues as above
378 for %%i in
("a b" c
) do echo '%%~zi'
380 for %%i in
("d e" f
) do echo %%~dpi
381 for %%i in
("g h" i
) do echo %%~sdi
382 for %%i in
("g h" i
) do echo %%~dsi
383 for %%i in
("j k" l.eh
) do echo '%%~xsi'
384 for %%i in
("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
386 echo --- in parameters
387 for %%i in
("A B" C
) do call :echoFun %%i
389 for %%i in
("A B" C
) do call :echoFunQ %%i
390 rem fully qualified path
391 for %%f in
("C D" E
) do call :echoFunF %%f
393 for %%i in
("F G" H
) do call :echoFunD %%i
395 for %%d in
("I J" K
) do call :echoFunP %%d
397 for %%i in
("L M" N
) do call :echoFunN %%i
399 for %%i in
("O. P.OOL" Q.TABC hello
) do call :echoFunX %%i
400 rem path with short path names
401 for %%I in
("R S" T ABCDEFGHIJK.LMNOP
) do call :echoFunS %%I
402 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
404 for %%i in
("d e" f
) do call :echoFunDP %%i
405 for %%i in
("g h" i
) do call :echoFunSD %%i
406 for %%i in
("g h" i
) do call :echoFunDS %%i
407 for %%i in
("j k" l.eh
) do call :echoFunXS %%i
439 rem some NT4 workaround
462 echo ------------ Testing variable delayed expansion
------------
463 rem NT4 doesn't support this
464 echo --- default
mode (load
-time expansion
)
468 if %WINE_FOO% == foo
(
470 if %WINE_FOO% == bar
(echo bar
) else echo foo
474 if %WINE_FOO% == foo
(
476 if !WINE_FOO
! == bar
(echo bar
) else echo foo
479 echo --- runtime
(delayed
) expansion
mode
480 setlocal EnableDelayedExpansion
484 if %WINE_FOO% == foo
(
486 if %WINE_FOO% == bar
(echo bar
) else echo foo
490 if %WINE_FOO% == foo
(
492 if !WINE_FOO
! == bar
(echo bar
) else echo foo
495 setlocal DisableDelayedExpansion
501 echo --- using
/V
cmd flag
502 echo @
echo off
> tmp.
cmd
503 echo set WINE_FOO
=foo
>> tmp.
cmd
504 echo echo %%WINE_FOO%%>> tmp.
cmd
505 echo echo !WINE_FOO
!>> tmp.
cmd
506 echo set WINE_FOO
=>> tmp.
cmd
508 cmd /V
:OfF /C tmp.
cmd
511 echo ------------ Testing conditional execution
------------
512 echo --- unconditional ampersand
513 call :setError 123 & echo foo1
514 echo bar2
& echo foo2
515 mkdir foobar
& cd foobar
517 cd ..
& rd /s
/q foobar
519 echo foobar
not deleted
!
522 ) else echo foobar deleted
523 echo --- on success conditional and
524 call :setError 456 && echo foo3
> foo3
528 ) else echo foo3
not created
529 echo bar4
&& echo foo4
530 echo --- on failure conditional or
531 call :setError 789 ||
echo foo5
532 echo foo6 ||
echo bar6
> bar6
538 echo ------------ Testing
cd ------------
541 echo blabla
> singleFile
543 echo Current
dir: %CD%
558 if not exist foobar
(cd ..
)
560 cd@tab@..@tab@@space@@tab@
562 if not exist foobar
(cd ..
)
576 cd "bar bak@space@
"@tab@@space@
587 echo ------------ Testing type ------------
601 echo ------------ Testing NUL ------------
602 md foobar & cd foobar
603 rem NUL file (non) creation + case insensitivity
604 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
613 rem NUL not special everywhere
616 if not exist foo (echo foo should have been created) else (
620 rem Empty file creation
630 copy a.a+NUL b.b >nul
631 call :CheckFileSize a.a 7 b.b 8
632 copy NUL+a.a b.b >nul
633 call :CheckFileSize a.a 7 b.b 8
635 copy a.a+NUL subdir\ >nul
636 call :CheckFileSize a.a 7 subdir\a.a 8
640 if exist a.a echo Failed
644 cd .. & rd foobar /s /q
646 echo ------------ Testing if/else ------------
647 echo --- if/else should work with blocks
649 echo if seems to work
651 echo if seems to be broken
654 echo else seems to be broken
656 echo else seems to work
659 echo if seems not to detect /c as parameter
661 echo parameter detection seems to be broken
664 echo --- case sensitivity with and without /i option
665 if bar==BAR echo if does not default to case sensitivity
666 if not bar==BAR echo if seems to default to case sensitivity
667 if /i foo==FOO echo if /i seems to work
668 if /i not foo==FOO echo if /i seems to be broken
669 if /I foo==FOO echo if /I seems to work
670 if /I not foo==FOO echo if /I seems to be broken
672 echo --- string comparisons
673 if abc == abc (echo equal) else echo non equal
674 if abc =="abc
" (echo equal) else echo non equal
675 if "abc
"== abc (echo equal) else echo non equal
676 if "abc
"== "abc
" (echo equal) else echo non equal
678 echo --- tabs handling
679 if@tab@1==1 echo doom
680 if @tab@1==1 echo doom
681 if 1==1 (echo doom) else@tab@echo quake
682 if@tab@not @tab@1==@tab@0 @tab@echo lol
683 if 1==0@tab@(echo doom) else echo quake
684 if 1==0 (echo doom)@tab@else echo quake
685 if 1==0 (echo doom) else@tab@echo quake
687 echo --- comparison operators
688 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
689 echo ------ for strings
690 rem NT4 stops processing of the whole batch file as soon as it finds a
691 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
692 rem can't test those here.
693 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
694 if LSS LSS LSS (echo bar)
695 if 1.1 LSS 1.10 (echo floats are handled as strings)
696 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
697 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
698 if /i foo LSS FoOc echo if /i seems to work for LSS
699 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
700 set WINE_STR_PARMS=A B AB BA AA
701 for %%i in (%WINE_STR_PARMS%) do (
702 for %%j in (%WINE_STR_PARMS%) do (
703 call :LSStest %%i %%j))
704 if b LSS B (echo b LSS B) else echo NT4
705 if /I b LSS B echo b LSS B insensitive
706 if b LSS A echo b LSS A
707 if /I b LSS A echo b LSS A insensitive
708 if a LSS B (echo a LSS B) else echo NT4
709 if /I a LSS B echo a LSS B insensitive
710 if A LSS b echo A LSS b
711 if /I A LSS b echo A LSS b insensitive
712 for %%i in (%WINE_STR_PARMS%) do (
713 for %%j in (%WINE_STR_PARMS%) do (
714 call :LEQtest %%i %%j))
715 if b LEQ B (echo b LEQ B) else echo NT4
716 if /I b LEQ B echo b LEQ B insensitive
717 if b LEQ A echo b LEQ A
718 if /I b LEQ A echo b LEQ A insensitive
719 if a LEQ B (echo a LEQ B) else echo NT4
720 if /I a LEQ B echo a LEQ B insensitive
721 if A LEQ b echo A LEQ b
722 if /I A LEQ b echo A LEQ b insensitive
723 for %%i in (%WINE_STR_PARMS%) do (
724 for %%j in (%WINE_STR_PARMS%) do (
725 call :EQUtest %%i %%j))
726 if /I A EQU a echo A EQU a insensitive
727 for %%i in (%WINE_STR_PARMS%) do (
728 for %%j in (%WINE_STR_PARMS%) do (
729 call :NEQtest %%i %%j))
730 for %%i in (%WINE_STR_PARMS%) do (
731 for %%j in (%WINE_STR_PARMS%) do (
732 call :GEQtest %%i %%j))
733 for %%i in (%WINE_STR_PARMS%) do (
734 for %%j in (%WINE_STR_PARMS%) do (
735 call :GTRtest %%i %%j))
736 echo ------ for numbers
737 if -1 LSS 1 (echo negative numbers handled)
738 if not -1 LSS -10 (echo negative numbers handled)
739 if not 9 LSS 010 (echo octal handled)
740 if not -010 LSS -8 (echo also in negative form)
741 if 4 LSS 0x5 (echo hexa handled)
742 if not -1 LSS -0x1A (echo also in negative form)
743 if 11 LSS 101 (echo 11 LSS 101)
744 set WINE_INT_PARMS=0 1 10 9
745 for %%i in (%WINE_INT_PARMS%) do (
746 for %%j in (%WINE_INT_PARMS%) do (
747 call :LSStest %%i %%j))
748 for %%i in (%WINE_INT_PARMS%) do (
749 for %%j in (%WINE_INT_PARMS%) do (
750 call :LEQtest %%i %%j))
751 for %%i in (%WINE_INT_PARMS%) do (
752 for %%j in (%WINE_INT_PARMS%) do (
753 call :EQUtest %%i %%j))
754 if 011 EQU 9 (echo octal ok)
755 if 0xA1 EQU 161 (echo hexa ok)
756 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
757 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
758 for %%i in (%WINE_INT_PARMS%) do (
759 for %%j in (%WINE_INT_PARMS%) do (
760 call :NEQtest %%i %%j))
761 for %%i in (%WINE_INT_PARMS%) do (
762 for %%j in (%WINE_INT_PARMS%) do (
763 call :GEQtest %%i %%j))
764 for %%i in (%WINE_INT_PARMS%) do (
765 for %%j in (%WINE_INT_PARMS%) do (
766 call :GTRtest %%i %%j))
767 echo ------ for numbers and stringified numbers
768 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
769 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
770 if '1' EQU 1 echo '1' EQU 1
771 if 1 EQU '1' echo 1 EQU '1'
772 if not "1" GEQ 1 (echo foo) else echo bar
773 if "10" GEQ "1" echo "10" GEQ "1"
774 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
775 if 1 GEQ "1" echo 1 GEQ "1"
776 if "1" GEQ "1" echo "1" GEQ "1"
777 if '1' GEQ "1" echo '1' GEQ "1"
778 if "10" GEQ "1" echo "10" GEQ "1"
779 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
780 for %%i in ("1" '1') do call :GEQtest %%i '1'
781 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
782 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
783 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
784 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
785 if "10" GEQ "10" (echo "10" GEQ "10")
786 goto :endIfCompOpsSubroutines
788 rem IF subroutines helpers
790 if %1 LSS %2 echo %1 LSS %2
793 if %1 LEQ %2 echo %1 LEQ %2
796 if %1 EQU %2 echo %1 EQU %2
799 if %1 NEQ %2 echo %1 NEQ %2
802 if %1 GEQ %2 echo %1 GEQ %2
805 if %1 GTR %2 echo %1 GTR %2
808 :endIfCompOpsSubroutines
812 echo ------------ Testing for ------------
814 for %%i in (A B C) do echo %%i
815 for %%i in (A B C) do echo %%I
816 for %%i in (A B C) do echo %%j
817 for %%i in (A B C) do call :forTestFun1 %%i
818 for %%i in (1,4,1) do echo %%i
819 for %%i in (A, B,C) do echo %%i
820 for %%i in (X) do echo %%i
821 for@tab@%%i in (X2) do echo %%i
822 for %%i in@tab@(X3) do echo %%i
823 for %%i in (@tab@ foo@tab@) do echo %%i
824 for@tab@ %%i in@tab@(@tab@M) do echo %%i
825 for %%i@tab@in (X)@tab@do@tab@echo %%i
826 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
827 for %%i in (`echo A B`) do echo %%i
828 for %%i in ('echo A B') do echo %%i
829 for %%i in ("echo A B
") do echo %%i
830 for %%i in ("A B
" C) do echo %%i
836 echo --- imbricated FORs
843 for %%i in (A B) do (
844 for %%j in (C D) do (
846 for %%i in (A B) do (
847 for %%j in (C D) do (
848 call :forTestFun2 %%i %%j ))
854 mkdir foobar & cd foobar
859 echo --- basic wildcards
860 for %%i in (ba*) do echo %%i
862 for /d %%i in (baz foo bar) do echo %%i 2>&1
863 rem Confirm we don't match files:
864 for /d %%i in (bazb*) do echo %%i 2>&1
865 for /d %%i in (bazb2*) do echo %%i 2>&1
866 rem Show we pass through non wildcards
867 for /d %%i in (PASSED) do echo %%i
868 for /d %%i in (xxx) do (
869 echo %%i - Should be xxx
870 echo Expected second line
872 rem Show we issue no messages on failures
873 for /d %%i in (FAILED?) do echo %%i 2>&1
874 for /d %%i in (FAILED?) do (
875 echo %%i - Unexpected!
876 echo FAILED Unexpected second line
878 for /d %%i in (FAILED*) do echo %%i 2>&1
879 for /d %%i in (FAILED*) do (
880 echo %%i - Unexpected!
881 echo FAILED Unexpected second line
883 rem FIXME can't test wildcard expansion here since it's listed in directory
884 rem order, and not in alphabetic order.
885 rem Proper testing would need a currently missing "sort" program implementation.
886 rem for /d %%i in (ba*) do echo %%i>> tmp
889 rem for /d %%i in (?a*) do echo %%i>> tmp
892 rem for /d %%i in (*) do echo %%i>> tmp
900 call :WriteLine set WINE_found=N
901 for /l %%i in (1,1,%WINE_expectedresults%) do (
902 call :WriteLine if "%%%%WINE_expectedresults.
%%i%%%%"=="%%%%1" set WINE_found=Y
903 call :WriteLine if "%%%%WINE_found%%%%"=="Y
" set WINE_expectedresults.%%i=
904 call :WriteLine if "%%%%WINE_found%%%%"=="Y
" goto :eof
906 call :WriteLine echo Got unexpected result: "%%%%1"
915 for /l %%i in (1,1,%WINE_expectedresults%) do (
916 call :WriteLine if not "%%%%WINE_expectedresults.
%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.
%%i%%%%"
923 rem %CD% does not tork on NT4 so use the following workaround
924 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
927 echo Plain directory enumeration
928 set WINE_expectedresults=4
929 set WINE_expectedresults.1=%WINE_CURDIR%\.
930 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
931 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
932 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
934 for /R %%i in (.) do call temp.bat %%i
935 call :ValidateExpected
937 echo Plain directory enumeration from provided root
938 set WINE_expectedresults=4
939 set WINE_expectedresults.1=%WINE_CURDIR%\.
940 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
941 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
942 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
943 if "%CD%"=="" goto :SkipBrokenNT4
945 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat %%i
946 call :ValidateExpected
949 echo File enumeration
950 set WINE_expectedresults=2
951 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
952 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
954 for /R %%i in (baz*) do call temp.bat %%i
955 call :ValidateExpected
957 echo File enumeration from provided root
958 set WINE_expectedresults=2
959 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
960 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
962 for /R %%i in (baz*) do call temp.bat %%i
963 call :ValidateExpected
965 echo Mixed enumeration
966 set WINE_expectedresults=6
967 set WINE_expectedresults.1=%WINE_CURDIR%\.
968 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
969 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
970 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
971 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
972 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
974 for /R %%i in (. baz*) do call temp.bat %%i
975 call :ValidateExpected
977 echo Mixed enumeration from provided root
978 set WINE_expectedresults=6
979 set WINE_expectedresults.1=%WINE_CURDIR%\.
980 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
981 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
982 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
983 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
984 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
986 for /R %%i in (. baz*) do call temp.bat %%i
987 call :ValidateExpected
989 echo With duplicates enumeration
990 set WINE_expectedresults=12
991 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
992 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
993 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
994 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
995 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
996 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
997 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
998 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
999 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1000 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1001 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1002 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1004 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat %%i
1005 call :ValidateExpected
1007 echo Strip missing wildcards, keep unwildcarded names
1008 set WINE_expectedresults=6
1009 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1010 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1011 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1012 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1013 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1014 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1016 for /R %%i in (baz* fred* jim) do call temp.bat %%i
1017 call :ValidateExpected
1020 echo --- Complex wildcards unix and windows slash
1022 echo Windows slashs, valid path
1023 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1024 for %%f in (foobar\baz\*) do echo WC : %%f
1025 echo Windows slashs, invalid path
1026 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1027 for %%f in (foobar\jim\*) do echo WC : %%f
1028 echo Unix slashs, valid path
1029 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1030 for %%f in (foobar/baz/*) do echo WC : %%f
1031 echo Unix slashs, invalid path
1032 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1033 for %%f in (foobar/jim/*) do echo WC : %%f
1037 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
1038 for /L %%i in (1,2,0) do echo %%i
1039 for@tab@/L %%i in (1,2,0) do echo %%i
1040 for /L %%i in (1,2,6) do echo %%i
1041 for /l %%i in (1 ,2,6) do echo %%i
1042 for /L %%i in (a,2,3) do echo %%i
1043 for /L %%i in (1,2,-1) do echo %%i
1044 for /L %%i in (-4,-1,-1) do echo %%i
1045 for /L %%i in (1,-2,-2) do echo %%i
1046 for /L %%i in (1,2,a) do echo %%i
1047 echo ErrorLevel %ErrorLevel%
1048 for /L %%i in (1,a,b) do echo %%i
1049 echo ErrorLevel %ErrorLevel%
1051 for /l %%i in (1,1,4) do echo %%i
1052 for /l %%i in (1,2,4) do echo %%i
1053 for /l %%i in (4,-1,1) do echo %%i
1054 for /l %%i in (4,-2,1) do echo %%i
1055 for /l %%i in (1,-1,4) do echo %%i
1056 for /l %%i in (4,1,1) do echo %%i
1057 for /L %%i in (a,2,b) do echo %%i
1058 for /L %%i in (1,1,1) do echo %%i
1059 for /L %%i in (1,-2,-1) do echo %%i
1060 for /L %%i in (-1,-1,-1) do echo %%i
1061 for /L %%i in (1,2, 3) do echo %%i
1062 rem Test zero iteration skips the body of the for
1063 for /L %%i in (2,2,1) do (
1070 Rem Ideally for /f can be used rather than building a command to execute
1071 rem but that does not work on NT4
1073 if "%1"=="" goto :eof
1074 call :executecmd set wine_result=%%%1%%
1075 if "%wine_result%"=="%2" (
1076 echo %1 correctly %2
1077 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1088 rem No output when using "set expr
" syntax, unless in interactive mode
1089 rem Need to use "set envvar
=expr
" to use in a batch script
1090 echo ------ individual operations
1092 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1093 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1094 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1095 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1096 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1097 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1098 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1099 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1100 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1101 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1102 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1103 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1104 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1105 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1106 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1107 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1108 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1109 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1110 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1111 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1112 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1113 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1114 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1115 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1116 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1117 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1118 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1119 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1120 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1121 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1122 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1123 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1124 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1125 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1126 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1127 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1128 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1129 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1130 echo ------ precedence and grouping
1131 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1132 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1133 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1134 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1135 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1136 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1137 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1138 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1139 echo ------ octal and hexadecimal
1140 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1141 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1142 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1143 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1144 echo ------ variables
1145 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1146 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1147 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
1149 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1150 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1152 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1154 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1156 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1157 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1159 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1161 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1163 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1164 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1165 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1167 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1170 call :checkenvvars WINE_foo 1
1172 call :checkenvvars WINE_foo 1
1173 set /a WINE_foo=1,WINE_bar=2
1174 call :checkenvvars WINE_foo 1 WINE_bar 2
1175 set /a "WINE_foo
=1,WINE_bar
=2"
1176 call :checkenvvars WINE_foo 1 WINE_bar 2
1177 set /a "WINE_foo
=1","WINE_bar
=2"
1178 call :checkenvvars WINE_foo 1 WINE_bar 2
1179 set /a ""WINE_foo=1","WINE_bar=2""
1180 call :checkenvvars WINE_foo 1 WINE_bar 2
1181 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1182 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1183 set /a "WINE_foo
=1,WINE_bar
=2,WINE_baz
=3"
1184 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1185 set /a "WINE_foo
=1","WINE_bar
=2","WINE_baz
=3"
1186 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1187 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1188 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1189 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz
=3"
1190 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1191 set /a """"""WINE_foo=1""""""
1192 call :checkenvvars WINE_foo 1
1193 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1194 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1195 set /a WINE_foo="3"+"4"+"5+6"
1196 call :checkenvvars WINE_foo 18
1198 set /a WINE_bar="WINE_
""foo
"+4
1199 call :checkenvvars WINE_foo 3 WINE_bar 7
1200 echo --- whitespace are ignored between double char operators
1203 set /a WINE_foo + = 6
1204 set /a WINE_bar * = WINE_foo
1205 call :checkenvvars WINE_foo 10 WINE_bar 50
1208 set /a WINE_foo + = "6 < < 7"
1209 set /a WINE_bar * = WINE_foo + WINE_foo
1210 call :checkenvvars WINE_foo 772 WINE_bar 7720
1214 echo --- invalid operator sequence
1220 set /a WINE_foo^>^<=4
1222 set /a WINE_foo^>^>^>=4
1224 echo ----- negative prefix
1226 call :checkenvvars WINE_foo -1
1228 call :checkenvvars WINE_foo 1
1229 set /a WINE_foo=3--3
1230 call :checkenvvars WINE_foo 6
1231 set /a WINE_foo=3---3
1232 call :checkenvvars WINE_foo 0
1233 set /a WINE_foo=3----3
1234 call :checkenvvars WINE_foo 6
1236 call :checkenvvars WINE_foo 2
1238 call :checkenvvars WINE_foo 0
1239 set /a WINE_foo=3+-~1
1240 call :checkenvvars WINE_foo 5
1241 set /a WINE_foo=3+~-1
1242 call :checkenvvars WINE_foo 3
1243 echo ----- assignment tests involving the end destination
1245 set /a WINE_foo+=3+(WINE_foo=4)
1246 call :checkenvvars WINE_foo 11
1248 set /a WINE_bar=3+(WINE_foo=6)
1249 call :checkenvvars WINE_foo 6 WINE_bar 9
1251 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1252 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1254 set /a WINE_bar=WINE_foo=7
1255 call :checkenvvars WINE_foo 7 WINE_bar 7
1256 echo ----- equal precedence on stack
1257 rem Unary - don't reduce if precedence is equal
1259 call :checkenvvars WINE_foo 1
1261 call :checkenvvars WINE_foo 0
1263 call :checkenvvars WINE_foo 1
1265 call :checkenvvars WINE_foo 0
1267 call :checkenvvars WINE_foo 1
1269 call :checkenvvars WINE_foo -1
1271 call :checkenvvars WINE_foo -1
1273 call :checkenvvars WINE_foo 1
1275 call :checkenvvars WINE_foo 0
1277 call :checkenvvars WINE_foo -1
1279 call :checkenvvars WINE_foo 0
1281 call :checkenvvars WINE_foo 0
1283 call :checkenvvars WINE_foo 1
1285 call :checkenvvars WINE_foo -1
1286 rem Aritmatic - Reduce if precedence is equal
1287 set /a WINE_foo=10*5/2
1288 call :checkenvvars WINE_foo 25
1289 set /a WINE_foo=5/2*10
1290 call :checkenvvars WINE_foo 20
1291 set /a WINE_foo=10/5/2
1292 call :checkenvvars WINE_foo 1
1293 set /a WINE_foo=5%%2*4
1294 call :checkenvvars WINE_foo 4
1295 set /a WINE_foo=10-5+2
1296 call :checkenvvars WINE_foo 7
1297 set /a WINE_foo=1^<^<4^>^>1
1298 call :checkenvvars WINE_foo 8
1299 rem Assignment - don't reduce if precedence is equal
1301 set /a WINE_bar=WINE_foo=6
1302 call :checkenvvars WINE_foo 6 WINE_bar 6
1305 mkdir foobar & cd foobar
1306 echo ------ string argument
1307 rem NT4 does not support usebackq
1308 for /F %%i in ("a b c
") do echo %%i
1309 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1310 if not exist output_file (echo no output) else (type output_file & del output_file)
1311 for /f %%i in ("a
") do echo %%i
1312 for /f usebackq %%i in ('a ') do echo %%i>output_file
1313 if not exist output_file (echo no output) else (type output_file & del output_file)
1314 for /f %%i in ("a
") do echo %%i
1315 for /f usebackq %%i in ('a') do echo %%i>output_file
1316 if not exist output_file (echo no output) else (type output_file & del output_file)
1317 fOr /f %%i in (" a
") do echo %%i
1318 for /f usebackq %%i in (' a') do echo %%i>output_file
1319 if not exist output_file (echo no output) else (type output_file & del output_file)
1320 for /f %%i in (" a
") do echo %%i
1321 for /f usebackq %%i in (' a ') do echo %%i>output_file
1322 if not exist output_file (echo no output) else (type output_file & del output_file)
1323 echo ------ fileset argument
1324 echo --------- basic blank handling
1326 for /f %%i in (foo) do echo %%i
1328 for /f %%i in (foo) do echo %%i
1330 for /f %%i in (foo) do echo %%i
1332 for /f %%i in (foo) do echo %%i
1334 for /f %%i in (foo) do echo %%i
1336 for /f %%i in (foo) do echo %%i
1339 for /f %%i in (foo) do echo %%i
1340 echo --------- multi-line with empty lines
1347 for /f %%b in (foo) do echo %%b
1348 echo --------- multiple files
1352 for /f %%k in (foo bar) do echo %%k
1353 for /f %%k in (bar foo) do echo %%k
1354 echo ------ command argument
1355 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1356 if "%CD%"=="" goto :SkipFORFcmdNT4
1357 for /f %%i in ('echo.Passed1') do echo %%i
1358 for /f "usebackq
" %%i in (`echo.Passed2`) do echo %%i
1359 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1362 for /l %%i in (1,1,3) do echo Missing functionality - Broken%%i
1364 rem FIXME: Rest not testable right now in wine: not implemented and would need
1365 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1366 rem for a simple todo_wine test
1367 rem (for /f "usebackq
" %%i in (`echo z a b`) do echo %%i) || echo not supported
1368 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1369 echo ------ eol option
1370 if "%CD%"=="" goto :SkipFORFeolNT4
1372 echo and Line two>>foo
1373 echo Line three>>foo
1374 for /f "eol
=L
" %%i in (foo) do echo %%i
1375 for /f "eol
=a
" %%i in (foo) do echo %%i
1377 goto :ContinueFORFeol
1379 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1381 for /f "eol
=@
" %%i in (" ad
") do echo %%i
1382 for /f "eol
=@
" %%i in (" z@y
") do echo %%i
1383 for /f "eol
=|
" %%i in ("a|d
") do echo %%i
1384 for /f "eol
=@
" %%i in ("@y
") do echo %%i > output_file
1385 if not exist output_file (echo no output) else (del output_file)
1386 for /f "eol
==" %%i in ("=y
") do echo %%i > output_file
1387 if not exist output_file (echo no output) else (del output_file)
1388 echo ------ delims option
1389 for /f "delims
=|
" %%i in ("a|d
") do echo %%i
1390 for /f "delims
=|
" %%i in ("a |d
") do echo %%i
1391 for /f "delims
=|
" %%i in ("a d|
") do echo %%i
1392 for /f "delims
=|
" %%i in ("a d|
") do echo %%i
1393 for /f "delims
==" %%i in ("C r
=d|
") do echo %%i
1394 for /f "delims
=" %%i in ("foo bar baz
") do echo %%i
1395 for /f "delims
=" %%i in ("c
:\foo bar baz\..
") do echo %%~fi
1396 echo ------ skip option
1400 for /f "skip
=2" %%i in (foo) do echo %%i
1401 for /f "skip
=3" %%i in (foo) do echo %%i > output_file
1402 if not exist output_file (echo no output) else (del output_file)
1403 for /f "skip
=4" %%i in (foo) do echo %%i > output_file
1404 if not exist output_file (echo no output) else (del output_file)
1405 for /f "skip
=02" %%i in (foo) do echo %%i
1406 for /f "skip
=0x2" %%i in (foo) do echo %%i
1407 for /f "skip
=1" %%i in ("skipme
") do echo %%i > output_file
1408 if not exist output_file (echo no output) else (del output_file)
1409 echo ------ tokens= option
1411 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
1412 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
1413 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
1414 rem Show * means the rest
1415 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
1416 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
1417 rem Show * means the rest (not tokenized and rebuilt)
1418 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
1419 rem Order is irrelevant
1420 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
1421 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
1422 rem Duplicates are ignored
1423 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
1424 rem Large tokens are allowed
1425 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
1426 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1427 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
1428 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
1429 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1430 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
1431 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
1432 rem Show negative ranges have no effect
1433 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
1434 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
1435 rem Show duplicates stop * from working
1436 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
1437 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
1438 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
1439 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
1443 echo ------------ Testing del /a ------------
1444 del /f/q *.test > nul
1447 echo not-r > not-r.test
1449 if not exist not-r.test echo not-r.test not found before delete, bad
1451 if not exist not-r.test echo not-r.test not found after delete, good
1453 if not exist r.test echo r.test not found before delete, bad
1454 if exist r.test echo r.test found before delete, good
1456 if not exist r.test echo r.test not found after delete, good
1457 if exist r.test echo r.test found after delete, bad
1459 echo ------------ Testing del /q ------------
1463 echo abc > file2.dat
1464 rem If /q doesn't work, cmd will prompt and the test case should hang
1466 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1467 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1471 echo ------------ Testing del /s ------------
1476 echo there > file2.dat
1477 echo bub > file3.dat
1478 echo bye > "file with spaces.dat
"
1480 del /s file1.dat > nul
1481 del file2.dat /s > nul
1482 del "file3.dat
" /s > nul
1483 del "file with spaces.dat
" /s > nul
1485 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1486 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1487 if exist "file with spaces.dat
" echo Del /s failed on "file with spaces.dat
"
1488 if exist "file with spaces.dat
" del "file with spaces.dat
"
1493 echo ------------ Testing rename ------------
1494 mkdir foobar & cd foobar
1495 echo --- ren and rename are synonymous
1498 if exist foo echo foo should be renamed!
1499 if exist bar echo foo renamed to bar
1501 if exist bar echo bar should be renamed!
1502 if exist foo echo bar renamed to foo
1503 echo --- name collision
1513 echo --- rename read-only files
1517 if not exist file1 (
1519 echo read-only file renamed
1522 echo read-only file not renamed!
1524 echo --- rename directories
1536 echo read-only dir renamed
1539 echo --- rename in other directory
1540 if not exist baz\abc (
1541 echo rename impossible in other directory
1542 if exist foo echo original file still present
1544 echo shouldn't rename in other directory!
1545 if not exist foo echo original file not present anymore
1547 cd .. & rd /s/q foobar
1549 echo ------------ Testing move ------------
1550 mkdir foobar & cd foobar
1553 move foo bar > nul 2>&1
1556 echo file move succeeded
1561 move /Y bar baz > nul 2>&1
1564 echo file move with overwrite succeeded
1567 echo file overwrite impossible!
1573 move baz bazro > nul 2>&1
1576 echo read-only files are moveable
1577 move bazro baz > nul 2>&1
1580 echo read-only file not moved!
1584 move baz rep > nul 2>&1
1587 echo file moved in subdirectory
1591 move rep\baz . > nul 2>&1
1592 move /Y baz baz > nul 2>&1
1594 echo moving a file to itself should be a no-op!
1596 echo moving a file to itself is a no-op
1598 echo ErrorLevel: %ErrorLevel%
1601 echo --- directory move
1605 move baz foo\bar > nul 2>&1
1607 if exist foo\bar\baz\baz2 (
1608 echo simple directory move succeeded
1613 move baz baz > nul 2>&1
1614 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1615 echo ------ dir in dir move
1620 move foo bar > nul 2>&1
1628 cd .. & rd /s/q foobar
1630 echo ------------ Testing mkdir ------------
1632 echo --- md and mkdir are synonymous
1639 echo --- creating an already existing directory/file must fail
1648 echo --- multilevel path creation
1660 mkdir ..\..\..\foo\bar2
1663 mkdir ..\..\..\foo\bar2
1665 rmdir ..\..\..\foo\bar2
1673 echo --- trailing backslashes
1676 if exist foo (rmdir foo & echo dir created
1677 ) else ( echo dir not created )
1679 echo --- invalid chars
1681 echo mkdir ? gives errorlevel %ErrorLevel%
1684 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1687 echo mkdir foo\? gives errorlevel %ErrorLevel%
1688 if exist foo (rmdir foo & echo ok, foo created
1689 ) else ( echo foo not created )
1692 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1695 echo bad, foo not created
1699 echo ok, foo\bar created
1705 echo --- multiple directories at once
1706 mkdir foobaz & cd foobaz
1707 mkdir foo bar\baz foobar "bazbaz
" .\"zabzab"
1708 if exist foo
(echo foo created
) else echo foo
not created
!
1709 if exist bar
(echo bar created
) else echo bar
not created
!
1710 if exist foobar
(echo foobar created
) else echo foobar
not created
!
1711 if exist bar
\baz
(echo bar
\baz created
) else echo bar
\baz
not created
!
1712 if exist bazbaz
(echo bazbaz created
) else echo bazbaz
not created
!
1713 if exist zabzab
(echo zabzab created
) else echo zabzab
not created
!
1714 cd ..
& rd /s
/q foobaz
1717 echo mkdir foo\
* errorlevel %ErrorLevel%
1718 if exist foo
(rmdir foo
& echo ok
, foo created
1719 ) else ( echo bad
, foo
not created
)
1721 echo ------------ Testing
rmdir ------------
1723 rem rd and rmdir are synonymous
1727 if not exist foobar
echo dir removed
1731 if not exist foobar
echo dir removed
1732 rem Removing nonexistent directory
1735 rem Removing single-level directories
1739 if exist foo
echo file
not removed
1745 if exist foo
echo non
-empty
dir not removed
1750 if exist foo
echo non
-empty
dir not removed
1757 echo recursive
rmdir succeeded
1764 echo foo
> foo
\bar
\brol
1765 rmdir /s
/Q foo
2>&1
1767 echo recursive
rmdir succeeded
1774 rem multiples directories at once
1775 mkdir foobaz
& cd foobaz
1779 rd /s
/q foo bar foobar
1780 if not exist foo
(echo foo removed
) else echo foo
not removed
!
1781 if not exist bar
(echo bar removed
) else echo bar
not removed
!
1782 if not exist foobar
(echo foobar removed
) else echo foobar
not removed
!
1783 if not exist bar
\baz
(echo bar
\baz removed
) else echo bar
\baz
not removed
!
1784 cd ..
& rd /s
/q foobaz
1786 echo ------------ Testing pushd
/popd
------------
1788 echo --- popd is no
-op
when dir stack is empty
1791 echo --- pushing non
-existing
dir
1794 echo --- basic behaviour
1819 echo ------------ Testing
attrib ------------
1820 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
1821 mkdir foobar
& cd foobar
1822 echo foo original contents
> foo
1825 echo --- read
-only attribute
1826 rem Read-only files cannot be altered or deleted, unless forced
1834 echo Read
-only file
not deleted
1836 echo Should
not delete read
-only file
!
1840 echo Read
-only file forcibly deleted
1842 echo Should delete read
-only file with
del /F
!
1846 cd ..
& rd /s
/q foobar
1847 echo --- recursive behaviour
1848 mkdir foobar
\baz
& cd foobar
1854 attrib +R l
*vel?
/S
> nul
2>&1
1860 cd ..
& rd /s
/q foobar
1861 echo --- folders processing
1867 attrib +r baz
/s
/d
> nul
2>&1
1873 rem Oddly windows allows file creation in a read-only directory...
1874 if exist baz\lala
(echo file created in read
-only
dir) else echo file
not created
1875 cd ..
& rd /s
/q foobar
1877 echo ------------ Testing assoc
------------
1878 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1879 rem FIXME Revise once || conditional execution is fixed
1880 mkdir foobar
& cd foobar
1881 echo --- setting association
1889 rem association set system-wide
1890 echo @
echo off
> tmp.
cmd
1891 echo echo +++>> tmp.
cmd
1892 echo assoc .foo
>> tmp.
cmd
1895 echo --- resetting association
1901 rem association removal set system-wide
1902 cmd /c tmp.
cmd > baz
1905 cd ..
& rd /s
/q foobar
1907 echo ------------ Testing ftype
------------
1908 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1909 rem FIXME Revise once || conditional execution is fixed
1910 mkdir foobar
& cd foobar
1911 echo --- setting association
1916 ftype footype
=foo_opencmd
1920 rem association set system-wide
1921 echo @
echo off
> tmp.
cmd
1922 echo echo +++>> tmp.
cmd
1923 echo ftype footype
>> tmp.
cmd
1926 echo --- resetting association
1929 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
1930 setlocal EnableDelayedExpansion
1931 set WINE_FOO
=original value
1934 for /F
%%i in
('type baz') do (set WINE_FOO
=buggyXP
)
1935 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
1936 rem FIXME Revisit once a grep-like program like ftype is implemented
1937 rem (e.g. to check baz's size using dir /b instead)
1940 rem cleanup registry
1941 echo REGEDIT4
> regCleanup.reg
1942 echo.
>> regCleanup.reg
1943 echo [-HKEY_CLASSES_ROOT
\footype
]>> regCleanup.reg
1944 regedit
/s regCleanup.reg
1947 cd ..
& rd /s
/q foobar
1949 echo ------------ Testing
CALL ------------
1950 mkdir foobar
& cd foobar
1951 echo --- external script
1952 echo echo foo
%%1> foo.
cmd
1955 echo echo %%1 %%2 > foo.
cmd
1957 call foo.
cmd foo bar
1964 echo --- internal routines
1965 call :testRoutine :testRoutine
1966 goto :endTestRoutine
1972 call :testRoutineArgs foo
1973 call :testRoutineArgs foo bar
1974 call :testRoutineArgs foo
""
1975 call :testRoutineArgs "" bar
1976 call :testRoutineArgs foo
''
1977 call :testRoutineArgs '' bar
1978 goto :endTestRoutineArgs
1984 echo --- with builtins
1987 if exist foo
(echo foo created
) else echo foo should
exist!
1989 set WINE_FOOBAZ_VAR
=foobaz
1990 call echo Should expand
%WINE_FOOBAZ_VAR%
1991 set WINE_FOOBAZ_VAR
=
1995 if 1==1 call del batfile
1997 if exist batfile
echo batfile shouldn
't exist
1998 rem ... but not for 'if' or 'for'
1999 call if 1==1 echo bar 2> nul
2002 call for %%i in (foo bar baz) do echo %%i 2> nul
2004 rem First look for programs in the path before trying a builtin
2005 echo echo non-builtin dir> dir.cmd
2008 rem The below line equates to call (, which does nothing, then the
2009 rem subsequent lines are executed.
2014 rem The below line equates to call if, which always fails, then the
2015 rem subsequent lines are executed. Note cmd.exe swallows all lines
2022 call call call echo passed
2023 cd .. & rd /s/q foobar
2025 echo ------------ Testing SHIFT ------------
2027 call :shiftFun p1 p2 p3 p4 p5
2031 echo '%1' '%2' '%3' '%4' '%5'
2033 echo '%1' '%2' '%3' '%4' '%5'
2035 echo '%1' '%2' '%3' '%4' '%5'
2037 echo '%1' '%2' '%3' '%4' '%5'
2039 echo '%1' '%2' '%3' '%4' '%5'
2041 echo '%1' '%2' '%3' '%4' '%5'
2045 echo ------------ Testing cmd invocation ------------
2046 rem FIXME: only a stub ATM
2047 echo --- a batch file can delete itself
2048 echo del foo.cmd>foo.cmd
2050 if not exist foo.cmd (
2051 echo file correctly deleted
2053 echo file should be deleted!
2056 echo --- a batch file can alter itself
2057 echo echo bar^>foo.cmd>foo.cmd
2058 cmd /q /c foo.cmd > NUL 2>&1
2063 echo file not created!
2066 echo ---------- Testing copy
2069 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2072 echo CCCCCCCCC> file3
2078 echo Passed: Found expected %1
2080 echo Failed: Did not find expected %1
2082 del /q "%1" >nul 2>&1
2084 if not "%1"=="" goto :CheckExist
2089 echo Passed: Did not find %1
2091 echo Failed: Unexpectedly found %1
2092 del /q "%1" >nul 2>&1
2095 if not "%1"=="" goto :CheckNotExist
2098 rem Note: No way to check file size on NT4 so skip the test
2101 echo Failed: File missing when requested filesize check [%2]
2102 goto :ContinueFileSizeChecks
2104 for %%i in (%1) do set WINE_filesize=%%~zi
2105 if "%WINE_filesize%"=="%2" (
2106 echo Passed: file size check on %1 [%WINE_filesize%]
2108 if "%WINE_filesize%"=="%%~zi" (
2109 echo Skipping file size check on NT4
2111 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2114 :ContinueFileSizeChecks
2117 if not "%1"=="" goto :CheckFileSize
2122 rem -----------------------
2123 rem Simple single file copy
2124 rem -----------------------
2125 rem Simple single file copy, normally used syntax
2126 copy file1 dummy.file >nul 2>&1
2127 if errorlevel 1 echo Incorrect errorlevel
2128 call :CheckExist dummy.file
2130 rem Simple single file copy, destination supplied as two forms of directory
2131 copy file1 dir1 >nul 2>&1
2132 if errorlevel 1 echo Incorrect errorlevel
2133 call :CheckExist dir1\file1
2135 copy file1 dir1\ >nul 2>&1
2136 if errorlevel 1 echo Incorrect errorlevel
2137 call :CheckExist dir1\file1
2139 rem Simple single file copy, destination supplied as fully qualified destination
2140 copy file1 dir1\file99 >nul 2>&1
2141 if errorlevel 1 echo Incorrect errorlevel
2142 call :CheckExist dir1\file99
2144 rem Simple single file copy, destination not supplied
2146 copy ..\file1 >nul 2>&1
2147 if errorlevel 1 echo Incorrect errorlevel
2148 call :CheckExist file1
2151 rem Simple single file copy, destination supplied as nonexistent directory
2152 copy file1 dir2\ >nul 2>&1
2153 if not errorlevel 1 echo Incorrect errorlevel
2154 call :CheckNotExist dir2 dir2\file1
2156 rem -----------------------
2158 rem -----------------------
2159 rem Simple single file copy, destination supplied as two forms of directory
2160 copy file? dir1 >nul 2>&1
2161 if errorlevel 1 echo Incorrect errorlevel
2162 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2164 copy file* dir1\ >nul 2>&1
2165 if errorlevel 1 echo Incorrect errorlevel
2166 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2168 rem Simple single file copy, destination not supplied
2170 copy ..\file*.* >nul 2>&1
2171 if errorlevel 1 echo Incorrect errorlevel
2172 call :CheckExist file1 file2 file3
2175 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2176 copy file? dir2\ >nul 2>&1
2177 if not errorlevel 1 echo Incorrect errorlevel
2178 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2180 rem ------------------------------------------------
2181 rem Confirm overwrite works (cannot test prompting!)
2182 rem ------------------------------------------------
2183 copy file1 testfile >nul 2>&1
2184 copy /y file2 testfile >nul 2>&1
2185 call :CheckExist testfile
2187 rem ------------------------------------------------
2188 rem Test concatenation
2189 rem ------------------------------------------------
2190 rem simple case, no wildcards
2191 copy file1+file2 testfile >nul 2>&1
2192 if errorlevel 1 echo Incorrect errorlevel
2193 call :CheckExist testfile
2195 rem simple case, wildcards, no concatenation
2196 copy file* testfile >nul 2>&1
2197 if errorlevel 1 echo Incorrect errorlevel
2198 call :CheckExist testfile
2200 rem simple case, wildcards, and concatenation
2202 copy file*+fred testfile >nul 2>&1
2203 if errorlevel 1 echo Incorrect errorlevel
2204 call :CheckExist testfile
2206 rem simple case, wildcards, and concatenation
2207 copy fred+file* testfile >nul 2>&1
2208 if errorlevel 1 echo Incorrect errorlevel
2209 call :CheckExist testfile
2211 rem Calculate destination name
2212 copy fred+file* dir1 >nul 2>&1
2213 if errorlevel 1 echo Incorrect errorlevel
2214 call :CheckExist dir1\fred
2216 rem Calculate destination name
2217 copy fred+file* dir1\ >nul 2>&1
2218 if errorlevel 1 echo Incorrect errorlevel
2219 call :CheckExist dir1\fred
2221 rem Calculate destination name (none supplied)
2223 copy ..\fred+..\file* >nul 2>&1
2224 if errorlevel 1 echo Incorrect errorlevel
2225 call :CheckExist fred
2227 copy ..\fr*+..\file1 >nul 2>&1
2228 if errorlevel 1 echo Incorrect errorlevel
2229 call :CheckExist fred
2232 rem ******************************************************************
2233 rem ASCII and BINARY tests
2234 rem Note: hard coded numbers deliberate because need to ensure whether
2235 rem an additional EOF has been added or not. There is no way to handle
2236 rem EOFs in batch, so assume if a single byte appears, its an EOF!
2237 rem ******************************************************************
2239 rem Confirm original sizes of file1,2,3
2240 call :CheckFileSize file1 5 file2 8 file3 11
2244 rem ----------------------------------------------
2245 rem Show concatenation defaults copy to ascii mode
2246 rem ----------------------------------------------
2247 rem Simple default copy source to destination (should not append EOF 5)
2248 copy ..\file1 file1_default >nul 2>&1
2249 call :CheckFileSize file1_default 5
2251 rem Simple binary copy source to destination (should not append EOF 5)
2252 copy /b ..\file1 file1_default2 >nul 2>&1
2253 call :CheckFileSize file1_default2 5
2255 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2256 copy /a ..\file1 file1_plus_eof >nul 2>&1
2257 call :CheckFileSize file1_plus_eof 6
2258 copy /a ..\file2 file2_plus_eof >nul 2>&1
2259 call :CheckFileSize file2_plus_eof 9
2260 copy /a ..\file3 file3_plus_eof >nul 2>&1
2261 call :CheckFileSize file3_plus_eof 12
2263 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2264 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2265 call :CheckFileSize file12_plus_eof 14
2267 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2268 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2269 call :CheckFileSize file12_no_eof 13
2271 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2272 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2273 call :CheckFileSize file12_eof2 14
2275 rem --------------------------------------------------------------
2276 rem Show ascii source copy stops at first EOF, binary does the lot
2277 rem --------------------------------------------------------------
2278 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2279 call :CheckFileSize file1_binary_srccopy 6
2281 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2282 call :CheckFileSize file1_ascii_srccopy 5
2284 rem --------------------------------------------------------------
2285 rem Show results of concatenating files (ending in EOFs) and /a /b
2286 rem --------------------------------------------------------------
2288 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2289 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2290 call :CheckFileSize file123_default_copy 25
2291 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2292 call :CheckFileSize file123_ascii_copy 25
2294 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2295 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2296 call :CheckFileSize file123_binary_copy 27
2298 rem We can select which we want the eofs from by postfixing it with /a or /b
2299 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2300 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2301 call :CheckFileSize file123_mixed_copy1 26
2303 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2304 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2305 rem Note the delta between this and the previous one also shows that the destination
2306 rem ascii/binary is inherited from the last /a or /b on the line
2307 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2308 call :CheckFileSize file123_mixed_copy2 27
2310 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2311 rem Note the delta between the next two also shows that the destination ascii/binary is
2312 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2313 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2314 call :CheckFileSize file123_mixed_copy3 26
2315 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2316 call :CheckFileSize file123_mixed_copy4 25
2318 rem -------------------------------------------------------------------------------------------
2319 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2320 rem are not concatenating, its a direct copy regardless of destination if being read as binary
2321 rem -------------------------------------------------------------------------------------------
2323 rem All 3 have eof's
, plus an extra
= 6 + 9 + 12 + eof
2324 copy /b file1_plus_eof
+ file2_plus_eof
+ file3_plus_eof file123_mixed_copy5
/a
>nul
2>&1
2325 call :CheckFileSize file123_mixed_copy5
28
2327 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2328 copy /b file1_plus_eof
+ file3_plus_eof file123_mixed_copy6
/a
>nul
2>&1
2329 call :CheckFileSize file123_mixed_copy6
19
2331 rem One file has EOF, but doesn't get an extra one, i.e. 6
2332 copy /b file1_plus_eof file123_mixed_copy7
/a
>nul
2>&1
2333 call :CheckFileSize file123_mixed_copy7
6
2335 rem Syntax means concatenate so ascii destination kicks in
2336 copy /b file1_plus_eof
* file123_mixed_copy8
/a
>nul
2>&1
2337 call :CheckFileSize file123_mixed_copy8
7
2342 rem ---------------------------------------
2343 rem Error combinations
2344 rem ---------------------------------------
2345 rem Specify source directory but name is a file
2347 copy file1\ dir1\
>NUL
2>&1
2348 if errorlevel 1 echo Passed
: errorlevel invalid check
1
2349 if not errorlevel 1 echo Failed
: errorlevel invalid check
1
2350 call :CheckNotExist dir1
\file
1
2352 rem Overwrite same file
2354 copy file1 file1
>NUL
2>&1
2355 if errorlevel 1 echo Passed
: errorlevel invalid check
2
2356 if not errorlevel 1 echo Failed
: errorlevel invalid check
2
2358 rem Supply same file identified as a directory
2360 copy file1 file1\
>NUL
2>&1
2361 if errorlevel 1 echo Passed
: errorlevel invalid check
3
2362 if not errorlevel 1 echo Failed
: errorlevel invalid check
3
2367 echo ------------ Testing
setlocal/endlocal ------------
2369 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2370 mkdir foobar
& cd foobar
2371 echo --- enable
/disable extensions
2372 setlocal DisableEXTensions
2373 echo ErrLev
: %ErrorLevel%
2375 echo ErrLev
: %ErrorLevel%
2376 echo @
echo off
> tmp.
cmd
2377 echo echo ErrLev
: %%ErrorLevel%%>> tmp.
cmd
2378 rem Enabled by default
2380 cmd /E
:OfF /C tmp.
cmd
2381 cmd /e
:oN /C tmp.
cmd
2383 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2384 echo --- setlocal with corresponding
endlocal
2385 rem %CD% does not tork on NT4 so use the following workaround
2386 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2387 echo @
echo off
> test.
cmd
2388 echo echo %%WINE_VAR%%>> test.
cmd
2389 echo setlocal>> test.
cmd
2390 echo set WINE_VAR
=localval
>> test.
cmd
2391 echo md foobar2
>> test.
cmd
2392 echo cd foobar2
>> test.
cmd
2393 echo echo %%WINE_VAR%%>> test.
cmd
2394 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2395 echo endlocal>> test.
cmd
2396 echo echo %%WINE_VAR%%>> test.
cmd
2397 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2398 set WINE_VAR
=globalval
2401 for /d
%%i in
(.
) do echo %%~dpnxi
2405 echo --- setlocal with no corresponding
endlocal
2406 echo @
echo off
> test.
cmd
2407 echo echo %%WINE_VAR%%>> test.
cmd
2408 echo setlocal>> test.
cmd
2409 echo set WINE_VAR
=localval
>> test.
cmd
2410 echo md foobar2
>> test.
cmd
2411 echo cd foobar2
>> test.
cmd
2412 echo echo %%WINE_VAR%%>> test.
cmd
2413 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> test.
cmd
2414 set WINE_VAR
=globalval
2415 rem %CD% does not tork on NT4 so use the following workaround
2416 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2419 for /d
%%i in
(.
) do echo %%~dpnxi
2423 echo --- setlocal within same batch program
2427 rem %CD% does not tork on NT4 so use the following workaround
2428 for /d
%%i in
(.
) do set WINE_CURDIR
=%%~dpnxi
2435 if "%WINE_var1%"=="one" echo Var1 ok
1
2436 if "%WINE_var2%"=="two" echo Var2 ok
2
2437 if "%WINE_var3%"=="three" echo Var3 ok
3
2438 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2439 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok
1
2441 if "%WINE_var1%"=="one" echo Var1 ok
1
2442 if "%WINE_var2%"=="two" echo Var2 ok
2
2443 if "%WINE_var3%"=="" echo Var3 ok
3
2444 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2445 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok
2
2447 if "%WINE_var1%"=="one" echo Var1 ok
1
2448 if "%WINE_var2%"=="" echo Var2 ok
2
2449 if "%WINE_var3%"=="" echo Var3 ok
3
2450 for /d
%%i in
(.
) do set WINE_curdir2
=%%~dpnxi
2451 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok
3
2455 echo --- Mismatched
set and
end locals
2459 rem %CD% does not tork on NT4 so use the following workaround
2460 for /d
%%i in
(.
) do set WINE_curdir
=%%~dpnxi
2462 echo @
echo off
> 2set1end.
cmd
2463 echo echo %%WINE_var%%>> 2set1end.
cmd
2464 echo setlocal>> 2set1end.
cmd
2465 echo set WINE_VAR
=2set1endvalue1
>> 2set1end.
cmd
2466 echo cd ..
\foodir
3>> 2set1end.
cmd
2467 echo setlocal>> 2set1end.
cmd
2468 echo set WINE_VAR
=2set1endvalue2
>> 2set1end.
cmd
2469 echo cd ..
\foodir
4>> 2set1end.
cmd
2470 echo endlocal>> 2set1end.
cmd
2471 echo echo %%WINE_var%%>> 2set1end.
cmd
2472 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 2set1end.
cmd
2474 echo @
echo off
> 1set2end.
cmd
2475 echo echo %%WINE_var%%>> 1set2end.
cmd
2476 echo setlocal>> 1set2end.
cmd
2477 echo set WINE_VAR
=1set2endvalue1
>> 1set2end.
cmd
2478 echo cd ..
\foodir
3>> 1set2end.
cmd
2479 echo endlocal>> 1set2end.
cmd
2480 echo echo %%WINE_var%%>> 1set2end.
cmd
2481 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 1set2end.
cmd
2482 echo endlocal>> 1set2end.
cmd
2483 echo echo %%WINE_var%%>> 1set2end.
cmd
2484 echo for /d
%%%%i in
(.
) do echo %%%%~dpnxi
>> 1set2end.
cmd
2486 echo --- Extra
setlocal in called batch
2488 rem -- setlocal1 == this batch, should never be used inside a called routine
2492 call %WINE_CURDIR%\
2set1end.
cmd
2495 for /d
%%i in
(.
) do echo %%~dpnxi
2498 for /d
%%i in
(.
) do echo %%~dpnxi
2501 echo --- Extra
endlocal in called batch
2503 rem -- setlocal1 == this batch, should never be used inside a called routine
2507 call %WINE_CURDIR%\
1set2end.
cmd
2510 for /d
%%i in
(.
) do echo %%~dpnxi
2513 for /d
%%i in
(.
) do echo %%~dpnxi
2516 echo --- endlocal in called function rather than batch pgm is ineffective
2522 call :endlocalroutine
2526 goto :endlocalfinished
2544 cd ..
& rd /q
/s foobar
2546 echo ------------ Testing
Errorlevel ------------
2547 rem WARNING: Do *not* add tests using ErrorLevel after this section
2548 should_not_exist
2> nul
> nul
2550 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2551 rem See http://www.robvanderwoude.com/exit.php
2554 if errorlevel 2 echo errorlevel too high
, bad
2555 if errorlevel 1 echo errorlevel just right
, good
2556 if errorlevel 01 echo errorlevel with leading zero just right
, good
2557 if errorlevel -1 echo errorlevel with negative number OK
2558 if errorlevel 0x1 echo hexa should
not be recognized
!
2559 if errorlevel 1a
echo invalid error level recognized
!
2561 echo abc
%ErrorLevel%def
2562 if errorlevel 1 echo errorlevel nonzero
, bad
2563 if not errorlevel 1 echo errorlevel zero
, good
2564 if not errorlevel 0x1 echo hexa should
not be recognized
!
2565 if not errorlevel 1a
echo invalid error level recognized
!
2566 rem Now verify that setting a real variable hides its magic variable
2568 echo %ErrorLevel% should be
7
2569 if errorlevel 7 echo setting var worked too well
, bad
2571 echo %ErrorLevel% should still be
7
2573 echo ------------ Testing
GOTO ------------
2575 echo FAILURE at dest
1
2577 echo goto with no leading space worked
2578 if a
==a
goto :dest1b
2579 echo FAILURE at dest
1b
2581 echo goto with colon and no leading space worked
2583 echo FAILURE at dest
2
2585 echo goto with a leading space worked
2587 echo FAILURE at dest
3
2589 echo goto with a leading tab worked
2591 echo FAILURE at dest
4
2593 echo goto with a following space worked
2595 echo FAILURE at dest
5
2596 :dest5&& echo FAILURE
2597 echo goto with following amphersands worked
2599 del failure.txt
>nul
2>&1
2601 echo FAILURE at dest
6
2603 if exist FAILURE.TXT
echo FAILURE at dest
6 as file exists
2604 echo goto with redirections worked
2605 del FAILURE.TXT
>nul
2>&1
2607 :: some text that is ignored |
dir >cmd_output | another test
2608 if exist cmd_output
echo FAILURE at dest
6 as file exists
2609 echo Ignoring double colons worked
2610 del cmd_output
>nul
2>&1
2612 rem goto a label which does not exist issues an error message and
2613 rem acts the same as goto :EOF, and ensure ::label is never matched
2614 del testgoto.bat
>nul
2>&1
2615 echo goto :dest7 ^
>nul
2^
>^
&1 >> testgoto.bat
2616 echo echo FAILURE at dest
7 - Should have
not found
label and issued an error plus ended the batch
>> testgoto.bat
2617 echo ::dest7>> testgoto.bat
2618 echo echo FAILURE at dest
7 - Incorrectly went to
label >> testgoto.bat
2620 del testgoto.bat
>nul
2>&1
2622 del testgoto.bat
>nul
2>&1
2623 echo goto ::dest8 ^
>nul
2^
>^
&1 >> testgoto.bat
2624 echo echo FAILURE at dest
8 - Should have
not found
label and issued an error plus ended the batch
>> testgoto.bat
2625 echo ::dest8>> testgoto.bat
2626 echo echo FAILURE at dest
8 - Incorrectly went to
label >> testgoto.bat
2628 del testgoto.bat
>nul
2>&1
2631 echo FAILURE at dest
9
2633 echo FAILURE at dest
91
2635 echo label with mixed whitespace and no
echo worked
2637 if h
==h
goto :dest10:this is ignored
2638 echo FAILURE at dest
10
2639 :dest10:this is also ignored
2640 echo Correctly ignored trailing information
2642 echo ------------ Testing
PATH ------------
2643 set WINE_backup_path
=%path%
2650 set path=%WINE_backup_path%
2651 set WINE_backup_path
=
2653 echo ------------ Testing combined CALLs
/GOTOs
------------
2654 echo @
echo off
>foo.
cmd
2655 echo goto :eof>>foot.
cmd
2657 echo echo world
>>foo.
cmd
2659 echo @
echo off
>foot.
cmd
2660 echo echo cheball
>>foot.
cmd
2662 echo call :bar>>foot.
cmd
2663 echo if "%%1"=="deleteMe" (del foot.
cmd)>>foot.
cmd
2664 echo goto :eof>>foot.
cmd
2667 echo echo barbare
>>foot.
cmd
2668 echo goto :eof>>foot.
cmd
2674 rem Script execution stops after the following line
2697 echo Final message is
not output since earlier
'foot' processing stops script execution
2698 echo Do NOT add any tests below this line
2700 echo ------------ Done
, jumping to EOF
-----------
2702 rem Subroutine to set errorlevel and return
2703 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
2706 rem This line runs under cmd in windows NT 4, but not in more modern versions.