crypt32: Add additional path for Solaris 11 Express.
[wine] / programs / cmd / tests / test_builtins.cmd
1 echo Tests for cmd's builtin commands
2
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@
16
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@
30
31 echo ------------ Testing 'set' --------------
32 echo %ErrorLevel%
33 set FOOBAR 2> nul > nul
34 echo %ErrorLevel%
35 set FOOBAR =  baz
36 echo %ErrorLevel%
37 echo %FOOBAR%FOOBAR not defined
38 echo %FOOBAR %
39 set FOOBAR 2> nul
40 set FOOBAR =  baz2
41 echo %ErrorLevel%
42 echo %fOObAr %
43 set FOOBAR= bar
44 echo %ErrorLevel%
45 echo %FOOBAR%
46 set FOO
47 set FOOBAR=
48 set FOOB
49 echo %FOOBAR%FOOBAR not defined
50 set FOOBAR =
51 set FOOBA 2> nul > nul
52 echo %ErrorLevel%
53 set FOO=bar
54 echo %FOO%
55 set FOO=foo
56 set BAR=bar
57 echo %FOO%%BAR%
58 set BAR=
59 set FOO=
60 set FOO=%FOO%
61 echo %FOO%FOO not defined
62 set BAZ%=bazbaz
63 set BA
64 echo %BAZ%%
65 set BAZ%=
66 echo set "FOO=bar" should not include the quotes in the variable value
67 set "FOO=bar"
68 echo %FOO%
69 set FOO=
70
71 echo ------------ Testing variable expansion --------------
72 call :setError 0
73 echo ~dp0 should be directory containing batch file
74 echo %~dp0
75 mkdir dummydir
76 cd dummydir
77 echo %~dp0
78 cd ..
79 rmdir dummydir
80 echo CD value %CD%
81 echo %%
82 echo P%
83 echo %P
84 echo %UNKNOWN%S
85 echo P%UNKNOWN%
86 echo P%UNKNOWN%S
87 echo %ERRORLEVEL
88 echo %ERRORLEVEL%
89 echo %ERRORLEVEL%%ERRORLEVEL%
90 echo %ERRORLEVEL%ERRORLEVEL%
91 echo %ERRORLEVEL%%
92 echo %ERRORLEVEL%%%
93 echo P%ERRORLEVEL%
94 echo %ERRORLEVEL%S
95 echo P%ERRORLEVEL%S
96
97 echo ------------ Testing type ------------
98 echo bar> foobaz
99 @echo on
100 type foobaz
101 echo ***
102 @echo off
103 type foobaz
104 echo ***
105 del foobaz
106
107 echo ------------ Testing if/else --------------
108 echo if/else should work with blocks
109 if 0 == 0 (
110   echo if seems to work
111 ) else (
112   echo if seems to be broken
113 )
114 if 1 == 0 (
115   echo else seems to be broken
116 ) else (
117   echo else seems to work
118 )
119 if /c==/c (
120   echo if seems not to detect /c as parameter
121 ) else (
122   echo parameter detection seems to be broken
123 )
124 echo Testing case sensitivity with and without /i option
125 if bar==BAR echo if does not default to case sensitivity
126 if not bar==BAR echo if seems to default to case sensitivity
127 if /i foo==FOO echo if /i seems to work
128 if /i not foo==FOO echo if /i seems to be broken
129 if /I foo==FOO echo if /I seems to work
130 if /I not foo==FOO echo if /I seems to be broken
131
132 echo -----------Testing for -----------
133 for %%i in (A B C) do echo %%i
134 for %%i in (A B C) do call :forTestFun1 %%i
135 goto :endForTestFun1
136 :forTestFun1
137 echo %1
138 goto :eof
139 :endForTestFun1
140 for %%i in (X) do (
141     for %%j in (Y) do (
142         echo %%i %%j ))
143 for %%i in (A B) do (
144     for %%j in (C D) do (
145         echo %%i %%j ))
146 for %%i in (A B) do (
147     for %%j in (C D) do (
148         call :forTestFun2 %%i %%j ))
149 goto :endForTestFun2
150 :forTestFun2
151 echo %1 %2
152 goto :eof
153 :endForTestFun2
154
155 echo -----------Testing del /a-----------
156 del /f/q *.test > nul
157 echo r > r.test
158 attrib +r r.test
159 echo not-r > not-r.test
160
161 if not exist not-r.test echo not-r.test not found before delete, bad
162 del /a:-r *.test
163 if not exist not-r.test echo not-r.test not found after delete, good
164
165 if not exist r.test echo r.test not found before delete, bad
166 if exist r.test echo r.test found before delete, good
167 del /a:r *.test
168 if not exist r.test echo r.test not found after delete, good
169 if exist r.test echo r.test found after delete, bad
170
171 echo ------------ Testing del /q --------------
172 mkdir del_q_dir
173 cd del_q_dir
174 echo abc > file1
175 echo abc > file2.dat
176 rem If /q doesn't work, cmd will prompt and the test case should hang
177 del /q * > nul
178 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
179 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
180 cd ..
181 rmdir del_q_dir
182
183 echo ------------ Testing del /s --------------
184 mkdir "foo bar"
185 cd "foo bar"
186 echo hi > file1.dat
187 echo there > file2.dat
188 echo bub > file3.dat
189 echo bye > "file with spaces.dat"
190 cd ..
191 del /s file1.dat > nul
192 del file2.dat /s > nul
193 del "file3.dat" /s > nul
194 del "file with spaces.dat" /s > nul
195 cd "foo bar"
196 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
197 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
198 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
199 if exist "file with spaces.dat" del "file with spaces.dat"
200 cd ..
201 rmdir "foo bar"
202
203 echo ----------- Testing mkdir -----------
204 call :setError 0
205 rem md and mkdir are synonymous
206 mkdir foobar
207 echo %ErrorLevel%
208 rmdir foobar
209 md foobar
210 echo %ErrorLevel%
211 rmdir foobar
212 rem Creating an already existing directory/file must fail
213 mkdir foobar
214 md foobar
215 echo %ErrorLevel%
216 rmdir foobar
217 echo > foobar
218 mkdir foobar
219 echo %ErrorLevel%
220 del foobar
221 rem Multi-level path creation
222 mkdir foo
223 echo %ErrorLevel%
224 mkdir foo\bar\baz
225 echo %ErrorLevel%
226 cd foo
227 echo %ErrorLevel%
228 cd bar
229 echo %ErrorLevel%
230 cd baz
231 echo %ErrorLevel%
232 echo > ..\..\bar2
233 mkdir ..\..\..\foo\bar2
234 echo %ErrorLevel%
235 del ..\..\bar2
236 mkdir ..\..\..\foo\bar2
237 echo %ErrorLevel%
238 rmdir ..\..\..\foo\bar2
239 cd ..
240 rmdir baz
241 cd ..
242 rmdir bar
243 cd ..
244 rmdir foo
245 echo %ErrorLevel%
246 rem Trailing backslashes
247 mkdir foo\\\\
248 echo %ErrorLevel%
249 if exist foo (rmdir foo && echo dir created
250 ) else ( echo dir not created )
251 echo %ErrorLevel%
252 rem Invalid chars
253 mkdir ?
254 echo %ErrorLevel%
255 call :setError 0
256 mkdir ?\foo
257 echo %ErrorLevel%
258 call :setError 0
259 mkdir foo\?
260 echo %ErrorLevel%
261 if exist foo (rmdir foo && echo ok, foo created
262 ) else ( echo foo not created )
263 call :setError 0
264 mkdir foo\bar\?
265 echo %ErrorLevel%
266 call :setError 0
267 if not exist foo (
268     echo bad, foo not created
269 ) else (
270     cd foo
271     if exist bar (
272         echo ok, foo\bar created
273         rmdir bar
274     )
275     cd ..
276     rmdir foo
277 )
278
279 echo ----------- Testing rmdir -----------
280 call :setError 0
281 rem rd and rmdir are synonymous
282 mkdir foobar
283 rmdir foobar
284 echo %ErrorLevel%
285 if not exist foobar echo dir removed
286 mkdir foobar
287 rd foobar
288 echo %ErrorLevel%
289 if not exist foobar echo dir removed
290 rem Removing non-existent directory
291 rmdir foobar
292 echo %ErrorLevel%
293 rem Removing single-level directories
294 echo > foo
295 rmdir foo
296 echo %ErrorLevel%
297 if exist foo echo file not removed
298 del foo
299 mkdir foo
300 echo > foo\bar
301 rmdir foo
302 echo %ErrorLevel%
303 if exist foo echo non-empty dir not removed
304 del foo\bar
305 mkdir foo\bar
306 rmdir foo
307 echo %ErrorLevel%
308 if exist foo echo non-empty dir not removed
309 rmdir foo\bar
310 rmdir foo
311
312 echo -----------Testing Errorlevel-----------
313 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
314 rem See http://www.robvanderwoude.com/exit.php
315 call :setError 1
316 echo %ErrorLevel%
317 if errorlevel 2 echo errorlevel too high, bad
318 if errorlevel 1 echo errorlevel just right, good
319 call :setError 0
320 echo abc%ErrorLevel%def
321 if errorlevel 1 echo errorlevel nonzero, bad
322 if not errorlevel 1 echo errorlevel zero, good
323 rem Now verify that setting a real variable hides its magic variable
324 set errorlevel=7
325 echo %ErrorLevel% should be 7
326 if errorlevel 7 echo setting var worked too well, bad
327 call :setError 3
328 echo %ErrorLevel% should still be 7
329
330 echo -----------Testing GOTO-----------
331 if a==a goto dest1
332 :dest1
333 echo goto with no leading space worked
334 if b==b goto dest2
335  :dest2
336 echo goto with a leading space worked
337 if c==c goto dest3
338         :dest3
339 echo goto with a leading tab worked
340 if d==d goto dest4
341 :dest4@space@
342 echo goto with a following space worked
343
344 echo -----------Done, jumping to EOF-----------
345 goto :eof
346 rem Subroutine to set errorlevel and return
347 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
348 :setError
349 exit /B %1
350 rem This line runs under cmd in windows NT 4, but not in more modern versions.