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@
31 echo ------------ Testing 'echo' [OFF] --------------
33 echo 'singlequotedword'
34 echo "doublequotedword"
47 echo word@space@@space@
51 echo@tab@word@tab@@space@
57 echo ------------ Testing mixed echo modes --------------
58 echo @echo on> mixedEchoModes.cmd
59 echo if 1==1 echo foo>> mixedEchoModes.cmd
60 echo if 1==1 @echo bar>> mixedEchoModes.cmd
61 echo @echo off>> mixedEchoModes.cmd
62 echo if 1==1 echo foo2>> mixedEchoModes.cmd
63 echo if 1==1 @echo bar2>> mixedEchoModes.cmd
64 type mixedEchoModes.cmd
65 cmd /c mixedEchoModes.cmd
66 del mixedEchoModes.cmd
68 echo ------------ Testing rem --------------
73 rem echo foo & echo bar
76 rem@tab@echo foo & echo bar
82 rem echo foo & echo bar
85 rem@tab@echo foo & echo bar
88 echo ------------ Testing redirection operators --------------
89 mkdir foobar & cd foobar
90 echo ...stdout redirection
99 echo foo@tab@1>@tab@foo
114 echo ...stdout appending
132 echo foo7 7>> foo || (echo not supported & del foo)
133 if exist foo (type foo) else echo not supported
134 echo ...redirections within IF statements
135 if 1==1 echo foo1>bar
137 if 1==1 (echo foo2>bar) else echo baz2>bar
139 if 1==1 (echo foo3) else echo baz3>bar
140 type bar || echo file does not exist, ok
141 if 1==1 (echo foo4>bar) else echo baz4>bar
143 if 1==0 (echo foo5>bar) else echo baz5>bar
145 if 1==0 (echo foo6) else echo baz6 1>bar
147 if 1==0 (echo foo7 1>bar) else echo baz7>bar
149 if 1==0 (echo foo8 1>bar) else echo baz8>bak
151 if 1==1 (echo foo>bar & echo baz)
158 (if 1==1 (echo A) else echo B) > C
160 (if 1==0 (echo A) else echo B) > C
162 (if 1==0 (echo A > B) else echo C)
163 cd .. & rd /s/q foobar
165 echo ------------ Testing ^^ escape character --------------
166 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
179 echo bak ^&& echo baz 2> nul
189 rem FIXME: echoing %FOO% gives an error (baz not recognized) but prematurely
190 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
199 echo ------------ Testing 'set' --------------
201 set FOOBAR 2> nul > nul
205 echo %FOOBAR%FOOBAR not defined
217 echo %FOOBAR%FOOBAR not defined
219 set FOOBA 2> nul > nul
229 echo %FOO%FOO not defined
234 echo set "FOO=bar" should not include the quotes in the variable value
247 echo ------------ Testing variable expansion --------------
249 echo ~dp0 should be directory containing batch file
265 echo %ERRORLEVEL%%ERRORLEVEL%
266 echo %ERRORLEVEL%ERRORLEVEL%
273 echo ------------ Testing variable substrings --------------
286 echo ------------ Testing variable substitution --------------
287 echo ...in FOR variables
288 for %%i in ("A B" C) do echo %%i
290 for %%i in ("A B" C) do echo '%%~i'
291 rem fully qualified path
292 for %%f in ("C D" E) do echo %%~ff
294 for %%i in ("F G" H) do echo %%~di
296 for %%d in ("I J" K) do echo %%~pd
298 for %%i in ("L M" N) do echo %%~ni
300 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
301 rem path with short path names
302 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
304 for %%i in ("U V" W) do echo '%%~ai'
306 for %%i in (foo) do echo '%%~ai'
309 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
310 for %%i in ("a b" c) do echo '%%~ti'
312 rem Similar issues as above
313 for %%i in ("a b" c) do echo '%%~zi'
315 for %%i in ("d e" f) do echo %%~dpi
316 for %%i in ("g h" i) do echo %%~sdi
317 for %%i in ("g h" i) do echo %%~dsi
318 for %%i in ("j k" l.eh) do echo '%%~xsi'
320 echo ...in parameters
321 for %%i in ("A B" C) do call :echoFun %%i
323 for %%i in ("A B" C) do call :echoFunQ %%i
324 rem fully qualified path
325 for %%f in ("C D" E) do call :echoFunF %%f
327 for %%i in ("F G" H) do call :echoFunD %%i
329 for %%d in ("I J" K) do call :echoFunP %%d
331 for %%i in ("L M" N) do call :echoFunN %%i
333 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
334 rem path with short path names
335 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
336 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
338 for %%i in ("d e" f) do call :echoFunDP %%i
339 for %%i in ("g h" i) do call :echoFunSD %%i
340 for %%i in ("g h" i) do call :echoFunDS %%i
341 for %%i in ("j k" l.eh) do call :echoFunXS %%i
373 rem some NT4 workaround
396 echo ------------ Testing variable delayed expansion --------------
397 rem NT4 doesn't support this
398 echo ...default mode (load-time expansion)
404 if %FOO% == bar (echo bar) else echo foo
410 if !FOO! == bar (echo bar) else echo foo
413 echo ...runtime (delayed) expansion mode
414 setlocal EnableDelayedExpansion
420 if %FOO% == bar (echo bar) else echo foo
426 if !FOO! == bar (echo bar) else echo foo
429 setlocal DisableDelayedExpansion
435 echo ...using /V cmd flag
436 echo @echo off> tmp.cmd
437 echo set FOO=foo>> tmp.cmd
438 echo echo %%FOO%%>> tmp.cmd
439 echo echo !FOO!>> tmp.cmd
440 echo set FOO=>> tmp.cmd
442 cmd /V:OfF /C tmp.cmd
445 echo ------------ Testing conditional execution --------------
446 echo ...unconditional ^&
447 call :setError 123 & echo foo1
448 echo bar2 & echo foo2
449 mkdir foobar & cd foobar
451 cd .. & rd /s/q foobar
453 echo foobar not deleted!
456 ) else echo foobar deleted
457 echo ...on success conditional ^&^&
458 call :setError 456 && echo foo3 > foo3
462 ) else echo foo3 not created
463 echo bar4 && echo foo4
464 echo ...on failure conditional ^|^|
465 call :setError 789 || echo foo5
466 echo foo6 || echo bar6 > bar6
472 echo ------------ Testing cd ------------
475 echo blabla > singleFile
477 echo Current dir: %CD%
492 if not exist foobar (cd ..)
494 cd@tab@..@tab@@space@@tab@
496 if not exist foobar (cd ..)
504 cd "bar bak@space@"@tab@@space@
515 echo ------------ Testing type ------------
525 echo ------------ Testing NUL ------------
526 md foobar & cd foobar
527 rem NUL file (non) creation + case insensitivity
528 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
537 rem NUL not special everywhere
540 if not exist foo (echo foo should have been created) else (
544 rem Empty file creation
555 echo ------------ Testing if/else --------------
556 echo if/else should work with blocks
558 echo if seems to work
560 echo if seems to be broken
563 echo else seems to be broken
565 echo else seems to work
568 echo if seems not to detect /c as parameter
570 echo parameter detection seems to be broken
572 echo Testing case sensitivity with and without /i option
573 if bar==BAR echo if does not default to case sensitivity
574 if not bar==BAR echo if seems to default to case sensitivity
575 if /i foo==FOO echo if /i seems to work
576 if /i not foo==FOO echo if /i seems to be broken
577 if /I foo==FOO echo if /I seems to work
578 if /I not foo==FOO echo if /I seems to be broken
579 echo Testing string comparisons
580 if abc == abc (echo equal) else echo non equal
581 if abc =="abc" (echo equal) else echo non equal
582 if "abc"== abc (echo equal) else echo non equal
583 if "abc"== "abc" (echo equal) else echo non equal
584 echo Testing tabs handling
585 if@tab@1==1 echo doom
586 if @tab@1==1 echo doom
587 if 1==1 (echo doom) else@tab@echo quake
588 if@tab@not @tab@1==@tab@0 @tab@echo lol
589 if 1==0@tab@(echo doom) else echo quake
590 if 1==0 (echo doom)@tab@else echo quake
591 if 1==0 (echo doom) else@tab@echo quake
593 echo -----------Testing for -----------
595 for %%i in (A B C) do echo %%i
596 for %%i in (A B C) do echo %%I
597 for %%i in (A B C) do echo %%j
598 for %%i in (A B C) do call :forTestFun1 %%i
599 for %%i in (1,4,1) do echo %%i
600 for %%i in (A, B,C) do echo %%i
601 for %%i in (X) do echo %%i
602 for@tab@%%i in (X2) do echo %%i
603 for %%i in@tab@(X3) do echo %%i
604 for %%i in (@tab@ foo@tab@) do echo %%i
605 for@tab@ %%i in@tab@(@tab@M) do echo %%i
606 for %%i@tab@in (X)@tab@do@tab@echo %%i
607 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
608 for %%i in (`echo A B`) do echo %%i
609 for %%i in ('echo A B') do echo %%i
610 for %%i in ("echo A B") do echo %%i
611 for %%i in ("A B" C) do echo %%i
617 echo ...imbricated FORs
624 for %%i in (A B) do (
625 for %%j in (C D) do (
627 for %%i in (A B) do (
628 for %%j in (C D) do (
629 call :forTestFun2 %%i %%j ))
635 mkdir foobar & cd foobar
640 echo ...basic wildcards
641 for %%i in (ba*) do echo %%i
643 for /d %%i in (baz foo bar) do echo %%i
644 rem FIXME for /d incorrectly parses when wildcards are used
645 rem for /d %%i in (bazb*) do echo %%i
646 rem FIXME can't test wildcard expansion here since it's listed in directory
647 rem order, and not in alphabetic order.
648 rem Proper testing would need a currently missing "sort" program implementation.
649 rem for /d %%i in (ba*) do echo %%i>> tmp
652 rem for /d %%i in (?a*) do echo %%i>> tmp
655 rem for /d %%i in (*) do echo %%i>> tmp
658 cd .. & rd /s/Q foobar
660 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
661 for /L %%i in (1,2,0) do echo %%i
662 for@tab@/L %%i in (1,2,0) do echo %%i
663 for /L %%i in (1,2,6) do echo %%i
664 for /l %%i in (1 ,2,6) do echo %%i
665 for /L %%i in (a,2,3) do echo %%i
666 for /L %%i in (1,2,-1) do echo %%i
667 for /L %%i in (-4,-1,-1) do echo %%i
668 for /L %%i in (1,-2,-2) do echo %%i
669 for /L %%i in (1,2,a) do echo %%i
670 echo ErrorLevel %ErrorLevel%
671 for /L %%i in (1,a,b) do echo %%i
672 echo ErrorLevel %ErrorLevel%
673 rem FIXME: following test cases cannot be currently tested due to an inconsistent/buggy 'for /L' parsing.
674 rem for /L %%i in (a,2,b) do echo %%i
675 rem for /L %%i in (1,1,1) do echo %%i
676 rem for /L %%i in (1,-2,-1) do echo %%i
677 rem for /L %%i in (-1,-1,-1) do echo %%i
678 rem for /L %%i in (1,2, 3) do echo %%i
680 rem No output when using "set expr" syntax, unless in interactive mode
681 rem Need to use "set envvar=expr" to use in a batch script
682 echo ......individual operations
684 set /a var=1 +2 & echo %var%
685 set /a var=1 +-2 & echo %var%
686 set /a var=1 --2 & echo %var%
687 set /a var=2* 3 & echo %var%
688 set /a var=-2* -5 & echo %var%
689 set /a var=12/3 & echo %var%
690 set /a var=13/3 & echo %var%
691 set /a var=-13/3 & echo %var%
692 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
693 set /a var=5 %% 5 & echo %var%
694 set /a var=5 %% 3 & echo %var%
695 set /a var=5 %% -3 & echo %var%
696 set /a var=-5 %% -3 & echo %var%
697 set /a var=1 ^<^< 0 & echo %var%
698 set /a var=1 ^<^< 2 & echo %var%
699 set /a var=1 ^<^< -2 & echo %var%
700 set /a var=-1 ^<^< -2 & echo %var%
701 set /a var=-1 ^<^< 2 & echo %var%
702 set /a var=9 ^>^> 0 & echo %var%
703 set /a var=9 ^>^> 2 & echo %var%
704 set /a var=9 ^>^> -2 & echo %var%
705 set /a var=-9 ^>^> -2 & echo %var%
706 set /a var=-9 ^>^> 2 & echo %var%
707 set /a var=5 ^& 0 & echo %var%
708 set /a var=5 ^& 1 & echo %var%
709 set /a var=5 ^& 3 & echo %var%
710 set /a var=5 ^& 4 & echo %var%
711 set /a var=5 ^& 1 & echo %var%
712 set /a var=5 ^| 0 & echo %var%
713 set /a var=5 ^| 1 & echo %var%
714 set /a var=5 ^| 3 & echo %var%
715 set /a var=5 ^| 4 & echo %var%
716 set /a var=5 ^| 1 & echo %var%
717 set /a var=5 ^^ 0 & echo %var%
718 set /a var=5 ^^ 1 & echo %var%
719 set /a var=5 ^^ 3 & echo %var%
720 set /a var=5 ^^ 4 & echo %var%
721 set /a var=5 ^^ 1 & echo %var%
722 echo ......precedence and grouping
723 set /a var=4 + 2*3 & echo %var%
724 set /a var=(4+2)*3 & echo %var%
725 set /a var=4 * 3/5 & echo %var%
726 set /a var=(4 * 3)/5 & echo %var%
727 set /a var=4 * 5 %% 4 & echo %var%
728 set /a var=4 * (5 %% 4) & echo %var%
729 set /a var=3 %% (5 + 8 %% 3 ^^ 2) & echo %var%
730 set /a var=3 %% (5 + 8 %% 3 ^^ -2) & echo %var%
731 echo ......octal and hexadecimal
732 set /a var=0xf + 3 & echo %var%
733 set /a var=0xF + 3 & echo %var%
734 set /a var=015 + 2 & echo %var%
735 set /a var=3, 8+3,0 & echo %var%
737 set /a var=foo=3, foo+1 & echo %var%
738 if defined foo (echo %foo%) else (
741 set /a var=foo=3, foo+=1 & echo %var%
742 set /a var=foo=3, bar=1, bar+=foo, bar & echo %var%
743 set /a var=foo*= foo & echo %var%
744 set /a var=whateverNonExistingVar & echo %var%
745 set /a var=whateverNonExistingVar + bar & echo %var%
746 set /a var=foo -= foo + 7 & echo %var%
747 set /a var=foo /= 3 + 2 & echo %var%
748 set /a var=foo=5, foo %%=2 & echo %var%
749 set /a var=foo ^<^<= 2 & echo %var%
750 set /a var=foo ^>^>= 2 & echo %var%
751 set /a var=foo ^&= 2 & echo %var%
752 set /a var=foo=5, foo ^|= 2 & echo %var%
753 set /a var=foo=5, foo ^^= 2 & echo %var%
754 set /a var=foo=19, foo %%= 4 + (bar %%= 7) & echo.
759 mkdir foobar & cd foobar
760 echo ......string argument
761 for /F %%i in ("a b c") do echo %%i
762 for /f %%i in ("a ") do echo %%i
763 for /f %%i in ("a") do echo %%i
764 fOr /f %%i in (" a") do echo %%i
765 for /f %%i in (" a ") do echo %%i
766 echo ......fileset argument
767 echo .........basic blank handling
769 for /f %%i in (foo) do echo %%i
771 for /f %%i in (foo) do echo %%i
773 for /f %%i in (foo) do echo %%i
775 for /f %%i in (foo) do echo %%i
777 for /f %%i in (foo) do echo %%i
779 for /f %%i in (foo) do echo %%i
782 for /f %%i in (foo) do echo %%i
783 echo .........multi-line with empty lines
790 for /f %%b in (foo) do echo %%b
791 echo .........multiple files
795 for /f %%k in (foo bar) do echo %%k
796 for /f %%k in (bar foo) do echo %%k
797 rem echo ......command argument
798 rem Not implemented on NT4
799 rem FIXME: Not testable right now in wine: not implemented and would need
800 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
801 rem for a simple todo_wine test
802 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
803 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
804 echo ......eol option
805 for /f "eol=@" %%i in (" ad") do echo %%i
806 for /f "eol=@" %%i in (" z@y") do echo %%i
807 for /f "eol=|" %%i in ("a|d") do echo %%i
808 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
809 if not exist output_file (echo no output) else (del output_file)
810 for /f "eol==" %%i in ("=y") do echo %%i > output_file
811 if not exist output_file (echo no output) else (del output_file)
812 echo ......delims option
813 for /f "delims=|" %%i in ("a|d") do echo %%i
814 for /f "delims=|" %%i in ("a |d") do echo %%i
815 for /f "delims=|" %%i in ("a d|") do echo %%i
816 for /f "delims=| " %%i in ("a d|") do echo %%i
817 for /f "delims==" %%i in ("C r=d|") do echo %%i
818 for /f "delims=" %%i in ("foo bar baz") do echo %%i
819 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
820 echo ......skip option
824 for /f "skip=2" %%i in (foo) do echo %%i
825 for /f "skip=3" %%i in (foo) do echo %%i > output_file
826 if not exist output_file (echo no output) else (del output_file)
827 for /f "skip=4" %%i in (foo) do echo %%i > output_file
828 if not exist output_file (echo no output) else (del output_file)
832 echo -----------Testing del /a-----------
833 del /f/q *.test > nul
836 echo not-r > not-r.test
838 if not exist not-r.test echo not-r.test not found before delete, bad
840 if not exist not-r.test echo not-r.test not found after delete, good
842 if not exist r.test echo r.test not found before delete, bad
843 if exist r.test echo r.test found before delete, good
845 if not exist r.test echo r.test not found after delete, good
846 if exist r.test echo r.test found after delete, bad
848 echo ------------ Testing del /q --------------
853 rem If /q doesn't work, cmd will prompt and the test case should hang
855 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
856 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
860 echo ------------ Testing del /s --------------
865 echo there > file2.dat
867 echo bye > "file with spaces.dat"
869 del /s file1.dat > nul
870 del file2.dat /s > nul
871 del "file3.dat" /s > nul
872 del "file with spaces.dat" /s > nul
874 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
875 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
876 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
877 if exist "file with spaces.dat" del "file with spaces.dat"
882 echo ----------- Testing mkdir -----------
884 echo ... md and mkdir are synonymous ...
891 echo ... creating an already existing directory/file must fail ...
900 echo ... multilevel path creation ...
912 mkdir ..\..\..\foo\bar2
915 mkdir ..\..\..\foo\bar2
917 rmdir ..\..\..\foo\bar2
925 echo ... trailing backslashes ...
928 if exist foo (rmdir foo & echo dir created
929 ) else ( echo dir not created )
931 echo ... invalid chars ...
933 echo mkdir ? gives errorlevel %ErrorLevel%
936 echo mkdir ?\foo gives errorlevel %ErrorLevel%
939 echo mkdir foo\? gives errorlevel %ErrorLevel%
940 if exist foo (rmdir foo & echo ok, foo created
941 ) else ( echo foo not created )
944 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
947 echo bad, foo not created
951 echo ok, foo\bar created
957 echo ... multiple directories at once ...
958 mkdir foobaz & cd foobaz
959 mkdir foo bar\baz foobar
960 if exist foo (echo foo created) else echo foo not created!
961 if exist bar (echo bar created) else echo bar not created!
962 if exist foobar (echo foobar created) else echo foobar not created!
963 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
964 cd .. & rd /s/q foobaz
967 echo mkdir foo\* errorlevel %ErrorLevel%
968 if exist foo (rmdir foo & echo ok, foo created
969 ) else ( echo bad, foo not created )
971 echo ----------- Testing rmdir -----------
973 rem rd and rmdir are synonymous
977 if not exist foobar echo dir removed
981 if not exist foobar echo dir removed
982 rem Removing nonexistent directory
985 rem Removing single-level directories
989 if exist foo echo file not removed
995 if exist foo echo non-empty dir not removed
1000 if exist foo echo non-empty dir not removed
1007 echo recursive rmdir succeeded
1014 echo foo > foo\bar\brol
1017 echo recursive rmdir succeeded
1024 rem multiples directories at once
1025 mkdir foobaz & cd foobaz
1029 rd /s/q foo bar foobar
1030 if not exist foo (echo foo removed) else echo foo not removed!
1031 if not exist bar (echo bar removed) else echo bar not removed!
1032 if not exist foobar (echo foobar removed) else echo foobar not removed!
1033 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
1034 cd .. & rd /s/q foobaz
1036 echo ----------- Testing pushd/popd -----------
1038 echo ...popd is no-op when dir stack is empty
1041 echo ...pushing non-existing dir
1044 echo ...basic behaviour
1069 echo ------------ Testing attrib --------------
1070 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
1071 mkdir foobar & cd foobar
1072 echo foo original contents> foo
1075 echo ... read-only attribute
1076 rem Read-only files cannot be altered or deleted, unless forced
1084 echo Read-only file not deleted
1086 echo Should not delete read-only file!
1090 echo Read-only file forcibly deleted
1092 echo Should delete read-only file with del /F!
1096 cd .. & rd /s/q foobar
1097 echo ... recursive behaviour
1098 mkdir foobar\baz & cd foobar
1104 attrib +R l*vel? /S > nul 2>&1
1110 cd .. & rd /s/q foobar
1111 echo ... folders processing
1117 attrib +r baz /s /d > nul 2>&1
1123 rem Oddly windows allows file creation in a read-only directory...
1124 if exist baz\lala (echo file created in read-only dir) else echo file not created
1125 cd .. & rd /s/q foobar
1127 echo ------------ Testing assoc --------------
1128 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1129 rem FIXME Revise once || conditional execution is fixed
1130 mkdir foobar & cd foobar
1131 echo ...setting association
1139 rem association set system-wide
1140 echo @echo off> tmp.cmd
1141 echo echo +++>> tmp.cmd
1142 echo assoc .foo>> tmp.cmd
1145 echo ...resetting association
1151 rem association removal set system-wide
1152 cmd /c tmp.cmd > baz
1155 cd .. & rd /s/q foobar
1157 echo ------------ Testing ftype --------------
1158 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1159 rem FIXME Revise once || conditional execution is fixed
1160 mkdir foobar & cd foobar
1161 echo ...setting association
1166 ftype footype=foo_opencmd
1170 rem association set system-wide
1171 echo @echo off> tmp.cmd
1172 echo echo +++>> tmp.cmd
1173 echo ftype footype>> tmp.cmd
1176 echo ...resetting association
1179 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
1180 setlocal EnableDelayedExpansion
1181 set FOO=original value
1184 for /F %%i in ('type baz') do (set FOO=buggyXP)
1185 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
1186 rem FIXME Revisit once a grep-like program like ftype is implemented
1187 rem (e.g. to check baz's size using dir /b instead)
1190 rem cleanup registry
1191 echo REGEDIT4> regCleanup.reg
1192 echo.>> regCleanup.reg
1193 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
1194 regedit /s regCleanup.reg
1197 cd .. & rd /s/q foobar
1199 echo ------------ Testing CALL ------------
1200 mkdir foobar & cd foobar
1201 echo ... external script ...
1202 echo echo foo %%1> foo.cmd
1205 echo echo %%1 %%2 > foo.cmd
1207 call foo.cmd foo bar
1214 echo ... internal routines ...
1215 call :testRoutine :testRoutine
1216 goto :endTestRoutine
1222 call :testRoutineArgs foo
1223 call :testRoutineArgs foo bar
1224 call :testRoutineArgs foo ""
1225 call :testRoutineArgs "" bar
1226 call :testRoutineArgs foo ''
1227 call :testRoutineArgs '' bar
1228 goto :endTestRoutineArgs
1234 echo ... with builtins ...
1237 if exist foo (echo foo created) else echo foo should exist!
1239 set FOOBAZ_VAR=foobaz
1240 call echo Should expand %FOOBAZ_VAR%
1245 if 1==1 call del batfile
1247 if exist batfile echo batfile shouldn't exist
1248 rem ... but not for 'if' or 'for'
1249 call if 1==1 echo bar 2> nul
1252 call for %%i in (foo bar baz) do echo %%i 2> nul
1254 rem First look for programs in the path before trying a builtin
1255 echo echo non-builtin dir> dir.cmd
1257 cd .. & rd /s/q foobar
1259 echo ------------ Testing SHIFT ------------
1261 call :shiftFun p1 p2 p3 p4 p5
1265 echo '%1' '%2' '%3' '%4' '%5'
1267 echo '%1' '%2' '%3' '%4' '%5'
1269 echo '%1' '%2' '%3' '%4' '%5'
1271 echo '%1' '%2' '%3' '%4' '%5'
1273 echo '%1' '%2' '%3' '%4' '%5'
1275 echo '%1' '%2' '%3' '%4' '%5'
1279 echo ------------ Testing cmd invocation ------------
1280 rem FIXME: only a stub ATM
1281 echo ... a batch file can delete itself ...
1282 echo del foo.cmd>foo.cmd
1284 if not exist foo.cmd (
1285 echo file correctly deleted
1287 echo file should be deleted!
1290 echo ... a batch file can alter itself ...
1291 echo echo bar^>foo.cmd>foo.cmd
1292 cmd /q /c foo.cmd > NUL 2>&1
1297 echo file not created!
1300 echo ------------ Testing setlocal/endlocal ------------
1302 rem Note: setlocal EnableDelayedExtension already tested in the variable delayed expansion test section
1303 mkdir foobar & cd foobar
1304 echo ...enable/disable extensions
1305 setlocal DisableEXTensions
1306 echo ErrLev: %ErrorLevel%
1308 echo ErrLev: %ErrorLevel%
1309 echo @echo off> tmp.cmd
1310 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
1311 rem Enabled by default
1313 cmd /E:OfF /C tmp.cmd
1314 cmd /e:oN /C tmp.cmd
1316 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
1317 echo ...setlocal with corresponding endlocal
1318 echo @echo off> test.cmd
1319 echo echo %%VAR%%>> test.cmd
1320 echo setlocal>> test.cmd
1321 echo set VAR=localval>> test.cmd
1322 echo echo %%VAR%%>> test.cmd
1323 echo endlocal>> test.cmd
1324 echo echo %%VAR%%>> test.cmd
1329 echo ...setlocal with no corresponding endlocal
1330 echo @echo off> test.cmd
1331 echo echo %%VAR%%>> test.cmd
1332 echo setlocal>> test.cmd
1333 echo set VAR=localval>> test.cmd
1334 echo echo %%VAR%%>> test.cmd
1339 cd .. & rd /q/s foobar
1341 echo -----------Testing Errorlevel-----------
1342 rem WARNING: Do *not* add tests using ErrorLevel after this section
1343 should_not_exist 2> nul > nul
1345 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
1346 rem See http://www.robvanderwoude.com/exit.php
1349 if errorlevel 2 echo errorlevel too high, bad
1350 if errorlevel 1 echo errorlevel just right, good
1352 echo abc%ErrorLevel%def
1353 if errorlevel 1 echo errorlevel nonzero, bad
1354 if not errorlevel 1 echo errorlevel zero, good
1355 rem Now verify that setting a real variable hides its magic variable
1357 echo %ErrorLevel% should be 7
1358 if errorlevel 7 echo setting var worked too well, bad
1360 echo %ErrorLevel% should still be 7
1362 echo -----------Testing GOTO-----------
1365 echo goto with no leading space worked
1368 echo goto with a leading space worked
1371 echo goto with a leading tab worked
1374 echo goto with a following space worked
1376 echo ---------- Testing combined CALLs/GOTOs -----------
1377 echo @echo off>foo.cmd
1378 echo goto :eof>>foot.cmd
1380 echo echo world>>foo.cmd
1382 echo @echo off>foot.cmd
1383 echo echo cheball>>foot.cmd
1385 echo call :bar>>foot.cmd
1386 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
1387 echo goto :eof>>foot.cmd
1390 echo echo barbare>>foot.cmd
1391 echo goto :eof>>foot.cmd
1397 rem Script execution stops after the following line
1420 echo Final message is not output since earlier 'foot' processing stops script execution
1421 echo Do NOT add any tests below this line
1423 echo -----------Done, jumping to EOF-----------
1425 rem Subroutine to set errorlevel and return
1426 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
1429 rem This line runs under cmd in windows NT 4, but not in more modern versions.