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@
291 echo ------------ Testing variable expansion ------------
293 echo ~dp0 should be directory containing batch file
306 echo P%WINE_UNKNOWN%S
309 echo %ERRORLEVEL%%ERRORLEVEL%
310 echo %ERRORLEVEL%ERRORLEVEL%
317 echo ------------ Testing variable substrings ------------
322 echo '%WINE_VAR:~-2,3%'
323 echo '%WINE_VAR:~-2,1%'
324 echo %WINE_VAR:~2,-1%
325 echo %WINE_VAR:~2,-3%
326 echo '%WINE_VAR:~-2,-4%'
327 echo %WINE_VAR:~-3,-2%
330 echo ------------ Testing variable substitution ------------
331 echo --- in FOR variables
332 for %%i in ("A B" C) do echo %%i
333 rem check works when prefix with @
334 @for %%i in ("A B" C) do echo %%i
336 for %%i in ("A B" C) do echo '%%~i'
337 rem fully qualified path
338 for %%f in ("C D" E) do echo %%~ff
340 for %%i in ("F G" H) do echo %%~di
342 for %%d in ("I J" K) do echo %%~pd
344 for %%i in ("L M" N) do echo %%~ni
346 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
347 rem path with short path names
348 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
350 for %%i in ("U V" W) do echo '%%~ai'
352 for %%i in (foo) do echo '%%~ai'
353 for %%i in (foo) do echo '%%~zi'
356 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
357 for %%i in ("a b" c) do echo '%%~ti'
359 rem Similar issues as above
360 for %%i in ("a b" c) do echo '%%~zi'
362 for %%i in ("d e" f) do echo %%~dpi
363 for %%i in ("g h" i) do echo %%~sdi
364 for %%i in ("g h" i) do echo %%~dsi
365 for %%i in ("j k" l.eh) do echo '%%~xsi'
367 echo --- in parameters
368 for %%i in ("A B" C) do call :echoFun %%i
370 for %%i in ("A B" C) do call :echoFunQ %%i
371 rem fully qualified path
372 for %%f in ("C D" E) do call :echoFunF %%f
374 for %%i in ("F G" H) do call :echoFunD %%i
376 for %%d in ("I J" K) do call :echoFunP %%d
378 for %%i in ("L M" N) do call :echoFunN %%i
380 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
381 rem path with short path names
382 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
383 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
385 for %%i in ("d e" f) do call :echoFunDP %%i
386 for %%i in ("g h" i) do call :echoFunSD %%i
387 for %%i in ("g h" i) do call :echoFunDS %%i
388 for %%i in ("j k" l.eh) do call :echoFunXS %%i
420 rem some NT4 workaround
443 echo ------------ Testing variable delayed expansion ------------
444 rem NT4 doesn't support this
445 echo --- default mode (load-time expansion)
449 if %WINE_FOO% == foo (
451 if %WINE_FOO% == bar (echo bar) else echo foo
455 if %WINE_FOO% == foo (
457 if !WINE_FOO! == bar (echo bar) else echo foo
460 echo --- runtime (delayed) expansion mode
461 setlocal EnableDelayedExpansion
465 if %WINE_FOO% == foo (
467 if %WINE_FOO% == bar (echo bar) else echo foo
471 if %WINE_FOO% == foo (
473 if !WINE_FOO! == bar (echo bar) else echo foo
476 setlocal DisableDelayedExpansion
482 echo --- using /V cmd flag
483 echo @echo off> tmp.cmd
484 echo set WINE_FOO=foo>> tmp.cmd
485 echo echo %%WINE_FOO%%>> tmp.cmd
486 echo echo !WINE_FOO!>> tmp.cmd
487 echo set WINE_FOO=>> tmp.cmd
489 cmd /V:OfF /C tmp.cmd
492 echo ------------ Testing conditional execution ------------
493 echo --- unconditional ampersand
494 call :setError 123 & echo foo1
495 echo bar2 & echo foo2
496 mkdir foobar & cd foobar
498 cd .. & rd /s/q foobar
500 echo foobar not deleted!
503 ) else echo foobar deleted
504 echo --- on success conditional and
505 call :setError 456 && echo foo3 > foo3
509 ) else echo foo3 not created
510 echo bar4 && echo foo4
511 echo --- on failure conditional or
512 call :setError 789 || echo foo5
513 echo foo6 || echo bar6 > bar6
519 echo ------------ Testing cd ------------
522 echo blabla > singleFile
524 echo Current dir: %CD%
539 if not exist foobar (cd ..)
541 cd@tab@..@tab@@space@@tab@
543 if not exist foobar (cd ..)
557 cd "bar bak@space@"@tab@@space@
568 echo ------------ Testing type ------------
582 echo ------------ Testing NUL ------------
583 md foobar & cd foobar
584 rem NUL file (non) creation + case insensitivity
585 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
594 rem NUL not special everywhere
597 if not exist foo (echo foo should have been created) else (
601 rem Empty file creation
611 copy a.a+NUL b.b >nul
612 call :CheckFileSize a.a 7 b.b 8
613 copy NUL+a.a b.b >nul
614 call :CheckFileSize a.a 7 b.b 8
616 copy a.a+NUL subdir\ >nul
617 call :CheckFileSize a.a 7 subdir\a.a 8
621 if exist a.a echo Failed
625 cd .. & rd foobar /s /q
627 echo ------------ Testing if/else ------------
628 echo --- if/else should work with blocks
630 echo if seems to work
632 echo if seems to be broken
635 echo else seems to be broken
637 echo else seems to work
640 echo if seems not to detect /c as parameter
642 echo parameter detection seems to be broken
645 echo --- case sensitivity with and without /i option
646 if bar==BAR echo if does not default to case sensitivity
647 if not bar==BAR echo if seems to default to case sensitivity
648 if /i foo==FOO echo if /i seems to work
649 if /i not foo==FOO echo if /i seems to be broken
650 if /I foo==FOO echo if /I seems to work
651 if /I not foo==FOO echo if /I seems to be broken
653 echo --- string comparisons
654 if abc == abc (echo equal) else echo non equal
655 if abc =="abc" (echo equal) else echo non equal
656 if "abc"== abc (echo equal) else echo non equal
657 if "abc"== "abc" (echo equal) else echo non equal
659 echo --- tabs handling
660 if@tab@1==1 echo doom
661 if @tab@1==1 echo doom
662 if 1==1 (echo doom) else@tab@echo quake
663 if@tab@not @tab@1==@tab@0 @tab@echo lol
664 if 1==0@tab@(echo doom) else echo quake
665 if 1==0 (echo doom)@tab@else echo quake
666 if 1==0 (echo doom) else@tab@echo quake
668 echo --- comparison operators
669 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
670 echo ------ for strings
671 rem NT4 stops processing of the whole batch file as soon as it finds a
672 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
673 rem can't test those here.
674 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
675 if LSS LSS LSS (echo bar)
676 if 1.1 LSS 1.10 (echo floats are handled as strings)
677 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
678 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
679 if /i foo LSS FoOc echo if /i seems to work for LSS
680 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
681 set WINE_STR_PARMS=A B AB BA AA
682 for %%i in (%WINE_STR_PARMS%) do (
683 for %%j in (%WINE_STR_PARMS%) do (
684 call :LSStest %%i %%j))
685 if b LSS B (echo b LSS B) else echo NT4
686 if /I b LSS B echo b LSS B insensitive
687 if b LSS A echo b LSS A
688 if /I b LSS A echo b LSS A insensitive
689 if a LSS B (echo a LSS B) else echo NT4
690 if /I a LSS B echo a LSS B insensitive
691 if A LSS b echo A LSS b
692 if /I A LSS b echo A LSS b insensitive
693 for %%i in (%WINE_STR_PARMS%) do (
694 for %%j in (%WINE_STR_PARMS%) do (
695 call :LEQtest %%i %%j))
696 if b LEQ B (echo b LEQ B) else echo NT4
697 if /I b LEQ B echo b LEQ B insensitive
698 if b LEQ A echo b LEQ A
699 if /I b LEQ A echo b LEQ A insensitive
700 if a LEQ B (echo a LEQ B) else echo NT4
701 if /I a LEQ B echo a LEQ B insensitive
702 if A LEQ b echo A LEQ b
703 if /I A LEQ b echo A LEQ b insensitive
704 for %%i in (%WINE_STR_PARMS%) do (
705 for %%j in (%WINE_STR_PARMS%) do (
706 call :EQUtest %%i %%j))
707 if /I A EQU a echo A EQU a insensitive
708 for %%i in (%WINE_STR_PARMS%) do (
709 for %%j in (%WINE_STR_PARMS%) do (
710 call :NEQtest %%i %%j))
711 for %%i in (%WINE_STR_PARMS%) do (
712 for %%j in (%WINE_STR_PARMS%) do (
713 call :GEQtest %%i %%j))
714 for %%i in (%WINE_STR_PARMS%) do (
715 for %%j in (%WINE_STR_PARMS%) do (
716 call :GTRtest %%i %%j))
717 echo ------ for numbers
718 if -1 LSS 1 (echo negative numbers handled)
719 if not -1 LSS -10 (echo negative numbers handled)
720 if not 9 LSS 010 (echo octal handled)
721 if not -010 LSS -8 (echo also in negative form)
722 if 4 LSS 0x5 (echo hexa handled)
723 if not -1 LSS -0x1A (echo also in negative form)
724 if 11 LSS 101 (echo 11 LSS 101)
725 set WINE_INT_PARMS=0 1 10 9
726 for %%i in (%WINE_INT_PARMS%) do (
727 for %%j in (%WINE_INT_PARMS%) do (
728 call :LSStest %%i %%j))
729 for %%i in (%WINE_INT_PARMS%) do (
730 for %%j in (%WINE_INT_PARMS%) do (
731 call :LEQtest %%i %%j))
732 for %%i in (%WINE_INT_PARMS%) do (
733 for %%j in (%WINE_INT_PARMS%) do (
734 call :EQUtest %%i %%j))
735 if 011 EQU 9 (echo octal ok)
736 if 0xA1 EQU 161 (echo hexa ok)
737 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
738 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
739 for %%i in (%WINE_INT_PARMS%) do (
740 for %%j in (%WINE_INT_PARMS%) do (
741 call :NEQtest %%i %%j))
742 for %%i in (%WINE_INT_PARMS%) do (
743 for %%j in (%WINE_INT_PARMS%) do (
744 call :GEQtest %%i %%j))
745 for %%i in (%WINE_INT_PARMS%) do (
746 for %%j in (%WINE_INT_PARMS%) do (
747 call :GTRtest %%i %%j))
748 echo ------ for numbers and stringified numbers
749 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
750 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
751 if '1' EQU 1 echo '1' EQU 1
752 if 1 EQU '1' echo 1 EQU '1'
753 if not "1" GEQ 1 (echo foo) else echo bar
754 if "10" GEQ "1" echo "10" GEQ "1"
755 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
756 if 1 GEQ "1" echo 1 GEQ "1"
757 if "1" GEQ "1" echo "1" GEQ "1"
758 if '1' GEQ "1" echo '1' GEQ "1"
759 if "10" GEQ "1" echo "10" GEQ "1"
760 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
761 for %%i in ("1" '1') do call :GEQtest %%i '1'
762 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
763 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
764 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
765 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
766 if "10" GEQ "10" (echo "10" GEQ "10")
767 goto :endIfCompOpsSubroutines
769 rem IF subroutines helpers
771 if %1 LSS %2 echo %1 LSS %2
774 if %1 LEQ %2 echo %1 LEQ %2
777 if %1 EQU %2 echo %1 EQU %2
780 if %1 NEQ %2 echo %1 NEQ %2
783 if %1 GEQ %2 echo %1 GEQ %2
786 if %1 GTR %2 echo %1 GTR %2
789 :endIfCompOpsSubroutines
793 echo ------------ Testing for ------------
795 for %%i in (A B C) do echo %%i
796 for %%i in (A B C) do echo %%I
797 for %%i in (A B C) do echo %%j
798 for %%i in (A B C) do call :forTestFun1 %%i
799 for %%i in (1,4,1) do echo %%i
800 for %%i in (A, B,C) do echo %%i
801 for %%i in (X) do echo %%i
802 for@tab@%%i in (X2) do echo %%i
803 for %%i in@tab@(X3) do echo %%i
804 for %%i in (@tab@ foo@tab@) do echo %%i
805 for@tab@ %%i in@tab@(@tab@M) do echo %%i
806 for %%i@tab@in (X)@tab@do@tab@echo %%i
807 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
808 for %%i in (`echo A B`) do echo %%i
809 for %%i in ('echo A B') do echo %%i
810 for %%i in ("echo A B") do echo %%i
811 for %%i in ("A B" C) do echo %%i
817 echo --- imbricated FORs
824 for %%i in (A B) do (
825 for %%j in (C D) do (
827 for %%i in (A B) do (
828 for %%j in (C D) do (
829 call :forTestFun2 %%i %%j ))
835 mkdir foobar & cd foobar
840 echo --- basic wildcards
841 for %%i in (ba*) do echo %%i
843 for /d %%i in (baz foo bar) do echo %%i 2>&1
844 rem Confirm we don't match files:
845 for /d %%i in (bazb*) do echo %%i 2>&1
846 for /d %%i in (bazb2*) do echo %%i 2>&1
847 rem Show we pass through non wildcards
848 for /d %%i in (PASSED) do echo %%i
849 for /d %%i in (xxx) do (
850 echo %%i - Should be xxx
851 echo Expected second line
853 rem Show we issue no messages on failures
854 for /d %%i in (FAILED?) do echo %%i 2>&1
855 for /d %%i in (FAILED?) do (
856 echo %%i - Unexpected!
857 echo FAILED Unexpected second line
859 for /d %%i in (FAILED*) do echo %%i 2>&1
860 for /d %%i in (FAILED*) do (
861 echo %%i - Unexpected!
862 echo FAILED Unexpected second line
864 rem FIXME can't test wildcard expansion here since it's listed in directory
865 rem order, and not in alphabetic order.
866 rem Proper testing would need a currently missing "sort" program implementation.
867 rem for /d %%i in (ba*) do echo %%i>> tmp
870 rem for /d %%i in (?a*) do echo %%i>> tmp
873 rem for /d %%i in (*) do echo %%i>> tmp
881 call :WriteLine set WINE_found=N
882 for /l %%i in (1,1,%WINE_expectedresults%) do (
883 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%1" set WINE_found=Y
884 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
885 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
887 call :WriteLine echo Got unexpected result: "%%%%1"
896 for /l %%i in (1,1,%WINE_expectedresults%) do (
897 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
904 rem %CD% does not tork on NT4 so use the following workaround
905 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
908 echo Plain directory enumeration
909 set WINE_expectedresults=4
910 set WINE_expectedresults.1=%WINE_CURDIR%\.
911 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
912 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
913 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
915 for /R %%i in (.) do call temp.bat %%i
916 call :ValidateExpected
918 echo Plain directory enumeration from provided root
919 set WINE_expectedresults=4
920 set WINE_expectedresults.1=%WINE_CURDIR%\.
921 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
922 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
923 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
924 if "%CD%"=="" goto :SkipBrokenNT4
926 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat %%i
927 call :ValidateExpected
930 echo File enumeration
931 set WINE_expectedresults=2
932 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
933 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
935 for /R %%i in (baz*) do call temp.bat %%i
936 call :ValidateExpected
938 echo File enumeration from provided root
939 set WINE_expectedresults=2
940 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
941 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
943 for /R %%i in (baz*) do call temp.bat %%i
944 call :ValidateExpected
946 echo Mixed enumeration
947 set WINE_expectedresults=6
948 set WINE_expectedresults.1=%WINE_CURDIR%\.
949 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
950 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
951 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
952 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
953 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
955 for /R %%i in (. baz*) do call temp.bat %%i
956 call :ValidateExpected
958 echo Mixed enumeration from provided root
959 set WINE_expectedresults=6
960 set WINE_expectedresults.1=%WINE_CURDIR%\.
961 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
962 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
963 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
964 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
965 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
967 for /R %%i in (. baz*) do call temp.bat %%i
968 call :ValidateExpected
970 echo With duplicates enumeration
971 set WINE_expectedresults=12
972 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
973 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
974 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
975 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
976 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
977 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
978 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
979 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
980 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
981 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
982 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
983 set WINE_expectedresults.12=%WINE_CURDIR%\fred
985 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat %%i
986 call :ValidateExpected
988 echo Strip missing wildcards, keep unwildcarded names
989 set WINE_expectedresults=6
990 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
991 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
992 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
993 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
994 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
995 set WINE_expectedresults.6=%WINE_CURDIR%\jim
997 for /R %%i in (baz* fred* jim) do call temp.bat %%i
998 call :ValidateExpected
1001 cd .. & rd /s/Q foobar
1003 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
1004 for /L %%i in (1,2,0) do echo %%i
1005 for@tab@/L %%i in (1,2,0) do echo %%i
1006 for /L %%i in (1,2,6) do echo %%i
1007 for /l %%i in (1 ,2,6) do echo %%i
1008 for /L %%i in (a,2,3) do echo %%i
1009 for /L %%i in (1,2,-1) do echo %%i
1010 for /L %%i in (-4,-1,-1) do echo %%i
1011 for /L %%i in (1,-2,-2) do echo %%i
1012 for /L %%i in (1,2,a) do echo %%i
1013 echo ErrorLevel %ErrorLevel%
1014 for /L %%i in (1,a,b) do echo %%i
1015 echo ErrorLevel %ErrorLevel%
1017 for /l %%i in (1,1,4) do echo %%i
1018 for /l %%i in (1,2,4) do echo %%i
1019 for /l %%i in (4,-1,1) do echo %%i
1020 for /l %%i in (4,-2,1) do echo %%i
1021 for /l %%i in (1,-1,4) do echo %%i
1022 for /l %%i in (4,1,1) do echo %%i
1023 for /L %%i in (a,2,b) do echo %%i
1024 for /L %%i in (1,1,1) do echo %%i
1025 for /L %%i in (1,-2,-1) do echo %%i
1026 for /L %%i in (-1,-1,-1) do echo %%i
1027 for /L %%i in (1,2, 3) do echo %%i
1028 rem Test zero iteration skips the body of the for
1029 for /L %%i in (2,2,1) do (
1036 Rem Ideally for /f can be used rather than building a command to execute
1037 rem but that does not work on NT4
1039 if "%1"=="" goto :eof
1040 call :executecmd set wine_result=%%%1%%
1041 if "%wine_result%"=="%2" (
1042 echo %1 correctly %2
1043 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1054 rem No output when using "set expr" syntax, unless in interactive mode
1055 rem Need to use "set envvar=expr" to use in a batch script
1056 echo ------ individual operations
1058 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1059 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1060 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1061 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1062 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1063 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1064 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1065 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1066 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1067 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1068 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1069 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1070 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1071 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1072 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1073 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1074 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1075 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1076 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1077 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1078 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1079 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1080 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1081 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1082 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1083 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1084 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1085 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1086 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1087 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1088 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1089 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1090 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1091 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1092 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1093 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1094 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1095 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1096 echo ------ precedence and grouping
1097 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1098 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1099 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1100 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1101 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1102 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1103 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1104 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1105 echo ------ octal and hexadecimal
1106 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1107 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1108 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1109 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1110 echo ------ variables
1111 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1112 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1113 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
1115 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1116 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1118 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1120 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1122 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1123 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1125 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1127 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1129 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1130 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1131 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1133 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1136 call :checkenvvars WINE_foo 1
1138 call :checkenvvars WINE_foo 1
1139 set /a WINE_foo=1,WINE_bar=2
1140 call :checkenvvars WINE_foo 1 WINE_bar 2
1141 set /a "WINE_foo=1,WINE_bar=2"
1142 call :checkenvvars WINE_foo 1 WINE_bar 2
1143 set /a "WINE_foo=1","WINE_bar=2"
1144 call :checkenvvars WINE_foo 1 WINE_bar 2
1145 set /a ""WINE_foo=1","WINE_bar=2""
1146 call :checkenvvars WINE_foo 1 WINE_bar 2
1147 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1148 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1149 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
1150 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1151 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
1152 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1153 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1154 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1155 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
1156 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1157 set /a """"""WINE_foo=1""""""
1158 call :checkenvvars WINE_foo 1
1159 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1160 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1161 set /a WINE_foo="3"+"4"+"5+6"
1162 call :checkenvvars WINE_foo 18
1164 set /a WINE_bar="WINE_""foo"+4
1165 call :checkenvvars WINE_foo 3 WINE_bar 7
1166 echo --- whitespace are ignored between double char operators
1169 set /a WINE_foo + = 6
1170 set /a WINE_bar * = WINE_foo
1171 call :checkenvvars WINE_foo 10 WINE_bar 50
1174 set /a WINE_foo + = "6 < < 7"
1175 set /a WINE_bar * = WINE_foo + WINE_foo
1176 call :checkenvvars WINE_foo 772 WINE_bar 7720
1180 echo --- invalid operator sequence
1186 set /a WINE_foo^>^<=4
1188 set /a WINE_foo^>^>^>=4
1190 echo ----- negative prefix
1192 call :checkenvvars WINE_foo -1
1194 call :checkenvvars WINE_foo 1
1195 set /a WINE_foo=3--3
1196 call :checkenvvars WINE_foo 6
1197 set /a WINE_foo=3---3
1198 call :checkenvvars WINE_foo 0
1199 set /a WINE_foo=3----3
1200 call :checkenvvars WINE_foo 6
1202 call :checkenvvars WINE_foo 2
1204 call :checkenvvars WINE_foo 0
1205 set /a WINE_foo=3+-~1
1206 call :checkenvvars WINE_foo 5
1207 set /a WINE_foo=3+~-1
1208 call :checkenvvars WINE_foo 3
1209 echo ----- assignment tests involving the end destination
1211 set /a WINE_foo+=3+(WINE_foo=4)
1212 call :checkenvvars WINE_foo 11
1214 set /a WINE_bar=3+(WINE_foo=6)
1215 call :checkenvvars WINE_foo 6 WINE_bar 9
1217 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1218 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1220 set /a WINE_bar=WINE_foo=7
1221 call :checkenvvars WINE_foo 7 WINE_bar 7
1222 echo ----- equal precedence on stack
1223 rem Unary - don't reduce if precedence is equal
1225 call :checkenvvars WINE_foo 1
1227 call :checkenvvars WINE_foo 0
1229 call :checkenvvars WINE_foo 1
1231 call :checkenvvars WINE_foo 0
1233 call :checkenvvars WINE_foo 1
1235 call :checkenvvars WINE_foo -1
1237 call :checkenvvars WINE_foo -1
1239 call :checkenvvars WINE_foo 1
1241 call :checkenvvars WINE_foo 0
1243 call :checkenvvars WINE_foo -1
1245 call :checkenvvars WINE_foo 0
1247 call :checkenvvars WINE_foo 0
1249 call :checkenvvars WINE_foo 1
1251 call :checkenvvars WINE_foo -1
1252 rem Aritmatic - Reduce if precedence is equal
1253 set /a WINE_foo=10*5/2
1254 call :checkenvvars WINE_foo 25
1255 set /a WINE_foo=5/2*10
1256 call :checkenvvars WINE_foo 20
1257 set /a WINE_foo=10/5/2
1258 call :checkenvvars WINE_foo 1
1259 set /a WINE_foo=5%%2*4
1260 call :checkenvvars WINE_foo 4
1261 set /a WINE_foo=10-5+2
1262 call :checkenvvars WINE_foo 7
1263 set /a WINE_foo=1^<^<4^>^>1
1264 call :checkenvvars WINE_foo 8
1265 rem Assignment - don't reduce if precedence is equal
1267 set /a WINE_bar=WINE_foo=6
1268 call :checkenvvars WINE_foo 6 WINE_bar 6
1271 mkdir foobar & cd foobar
1272 echo ------ string argument
1273 rem NT4 does not support usebackq
1274 for /F %%i in ("a b c") do echo %%i
1275 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1276 if not exist output_file (echo no output) else (type output_file & del output_file)
1277 for /f %%i in ("a ") do echo %%i
1278 for /f usebackq %%i in ('a ') do echo %%i>output_file
1279 if not exist output_file (echo no output) else (type output_file & del output_file)
1280 for /f %%i in ("a") do echo %%i
1281 for /f usebackq %%i in ('a') do echo %%i>output_file
1282 if not exist output_file (echo no output) else (type output_file & del output_file)
1283 fOr /f %%i in (" a") do echo %%i
1284 for /f usebackq %%i in (' a') do echo %%i>output_file
1285 if not exist output_file (echo no output) else (type output_file & del output_file)
1286 for /f %%i in (" a ") do echo %%i
1287 for /f usebackq %%i in (' a ') do echo %%i>output_file
1288 if not exist output_file (echo no output) else (type output_file & del output_file)
1289 echo ------ fileset argument
1290 echo --------- basic blank handling
1292 for /f %%i in (foo) do echo %%i
1294 for /f %%i in (foo) do echo %%i
1296 for /f %%i in (foo) do echo %%i
1298 for /f %%i in (foo) do echo %%i
1300 for /f %%i in (foo) do echo %%i
1302 for /f %%i in (foo) do echo %%i
1305 for /f %%i in (foo) do echo %%i
1306 echo --------- multi-line with empty lines
1313 for /f %%b in (foo) do echo %%b
1314 echo --------- multiple files
1318 for /f %%k in (foo bar) do echo %%k
1319 for /f %%k in (bar foo) do echo %%k
1320 echo ------ command argument
1321 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1322 if "%CD%"=="" goto :SkipFORFcmdNT4
1323 for /f %%i in ('echo.Passed1') do echo %%i
1324 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
1325 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1328 for /l %%i in (1,1,3) do echo Missing functionality - Broken%%i
1330 rem FIXME: Rest not testable right now in wine: not implemented and would need
1331 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1332 rem for a simple todo_wine test
1333 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1334 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1335 echo ------ eol option
1336 if "%CD%"=="" goto :SkipFORFeolNT4
1338 echo and Line two>>foo
1339 echo Line three>>foo
1340 for /f "eol=L" %%i in (foo) do echo %%i
1341 for /f "eol=a" %%i in (foo) do echo %%i
1343 goto :ContinueFORFeol
1345 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1347 for /f "eol=@" %%i in (" ad") do echo %%i
1348 for /f "eol=@" %%i in (" z@y") do echo %%i
1349 for /f "eol=|" %%i in ("a|d") do echo %%i
1350 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
1351 if not exist output_file (echo no output) else (del output_file)
1352 for /f "eol==" %%i in ("=y") do echo %%i > output_file
1353 if not exist output_file (echo no output) else (del output_file)
1354 echo ------ delims option
1355 for /f "delims=|" %%i in ("a|d") do echo %%i
1356 for /f "delims=|" %%i in ("a |d") do echo %%i
1357 for /f "delims=|" %%i in ("a d|") do echo %%i
1358 for /f "delims=| " %%i in ("a d|") do echo %%i
1359 for /f "delims==" %%i in ("C r=d|") do echo %%i
1360 for /f "delims=" %%i in ("foo bar baz") do echo %%i
1361 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
1362 echo ------ skip option
1366 for /f "skip=2" %%i in (foo) do echo %%i
1367 for /f "skip=3" %%i in (foo) do echo %%i > output_file
1368 if not exist output_file (echo no output) else (del output_file)
1369 for /f "skip=4" %%i in (foo) do echo %%i > output_file
1370 if not exist output_file (echo no output) else (del output_file)
1371 for /f "skip=02" %%i in (foo) do echo %%i
1372 for /f "skip=0x2" %%i in (foo) do echo %%i
1373 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
1374 if not exist output_file (echo no output) else (del output_file)
1375 echo ------ tokens= option
1377 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
1378 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
1379 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
1380 rem Show * means the rest
1381 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
1382 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
1383 rem Show * means the rest (not tokenized and rebuilt)
1384 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
1385 rem Order is irrelevant
1386 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
1387 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
1388 rem Duplicates are ignored
1389 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
1390 rem Large tokens are allowed
1391 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
1392 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1393 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
1394 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
1395 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1396 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
1397 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
1398 rem Show negative ranges have no effect
1399 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
1400 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
1401 rem Show duplicates stop * from working
1402 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
1403 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
1404 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
1405 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
1409 echo ------------ Testing del /a ------------
1410 del /f/q *.test > nul
1413 echo not-r > not-r.test
1415 if not exist not-r.test echo not-r.test not found before delete, bad
1417 if not exist not-r.test echo not-r.test not found after delete, good
1419 if not exist r.test echo r.test not found before delete, bad
1420 if exist r.test echo r.test found before delete, good
1422 if not exist r.test echo r.test not found after delete, good
1423 if exist r.test echo r.test found after delete, bad
1425 echo ------------ Testing del /q ------------
1429 echo abc > file2.dat
1430 rem If /q doesn't work, cmd will prompt and the test case should hang
1432 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1433 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1437 echo ------------ Testing del /s ------------
1442 echo there > file2.dat
1443 echo bub > file3.dat
1444 echo bye > "file with spaces.dat"
1446 del /s file1.dat > nul
1447 del file2.dat /s > nul
1448 del "file3.dat" /s > nul
1449 del "file with spaces.dat" /s > nul
1451 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1452 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1453 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
1454 if exist "file with spaces.dat" del "file with spaces.dat"
1459 echo ------------ Testing rename ------------
1460 mkdir foobar & cd foobar
1461 echo --- ren and rename are synonymous
1464 if exist foo echo foo should be renamed!
1465 if exist bar echo foo renamed to bar
1467 if exist bar echo bar should be renamed!
1468 if exist foo echo bar renamed to foo
1469 echo --- name collision
1479 echo --- rename read-only files
1483 if not exist file1 (
1485 echo read-only file renamed
1488 echo read-only file not renamed!
1490 echo --- rename directories
1502 echo read-only dir renamed
1505 echo --- rename in other directory
1506 if not exist baz\abc (
1507 echo rename impossible in other directory
1508 if exist foo echo original file still present
1510 echo shouldn't rename in other directory!
1511 if not exist foo echo original file not present anymore
1513 cd .. & rd /s/q foobar
1515 echo ------------ Testing move ------------
1516 mkdir foobar & cd foobar
1519 move foo bar > nul 2>&1
1522 echo file move succeeded
1527 move /Y bar baz > nul 2>&1
1530 echo file move with overwrite succeeded
1533 echo file overwrite impossible!
1539 move baz bazro > nul 2>&1
1542 echo read-only files are moveable
1543 move bazro baz > nul 2>&1
1546 echo read-only file not moved!
1550 move baz rep > nul 2>&1
1553 echo file moved in subdirectory
1557 move rep\baz . > nul 2>&1
1558 move /Y baz baz > nul 2>&1
1560 echo moving a file to itself should be a no-op!
1562 echo moving a file to itself is a no-op
1564 echo ErrorLevel: %ErrorLevel%
1567 echo --- directory move
1571 move baz foo\bar > nul 2>&1
1573 if exist foo\bar\baz\baz2 (
1574 echo simple directory move succeeded
1579 move baz baz > nul 2>&1
1580 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1581 echo ------ dir in dir move
1586 move foo bar > nul 2>&1
1594 cd .. & rd /s/q foobar
1596 echo ------------ Testing mkdir ------------
1598 echo --- md and mkdir are synonymous
1605 echo --- creating an already existing directory/file must fail
1614 echo --- multilevel path creation
1626 mkdir ..\..\..\foo\bar2
1629 mkdir ..\..\..\foo\bar2
1631 rmdir ..\..\..\foo\bar2
1639 echo --- trailing backslashes
1642 if exist foo (rmdir foo & echo dir created
1643 ) else ( echo dir not created )
1645 echo --- invalid chars
1647 echo mkdir ? gives errorlevel %ErrorLevel%
1650 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1653 echo mkdir foo\? gives errorlevel %ErrorLevel%
1654 if exist foo (rmdir foo & echo ok, foo created
1655 ) else ( echo foo not created )
1658 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1661 echo bad, foo not created
1665 echo ok, foo\bar created
1671 echo --- multiple directories at once
1672 mkdir foobaz & cd foobaz
1673 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
1674 if exist foo (echo foo created) else echo foo not created!
1675 if exist bar (echo bar created) else echo bar not created!
1676 if exist foobar (echo foobar created) else echo foobar not created!
1677 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
1678 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
1679 if exist zabzab (echo zabzab created) else echo zabzab not created!
1680 cd .. & rd /s/q foobaz
1683 echo mkdir foo\* errorlevel %ErrorLevel%
1684 if exist foo (rmdir foo & echo ok, foo created
1685 ) else ( echo bad, foo not created )
1687 echo ------------ Testing rmdir ------------
1689 rem rd and rmdir are synonymous
1693 if not exist foobar echo dir removed
1697 if not exist foobar echo dir removed
1698 rem Removing nonexistent directory
1701 rem Removing single-level directories
1705 if exist foo echo file not removed
1711 if exist foo echo non-empty dir not removed
1716 if exist foo echo non-empty dir not removed
1723 echo recursive rmdir succeeded
1730 echo foo > foo\bar\brol
1731 rmdir /s /Q foo 2>&1
1733 echo recursive rmdir succeeded
1740 rem multiples directories at once
1741 mkdir foobaz & cd foobaz
1745 rd /s/q foo bar foobar
1746 if not exist foo (echo foo removed) else echo foo not removed!
1747 if not exist bar (echo bar removed) else echo bar not removed!
1748 if not exist foobar (echo foobar removed) else echo foobar not removed!
1749 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
1750 cd .. & rd /s/q foobaz
1752 echo ------------ Testing pushd/popd ------------
1754 echo --- popd is no-op when dir stack is empty
1757 echo --- pushing non-existing dir
1760 echo --- basic behaviour
1785 echo ------------ Testing attrib ------------
1786 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
1787 mkdir foobar & cd foobar
1788 echo foo original contents> foo
1791 echo --- read-only attribute
1792 rem Read-only files cannot be altered or deleted, unless forced
1800 echo Read-only file not deleted
1802 echo Should not delete read-only file!
1806 echo Read-only file forcibly deleted
1808 echo Should delete read-only file with del /F!
1812 cd .. & rd /s/q foobar
1813 echo --- recursive behaviour
1814 mkdir foobar\baz & cd foobar
1820 attrib +R l*vel? /S > nul 2>&1
1826 cd .. & rd /s/q foobar
1827 echo --- folders processing
1833 attrib +r baz /s /d > nul 2>&1
1839 rem Oddly windows allows file creation in a read-only directory...
1840 if exist baz\lala (echo file created in read-only dir) else echo file not created
1841 cd .. & rd /s/q foobar
1843 echo ------------ Testing assoc ------------
1844 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1845 rem FIXME Revise once || conditional execution is fixed
1846 mkdir foobar & cd foobar
1847 echo --- setting association
1855 rem association set system-wide
1856 echo @echo off> tmp.cmd
1857 echo echo +++>> tmp.cmd
1858 echo assoc .foo>> tmp.cmd
1861 echo --- resetting association
1867 rem association removal set system-wide
1868 cmd /c tmp.cmd > baz
1871 cd .. & rd /s/q foobar
1873 echo ------------ Testing ftype ------------
1874 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1875 rem FIXME Revise once || conditional execution is fixed
1876 mkdir foobar & cd foobar
1877 echo --- setting association
1882 ftype footype=foo_opencmd
1886 rem association set system-wide
1887 echo @echo off> tmp.cmd
1888 echo echo +++>> tmp.cmd
1889 echo ftype footype>> tmp.cmd
1892 echo --- resetting association
1895 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
1896 setlocal EnableDelayedExpansion
1897 set WINE_FOO=original value
1900 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
1901 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
1902 rem FIXME Revisit once a grep-like program like ftype is implemented
1903 rem (e.g. to check baz's size using dir /b instead)
1906 rem cleanup registry
1907 echo REGEDIT4> regCleanup.reg
1908 echo.>> regCleanup.reg
1909 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
1910 regedit /s regCleanup.reg
1913 cd .. & rd /s/q foobar
1915 echo ------------ Testing CALL ------------
1916 mkdir foobar & cd foobar
1917 echo --- external script
1918 echo echo foo %%1> foo.cmd
1921 echo echo %%1 %%2 > foo.cmd
1923 call foo.cmd foo bar
1930 echo --- internal routines
1931 call :testRoutine :testRoutine
1932 goto :endTestRoutine
1938 call :testRoutineArgs foo
1939 call :testRoutineArgs foo bar
1940 call :testRoutineArgs foo ""
1941 call :testRoutineArgs "" bar
1942 call :testRoutineArgs foo ''
1943 call :testRoutineArgs '' bar
1944 goto :endTestRoutineArgs
1950 echo --- with builtins
1953 if exist foo (echo foo created) else echo foo should exist!
1955 set WINE_FOOBAZ_VAR=foobaz
1956 call echo Should expand %WINE_FOOBAZ_VAR%
1957 set WINE_FOOBAZ_VAR=
1961 if 1==1 call del batfile
1963 if exist batfile echo batfile shouldn't exist
1964 rem ... but not for 'if' or 'for'
1965 call if 1==1 echo bar 2> nul
1968 call for %%i in (foo bar baz) do echo %%i 2> nul
1970 rem First look for programs in the path before trying a builtin
1971 echo echo non-builtin dir> dir.cmd
1974 rem The below line equates to call (, which does nothing, then the
1975 rem subsequent lines are executed.
1980 rem The below line equates to call if, which always fails, then the
1981 rem subsequent lines are executed. Note cmd.exe swallows all lines
1988 call call call echo passed
1989 cd .. & rd /s/q foobar
1991 echo ------------ Testing SHIFT ------------
1993 call :shiftFun p1 p2 p3 p4 p5
1997 echo '%1' '%2' '%3' '%4' '%5'
1999 echo '%1' '%2' '%3' '%4' '%5'
2001 echo '%1' '%2' '%3' '%4' '%5'
2003 echo '%1' '%2' '%3' '%4' '%5'
2005 echo '%1' '%2' '%3' '%4' '%5'
2007 echo '%1' '%2' '%3' '%4' '%5'
2011 echo ------------ Testing cmd invocation ------------
2012 rem FIXME: only a stub ATM
2013 echo --- a batch file can delete itself
2014 echo del foo.cmd>foo.cmd
2016 if not exist foo.cmd (
2017 echo file correctly deleted
2019 echo file should be deleted!
2022 echo --- a batch file can alter itself
2023 echo echo bar^>foo.cmd>foo.cmd
2024 cmd /q /c foo.cmd > NUL 2>&1
2029 echo file not created!
2032 echo ---------- Testing copy
2035 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2038 echo CCCCCCCCC> file3
2044 echo Passed: Found expected %1
2046 echo Failed: Did not find expected %1
2048 del /q "%1" >nul 2>&1
2050 if not "%1"=="" goto :CheckExist
2055 echo Passed: Did not find %1
2057 echo Failed: Unexpectedly found %1
2058 del /q "%1" >nul 2>&1
2061 if not "%1"=="" goto :CheckNotExist
2064 rem Note: No way to check file size on NT4 so skip the test
2067 echo Failed: File missing when requested filesize check [%2]
2068 goto :ContinueFileSizeChecks
2070 for %%i in (%1) do set WINE_filesize=%%~zi
2071 if "%WINE_filesize%"=="%2" (
2072 echo Passed: file size check on %1 [%WINE_filesize%]
2074 if "%WINE_filesize%"=="%%~zi" (
2075 echo Skipping file size check on NT4
2077 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2080 :ContinueFileSizeChecks
2083 if not "%1"=="" goto :CheckFileSize
2088 rem -----------------------
2089 rem Simple single file copy
2090 rem -----------------------
2091 rem Simple single file copy, normally used syntax
2092 copy file1 dummy.file >nul 2>&1
2093 if errorlevel 1 echo Incorrect errorlevel
2094 call :CheckExist dummy.file
2096 rem Simple single file copy, destination supplied as two forms of directory
2097 copy file1 dir1 >nul 2>&1
2098 if errorlevel 1 echo Incorrect errorlevel
2099 call :CheckExist dir1\file1
2101 copy file1 dir1\ >nul 2>&1
2102 if errorlevel 1 echo Incorrect errorlevel
2103 call :CheckExist dir1\file1
2105 rem Simple single file copy, destination supplied as fully qualified destination
2106 copy file1 dir1\file99 >nul 2>&1
2107 if errorlevel 1 echo Incorrect errorlevel
2108 call :CheckExist dir1\file99
2110 rem Simple single file copy, destination not supplied
2112 copy ..\file1 >nul 2>&1
2113 if errorlevel 1 echo Incorrect errorlevel
2114 call :CheckExist file1
2117 rem Simple single file copy, destination supplied as nonexistent directory
2118 copy file1 dir2\ >nul 2>&1
2119 if not errorlevel 1 echo Incorrect errorlevel
2120 call :CheckNotExist dir2 dir2\file1
2122 rem -----------------------
2124 rem -----------------------
2125 rem Simple single file copy, destination supplied as two forms of directory
2126 copy file? dir1 >nul 2>&1
2127 if errorlevel 1 echo Incorrect errorlevel
2128 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2130 copy file* dir1\ >nul 2>&1
2131 if errorlevel 1 echo Incorrect errorlevel
2132 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2134 rem Simple single file copy, destination not supplied
2136 copy ..\file*.* >nul 2>&1
2137 if errorlevel 1 echo Incorrect errorlevel
2138 call :CheckExist file1 file2 file3
2141 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2142 copy file? dir2\ >nul 2>&1
2143 if not errorlevel 1 echo Incorrect errorlevel
2144 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2146 rem ------------------------------------------------
2147 rem Confirm overwrite works (cannot test prompting!)
2148 rem ------------------------------------------------
2149 copy file1 testfile >nul 2>&1
2150 copy /y file2 testfile >nul 2>&1
2151 call :CheckExist testfile
2153 rem ------------------------------------------------
2154 rem Test concatenation
2155 rem ------------------------------------------------
2156 rem simple case, no wildcards
2157 copy file1+file2 testfile >nul 2>&1
2158 if errorlevel 1 echo Incorrect errorlevel
2159 call :CheckExist testfile
2161 rem simple case, wildcards, no concatenation
2162 copy file* testfile >nul 2>&1
2163 if errorlevel 1 echo Incorrect errorlevel
2164 call :CheckExist testfile
2166 rem simple case, wildcards, and concatenation
2168 copy file*+fred testfile >nul 2>&1
2169 if errorlevel 1 echo Incorrect errorlevel
2170 call :CheckExist testfile
2172 rem simple case, wildcards, and concatenation
2173 copy fred+file* testfile >nul 2>&1
2174 if errorlevel 1 echo Incorrect errorlevel
2175 call :CheckExist testfile
2177 rem Calculate destination name
2178 copy fred+file* dir1 >nul 2>&1
2179 if errorlevel 1 echo Incorrect errorlevel
2180 call :CheckExist dir1\fred
2182 rem Calculate destination name
2183 copy fred+file* dir1\ >nul 2>&1
2184 if errorlevel 1 echo Incorrect errorlevel
2185 call :CheckExist dir1\fred
2187 rem Calculate destination name (none supplied)
2189 copy ..\fred+..\file* >nul 2>&1
2190 if errorlevel 1 echo Incorrect errorlevel
2191 call :CheckExist fred
2193 copy ..\fr*+..\file1 >nul 2>&1
2194 if errorlevel 1 echo Incorrect errorlevel
2195 call :CheckExist fred
2198 rem ******************************************************************
2199 rem ASCII and BINARY tests
2200 rem Note: hard coded numbers deliberate because need to ensure whether
2201 rem an additional EOF has been added or not. There is no way to handle
2202 rem EOFs in batch, so assume if a single byte appears, its an EOF!
2203 rem ******************************************************************
2205 rem Confirm original sizes of file1,2,3
2206 call :CheckFileSize file1 5 file2 8 file3 11
2210 rem ----------------------------------------------
2211 rem Show concatenation defaults copy to ascii mode
2212 rem ----------------------------------------------
2213 rem Simple default copy source to destination (should not append EOF 5)
2214 copy ..\file1 file1_default >nul 2>&1
2215 call :CheckFileSize file1_default 5
2217 rem Simple binary copy source to destination (should not append EOF 5)
2218 copy /b ..\file1 file1_default2 >nul 2>&1
2219 call :CheckFileSize file1_default2 5
2221 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2222 copy /a ..\file1 file1_plus_eof >nul 2>&1
2223 call :CheckFileSize file1_plus_eof 6
2224 copy /a ..\file2 file2_plus_eof >nul 2>&1
2225 call :CheckFileSize file2_plus_eof 9
2226 copy /a ..\file3 file3_plus_eof >nul 2>&1
2227 call :CheckFileSize file3_plus_eof 12
2229 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2230 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2231 call :CheckFileSize file12_plus_eof 14
2233 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2234 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2235 call :CheckFileSize file12_no_eof 13
2237 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2238 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2239 call :CheckFileSize file12_eof2 14
2241 rem --------------------------------------------------------------
2242 rem Show ascii source copy stops at first EOF, binary does the lot
2243 rem --------------------------------------------------------------
2244 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2245 call :CheckFileSize file1_binary_srccopy 6
2247 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2248 call :CheckFileSize file1_ascii_srccopy 5
2250 rem --------------------------------------------------------------
2251 rem Show results of concatenating files (ending in EOFs) and /a /b
2252 rem --------------------------------------------------------------
2254 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2255 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2256 call :CheckFileSize file123_default_copy 25
2257 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2258 call :CheckFileSize file123_ascii_copy 25
2260 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2261 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2262 call :CheckFileSize file123_binary_copy 27
2264 rem We can select which we want the eofs from by postfixing it with /a or /b
2265 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2266 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2267 call :CheckFileSize file123_mixed_copy1 26
2269 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2270 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2271 rem Note the delta between this and the previous one also shows that the destination
2272 rem ascii/binary is inherited from the last /a or /b on the line
2273 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2274 call :CheckFileSize file123_mixed_copy2 27
2276 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2277 rem Note the delta between the next two also shows that the destination ascii/binary is
2278 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2279 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2280 call :CheckFileSize file123_mixed_copy3 26
2281 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2282 call :CheckFileSize file123_mixed_copy4 25
2284 rem -------------------------------------------------------------------------------------------
2285 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2286 rem are not concatenating, its a direct copy regardless of destination if being read as binary
2287 rem -------------------------------------------------------------------------------------------
2289 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2290 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2291 call :CheckFileSize file123_mixed_copy5 28
2293 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2294 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2295 call :CheckFileSize file123_mixed_copy6 19
2297 rem One file has EOF, but doesn't get an extra one, i.e. 6
2298 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2299 call :CheckFileSize file123_mixed_copy7 6
2301 rem Syntax means concatenate so ascii destination kicks in
2302 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2303 call :CheckFileSize file123_mixed_copy8 7
2308 rem ---------------------------------------
2309 rem Error combinations
2310 rem ---------------------------------------
2311 rem Specify source directory but name is a file
2313 copy file1\ dir1\ >NUL 2>&1
2314 if errorlevel 1 echo Passed: errorlevel invalid check 1
2315 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2316 call :CheckNotExist dir1\file1
2318 rem Overwrite same file
2320 copy file1 file1 >NUL 2>&1
2321 if errorlevel 1 echo Passed: errorlevel invalid check 2
2322 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2324 rem Supply same file identified as a directory
2326 copy file1 file1\ >NUL 2>&1
2327 if errorlevel 1 echo Passed: errorlevel invalid check 3
2328 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2333 echo ------------ Testing setlocal/endlocal ------------
2335 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2336 mkdir foobar & cd foobar
2337 echo --- enable/disable extensions
2338 setlocal DisableEXTensions
2339 echo ErrLev: %ErrorLevel%
2341 echo ErrLev: %ErrorLevel%
2342 echo @echo off> tmp.cmd
2343 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2344 rem Enabled by default
2346 cmd /E:OfF /C tmp.cmd
2347 cmd /e:oN /C tmp.cmd
2349 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2350 echo --- setlocal with corresponding endlocal
2351 rem %CD% does not tork on NT4 so use the following workaround
2352 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2353 echo @echo off> test.cmd
2354 echo echo %%WINE_VAR%%>> test.cmd
2355 echo setlocal>> test.cmd
2356 echo set WINE_VAR=localval>> test.cmd
2357 echo md foobar2>> test.cmd
2358 echo cd foobar2>> test.cmd
2359 echo echo %%WINE_VAR%%>> test.cmd
2360 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2361 echo endlocal>> test.cmd
2362 echo echo %%WINE_VAR%%>> test.cmd
2363 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2364 set WINE_VAR=globalval
2367 for /d %%i in (.) do echo %%~dpnxi
2371 echo --- setlocal with no corresponding endlocal
2372 echo @echo off> test.cmd
2373 echo echo %%WINE_VAR%%>> test.cmd
2374 echo setlocal>> test.cmd
2375 echo set WINE_VAR=localval>> test.cmd
2376 echo md foobar2>> test.cmd
2377 echo cd foobar2>> test.cmd
2378 echo echo %%WINE_VAR%%>> test.cmd
2379 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2380 set WINE_VAR=globalval
2381 rem %CD% does not tork on NT4 so use the following workaround
2382 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2385 for /d %%i in (.) do echo %%~dpnxi
2389 echo --- setlocal within same batch program
2393 rem %CD% does not tork on NT4 so use the following workaround
2394 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2401 if "%WINE_var1%"=="one" echo Var1 ok 1
2402 if "%WINE_var2%"=="two" echo Var2 ok 2
2403 if "%WINE_var3%"=="three" echo Var3 ok 3
2404 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2405 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
2407 if "%WINE_var1%"=="one" echo Var1 ok 1
2408 if "%WINE_var2%"=="two" echo Var2 ok 2
2409 if "%WINE_var3%"=="" echo Var3 ok 3
2410 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2411 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
2413 if "%WINE_var1%"=="one" echo Var1 ok 1
2414 if "%WINE_var2%"=="" echo Var2 ok 2
2415 if "%WINE_var3%"=="" echo Var3 ok 3
2416 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2417 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
2421 echo --- Mismatched set and end locals
2425 rem %CD% does not tork on NT4 so use the following workaround
2426 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
2428 echo @echo off> 2set1end.cmd
2429 echo echo %%WINE_var%%>> 2set1end.cmd
2430 echo setlocal>> 2set1end.cmd
2431 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
2432 echo cd ..\foodir3>> 2set1end.cmd
2433 echo setlocal>> 2set1end.cmd
2434 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
2435 echo cd ..\foodir4>> 2set1end.cmd
2436 echo endlocal>> 2set1end.cmd
2437 echo echo %%WINE_var%%>> 2set1end.cmd
2438 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
2440 echo @echo off> 1set2end.cmd
2441 echo echo %%WINE_var%%>> 1set2end.cmd
2442 echo setlocal>> 1set2end.cmd
2443 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
2444 echo cd ..\foodir3>> 1set2end.cmd
2445 echo endlocal>> 1set2end.cmd
2446 echo echo %%WINE_var%%>> 1set2end.cmd
2447 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2448 echo endlocal>> 1set2end.cmd
2449 echo echo %%WINE_var%%>> 1set2end.cmd
2450 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2452 echo --- Extra setlocal in called batch
2454 rem -- setlocal1 == this batch, should never be used inside a called routine
2458 call %WINE_CURDIR%\2set1end.cmd
2461 for /d %%i in (.) do echo %%~dpnxi
2464 for /d %%i in (.) do echo %%~dpnxi
2467 echo --- Extra endlocal in called batch
2469 rem -- setlocal1 == this batch, should never be used inside a called routine
2473 call %WINE_CURDIR%\1set2end.cmd
2476 for /d %%i in (.) do echo %%~dpnxi
2479 for /d %%i in (.) do echo %%~dpnxi
2482 echo --- endlocal in called function rather than batch pgm is ineffective
2488 call :endlocalroutine
2492 goto :endlocalfinished
2510 cd .. & rd /q/s foobar
2512 echo ------------ Testing Errorlevel ------------
2513 rem WARNING: Do *not* add tests using ErrorLevel after this section
2514 should_not_exist 2> nul > nul
2516 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2517 rem See http://www.robvanderwoude.com/exit.php
2520 if errorlevel 2 echo errorlevel too high, bad
2521 if errorlevel 1 echo errorlevel just right, good
2522 if errorlevel 01 echo errorlevel with leading zero just right, good
2523 if errorlevel -1 echo errorlevel with negative number OK
2524 if errorlevel 0x1 echo hexa should not be recognized!
2525 if errorlevel 1a echo invalid error level recognized!
2527 echo abc%ErrorLevel%def
2528 if errorlevel 1 echo errorlevel nonzero, bad
2529 if not errorlevel 1 echo errorlevel zero, good
2530 if not errorlevel 0x1 echo hexa should not be recognized!
2531 if not errorlevel 1a echo invalid error level recognized!
2532 rem Now verify that setting a real variable hides its magic variable
2534 echo %ErrorLevel% should be 7
2535 if errorlevel 7 echo setting var worked too well, bad
2537 echo %ErrorLevel% should still be 7
2539 echo ------------ Testing GOTO ------------
2542 echo goto with no leading space worked
2545 echo goto with a leading space worked
2548 echo goto with a leading tab worked
2551 echo goto with a following space worked
2553 echo ------------ Testing PATH ------------
2554 set WINE_backup_path=%path%
2561 set path=%WINE_backup_path%
2562 set WINE_backup_path=
2564 echo ------------ Testing combined CALLs/GOTOs ------------
2565 echo @echo off>foo.cmd
2566 echo goto :eof>>foot.cmd
2568 echo echo world>>foo.cmd
2570 echo @echo off>foot.cmd
2571 echo echo cheball>>foot.cmd
2573 echo call :bar>>foot.cmd
2574 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
2575 echo goto :eof>>foot.cmd
2578 echo echo barbare>>foot.cmd
2579 echo goto :eof>>foot.cmd
2585 rem Script execution stops after the following line
2608 echo Final message is not output since earlier 'foot' processing stops script execution
2609 echo Do NOT add any tests below this line
2611 echo ------------ Done, jumping to EOF -----------
2613 rem Subroutine to set errorlevel and return
2614 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
2617 rem This line runs under cmd in windows NT 4, but not in more modern versions.