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 ~p0 should be path containing batch file
318 echo ~dp0 should be directory containing batch file
331 echo P%WINE_UNKNOWN%S
334 echo %ERRORLEVEL%%ERRORLEVEL%
335 echo %ERRORLEVEL%ERRORLEVEL%
342 echo ------------ Testing variable substrings ------------
347 echo '%WINE_VAR:~-2,3%'
348 echo '%WINE_VAR:~-2,1%'
349 echo %WINE_VAR:~2,-1%
350 echo %WINE_VAR:~2,-3%
351 echo '%WINE_VAR:~-2,-4%'
352 echo %WINE_VAR:~-3,-2%
355 echo ------------ Testing variable substitution ------------
356 echo --- in FOR variables
357 for %%i in ("A B" C) do echo %%i
358 rem check works when prefix with @
359 @for %%i in ("A B" C) do echo %%i
361 for %%i in ("A B" C) do echo '%%~i'
362 rem fully qualified path
363 for %%f in ("C D" E) do echo %%~ff
365 for %%i in ("F G" H) do echo %%~di
367 for %%d in ("I J" K) do echo %%~pd
369 for %%i in ("L M" N) do echo %%~ni
371 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
372 rem path with short path names
373 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
375 for %%i in ("U V" W) do echo '%%~ai'
377 for %%i in (foo) do echo '%%~ai'
378 for %%i in (foo) do echo '%%~zi'
381 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
382 for %%i in ("a b" c) do echo '%%~ti'
384 rem Similar issues as above
385 for %%i in ("a b" c) do echo '%%~zi'
387 for %%i in ("d e" f) do echo %%~dpi
388 for %%i in ("g h" i) do echo %%~sdi
389 for %%i in ("g h" i) do echo %%~dsi
390 for %%i in ("j k" l.eh) do echo '%%~xsi'
391 for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
393 echo --- in parameters
394 for %%i in ("A B" C) do call :echoFun %%i
396 for %%i in ("A B" C) do call :echoFunQ %%i
397 rem fully qualified path
398 for %%f in ("C D" E) do call :echoFunF %%f
400 for %%i in ("F G" H) do call :echoFunD %%i
402 for %%d in ("I J" K) do call :echoFunP %%d
404 for %%i in ("L M" N) do call :echoFunN %%i
406 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
407 rem path with short path names
408 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
409 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
411 for %%i in ("d e" f) do call :echoFunDP %%i
412 for %%i in ("g h" i) do call :echoFunSD %%i
413 for %%i in ("g h" i) do call :echoFunDS %%i
414 for %%i in ("j k" l.eh) do call :echoFunXS %%i
446 rem some NT4 workaround
469 echo ------------ Testing variable delayed expansion ------------
470 rem NT4 doesn't support this
471 echo --- default mode (load-time expansion)
475 if %WINE_FOO% == foo (
477 if %WINE_FOO% == bar (echo bar) else echo foo
481 if %WINE_FOO% == foo (
483 if !WINE_FOO! == bar (echo bar) else echo foo
486 echo --- runtime (delayed) expansion mode
487 setlocal EnableDelayedExpansion
491 if %WINE_FOO% == foo (
493 if %WINE_FOO% == bar (echo bar) else echo foo
497 if %WINE_FOO% == foo (
499 if !WINE_FOO! == bar (echo bar) else echo foo
502 setlocal DisableDelayedExpansion
508 echo --- using /V cmd flag
509 echo @echo off> tmp.cmd
510 echo set WINE_FOO=foo>> tmp.cmd
511 echo echo %%WINE_FOO%%>> tmp.cmd
512 echo echo !WINE_FOO!>> tmp.cmd
513 echo set WINE_FOO=>> tmp.cmd
515 cmd /V:OfF /C tmp.cmd
518 echo ------------ Testing conditional execution ------------
519 echo --- unconditional ampersand
520 call :setError 123 & echo foo1
521 echo bar2 & echo foo2
522 mkdir foobar & cd foobar
524 cd .. & rd /s/q foobar
526 echo foobar not deleted!
529 ) else echo foobar deleted
530 echo --- on success conditional and
531 call :setError 456 && echo foo3 > foo3
535 ) else echo foo3 not created
536 echo bar4 && echo foo4
537 echo --- on failure conditional or
538 call :setError 789 || echo foo5
539 echo foo6 || echo bar6 > bar6
545 echo ------------ Testing cd ------------
548 echo blabla > singleFile
550 echo Current dir: %CD%
565 if not exist foobar (cd ..)
567 cd@tab@..@tab@@space@@tab@
569 if not exist foobar (cd ..)
583 cd "bar bak@space@"@tab@@space@
594 echo ------------ Testing type ------------
608 echo ------------ Testing NUL ------------
609 md foobar & cd foobar
610 rem NUL file (non) creation + case insensitivity
611 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
620 rem NUL not special everywhere
623 if not exist foo (echo foo should have been created) else (
627 rem Empty file creation
637 copy a.a+NUL b.b >nul
638 call :CheckFileSize a.a 7 b.b 8
639 copy NUL+a.a b.b >nul
640 call :CheckFileSize a.a 7 b.b 8
642 copy a.a+NUL subdir\ >nul
643 call :CheckFileSize a.a 7 subdir\a.a 8
647 if exist a.a echo Failed
651 cd .. & rd foobar /s /q
653 echo ------------ Testing if/else ------------
654 echo --- if/else should work with blocks
656 echo if seems to work
658 echo if seems to be broken
661 echo else seems to be broken
663 echo else seems to work
666 echo if seems not to detect /c as parameter
668 echo parameter detection seems to be broken
671 echo --- case sensitivity with and without /i option
672 if bar==BAR echo if does not default to case sensitivity
673 if not bar==BAR echo if seems to default to case sensitivity
674 if /i foo==FOO echo if /i seems to work
675 if /i not foo==FOO echo if /i seems to be broken
676 if /I foo==FOO echo if /I seems to work
677 if /I not foo==FOO echo if /I seems to be broken
679 echo --- string comparisons
680 if abc == abc (echo equal) else echo non equal
681 if abc =="abc" (echo equal) else echo non equal
682 if "abc"== abc (echo equal) else echo non equal
683 if "abc"== "abc" (echo equal) else echo non equal
685 echo --- tabs handling
686 if@tab@1==1 echo doom
687 if @tab@1==1 echo doom
688 if 1==1 (echo doom) else@tab@echo quake
689 if@tab@not @tab@1==@tab@0 @tab@echo lol
690 if 1==0@tab@(echo doom) else echo quake
691 if 1==0 (echo doom)@tab@else echo quake
692 if 1==0 (echo doom) else@tab@echo quake
694 echo --- comparison operators
695 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
696 echo ------ for strings
697 rem NT4 stops processing of the whole batch file as soon as it finds a
698 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
699 rem can't test those here.
700 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
701 if LSS LSS LSS (echo bar)
702 if 1.1 LSS 1.10 (echo floats are handled as strings)
703 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
704 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
705 if /i foo LSS FoOc echo if /i seems to work for LSS
706 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
707 set WINE_STR_PARMS=A B AB BA AA
708 for %%i in (%WINE_STR_PARMS%) do (
709 for %%j in (%WINE_STR_PARMS%) do (
710 call :LSStest %%i %%j))
711 if b LSS B (echo b LSS B) else echo NT4
712 if /I b LSS B echo b LSS B insensitive
713 if b LSS A echo b LSS A
714 if /I b LSS A echo b LSS A insensitive
715 if a LSS B (echo a LSS B) else echo NT4
716 if /I a LSS B echo a LSS B insensitive
717 if A LSS b echo A LSS b
718 if /I A LSS b echo A LSS b insensitive
719 for %%i in (%WINE_STR_PARMS%) do (
720 for %%j in (%WINE_STR_PARMS%) do (
721 call :LEQtest %%i %%j))
722 if b LEQ B (echo b LEQ B) else echo NT4
723 if /I b LEQ B echo b LEQ B insensitive
724 if b LEQ A echo b LEQ A
725 if /I b LEQ A echo b LEQ A insensitive
726 if a LEQ B (echo a LEQ B) else echo NT4
727 if /I a LEQ B echo a LEQ B insensitive
728 if A LEQ b echo A LEQ b
729 if /I A LEQ b echo A LEQ b insensitive
730 for %%i in (%WINE_STR_PARMS%) do (
731 for %%j in (%WINE_STR_PARMS%) do (
732 call :EQUtest %%i %%j))
733 if /I A EQU a echo A EQU a insensitive
734 for %%i in (%WINE_STR_PARMS%) do (
735 for %%j in (%WINE_STR_PARMS%) do (
736 call :NEQtest %%i %%j))
737 for %%i in (%WINE_STR_PARMS%) do (
738 for %%j in (%WINE_STR_PARMS%) do (
739 call :GEQtest %%i %%j))
740 for %%i in (%WINE_STR_PARMS%) do (
741 for %%j in (%WINE_STR_PARMS%) do (
742 call :GTRtest %%i %%j))
743 echo ------ for numbers
744 if -1 LSS 1 (echo negative numbers handled)
745 if not -1 LSS -10 (echo negative numbers handled)
746 if not 9 LSS 010 (echo octal handled)
747 if not -010 LSS -8 (echo also in negative form)
748 if 4 LSS 0x5 (echo hexa handled)
749 if not -1 LSS -0x1A (echo also in negative form)
750 if 11 LSS 101 (echo 11 LSS 101)
751 set WINE_INT_PARMS=0 1 10 9
752 for %%i in (%WINE_INT_PARMS%) do (
753 for %%j in (%WINE_INT_PARMS%) do (
754 call :LSStest %%i %%j))
755 for %%i in (%WINE_INT_PARMS%) do (
756 for %%j in (%WINE_INT_PARMS%) do (
757 call :LEQtest %%i %%j))
758 for %%i in (%WINE_INT_PARMS%) do (
759 for %%j in (%WINE_INT_PARMS%) do (
760 call :EQUtest %%i %%j))
761 if 011 EQU 9 (echo octal ok)
762 if 0xA1 EQU 161 (echo hexa ok)
763 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
764 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
765 for %%i in (%WINE_INT_PARMS%) do (
766 for %%j in (%WINE_INT_PARMS%) do (
767 call :NEQtest %%i %%j))
768 for %%i in (%WINE_INT_PARMS%) do (
769 for %%j in (%WINE_INT_PARMS%) do (
770 call :GEQtest %%i %%j))
771 for %%i in (%WINE_INT_PARMS%) do (
772 for %%j in (%WINE_INT_PARMS%) do (
773 call :GTRtest %%i %%j))
774 echo ------ for numbers and stringified numbers
775 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
776 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
777 if '1' EQU 1 echo '1' EQU 1
778 if 1 EQU '1' echo 1 EQU '1'
779 if not "1" GEQ 1 (echo foo) else echo bar
780 if "10" GEQ "1" echo "10" GEQ "1"
781 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
782 if 1 GEQ "1" echo 1 GEQ "1"
783 if "1" GEQ "1" echo "1" GEQ "1"
784 if '1' GEQ "1" echo '1' GEQ "1"
785 if "10" GEQ "1" echo "10" GEQ "1"
786 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
787 for %%i in ("1" '1') do call :GEQtest %%i '1'
788 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
789 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
790 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
791 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
792 if "10" GEQ "10" (echo "10" GEQ "10")
793 goto :endIfCompOpsSubroutines
795 rem IF subroutines helpers
797 if %1 LSS %2 echo %1 LSS %2
800 if %1 LEQ %2 echo %1 LEQ %2
803 if %1 EQU %2 echo %1 EQU %2
806 if %1 NEQ %2 echo %1 NEQ %2
809 if %1 GEQ %2 echo %1 GEQ %2
812 if %1 GTR %2 echo %1 GTR %2
815 :endIfCompOpsSubroutines
819 echo ------------ Testing for ------------
821 for %%i in (A B C) do echo %%i
822 for %%i in (A B C) do echo %%I
823 for %%i in (A B C) do echo %%j
824 for %%i in (A B C) do call :forTestFun1 %%i
825 for %%i in (1,4,1) do echo %%i
826 for %%i in (A, B,C) do echo %%i
827 for %%i in (X) do echo %%i
828 for@tab@%%i in (X2) do echo %%i
829 for %%i in@tab@(X3) do echo %%i
830 for %%i in (@tab@ foo@tab@) do echo %%i
831 for@tab@ %%i in@tab@(@tab@M) do echo %%i
832 for %%i@tab@in (X)@tab@do@tab@echo %%i
833 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
834 for %%i in (`echo A B`) do echo %%i
835 for %%i in ('echo A B') do echo %%i
836 for %%i in ("echo A B") do echo %%i
837 for %%i in ("A B" C) do echo %%i
843 echo --- imbricated FORs
850 for %%i in (A B) do (
851 for %%j in (C D) do (
853 for %%i in (A B) do (
854 for %%j in (C D) do (
855 call :forTestFun2 %%i %%j ))
861 mkdir foobar & cd foobar
866 echo --- basic wildcards
867 for %%i in (ba*) do echo %%i
869 for /d %%i in (baz foo bar) do echo %%i 2>&1
870 rem Confirm we don't match files:
871 for /d %%i in (bazb*) do echo %%i 2>&1
872 for /d %%i in (bazb2*) do echo %%i 2>&1
873 rem Show we pass through non wildcards
874 for /d %%i in (PASSED) do echo %%i
875 for /d %%i in (xxx) do (
876 echo %%i - Should be xxx
877 echo Expected second line
879 rem Show we issue no messages on failures
880 for /d %%i in (FAILED?) do echo %%i 2>&1
881 for /d %%i in (FAILED?) do (
882 echo %%i - Unexpected!
883 echo FAILED Unexpected second line
885 for /d %%i in (FAILED*) do echo %%i 2>&1
886 for /d %%i in (FAILED*) do (
887 echo %%i - Unexpected!
888 echo FAILED Unexpected second line
890 rem FIXME can't test wildcard expansion here since it's listed in directory
891 rem order, and not in alphabetic order.
892 rem Proper testing would need a currently missing "sort" program implementation.
893 rem for /d %%i in (ba*) do echo %%i>> tmp
896 rem for /d %%i in (?a*) do echo %%i>> tmp
899 rem for /d %%i in (*) do echo %%i>> tmp
907 call :WriteLine set WINE_found=N
908 for /l %%i in (1,1,%WINE_expectedresults%) do (
909 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%1" set WINE_found=Y
910 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
911 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
913 call :WriteLine echo Got unexpected result: "%%%%1"
922 for /l %%i in (1,1,%WINE_expectedresults%) do (
923 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
930 rem %CD% does not tork on NT4 so use the following workaround
931 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
934 echo Plain directory enumeration
935 set WINE_expectedresults=4
936 set WINE_expectedresults.1=%WINE_CURDIR%\.
937 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
938 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
939 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
941 for /R %%i in (.) do call temp.bat %%i
942 call :ValidateExpected
944 echo Plain directory enumeration from provided root
945 set WINE_expectedresults=4
946 set WINE_expectedresults.1=%WINE_CURDIR%\.
947 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
948 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
949 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
950 if "%CD%"=="" goto :SkipBrokenNT4
952 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat %%i
953 call :ValidateExpected
956 echo File enumeration
957 set WINE_expectedresults=2
958 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
959 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
961 for /R %%i in (baz*) do call temp.bat %%i
962 call :ValidateExpected
964 echo File enumeration from provided root
965 set WINE_expectedresults=2
966 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
967 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
969 for /R %%i in (baz*) do call temp.bat %%i
970 call :ValidateExpected
972 echo Mixed enumeration
973 set WINE_expectedresults=6
974 set WINE_expectedresults.1=%WINE_CURDIR%\.
975 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
976 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
977 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
978 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
979 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
981 for /R %%i in (. baz*) do call temp.bat %%i
982 call :ValidateExpected
984 echo Mixed enumeration from provided root
985 set WINE_expectedresults=6
986 set WINE_expectedresults.1=%WINE_CURDIR%\.
987 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
988 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
989 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
990 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
991 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
993 for /R %%i in (. baz*) do call temp.bat %%i
994 call :ValidateExpected
996 echo With duplicates enumeration
997 set WINE_expectedresults=12
998 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
999 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
1000 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
1001 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1002 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
1003 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
1004 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
1005 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
1006 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1007 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1008 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1009 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1011 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat %%i
1012 call :ValidateExpected
1014 echo Strip missing wildcards, keep unwildcarded names
1015 set WINE_expectedresults=6
1016 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1017 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1018 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1019 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1020 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1021 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1023 for /R %%i in (baz* fred* jim) do call temp.bat %%i
1024 call :ValidateExpected
1027 echo --- Complex wildcards unix and windows slash
1029 echo Windows slashs, valid path
1030 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1031 for %%f in (foobar\baz\*) do echo WC : %%f
1032 echo Windows slashs, invalid path
1033 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1034 for %%f in (foobar\jim\*) do echo WC : %%f
1035 echo Unix slashs, valid path
1036 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1037 for %%f in (foobar/baz/*) do echo WC : %%f
1038 echo Unix slashs, invalid path
1039 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1040 for %%f in (foobar/jim/*) do echo WC : %%f
1044 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
1045 for /L %%i in (1,2,0) do echo %%i
1046 for@tab@/L %%i in (1,2,0) do echo %%i
1047 for /L %%i in (1,2,6) do echo %%i
1048 for /l %%i in (1 ,2,6) do echo %%i
1049 for /L %%i in (a,2,3) do echo %%i
1050 for /L %%i in (1,2,-1) do echo %%i
1051 for /L %%i in (-4,-1,-1) do echo %%i
1052 for /L %%i in (1,-2,-2) do echo %%i
1053 for /L %%i in (1,2,a) do echo %%i
1054 echo ErrorLevel %ErrorLevel%
1055 for /L %%i in (1,a,b) do echo %%i
1056 echo ErrorLevel %ErrorLevel%
1058 for /l %%i in (1,1,4) do echo %%i
1059 for /l %%i in (1,2,4) do echo %%i
1060 for /l %%i in (4,-1,1) do echo %%i
1061 for /l %%i in (4,-2,1) do echo %%i
1062 for /l %%i in (1,-1,4) do echo %%i
1063 for /l %%i in (4,1,1) do echo %%i
1064 for /L %%i in (a,2,b) do echo %%i
1065 for /L %%i in (1,1,1) do echo %%i
1066 for /L %%i in (1,-2,-1) do echo %%i
1067 for /L %%i in (-1,-1,-1) do echo %%i
1068 for /L %%i in (1,2, 3) do echo %%i
1069 rem Test zero iteration skips the body of the for
1070 for /L %%i in (2,2,1) do (
1077 Rem Ideally for /f can be used rather than building a command to execute
1078 rem but that does not work on NT4
1080 if "%1"=="" goto :eof
1081 call :executecmd set wine_result=%%%1%%
1082 if "%wine_result%"=="%2" (
1083 echo %1 correctly %2
1084 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1095 rem No output when using "set expr" syntax, unless in interactive mode
1096 rem Need to use "set envvar=expr" to use in a batch script
1097 echo ------ individual operations
1099 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1100 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1101 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1102 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1103 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1104 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1105 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1106 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1107 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1108 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1109 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1110 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1111 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1112 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1113 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1114 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1115 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1116 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1117 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1118 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1119 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1120 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1121 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1122 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1123 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1124 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1125 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1126 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1127 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1128 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1129 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1130 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1131 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1132 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1133 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1134 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1135 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1136 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1137 echo ------ precedence and grouping
1138 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1139 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1140 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1141 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1142 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1143 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1144 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1145 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1146 echo ------ octal and hexadecimal
1147 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1148 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1149 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1150 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1151 echo ------ variables
1152 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1153 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1154 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
1156 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1157 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1159 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1161 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1163 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1164 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1166 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1168 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1170 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1171 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1172 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1174 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1177 call :checkenvvars WINE_foo 1
1179 call :checkenvvars WINE_foo 1
1180 set /a WINE_foo=1,WINE_bar=2
1181 call :checkenvvars WINE_foo 1 WINE_bar 2
1182 set /a "WINE_foo=1,WINE_bar=2"
1183 call :checkenvvars WINE_foo 1 WINE_bar 2
1184 set /a "WINE_foo=1","WINE_bar=2"
1185 call :checkenvvars WINE_foo 1 WINE_bar 2
1186 set /a ""WINE_foo=1","WINE_bar=2""
1187 call :checkenvvars WINE_foo 1 WINE_bar 2
1188 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1189 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1190 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
1191 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1192 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
1193 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1194 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1195 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1196 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
1197 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1198 set /a """"""WINE_foo=1""""""
1199 call :checkenvvars WINE_foo 1
1200 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1201 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1202 set /a WINE_foo="3"+"4"+"5+6"
1203 call :checkenvvars WINE_foo 18
1205 set /a WINE_bar="WINE_""foo"+4
1206 call :checkenvvars WINE_foo 3 WINE_bar 7
1207 echo --- whitespace are ignored between double char operators
1210 set /a WINE_foo + = 6
1211 set /a WINE_bar * = WINE_foo
1212 call :checkenvvars WINE_foo 10 WINE_bar 50
1215 set /a WINE_foo + = "6 < < 7"
1216 set /a WINE_bar * = WINE_foo + WINE_foo
1217 call :checkenvvars WINE_foo 772 WINE_bar 7720
1221 echo --- invalid operator sequence
1227 set /a WINE_foo^>^<=4
1229 set /a WINE_foo^>^>^>=4
1231 echo ----- negative prefix
1233 call :checkenvvars WINE_foo -1
1235 call :checkenvvars WINE_foo 1
1236 set /a WINE_foo=3--3
1237 call :checkenvvars WINE_foo 6
1238 set /a WINE_foo=3---3
1239 call :checkenvvars WINE_foo 0
1240 set /a WINE_foo=3----3
1241 call :checkenvvars WINE_foo 6
1243 call :checkenvvars WINE_foo 2
1245 call :checkenvvars WINE_foo 0
1246 set /a WINE_foo=3+-~1
1247 call :checkenvvars WINE_foo 5
1248 set /a WINE_foo=3+~-1
1249 call :checkenvvars WINE_foo 3
1250 echo ----- assignment tests involving the end destination
1252 set /a WINE_foo+=3+(WINE_foo=4)
1253 call :checkenvvars WINE_foo 11
1255 set /a WINE_bar=3+(WINE_foo=6)
1256 call :checkenvvars WINE_foo 6 WINE_bar 9
1258 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1259 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1261 set /a WINE_bar=WINE_foo=7
1262 call :checkenvvars WINE_foo 7 WINE_bar 7
1263 echo ----- equal precedence on stack
1264 rem Unary - don't reduce if precedence is equal
1266 call :checkenvvars WINE_foo 1
1268 call :checkenvvars WINE_foo 0
1270 call :checkenvvars WINE_foo 1
1272 call :checkenvvars WINE_foo 0
1274 call :checkenvvars WINE_foo 1
1276 call :checkenvvars WINE_foo -1
1278 call :checkenvvars WINE_foo -1
1280 call :checkenvvars WINE_foo 1
1282 call :checkenvvars WINE_foo 0
1284 call :checkenvvars WINE_foo -1
1286 call :checkenvvars WINE_foo 0
1288 call :checkenvvars WINE_foo 0
1290 call :checkenvvars WINE_foo 1
1292 call :checkenvvars WINE_foo -1
1293 rem Aritmatic - Reduce if precedence is equal
1294 set /a WINE_foo=10*5/2
1295 call :checkenvvars WINE_foo 25
1296 set /a WINE_foo=5/2*10
1297 call :checkenvvars WINE_foo 20
1298 set /a WINE_foo=10/5/2
1299 call :checkenvvars WINE_foo 1
1300 set /a WINE_foo=5%%2*4
1301 call :checkenvvars WINE_foo 4
1302 set /a WINE_foo=10-5+2
1303 call :checkenvvars WINE_foo 7
1304 set /a WINE_foo=1^<^<4^>^>1
1305 call :checkenvvars WINE_foo 8
1306 rem Assignment - don't reduce if precedence is equal
1308 set /a WINE_bar=WINE_foo=6
1309 call :checkenvvars WINE_foo 6 WINE_bar 6
1312 mkdir foobar & cd foobar
1313 echo ------ string argument
1314 rem NT4 does not support usebackq
1315 for /F %%i in ("a b c") do echo %%i
1316 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1317 if not exist output_file (echo no output) else (type output_file & del output_file)
1318 for /f %%i in ("a ") do echo %%i
1319 for /f usebackq %%i in ('a ') do echo %%i>output_file
1320 if not exist output_file (echo no output) else (type output_file & del output_file)
1321 for /f %%i in ("a") do echo %%i
1322 for /f usebackq %%i in ('a') do echo %%i>output_file
1323 if not exist output_file (echo no output) else (type output_file & del output_file)
1324 fOr /f %%i in (" a") do echo %%i
1325 for /f usebackq %%i in (' a') do echo %%i>output_file
1326 if not exist output_file (echo no output) else (type output_file & del output_file)
1327 for /f %%i in (" a ") do echo %%i
1328 for /f usebackq %%i in (' a ') do echo %%i>output_file
1329 if not exist output_file (echo no output) else (type output_file & del output_file)
1330 echo ------ fileset argument
1331 echo --------- basic blank handling
1333 for /f %%i in (foo) do echo %%i
1335 for /f %%i in (foo) do echo %%i
1337 for /f %%i in (foo) do echo %%i
1339 for /f %%i in (foo) do echo %%i
1341 for /f %%i in (foo) do echo %%i
1343 for /f %%i in (foo) do echo %%i
1346 for /f %%i in (foo) do echo %%i
1347 echo --------- multi-line with empty lines
1354 for /f %%b in (foo) do echo %%b
1355 echo --------- multiple files
1359 for /f %%k in (foo bar) do echo %%k
1360 for /f %%k in (bar foo) do echo %%k
1361 echo ------ command argument
1362 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1363 if "%CD%"=="" goto :SkipFORFcmdNT4
1364 for /f %%i in ('echo.Passed1') do echo %%i
1365 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
1366 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1369 for /l %%i in (1,1,3) do echo Missing functionality - Broken%%i
1371 rem FIXME: Rest not testable right now in wine: not implemented and would need
1372 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1373 rem for a simple todo_wine test
1374 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1375 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1376 echo ------ eol option
1377 if "%CD%"=="" goto :SkipFORFeolNT4
1379 echo and Line two>>foo
1380 echo Line three>>foo
1381 for /f "eol=L" %%i in (foo) do echo %%i
1382 for /f "eol=a" %%i in (foo) do echo %%i
1384 goto :ContinueFORFeol
1386 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1388 for /f "eol=@" %%i in (" ad") do echo %%i
1389 for /f "eol=@" %%i in (" z@y") do echo %%i
1390 for /f "eol=|" %%i in ("a|d") do echo %%i
1391 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
1392 if not exist output_file (echo no output) else (del output_file)
1393 for /f "eol==" %%i in ("=y") do echo %%i > output_file
1394 if not exist output_file (echo no output) else (del output_file)
1395 echo ------ delims option
1396 for /f "delims=|" %%i in ("a|d") do echo %%i
1397 for /f "delims=|" %%i in ("a |d") do echo %%i
1398 for /f "delims=|" %%i in ("a d|") do echo %%i
1399 for /f "delims=| " %%i in ("a d|") do echo %%i
1400 for /f "delims==" %%i in ("C r=d|") do echo %%i
1401 for /f "delims=" %%i in ("foo bar baz") do echo %%i
1402 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
1403 echo ------ skip option
1407 for /f "skip=2" %%i in (foo) do echo %%i
1408 for /f "skip=3" %%i in (foo) do echo %%i > output_file
1409 if not exist output_file (echo no output) else (del output_file)
1410 for /f "skip=4" %%i in (foo) do echo %%i > output_file
1411 if not exist output_file (echo no output) else (del output_file)
1412 for /f "skip=02" %%i in (foo) do echo %%i
1413 for /f "skip=0x2" %%i in (foo) do echo %%i
1414 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
1415 if not exist output_file (echo no output) else (del output_file)
1416 echo ------ tokens= option
1418 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
1419 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
1420 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
1421 rem Show * means the rest
1422 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
1423 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
1424 rem Show * means the rest (not tokenized and rebuilt)
1425 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
1426 rem Order is irrelevant
1427 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
1428 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
1429 rem Duplicates are ignored
1430 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
1431 rem Large tokens are allowed
1432 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
1433 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1434 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
1435 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
1436 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1437 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
1438 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
1439 rem Show negative ranges have no effect
1440 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
1441 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
1442 rem Show duplicates stop * from working
1443 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
1444 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
1445 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
1446 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
1450 echo ------------ Testing del /a ------------
1451 del /f/q *.test > nul
1454 echo not-r > not-r.test
1456 if not exist not-r.test echo not-r.test not found before delete, bad
1458 if not exist not-r.test echo not-r.test not found after delete, good
1460 if not exist r.test echo r.test not found before delete, bad
1461 if exist r.test echo r.test found before delete, good
1463 if not exist r.test echo r.test not found after delete, good
1464 if exist r.test echo r.test found after delete, bad
1466 echo ------------ Testing del /q ------------
1470 echo abc > file2.dat
1471 rem If /q doesn't work, cmd will prompt and the test case should hang
1473 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1474 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1478 echo ------------ Testing del /s ------------
1483 echo there > file2.dat
1484 echo bub > file3.dat
1485 echo bye > "file with spaces.dat"
1487 del /s file1.dat > nul
1488 del file2.dat /s > nul
1489 del "file3.dat" /s > nul
1490 del "file with spaces.dat" /s > nul
1492 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1493 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1494 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
1495 if exist "file with spaces.dat" del "file with spaces.dat"
1500 echo ------------ Testing rename ------------
1501 mkdir foobar & cd foobar
1502 echo --- ren and rename are synonymous
1505 if exist foo echo foo should be renamed!
1506 if exist bar echo foo renamed to bar
1508 if exist bar echo bar should be renamed!
1509 if exist foo echo bar renamed to foo
1510 echo --- name collision
1520 echo --- rename read-only files
1524 if not exist file1 (
1526 echo read-only file renamed
1529 echo read-only file not renamed!
1531 echo --- rename directories
1543 echo read-only dir renamed
1546 echo --- rename in other directory
1547 if not exist baz\abc (
1548 echo rename impossible in other directory
1549 if exist foo echo original file still present
1551 echo shouldn't rename in other directory!
1552 if not exist foo echo original file not present anymore
1554 cd .. & rd /s/q foobar
1556 echo ------------ Testing move ------------
1557 mkdir foobar & cd foobar
1560 move foo bar > nul 2>&1
1563 echo file move succeeded
1568 move /Y bar baz > nul 2>&1
1571 echo file move with overwrite succeeded
1574 echo file overwrite impossible!
1580 move baz bazro > nul 2>&1
1583 echo read-only files are moveable
1584 move bazro baz > nul 2>&1
1587 echo read-only file not moved!
1591 move baz rep > nul 2>&1
1594 echo file moved in subdirectory
1598 move rep\baz . > nul 2>&1
1599 move /Y baz baz > nul 2>&1
1601 echo moving a file to itself should be a no-op!
1603 echo moving a file to itself is a no-op
1605 echo ErrorLevel: %ErrorLevel%
1608 echo --- directory move
1612 move baz foo\bar > nul 2>&1
1614 if exist foo\bar\baz\baz2 (
1615 echo simple directory move succeeded
1620 move baz baz > nul 2>&1
1621 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1622 echo ------ dir in dir move
1627 move foo bar > nul 2>&1
1635 cd .. & rd /s/q foobar
1637 echo ------------ Testing mkdir ------------
1639 echo --- md and mkdir are synonymous
1646 echo --- creating an already existing directory/file must fail
1655 echo --- multilevel path creation
1667 mkdir ..\..\..\foo\bar2
1670 mkdir ..\..\..\foo\bar2
1672 rmdir ..\..\..\foo\bar2
1680 echo --- trailing backslashes
1683 if exist foo (rmdir foo & echo dir created
1684 ) else ( echo dir not created )
1686 echo --- invalid chars
1688 echo mkdir ? gives errorlevel %ErrorLevel%
1691 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1694 echo mkdir foo\? gives errorlevel %ErrorLevel%
1695 if exist foo (rmdir foo & echo ok, foo created
1696 ) else ( echo foo not created )
1699 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1702 echo bad, foo not created
1706 echo ok, foo\bar created
1712 echo --- multiple directories at once
1713 mkdir foobaz & cd foobaz
1714 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
1715 if exist foo (echo foo created) else echo foo not created!
1716 if exist bar (echo bar created) else echo bar not created!
1717 if exist foobar (echo foobar created) else echo foobar not created!
1718 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
1719 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
1720 if exist zabzab (echo zabzab created) else echo zabzab not created!
1721 cd .. & rd /s/q foobaz
1724 echo mkdir foo\* errorlevel %ErrorLevel%
1725 if exist foo (rmdir foo & echo ok, foo created
1726 ) else ( echo bad, foo not created )
1728 echo ------------ Testing rmdir ------------
1730 rem rd and rmdir are synonymous
1734 if not exist foobar echo dir removed
1738 if not exist foobar echo dir removed
1739 rem Removing nonexistent directory
1742 rem Removing single-level directories
1746 if exist foo echo file not removed
1752 if exist foo echo non-empty dir not removed
1757 if exist foo echo non-empty dir not removed
1764 echo recursive rmdir succeeded
1771 echo foo > foo\bar\brol
1772 rmdir /s /Q foo 2>&1
1774 echo recursive rmdir succeeded
1781 rem multiples directories at once
1782 mkdir foobaz & cd foobaz
1786 rd /s/q foo bar foobar
1787 if not exist foo (echo foo removed) else echo foo not removed!
1788 if not exist bar (echo bar removed) else echo bar not removed!
1789 if not exist foobar (echo foobar removed) else echo foobar not removed!
1790 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
1791 cd .. & rd /s/q foobaz
1793 echo ------------ Testing pushd/popd ------------
1795 echo --- popd is no-op when dir stack is empty
1798 echo --- pushing non-existing dir
1801 echo --- basic behaviour
1826 echo ------------ Testing attrib ------------
1827 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
1828 mkdir foobar & cd foobar
1829 echo foo original contents> foo
1832 echo --- read-only attribute
1833 rem Read-only files cannot be altered or deleted, unless forced
1841 echo Read-only file not deleted
1843 echo Should not delete read-only file!
1847 echo Read-only file forcibly deleted
1849 echo Should delete read-only file with del /F!
1853 cd .. & rd /s/q foobar
1854 echo --- recursive behaviour
1855 mkdir foobar\baz & cd foobar
1861 attrib +R l*vel? /S > nul 2>&1
1867 cd .. & rd /s/q foobar
1868 echo --- folders processing
1874 attrib +r baz /s /d > nul 2>&1
1880 rem Oddly windows allows file creation in a read-only directory...
1881 if exist baz\lala (echo file created in read-only dir) else echo file not created
1882 cd .. & rd /s/q foobar
1884 echo ------------ Testing assoc ------------
1885 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1886 rem FIXME Revise once || conditional execution is fixed
1887 mkdir foobar & cd foobar
1888 echo --- setting association
1896 rem association set system-wide
1897 echo @echo off> tmp.cmd
1898 echo echo +++>> tmp.cmd
1899 echo assoc .foo>> tmp.cmd
1902 echo --- resetting association
1908 rem association removal set system-wide
1909 cmd /c tmp.cmd > baz
1912 cd .. & rd /s/q foobar
1914 echo ------------ Testing ftype ------------
1915 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1916 rem FIXME Revise once || conditional execution is fixed
1917 mkdir foobar & cd foobar
1918 echo --- setting association
1923 ftype footype=foo_opencmd
1927 rem association set system-wide
1928 echo @echo off> tmp.cmd
1929 echo echo +++>> tmp.cmd
1930 echo ftype footype>> tmp.cmd
1933 echo --- resetting association
1936 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
1937 setlocal EnableDelayedExpansion
1938 set WINE_FOO=original value
1941 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
1942 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
1943 rem FIXME Revisit once a grep-like program like ftype is implemented
1944 rem (e.g. to check baz's size using dir /b instead)
1947 rem cleanup registry
1948 echo REGEDIT4> regCleanup.reg
1949 echo.>> regCleanup.reg
1950 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
1951 regedit /s regCleanup.reg
1954 cd .. & rd /s/q foobar
1956 echo ------------ Testing CALL ------------
1957 mkdir foobar & cd foobar
1958 echo --- external script
1959 echo echo foo %%1> foo.cmd
1962 echo echo %%1 %%2 > foo.cmd
1964 call foo.cmd foo bar
1971 echo --- internal routines
1972 call :testRoutine :testRoutine
1973 goto :endTestRoutine
1979 call :testRoutineArgs foo
1980 call :testRoutineArgs foo bar
1981 call :testRoutineArgs foo ""
1982 call :testRoutineArgs "" bar
1983 call :testRoutineArgs foo ''
1984 call :testRoutineArgs '' bar
1985 goto :endTestRoutineArgs
1991 echo --- with builtins
1994 if exist foo (echo foo created) else echo foo should exist!
1996 set WINE_FOOBAZ_VAR=foobaz
1997 call echo Should expand %WINE_FOOBAZ_VAR%
1998 set WINE_FOOBAZ_VAR=
2002 if 1==1 call del batfile
2004 if exist batfile echo batfile shouldn't exist
2005 rem ... but not for 'if' or 'for'
2006 call if 1==1 echo bar 2> nul
2009 call for %%i in (foo bar baz) do echo %%i 2> nul
2011 rem First look for programs in the path before trying a builtin
2012 echo echo non-builtin dir> dir.cmd
2015 rem The below line equates to call (, which does nothing, then the
2016 rem subsequent lines are executed.
2021 rem The below line equates to call if, which always fails, then the
2022 rem subsequent lines are executed. Note cmd.exe swallows all lines
2029 call call call echo passed
2030 cd .. & rd /s/q foobar
2032 echo ------------ Testing SHIFT ------------
2034 call :shiftFun p1 p2 p3 p4 p5
2038 echo '%1' '%2' '%3' '%4' '%5'
2040 echo '%1' '%2' '%3' '%4' '%5'
2042 echo '%1' '%2' '%3' '%4' '%5'
2044 echo '%1' '%2' '%3' '%4' '%5'
2046 echo '%1' '%2' '%3' '%4' '%5'
2048 echo '%1' '%2' '%3' '%4' '%5'
2052 echo ------------ Testing cmd invocation ------------
2053 rem FIXME: only a stub ATM
2054 echo --- a batch file can delete itself
2055 echo del foo.cmd>foo.cmd
2057 if not exist foo.cmd (
2058 echo file correctly deleted
2060 echo file should be deleted!
2063 echo --- a batch file can alter itself
2064 echo echo bar^>foo.cmd>foo.cmd
2065 cmd /q /c foo.cmd > NUL 2>&1
2070 echo file not created!
2073 echo ---------- Testing copy
2076 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2079 echo CCCCCCCCC> file3
2085 echo Passed: Found expected %1
2087 echo Failed: Did not find expected %1
2089 del /q "%1" >nul 2>&1
2091 if not "%1"=="" goto :CheckExist
2096 echo Passed: Did not find %1
2098 echo Failed: Unexpectedly found %1
2099 del /q "%1" >nul 2>&1
2102 if not "%1"=="" goto :CheckNotExist
2105 rem Note: No way to check file size on NT4 so skip the test
2108 echo Failed: File missing when requested filesize check [%2]
2109 goto :ContinueFileSizeChecks
2111 for %%i in (%1) do set WINE_filesize=%%~zi
2112 if "%WINE_filesize%"=="%2" (
2113 echo Passed: file size check on %1 [%WINE_filesize%]
2115 if "%WINE_filesize%"=="%%~zi" (
2116 echo Skipping file size check on NT4
2118 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2121 :ContinueFileSizeChecks
2124 if not "%1"=="" goto :CheckFileSize
2129 rem -----------------------
2130 rem Simple single file copy
2131 rem -----------------------
2132 rem Simple single file copy, normally used syntax
2133 copy file1 dummy.file >nul 2>&1
2134 if errorlevel 1 echo Incorrect errorlevel
2135 call :CheckExist dummy.file
2137 rem Simple single file copy, destination supplied as two forms of directory
2138 copy file1 dir1 >nul 2>&1
2139 if errorlevel 1 echo Incorrect errorlevel
2140 call :CheckExist dir1\file1
2142 copy file1 dir1\ >nul 2>&1
2143 if errorlevel 1 echo Incorrect errorlevel
2144 call :CheckExist dir1\file1
2146 rem Simple single file copy, destination supplied as fully qualified destination
2147 copy file1 dir1\file99 >nul 2>&1
2148 if errorlevel 1 echo Incorrect errorlevel
2149 call :CheckExist dir1\file99
2151 rem Simple single file copy, destination not supplied
2153 copy ..\file1 >nul 2>&1
2154 if errorlevel 1 echo Incorrect errorlevel
2155 call :CheckExist file1
2158 rem Simple single file copy, destination supplied as nonexistent directory
2159 copy file1 dir2\ >nul 2>&1
2160 if not errorlevel 1 echo Incorrect errorlevel
2161 call :CheckNotExist dir2 dir2\file1
2163 rem -----------------------
2165 rem -----------------------
2166 rem Simple single file copy, destination supplied as two forms of directory
2167 copy file? dir1 >nul 2>&1
2168 if errorlevel 1 echo Incorrect errorlevel
2169 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2171 copy file* dir1\ >nul 2>&1
2172 if errorlevel 1 echo Incorrect errorlevel
2173 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2175 rem Simple single file copy, destination not supplied
2177 copy ..\file*.* >nul 2>&1
2178 if errorlevel 1 echo Incorrect errorlevel
2179 call :CheckExist file1 file2 file3
2182 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2183 copy file? dir2\ >nul 2>&1
2184 if not errorlevel 1 echo Incorrect errorlevel
2185 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2187 rem ------------------------------------------------
2188 rem Confirm overwrite works (cannot test prompting!)
2189 rem ------------------------------------------------
2190 copy file1 testfile >nul 2>&1
2191 copy /y file2 testfile >nul 2>&1
2192 call :CheckExist testfile
2194 rem ------------------------------------------------
2195 rem Test concatenation
2196 rem ------------------------------------------------
2197 rem simple case, no wildcards
2198 copy file1+file2 testfile >nul 2>&1
2199 if errorlevel 1 echo Incorrect errorlevel
2200 call :CheckExist testfile
2202 rem simple case, wildcards, no concatenation
2203 copy file* testfile >nul 2>&1
2204 if errorlevel 1 echo Incorrect errorlevel
2205 call :CheckExist testfile
2207 rem simple case, wildcards, and concatenation
2209 copy file*+fred testfile >nul 2>&1
2210 if errorlevel 1 echo Incorrect errorlevel
2211 call :CheckExist testfile
2213 rem simple case, wildcards, and concatenation
2214 copy fred+file* testfile >nul 2>&1
2215 if errorlevel 1 echo Incorrect errorlevel
2216 call :CheckExist testfile
2218 rem Calculate destination name
2219 copy fred+file* dir1 >nul 2>&1
2220 if errorlevel 1 echo Incorrect errorlevel
2221 call :CheckExist dir1\fred
2223 rem Calculate destination name
2224 copy fred+file* dir1\ >nul 2>&1
2225 if errorlevel 1 echo Incorrect errorlevel
2226 call :CheckExist dir1\fred
2228 rem Calculate destination name (none supplied)
2230 copy ..\fred+..\file* >nul 2>&1
2231 if errorlevel 1 echo Incorrect errorlevel
2232 call :CheckExist fred
2234 copy ..\fr*+..\file1 >nul 2>&1
2235 if errorlevel 1 echo Incorrect errorlevel
2236 call :CheckExist fred
2239 rem ******************************************************************
2240 rem ASCII and BINARY tests
2241 rem Note: hard coded numbers deliberate because need to ensure whether
2242 rem an additional EOF has been added or not. There is no way to handle
2243 rem EOFs in batch, so assume if a single byte appears, it's an EOF!
2244 rem ******************************************************************
2246 rem Confirm original sizes of file1,2,3
2247 call :CheckFileSize file1 5 file2 8 file3 11
2251 rem ----------------------------------------------
2252 rem Show concatenation defaults copy to ascii mode
2253 rem ----------------------------------------------
2254 rem Simple default copy source to destination (should not append EOF 5)
2255 copy ..\file1 file1_default >nul 2>&1
2256 call :CheckFileSize file1_default 5
2258 rem Simple binary copy source to destination (should not append EOF 5)
2259 copy /b ..\file1 file1_default2 >nul 2>&1
2260 call :CheckFileSize file1_default2 5
2262 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2263 copy /a ..\file1 file1_plus_eof >nul 2>&1
2264 call :CheckFileSize file1_plus_eof 6
2265 copy /a ..\file2 file2_plus_eof >nul 2>&1
2266 call :CheckFileSize file2_plus_eof 9
2267 copy /a ..\file3 file3_plus_eof >nul 2>&1
2268 call :CheckFileSize file3_plus_eof 12
2270 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2271 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2272 call :CheckFileSize file12_plus_eof 14
2274 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2275 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2276 call :CheckFileSize file12_no_eof 13
2278 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2279 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2280 call :CheckFileSize file12_eof2 14
2282 rem --------------------------------------------------------------
2283 rem Show ascii source copy stops at first EOF, binary does the lot
2284 rem --------------------------------------------------------------
2285 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2286 call :CheckFileSize file1_binary_srccopy 6
2288 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2289 call :CheckFileSize file1_ascii_srccopy 5
2291 rem --------------------------------------------------------------
2292 rem Show results of concatenating files (ending in EOFs) and /a /b
2293 rem --------------------------------------------------------------
2295 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2296 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2297 call :CheckFileSize file123_default_copy 25
2298 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2299 call :CheckFileSize file123_ascii_copy 25
2301 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2302 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2303 call :CheckFileSize file123_binary_copy 27
2305 rem We can select which we want the eofs from by postfixing it with /a or /b
2306 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2307 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2308 call :CheckFileSize file123_mixed_copy1 26
2310 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2311 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2312 rem Note the delta between this and the previous one also shows that the destination
2313 rem ascii/binary is inherited from the last /a or /b on the line
2314 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2315 call :CheckFileSize file123_mixed_copy2 27
2317 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2318 rem Note the delta between the next two also shows that the destination ascii/binary is
2319 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2320 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2321 call :CheckFileSize file123_mixed_copy3 26
2322 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2323 call :CheckFileSize file123_mixed_copy4 25
2325 rem -------------------------------------------------------------------------------------------
2326 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2327 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2328 rem -------------------------------------------------------------------------------------------
2330 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2331 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2332 call :CheckFileSize file123_mixed_copy5 28
2334 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2335 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2336 call :CheckFileSize file123_mixed_copy6 19
2338 rem One file has EOF, but doesn't get an extra one, i.e. 6
2339 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2340 call :CheckFileSize file123_mixed_copy7 6
2342 rem Syntax means concatenate so ascii destination kicks in
2343 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2344 call :CheckFileSize file123_mixed_copy8 7
2349 rem ---------------------------------------
2350 rem Error combinations
2351 rem ---------------------------------------
2352 rem Specify source directory but name is a file
2354 copy file1\ dir1\ >NUL 2>&1
2355 if errorlevel 1 echo Passed: errorlevel invalid check 1
2356 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2357 call :CheckNotExist dir1\file1
2359 rem Overwrite same file
2361 copy file1 file1 >NUL 2>&1
2362 if errorlevel 1 echo Passed: errorlevel invalid check 2
2363 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2365 rem Supply same file identified as a directory
2367 copy file1 file1\ >NUL 2>&1
2368 if errorlevel 1 echo Passed: errorlevel invalid check 3
2369 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2374 echo ------------ Testing setlocal/endlocal ------------
2376 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2377 mkdir foobar & cd foobar
2378 echo --- enable/disable extensions
2379 setlocal DisableEXTensions
2380 echo ErrLev: %ErrorLevel%
2382 echo ErrLev: %ErrorLevel%
2383 echo @echo off> tmp.cmd
2384 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2385 rem Enabled by default
2387 cmd /E:OfF /C tmp.cmd
2388 cmd /e:oN /C tmp.cmd
2390 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2391 echo --- setlocal with corresponding endlocal
2392 rem %CD% does not tork on NT4 so use the following workaround
2393 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2394 echo @echo off> test.cmd
2395 echo echo %%WINE_VAR%%>> test.cmd
2396 echo setlocal>> test.cmd
2397 echo set WINE_VAR=localval>> test.cmd
2398 echo md foobar2>> test.cmd
2399 echo cd foobar2>> test.cmd
2400 echo echo %%WINE_VAR%%>> test.cmd
2401 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2402 echo endlocal>> test.cmd
2403 echo echo %%WINE_VAR%%>> test.cmd
2404 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2405 set WINE_VAR=globalval
2408 for /d %%i in (.) do echo %%~dpnxi
2412 echo --- setlocal with no corresponding endlocal
2413 echo @echo off> test.cmd
2414 echo echo %%WINE_VAR%%>> test.cmd
2415 echo setlocal>> test.cmd
2416 echo set WINE_VAR=localval>> test.cmd
2417 echo md foobar2>> test.cmd
2418 echo cd foobar2>> test.cmd
2419 echo echo %%WINE_VAR%%>> test.cmd
2420 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2421 set WINE_VAR=globalval
2422 rem %CD% does not tork on NT4 so use the following workaround
2423 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2426 for /d %%i in (.) do echo %%~dpnxi
2430 echo --- setlocal within same batch program
2434 rem %CD% does not tork on NT4 so use the following workaround
2435 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2442 if "%WINE_var1%"=="one" echo Var1 ok 1
2443 if "%WINE_var2%"=="two" echo Var2 ok 2
2444 if "%WINE_var3%"=="three" echo Var3 ok 3
2445 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2446 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
2448 if "%WINE_var1%"=="one" echo Var1 ok 1
2449 if "%WINE_var2%"=="two" echo Var2 ok 2
2450 if "%WINE_var3%"=="" echo Var3 ok 3
2451 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2452 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
2454 if "%WINE_var1%"=="one" echo Var1 ok 1
2455 if "%WINE_var2%"=="" echo Var2 ok 2
2456 if "%WINE_var3%"=="" echo Var3 ok 3
2457 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2458 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
2462 echo --- Mismatched set and end locals
2466 rem %CD% does not tork on NT4 so use the following workaround
2467 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
2469 echo @echo off> 2set1end.cmd
2470 echo echo %%WINE_var%%>> 2set1end.cmd
2471 echo setlocal>> 2set1end.cmd
2472 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
2473 echo cd ..\foodir3>> 2set1end.cmd
2474 echo setlocal>> 2set1end.cmd
2475 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
2476 echo cd ..\foodir4>> 2set1end.cmd
2477 echo endlocal>> 2set1end.cmd
2478 echo echo %%WINE_var%%>> 2set1end.cmd
2479 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
2481 echo @echo off> 1set2end.cmd
2482 echo echo %%WINE_var%%>> 1set2end.cmd
2483 echo setlocal>> 1set2end.cmd
2484 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
2485 echo cd ..\foodir3>> 1set2end.cmd
2486 echo endlocal>> 1set2end.cmd
2487 echo echo %%WINE_var%%>> 1set2end.cmd
2488 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2489 echo endlocal>> 1set2end.cmd
2490 echo echo %%WINE_var%%>> 1set2end.cmd
2491 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2493 echo --- Extra setlocal in called batch
2495 rem -- setlocal1 == this batch, should never be used inside a called routine
2499 call %WINE_CURDIR%\2set1end.cmd
2502 for /d %%i in (.) do echo %%~dpnxi
2505 for /d %%i in (.) do echo %%~dpnxi
2508 echo --- Extra endlocal in called batch
2510 rem -- setlocal1 == this batch, should never be used inside a called routine
2514 call %WINE_CURDIR%\1set2end.cmd
2517 for /d %%i in (.) do echo %%~dpnxi
2520 for /d %%i in (.) do echo %%~dpnxi
2523 echo --- endlocal in called function rather than batch pgm is ineffective
2529 call :endlocalroutine
2533 goto :endlocalfinished
2551 cd .. & rd /q/s foobar
2553 echo ------------ Testing Errorlevel ------------
2554 rem WARNING: Do *not* add tests using ErrorLevel after this section
2555 should_not_exist 2> nul > nul
2557 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2558 rem See http://www.robvanderwoude.com/exit.php
2561 if errorlevel 2 echo errorlevel too high, bad
2562 if errorlevel 1 echo errorlevel just right, good
2563 if errorlevel 01 echo errorlevel with leading zero just right, good
2564 if errorlevel -1 echo errorlevel with negative number OK
2565 if errorlevel 0x1 echo hexa should not be recognized!
2566 if errorlevel 1a echo invalid error level recognized!
2568 echo abc%ErrorLevel%def
2569 if errorlevel 1 echo errorlevel nonzero, bad
2570 if not errorlevel 1 echo errorlevel zero, good
2571 if not errorlevel 0x1 echo hexa should not be recognized!
2572 if not errorlevel 1a echo invalid error level recognized!
2573 rem Now verify that setting a real variable hides its magic variable
2575 echo %ErrorLevel% should be 7
2576 if errorlevel 7 echo setting var worked too well, bad
2578 echo %ErrorLevel% should still be 7
2580 echo ------------ Testing GOTO ------------
2582 echo FAILURE at dest 1
2584 echo goto with no leading space worked
2585 if a==a goto :dest1b
2586 echo FAILURE at dest 1b
2588 echo goto with colon and no leading space worked
2590 echo FAILURE at dest 2
2592 echo goto with a leading space worked
2594 echo FAILURE at dest 3
2596 echo goto with a leading tab worked
2598 echo FAILURE at dest 4
2600 echo goto with a following space worked
2602 echo FAILURE at dest 5
2603 :dest5&& echo FAILURE
2604 echo goto with following amphersands worked
2606 del failure.txt >nul 2>&1
2608 echo FAILURE at dest 6
2610 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
2611 echo goto with redirections worked
2612 del FAILURE.TXT >nul 2>&1
2614 :: some text that is ignored | dir >cmd_output | another test
2615 if exist cmd_output echo FAILURE at dest 6 as file exists
2616 echo Ignoring double colons worked
2617 del cmd_output >nul 2>&1
2619 rem goto a label which does not exist issues an error message and
2620 rem acts the same as goto :EOF, and ensure ::label is never matched
2621 del testgoto.bat >nul 2>&1
2622 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
2623 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2624 echo ::dest7>> testgoto.bat
2625 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
2627 del testgoto.bat >nul 2>&1
2629 del testgoto.bat >nul 2>&1
2630 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
2631 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2632 echo ::dest8>> testgoto.bat
2633 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
2635 del testgoto.bat >nul 2>&1
2638 echo FAILURE at dest 9
2640 echo FAILURE at dest 91
2642 echo label with mixed whitespace and no echo worked
2644 if h==h goto :dest10:this is ignored
2645 echo FAILURE at dest 10
2646 :dest10:this is also ignored
2647 echo Correctly ignored trailing information
2649 echo ------------ Testing PATH ------------
2650 set WINE_backup_path=%path%
2657 set path=%WINE_backup_path%
2658 set WINE_backup_path=
2660 echo ------------ Testing combined CALLs/GOTOs ------------
2661 echo @echo off>foo.cmd
2662 echo goto :eof>>foot.cmd
2664 echo echo world>>foo.cmd
2666 echo @echo off>foot.cmd
2667 echo echo cheball>>foot.cmd
2669 echo call :bar>>foot.cmd
2670 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
2671 echo goto :eof>>foot.cmd
2674 echo echo barbare>>foot.cmd
2675 echo goto :eof>>foot.cmd
2681 rem Script execution stops after the following line
2704 echo Final message is not output since earlier 'foot' processing stops script execution
2705 echo Do NOT add any tests below this line
2707 echo ------------ Done, jumping to EOF -----------
2709 rem Subroutine to set errorlevel and return
2710 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
2713 rem This line runs under cmd in windows NT 4, but not in more modern versions.