ieframe: Moved dialog resources to ieframe.
[wine/testsucceed.git] / programs / cmd / tests / test_builtins.cmd
blob572fb386e269f454c799ee76b6a0dc2bb90594ed
1 echo Tests for cmd's builtin commands
3 @echo on
4 echo ------------ Testing 'echo' [ON] --------------
5 echo word
6 echo 'singlequotedword'
7 echo "doublequotedword"
8 @echo at-echoed-word
9 echo "/?"
10 echo.
11 echo .
12 echo.word
13 echo .word
14 echo word@space@
15 echo word@space@@space@
17 @echo off
18 echo ------------ Testing 'echo' [OFF] --------------
19 echo word
20 echo 'singlequotedword'
21 echo "doublequotedword"
22 @echo at-echoed-word
23 echo "/?"
24 echo.
25 echo .
26 echo.word
27 echo .word
28 echo word@space@
29 echo word@space@@space@
31 echo ------------ Testing redirection operators --------------
32 mkdir foobar & cd foobar
33 echo ...stdout redirection
34 echo foo>foo
35 type foo
36 echo foo 1> foo
37 type foo
38 echo foo1> foo
39 type foo
40 echo foo11> foo
41 type foo
42 echo foo12> foo
43 type foo
44 echo ...stdout appending
45 echo foo>foo
46 echo foo >>foo
47 type foo
48 del foo
49 echo foob >> foo
50 type foo
51 echo fooc 1>>foo
52 type foo
53 echo food1>>foo
54 type foo
55 echo food2>>foo
56 type foo
57 del foo
58 echo food21>>foo
59 type foo
60 cd ..
61 rd /s/q foobar
63 echo ------------ Testing ^^ escape character --------------
64 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
65 echo ^hell^o, world
66 echo hell^o, world
67 echo hell^^o, world
68 echo hell^^^o, world
69 mkdir foobar
70 echo baz> foobar\baz
71 type foobar\baz
72 type foobar^\baz
73 rd /s/q foobar
74 echo foo ^| echo bar
75 echo foo ^& echo bar
76 call :setError 0
77 echo bak ^&& echo baz 2> nul
78 echo %ErrorLevel%
79 echo foo ^> foo
80 echo ^<> foo
81 type foo
82 del foo
83 set FOO=oof
84 echo ff^%FOO%
85 set FOO=bar ^| baz
86 set FOO
87 rem FIXME: echoing %FOO% gives an error (baz not recognized) but prematurely
88 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
89 echo %ErrorLevel%
90 call :setError 0
91 set FOO=bar ^^^| baz
92 set FOO
93 echo %FOO%
94 echo %ErrorLevel%
95 set FOO=
97 echo ------------ Testing 'set' --------------
98 call :setError 0
99 set FOOBAR 2> nul > nul
100 echo %ErrorLevel%
101 set FOOBAR = baz
102 echo %ErrorLevel%
103 echo %FOOBAR%FOOBAR not defined
104 echo %FOOBAR %
105 set FOOBAR 2> nul
106 set FOOBAR = baz2
107 echo %ErrorLevel%
108 echo %fOObAr %
109 set FOOBAR= bar
110 echo %ErrorLevel%
111 echo %FOOBAR%
112 set FOO
113 set FOOBAR=
114 set FOOB
115 echo %FOOBAR%FOOBAR not defined
116 set FOOBAR =
117 set FOOBA 2> nul > nul
118 echo %ErrorLevel%
119 set FOO=bar
120 echo %FOO%
121 set FOO=foo
122 set BAR=bar
123 echo %FOO%%BAR%
124 set BAR=
125 set FOO=
126 set FOO=%FOO%
127 echo %FOO%FOO not defined
128 set BAZ%=bazbaz
129 set BA
130 echo %BAZ%%
131 set BAZ%=
132 echo set "FOO=bar" should not include the quotes in the variable value
133 set "FOO=bar"
134 echo %FOO%
135 set FOO=
137 echo ------------ Testing variable expansion --------------
138 call :setError 0
139 echo ~dp0 should be directory containing batch file
140 echo %~dp0
141 mkdir dummydir
142 cd dummydir
143 echo %~dp0
144 cd ..
145 rmdir dummydir
146 echo CD value %CD%
147 echo %%
148 echo P%
149 echo %P
150 echo %UNKNOWN%S
151 echo P%UNKNOWN%
152 echo P%UNKNOWN%S
153 echo %ERRORLEVEL
154 echo %ERRORLEVEL%
155 echo %ERRORLEVEL%%ERRORLEVEL%
156 echo %ERRORLEVEL%ERRORLEVEL%
157 echo %ERRORLEVEL%%
158 echo %ERRORLEVEL%%%
159 echo P%ERRORLEVEL%
160 echo %ERRORLEVEL%S
161 echo P%ERRORLEVEL%S
163 echo ------------ Testing conditional execution --------------
164 echo ...unconditional ^&
165 call :setError 123 & echo foo1
166 echo bar2 & echo foo2
167 mkdir foobar & cd foobar
168 echo > foobazbar
169 cd .. & rd /s/q foobar
170 if exist foobazbar (
171 echo foobar not deleted!
172 cd ..
173 rd /s/q foobar
174 ) else echo foobar deleted
175 echo ...on success conditional ^&^&
176 call :setError 456 && echo foo3 > foo3
177 if exist foo3 (
178 echo foo3 created
179 del foo3
180 ) else echo foo3 not created
181 echo bar4 && echo foo4
182 echo ...on failure conditional ^|^|
183 call :setError 789 || echo foo5
184 echo foo6 || echo bar6 > bar6
185 if exist bar6 (
186 echo bar6 created
187 del bar6
190 echo ------------ Testing type ------------
191 echo bar> foobaz
192 @echo on
193 type foobaz
194 echo ***
195 @echo off
196 type foobaz
197 echo ***
198 del foobaz
200 echo ------------ Testing NUL ------------
201 md foobar & cd foobar
202 rem NUL file (non) creation + case insensitivity
203 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
204 echo > bar
205 echo foo > NUL
206 dir /b /a-d
207 echo foo > nul
208 dir /b /a-d
209 echo foo > NuL
210 dir /b /a-d
211 del bar
212 rem NUL not special everywhere
213 call :setError 123
214 echo NUL> foo
215 if not exist foo (echo foo should have been created) else (
216 type foo
217 del foo
219 rem Empty file creation
220 copy nul foo > nul
221 if exist foo (
222 echo foo created
223 del foo
224 type foo
225 ) else (
226 echo ***
228 cd ..
229 rd foobar
231 echo ------------ Testing if/else --------------
232 echo if/else should work with blocks
233 if 0 == 0 (
234 echo if seems to work
235 ) else (
236 echo if seems to be broken
238 if 1 == 0 (
239 echo else seems to be broken
240 ) else (
241 echo else seems to work
243 if /c==/c (
244 echo if seems not to detect /c as parameter
245 ) else (
246 echo parameter detection seems to be broken
248 echo Testing case sensitivity with and without /i option
249 if bar==BAR echo if does not default to case sensitivity
250 if not bar==BAR echo if seems to default to case sensitivity
251 if /i foo==FOO echo if /i seems to work
252 if /i not foo==FOO echo if /i seems to be broken
253 if /I foo==FOO echo if /I seems to work
254 if /I not foo==FOO echo if /I seems to be broken
256 echo -----------Testing for -----------
257 for %%i in (A B C) do echo %%i
258 for %%i in (A B C) do call :forTestFun1 %%i
259 goto :endForTestFun1
260 :forTestFun1
261 echo %1
262 goto :eof
263 :endForTestFun1
264 for %%i in (X) do (
265 for %%j in (Y) do (
266 echo %%i %%j ))
267 for %%i in (A B) do (
268 for %%j in (C D) do (
269 echo %%i %%j ))
270 for %%i in (A B) do (
271 for %%j in (C D) do (
272 call :forTestFun2 %%i %%j ))
273 goto :endForTestFun2
274 :forTestFun2
275 echo %1 %2
276 goto :eof
277 :endForTestFun2
279 echo -----------Testing del /a-----------
280 del /f/q *.test > nul
281 echo r > r.test
282 attrib +r r.test
283 echo not-r > not-r.test
285 if not exist not-r.test echo not-r.test not found before delete, bad
286 del /a:-r *.test
287 if not exist not-r.test echo not-r.test not found after delete, good
289 if not exist r.test echo r.test not found before delete, bad
290 if exist r.test echo r.test found before delete, good
291 del /a:r *.test
292 if not exist r.test echo r.test not found after delete, good
293 if exist r.test echo r.test found after delete, bad
295 echo ------------ Testing del /q --------------
296 mkdir del_q_dir
297 cd del_q_dir
298 echo abc > file1
299 echo abc > file2.dat
300 rem If /q doesn't work, cmd will prompt and the test case should hang
301 del /q * > nul
302 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
303 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
304 cd ..
305 rmdir del_q_dir
307 echo ------------ Testing del /s --------------
308 mkdir "foo bar"
309 cd "foo bar"
310 echo hi > file1.dat
311 echo there > file2.dat
312 echo bub > file3.dat
313 echo bye > "file with spaces.dat"
314 cd ..
315 del /s file1.dat > nul
316 del file2.dat /s > nul
317 del "file3.dat" /s > nul
318 del "file with spaces.dat" /s > nul
319 cd "foo bar"
320 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
321 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
322 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
323 if exist "file with spaces.dat" del "file with spaces.dat"
324 cd ..
325 rmdir "foo bar"
327 echo ----------- Testing mkdir -----------
328 call :setError 0
329 rem md and mkdir are synonymous
330 mkdir foobar
331 echo %ErrorLevel%
332 rmdir foobar
333 md foobar
334 echo %ErrorLevel%
335 rmdir foobar
336 rem Creating an already existing directory/file must fail
337 mkdir foobar
338 md foobar
339 echo %ErrorLevel%
340 rmdir foobar
341 echo > foobar
342 mkdir foobar
343 echo %ErrorLevel%
344 del foobar
345 rem Multi-level path creation
346 mkdir foo
347 echo %ErrorLevel%
348 mkdir foo\bar\baz
349 echo %ErrorLevel%
350 cd foo
351 echo %ErrorLevel%
352 cd bar
353 echo %ErrorLevel%
354 cd baz
355 echo %ErrorLevel%
356 echo > ..\..\bar2
357 mkdir ..\..\..\foo\bar2
358 echo %ErrorLevel%
359 del ..\..\bar2
360 mkdir ..\..\..\foo\bar2
361 echo %ErrorLevel%
362 rmdir ..\..\..\foo\bar2
363 cd ..
364 rmdir baz
365 cd ..
366 rmdir bar
367 cd ..
368 rmdir foo
369 echo %ErrorLevel%
370 rem Trailing backslashes
371 mkdir foo\\\\
372 echo %ErrorLevel%
373 if exist foo (rmdir foo & echo dir created
374 ) else ( echo dir not created )
375 echo %ErrorLevel%
376 rem Invalid chars
377 mkdir ?
378 echo %ErrorLevel%
379 call :setError 0
380 mkdir ?\foo
381 echo %ErrorLevel%
382 call :setError 0
383 mkdir foo\?
384 echo %ErrorLevel%
385 if exist foo (rmdir foo & echo ok, foo created
386 ) else ( echo foo not created )
387 call :setError 0
388 mkdir foo\bar\?
389 echo %ErrorLevel%
390 call :setError 0
391 if not exist foo (
392 echo bad, foo not created
393 ) else (
394 cd foo
395 if exist bar (
396 echo ok, foo\bar created
397 rmdir bar
399 cd ..
400 rmdir foo
402 rem multiples directories at once
403 mkdir foobaz & cd foobaz
404 mkdir foo bar\baz foobar
405 if exist foo (echo foo created) else echo foo not created!
406 if exist bar (echo bar created) else echo bar not created!
407 if exist foobar (echo foobar created) else echo foobar not created!
408 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
409 cd ..
410 rd /s/q foobaz
412 echo ----------- Testing rmdir -----------
413 call :setError 0
414 rem rd and rmdir are synonymous
415 mkdir foobar
416 rmdir foobar
417 echo %ErrorLevel%
418 if not exist foobar echo dir removed
419 mkdir foobar
420 rd foobar
421 echo %ErrorLevel%
422 if not exist foobar echo dir removed
423 rem Removing non-existent directory
424 rmdir foobar
425 echo %ErrorLevel%
426 rem Removing single-level directories
427 echo > foo
428 rmdir foo
429 echo %ErrorLevel%
430 if exist foo echo file not removed
431 del foo
432 mkdir foo
433 echo > foo\bar
434 rmdir foo
435 echo %ErrorLevel%
436 if exist foo echo non-empty dir not removed
437 del foo\bar
438 mkdir foo\bar
439 rmdir foo
440 echo %ErrorLevel%
441 if exist foo echo non-empty dir not removed
442 rmdir foo\bar
443 rmdir foo
444 rem Recursive rmdir
445 mkdir foo\bar\baz
446 rmdir /s /Q foo
447 if not exist foo (
448 echo recursive rmdir succeeded
449 ) else (
450 rd foo\bar\baz
451 rd foo\bar
452 rd foo
454 mkdir foo\bar\baz
455 echo foo > foo\bar\brol
456 rmdir /s /Q foo
457 if not exist foo (
458 echo recursive rmdir succeeded
459 ) else (
460 rd foo\bar\baz
461 del foo\bar\brol
462 rd foo\bar
463 rd foo
465 rem multiples directories at once
466 mkdir foobaz & cd foobaz
467 mkdir foo
468 mkdir bar\baz
469 mkdir foobar
470 rd /s/q foo bar foobar
471 if not exist foo (echo foo removed) else echo foo not removed!
472 if not exist bar (echo bar removed) else echo bar not removed!
473 if not exist foobar (echo foobar removed) else echo foobar not removed!
474 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
475 cd ..
476 rd /s/q foobaz
478 echo ------------ Testing CALL --------------
479 mkdir foobar & cd foobar
480 rem External script
481 echo echo foo %%1 > foo.cmd
482 call foo
483 call foo.cmd 8
484 del foo.cmd
485 rem Internal routines
486 call :testRoutine :testRoutine
487 goto :endTestRoutine
488 :testRoutine
489 echo bar %1
490 goto :eof
491 :endTestRoutine
492 rem Should work for builtins...
493 call mkdir foo
494 echo %ErrorLevel%
495 if exist foo (echo foo created) else echo foo should exist!
496 rmdir foo
497 set FOOBAZ_VAR=foobaz
498 call echo Should expand %FOOBAZ_VAR%
499 set FOOBAZ_VAR=
500 echo>batfile
501 call dir /b
502 echo>robinfile
503 if 1==1 call del batfile
504 dir /b
505 if exist batfile echo batfile shouldn't exist
506 rem ... but not for 'if' or 'for'
507 call if 1==1 echo bar 2> nul
508 echo %ErrorLevel%
509 call :setError 0
510 call for %%i in (foo bar baz) do echo %%i 2> nul
511 echo %ErrorLevel%
512 rem First look for programs in the path before trying a builtin
513 echo echo non-builtin dir > dir.cmd
514 call dir /b
515 cd ..
516 rd /s/q foobar
518 echo -----------Testing Errorlevel-----------
519 rem WARNING: Do *not* add tests using ErrorLevel after this section
520 should_not_exist 2> nul > nul
521 echo %ErrorLevel%
522 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
523 rem See http://www.robvanderwoude.com/exit.php
524 call :setError 1
525 echo %ErrorLevel%
526 if errorlevel 2 echo errorlevel too high, bad
527 if errorlevel 1 echo errorlevel just right, good
528 call :setError 0
529 echo abc%ErrorLevel%def
530 if errorlevel 1 echo errorlevel nonzero, bad
531 if not errorlevel 1 echo errorlevel zero, good
532 rem Now verify that setting a real variable hides its magic variable
533 set errorlevel=7
534 echo %ErrorLevel% should be 7
535 if errorlevel 7 echo setting var worked too well, bad
536 call :setError 3
537 echo %ErrorLevel% should still be 7
539 echo -----------Testing GOTO-----------
540 if a==a goto dest1
541 :dest1
542 echo goto with no leading space worked
543 if b==b goto dest2
544 :dest2
545 echo goto with a leading space worked
546 if c==c goto dest3
547 :dest3
548 echo goto with a leading tab worked
549 if d==d goto dest4
550 :dest4@space@
551 echo goto with a following space worked
553 echo -----------Done, jumping to EOF-----------
554 goto :eof
555 rem Subroutine to set errorlevel and return
556 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
557 :setError
558 exit /B %1
559 rem This line runs under cmd in windows NT 4, but not in more modern versions.