1 echo Tests for cmd's builtin commands
4 echo ------------ Testing 'echo' [ON] --------------
6 echo 'singlequotedword'
7 echo "doublequotedword"
15 echo word@space@@space@
18 echo ------------ Testing 'echo' [OFF] --------------
20 echo 'singlequotedword'
21 echo "doublequotedword"
29 echo word@space@@space@
31 echo ------------ Testing 'set' --------------
33 set FOOBAR 2> nul > nul
37 echo %FOOBAR%FOOBAR not defined
49 echo %FOOBAR%FOOBAR not defined
51 set FOOBA 2> nul > nul
61 echo %FOO%FOO not defined
66 echo set "FOO=bar" should not include the quotes in the variable value
71 echo ------------ Testing variable expansion --------------
73 echo ~dp0 should be directory containing batch file
89 echo %ERRORLEVEL%%ERRORLEVEL%
90 echo %ERRORLEVEL%ERRORLEVEL%
97 echo ------------ Testing type ------------
107 echo ------------ Testing NUL ------------
108 md foobar && cd foobar
109 rem NUL file (non) creation + case insensitivity
110 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
119 rem NUL not special everywhere
122 if not exist foo (echo foo should have been created) else (
126 rem Empty file creation
138 echo ------------ Testing if/else --------------
139 echo if/else should work with blocks
141 echo if seems to work
143 echo if seems to be broken
146 echo else seems to be broken
148 echo else seems to work
151 echo if seems not to detect /c as parameter
153 echo parameter detection seems to be broken
155 echo Testing case sensitivity with and without /i option
156 if bar==BAR echo if does not default to case sensitivity
157 if not bar==BAR echo if seems to default to case sensitivity
158 if /i foo==FOO echo if /i seems to work
159 if /i not foo==FOO echo if /i seems to be broken
160 if /I foo==FOO echo if /I seems to work
161 if /I not foo==FOO echo if /I seems to be broken
163 echo -----------Testing for -----------
164 for %%i in (A B C) do echo %%i
165 for %%i in (A B C) do call :forTestFun1 %%i
174 for %%i in (A B) do (
175 for %%j in (C D) do (
177 for %%i in (A B) do (
178 for %%j in (C D) do (
179 call :forTestFun2 %%i %%j ))
186 echo -----------Testing del /a-----------
187 del /f/q *.test > nul
190 echo not-r > not-r.test
192 if not exist not-r.test echo not-r.test not found before delete, bad
194 if not exist not-r.test echo not-r.test not found after delete, good
196 if not exist r.test echo r.test not found before delete, bad
197 if exist r.test echo r.test found before delete, good
199 if not exist r.test echo r.test not found after delete, good
200 if exist r.test echo r.test found after delete, bad
202 echo ------------ Testing del /q --------------
207 rem If /q doesn't work, cmd will prompt and the test case should hang
209 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
210 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
214 echo ------------ Testing del /s --------------
218 echo there > file2.dat
220 echo bye > "file with spaces.dat"
222 del /s file1.dat > nul
223 del file2.dat /s > nul
224 del "file3.dat" /s > nul
225 del "file with spaces.dat" /s > nul
227 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
228 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
229 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
230 if exist "file with spaces.dat" del "file with spaces.dat"
234 echo ----------- Testing mkdir -----------
236 rem md and mkdir are synonymous
243 rem Creating an already existing directory/file must fail
252 rem Multi-level path creation
264 mkdir ..\..\..\foo\bar2
267 mkdir ..\..\..\foo\bar2
269 rmdir ..\..\..\foo\bar2
277 rem Trailing backslashes
280 if exist foo (rmdir foo && echo dir created
281 ) else ( echo dir not created )
292 if exist foo (rmdir foo && echo ok, foo created
293 ) else ( echo foo not created )
299 echo bad, foo not created
303 echo ok, foo\bar created
310 echo ----------- Testing rmdir -----------
312 rem rd and rmdir are synonymous
316 if not exist foobar echo dir removed
320 if not exist foobar echo dir removed
321 rem Removing non-existent directory
324 rem Removing single-level directories
328 if exist foo echo file not removed
334 if exist foo echo non-empty dir not removed
339 if exist foo echo non-empty dir not removed
346 echo recursive rmdir succeeded
353 echo foo > foo\bar\brol
356 echo recursive rmdir succeeded
364 echo ------------ Testing CALL --------------
365 mkdir foobar & cd foobar
367 echo echo foo %%1 > foo.cmd
371 rem Internal routines
372 call :testRoutine :testRoutine
378 rem Should work for builtins...
381 if exist foo (echo foo created) else echo foo should exist!
383 set FOOBAZ_VAR=foobaz
384 call echo Should expand %FOOBAZ_VAR%
389 if 1==1 call del batfile
391 if exist batfile echo batfile shouldn't exist
392 rem ... but not for 'if' or 'for'
393 call if 1==1 echo bar 2> nul
396 call for %%i in (foo bar baz) do echo %%i 2> nul
398 rem First look for programs in the path before trying a builtin
399 echo echo non-builtin dir > dir.cmd
404 echo -----------Testing Errorlevel-----------
405 rem WARNING: Do *not* add tests using ErrorLevel after this section
406 should_not_exist 2> nul > nul
408 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
409 rem See http://www.robvanderwoude.com/exit.php
412 if errorlevel 2 echo errorlevel too high, bad
413 if errorlevel 1 echo errorlevel just right, good
415 echo abc%ErrorLevel%def
416 if errorlevel 1 echo errorlevel nonzero, bad
417 if not errorlevel 1 echo errorlevel zero, good
418 rem Now verify that setting a real variable hides its magic variable
420 echo %ErrorLevel% should be 7
421 if errorlevel 7 echo setting var worked too well, bad
423 echo %ErrorLevel% should still be 7
425 echo -----------Testing GOTO-----------
428 echo goto with no leading space worked
431 echo goto with a leading space worked
434 echo goto with a leading tab worked
437 echo goto with a following space worked
439 echo -----------Done, jumping to EOF-----------
441 rem Subroutine to set errorlevel and return
442 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
445 rem This line runs under cmd in windows NT 4, but not in more modern versions.