mf/tests: Add some IV50 encoder / decoder tests.
[wine.git] / programs / cmd / tests / test_builtins.cmd
blob3829be50f1a44c77315ae6922f3d4ac7d3b96dcd
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:
15 echo :
16 echo:word
17 echo :word
18 echo/
19 echo /
20 echo/word
21 echo /word
22 echo off now
23 echo word@space@
24 echo word@space@@space@
25 echo word
26 echo@tab@word
27 echo@tab@word @tab@
28 echo@tab@word@tab@@space@
29 @tab@echo word
30 echo @tab@word
31 echo @tab@word
32 echo@tab@@tab@word
33 echo @tab@ on @space@
34 @echo --- @ with chains and brackets
35 (echo the @ character chains until&&@echo we leave the current depth||(
36 echo hidden
37 @echo hidden
38 ))&&echo and can hide brackets||(@echo command hidden)||@(echo brackets hidden)
39 @echo ---
41 @echo off
42 echo off@tab@@space@
43 @echo noecho1
44 @echo noecho2
45 @@@@@echo echo3
46 echo ------------ Testing 'echo' [OFF] ------------
47 echo word
48 echo 'singlequotedword'
49 echo "doublequotedword"
50 @echo at-echoed-word
51 echo "/?"
52 echo.
53 echo .
54 echo.word
55 echo .word
56 echo:
57 echo :
58 echo:word
59 echo :word
60 echo/
61 echo /
62 echo/word
63 echo /word
64 echo on again
65 echo word@space@
66 echo word@space@@space@
67 echo word
68 echo@tab@word
69 echo@tab@word @tab@
70 echo@tab@word@tab@@space@
71 @tab@echo word
72 echo @tab@word
73 echo @tab@word
74 echo@tab@@tab@word
76 echo ------------ Testing mixed echo modes ------------
77 echo @echo on> mixedEchoModes.cmd
78 echo if 1==1 echo foo>> mixedEchoModes.cmd
79 echo if 1==1 @echo bar>> mixedEchoModes.cmd
80 echo @echo off>> mixedEchoModes.cmd
81 echo if 1==1 echo foo2>> mixedEchoModes.cmd
82 echo if 1==1 @echo bar2>> mixedEchoModes.cmd
83 type mixedEchoModes.cmd
84 cmd /c mixedEchoModes.cmd
85 del mixedEchoModes.cmd
87 echo ------------ Testing parameterization ------------
88 call :TestParm a b c
89 call :TestParm "a b c"
90 call :TestParm "a b"\c
91 call :TestParm a=~`+,.{}!+b
92 call :TestParm a;b
93 call :TestParm "a;b"
94 call :TestParm a^;b
95 call :TestParm a[b]{c}(d)e
96 call :TestParm a&echo second line
97 call :TestParm a b,,,c
98 call :TestParm a==b;;c
99 call :TestParm a,,, b
100 goto :TestRem
102 :TestParm
103 echo '%1', '%2', '%3'
104 goto :eof
106 :TestRem
107 echo ------------ Testing rem ------------
108 rem Hello
109 rem Hello
110 rem Hello || foo
111 rem echo lol
112 rem echo foo & echo bar
113 rem @tab@ Hello
114 rem@tab@ Hello
115 rem@tab@echo foo & echo bar
116 @echo on
117 rem Hello
118 rem Hello
119 rem Hello || foo
120 rem echo lol
121 rem echo foo & echo bar
122 rem @tab@ Hello
123 rem@tab@ Hello
124 rem@tab@echo foo & echo bar
125 @echo off
127 echo ------------ Testing redirection operators ------------
128 mkdir foobar & cd foobar
129 echo --- stdout redirection
130 echo foo>foo
131 type foo
132 echo foo 1> foo
133 type foo
134 echo foo@tab@1> foo
135 type foo
136 echo foo 1>@tab@foo
137 type foo
138 echo foo@tab@1>@tab@foo
139 type foo
140 echo foo7 7> foo
141 type foo
142 echo foo9 9> foo
143 type foo
144 echo foo1> foo
145 type foo
146 echo foo11> foo
147 type foo
148 echo foo12> foo
149 type foo
150 echo foo13>"foo"
151 type foo
152 echo foo14>."\foo"
153 type foo
154 echo foo15>."\f"oo
155 type foo
156 del foo
157 echo1>foo
158 type foo
159 echo --- stdout appending
160 echo foo>foo
161 echo foo >>foo
162 type foo
163 del foo
164 echo foob >> foo
165 type foo
166 echo fooc 1>>foo
167 type foo
168 echo food1>>foo
169 type foo
170 echo food2>>"foo"
171 type foo
172 del foo
173 echo food21>>foo
174 type foo
175 del foo
176 echo foo> foo
177 echo foo7 7>> foo || (echo not supported & del foo)
178 if exist foo (type foo) else echo not supported
179 echo --- redirections within IF statements
180 if 1==1 echo foo1>bar
181 type bar & del bar
182 if 1==1 echo foo2>>bar
183 type bar & del bar
184 echo -----
185 if 1==1 (echo foo2>bar) else echo baz2>bar
186 type bar & del bar
187 if 1==1 (echo foo3) else echo baz3>bar
188 type bar || echo file does not exist, ok
189 if 1==1 (echo foo4>bar) else echo baz4>bar
190 type bar & del bar
191 if 1==0 (echo foo5>bar) else echo baz5>bar
192 type bar & del bar
193 if 1==0 (echo foo6) else echo baz6 1>bar
194 type bar & del bar
195 if 1==0 (echo foo7 1>bar) else echo baz7>bar
196 type bar & del bar
197 if 1==0 (echo foo8 1>bar) else echo baz8>bak
198 type bak
199 if 1==1 (echo foo>bar & echo baz)
200 type bar
201 if 1==1 (
202 echo foo>bar
203 echo baz
205 type bar
206 (if 1==1 (echo A) else echo B) > C
207 type C
208 (if 1==0 (echo A) else echo B) > C
209 type C
210 (if 1==0 (echo A > B) else echo C)
211 cd .. & rd /s/q foobar
213 echo ------------ Testing circumflex escape character ------------
214 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
215 echo ^hell^o, world
216 echo hell^o, world
217 echo hell^^o, world
218 echo hell^^^o, world
219 echo hello^
220 world
221 echo hello^
223 world
224 echo hello^
227 echo finished
228 mkdir foobar
229 echo baz> foobar\baz
230 type foobar\baz
231 type foobar^\baz
232 rd /s/q foobar
233 echo foo ^| echo bar
234 echo foo ^& echo bar
235 call :setError 0
236 echo bak ^&& echo baz 2> nul
237 echo %ErrorLevel%
238 echo foo ^> foo
239 echo ^<> foo
240 type foo
241 del foo
242 set WINE_FOO=oof
243 echo ff^%WINE_FOO%
244 set WINE_FOO=bar ^| baz
245 set WINE_FOO
246 rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
247 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
248 echo %ErrorLevel%
249 call :setError 0
250 set WINE_FOO=bar ^^^| baz
251 set WINE_FOO
252 echo %WINE_FOO%
253 echo %ErrorLevel%
254 set WINE_FOO=
256 echo ------------ Testing chains ------------
257 rem The chain operators have the following bottom-up precedence:
258 rem 'else' precedes nothing and matches the closest unmatched 'if' in the same bracket depth
259 rem '&' precedes 'else'
260 rem '||' precedes '&' and 'else'
261 rem '&&' precedes '||', '&' and 'else'
262 rem '|' precedes '&&', '||', '&' and 'else'
264 rem Example: 'if 1==1 if 2==2 if 3==3 a | b && c || d & e else f else g' is interpreted as
265 rem 'if 1==1 (if 2==2 (if 3==3 ((((a | b) && c) || d) & e) else f) else g)'
266 goto :cfailend
267 :cfail
268 echo %1
269 call :setError 1
270 goto :eof
271 :cfailend
272 echo --- chain success
273 echo a1&echo a2
274 echo b1&&echo b2
275 echo c1||echo c2
276 echo ---
277 echo d1&echo d2&echo d3
278 echo e1&echo e2&&echo e3
279 echo f1&echo f2||echo f3
280 echo ---
281 echo g1&&echo g2&echo g3
282 echo h1&&echo h2&&echo h3
283 echo i1&&echo i2||echo i3
284 echo ---
285 echo j1||echo j2&echo j3
286 echo ---
287 echo k1||echo k2&&echo k3
288 echo ---
289 echo l1||echo l2||echo l3
290 echo ---
291 echo --- chain failure
292 call :cfail a1&call :cfail a2
293 call :cfail b1&&call :cfail b2
294 echo ---
295 call :cfail c1||call :cfail c2
296 call :cfail d1&call :cfail d2&call :cfail d3
297 call :cfail e1&call :cfail e2&&call :cfail e3
298 echo ---
299 call :cfail f1&call :cfail f2||call :cfail f3
300 call :cfail g1&&call :cfail g2&call :cfail g3
301 echo ---
302 call :cfail h1&&call :cfail h2&&call :cfail h3
303 echo ---
304 call :cfail i1&&call :cfail i2||call :cfail i3
305 echo ---
306 call :cfail j1||call :cfail j2&call :cfail j3
307 call :cfail k1||call :cfail k2&&call :cfail k3
308 echo ---
309 call :cfail l1||call :cfail l2||call :cfail l3
310 echo --- chain brackets
311 rem Brackets are like regular commands, they support redirections
312 rem and have the same precedence as regular commands.
313 echo a1&(echo a2&echo a3)
314 echo b1&(echo b2&&echo b3)
315 echo c1&(echo c2||echo c3)
316 echo ---
317 echo d1&&(echo d2&echo d3)
318 echo e1&&(echo e2&&echo e3)
319 echo f1&&(echo f2||echo f3)
320 echo ---
321 echo g1||(echo g2&echo g3)
322 echo ---
323 echo h1||(echo h2&&echo h3)
324 echo ---
325 echo i1||(echo i2||echo i3)
326 echo ---
327 call :cfail j1&(call :cfail j2&call :cfail j3)
328 call :cfail k1&(call :cfail k2&&call :cfail k3)
329 echo ---
330 call :cfail l1&(call :cfail l2||call :cfail l3)
331 call :cfail m1&&(call :cfail m2&call :cfail m3)
332 echo ---
333 call :cfail n1&&(call :cfail n2&&call :cfail n3)
334 echo ---
335 call :cfail o1&&(call :cfail o2||call :cfail o3)
336 echo ---
337 call :cfail p1||(call :cfail p2&call :cfail p3)
338 call :cfail q1||(call :cfail q2&&call :cfail q3)
339 echo ---
340 call :cfail r1||(call :cfail r2||call :cfail r3)
341 echo --- chain pipe
342 rem Piped commands run at the same time, so the print order varies.
343 rem Additionally, they don't run in the batch script context, as shown by
344 rem 'call :existing_label|echo read the error message'.
345 (echo a 1>&2|echo a 1>&2) 2>&1
346 echo ---
347 echo b1|echo b2
348 echo c1&&echo c2|echo c3
349 echo d1||echo d2|echo d3
350 echo ---
351 echo e1&echo e2|echo e3
352 echo f1|echo f2&&echo f3
353 echo g1|echo g2||echo g3
354 echo ---
355 echo h1|echo h2&echo h3
356 echo i1|echo i2|echo i3
357 echo --- chain pipe input
358 rem The output data of the left side of a pipe can disappear, probably
359 rem because it finished too fast and closed the pipe before it could be read,
360 rem which means we can get broken results for the tests of this section.
361 echo @echo off> tmp.cmd
362 echo set IN=X>> tmp.cmd
363 echo set /p IN=%%1:>> tmp.cmd
364 echo setlocal EnableDelayedExpansion>> tmp.cmd
365 echo echo [!IN!,%%1]>> tmp.cmd
366 echo endlocal>> tmp.cmd
367 echo set IN=>> tmp.cmd
368 echo a1|cmd /ctmp.cmd a2
369 echo b1|cmd /ctmp.cmd b2|cmd /ctmp.cmd b3
370 echo c1|cmd /ctmp.cmd c2|cmd /ctmp.cmd c3|cmd /ctmp.cmd c4
371 echo d1|call tmp.cmd d2
372 echo e1|call tmp.cmd e2|call tmp.cmd e3
373 echo f1|call tmp.cmd f2|call tmp.cmd f3|call tmp.cmd f4
374 rem FIXME these 3 tests cause "unexpected end of output"
375 rem test : echo g1|tmp.cmd g2
376 rem result: g2:[g1,g2]
377 rem test : echo h1|tmp.cmd h2|tmp.cmd h3
378 rem result: h3:[h2:[h1,h2],h3]@or_broken@h3:[h2:,h3]
379 rem test : echo i1|tmp.cmd i2|tmp.cmd i3|tmp.cmd i4
380 rem result: i4:[i3:[i2:[i1,i2],i3],i4]@or_broken@i4:[i3:[i2:,i3],i4]@or_broken@i4:[i3:,i4]
381 del tmp.cmd
382 echo --- chain else
383 rem Command arguments are greedy and eat up the 'else' unless terminated by
384 rem brackets, which means the 'else' can only be recognized when the
385 rem 'if true' command chain ends with brackets.
386 if 1==1 if 2==2 if 3==3 (echo a1) else (echo a2) else echo a3
387 if 1==1 if 2==2 if 3==0 (echo b1) else (echo b2) else echo b3
388 echo ---
389 if 1==1 if 2==0 if 3==3 (echo c1) else (echo c2) else echo c3
390 echo ---
391 if 1==1 if 2==0 if 3==0 (echo d1) else (echo d2) else echo d3
392 echo ---
393 if 1==0 if 2==2 if 3==3 (echo e1) else (echo e2) else echo e3
394 echo ---
395 if 1==0 if 2==2 if 3==0 (echo f1) else (echo f2) else echo f3
396 echo ---
397 if 1==0 if 2==0 if 3==3 (echo g1) else (echo g2) else echo g3
398 echo ---
399 if 1==0 if 2==0 if 3==0 (echo h1) else (echo h2) else echo h3
400 echo ---
401 echo --- chain else (if true)
402 if 1==1 echo a1 else echo a2
403 if 1==1 echo b1|echo b2 else echo b3
404 if 1==1 echo c1&&echo c2 else echo c3
405 if 1==1 echo d1||echo d2 else echo d3
406 echo ---
407 if 1==1 echo e1&echo e2 else echo e3
408 if 1==1 echo f1 else echo f2|echo f3
409 if 1==1 echo g1 else echo g2&&echo g3
410 if 1==1 echo h1 else echo h2||echo h3
411 echo ---
412 if 1==1 echo i1 else echo i2&echo i3
413 if 1==1 echo j1|(echo j2) else echo j3
414 echo ---
415 if 1==1 echo k1&&(echo k2) else echo k3
416 if 1==1 echo l1||(echo l2) else echo l3
417 echo ---
418 if 1==1 echo m1&(echo m2) else echo m3
419 if 1==1 (echo n1) else echo n2|echo n3
420 if 1==1 (echo o1) else echo o2&&echo o3
421 if 1==1 (echo p1) else echo p2||echo p3
422 if 1==1 (echo q1) else echo q2&echo q3
423 echo ---
424 echo --- chain else (if false)
425 if 1==0 echo a1 else echo a2
426 if 1==0 echo b1|echo b2 else echo b3
427 if 1==0 echo c1&&echo c2 else echo c3
428 if 1==0 echo d1||echo d2 else echo d3
429 if 1==0 echo e1&echo e2 else echo e3
430 if 1==0 echo f1 else echo f2|echo f3
431 if 1==0 echo g1 else echo g2&&echo g3
432 if 1==0 echo h1 else echo h2||echo h3
433 if 1==0 echo i1 else echo i2&echo i3
434 if 1==0 echo j1|(echo j2) else echo j3
435 echo ---
436 if 1==0 echo k1&&(echo k2) else echo k3
437 if 1==0 echo l1||(echo l2) else echo l3
438 if 1==0 echo m1&(echo m2) else echo m3
439 if 1==0 (echo n1) else echo n2|echo n3
440 if 1==0 (echo o1) else echo o2&&echo o3
441 if 1==0 (echo p1) else echo p2||echo p3
442 echo ---
443 if 1==0 (echo q1) else echo q2&echo q3
444 echo ------------ Testing 'set' ------------
445 call :setError 0
446 rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
447 for /f "delims==" %%i in ('set WINE_ba') do set %%i=
448 for /f "delims==" %%i in ('set WINE_foo') do set %%i=
449 set WINE_FOOBAR 2> nul > nul
450 echo %ErrorLevel%
451 set WINE_FOOBAR = baz
452 echo %ErrorLevel%
453 echo %WINE_FOOBAR%WINE_FOOBAR not defined
454 echo %WINE_FOOBAR %
455 set WINE_FOOBAR 2> nul
456 set WINE_FOOBAR = baz2
457 echo %ErrorLevel%
458 echo %WINE_fOObAr %
459 set WINE_FOOBAR= bar
460 echo %ErrorLevel%
461 echo %WINE_FOOBAR%
462 set WINE_FOO
463 set WINE_FOOBAR=
464 set WINE_FOOB
465 echo %WINE_FOOBAR%WINE_FOOBAR not defined
466 set WINE_FOOBAR =
467 set WINE_FOOBA 2> nul > nul
468 echo %ErrorLevel%
469 set WINE_FOO=bar
470 echo %WINE_FOO%
471 set WINE_FOO=foo
472 set WINE_BAR=bar
473 echo %WINE_FOO%%WINE_BAR%
474 set WINE_BAR=
475 set WINE_FOO=
476 set WINE_FOO=%WINE_FOO%
477 echo %WINE_FOO%WINE_FOO not defined
478 set WINE_BAZ%=bazbaz
479 set WINE_BA
480 echo %WINE_BAZ%%
481 set WINE_BAZ%=
482 echo set "WINE_FOO=bar" should not include the quotes in the variable value
483 set "WINE_FOO=bar"
484 echo %WINE_FOO%
485 set@tab@WINE_FOO=foo
486 echo %WINE_FOO%
487 set@tab@WINE_FOO=
488 echo '%WINE_FOO%'
489 set WINE_FOO=foo@space@
490 echo '%WINE_FOO%'
491 set WINE_FOO=foo@tab@
492 echo '%WINE_FOO%'
493 rem Space symbol must appear in `var`
494 set WINE_FOO=value@space@
495 echo '%WINE_FOO%'
496 rem Space symbol must NOT appear in `var`
497 set "WINE_FOO=value"@space@
498 echo '%WINE_FOO%'
499 rem Mixed examples:
500 set WINE_FOO=jim fred
501 echo '%WINE_FOO%'
502 set WINE_FOO="jim" fred
503 echo '%WINE_FOO%'
504 set "WINE_FOO=jim fred"
505 echo '%WINE_FOO%'
506 set "WINE_FOO=jim" fred
507 echo '%WINE_FOO%'
508 rem Only the final quote ends the string
509 set "WINE_FOO=apple"banana"grape"orange
510 echo '%WINE_FOO%'
511 set WINE_FOO=
512 rem set PATH must work with quotes
513 set PATH_BACKUP=%PATH%
514 mkdir folder
515 mkdir "fol;der"
516 echo echo I'm here! > "fol;der\sub1.bat"
517 echo echo I'm here! > folder\sub1.bat
518 set PATH=nothing;"fol;der"
519 call sub1
520 set PATH="folder
521 call sub1
522 set PATH=folder"
523 call sub1
524 del "fol;der\sub1.bat"
525 del folder\sub1.bat
526 rmdir "fol;der"
527 rmdir folder
528 PATH=%PATH_BACKUP%
530 echo ------------ Testing 'choice' ------------
532 rem Windows XP and Windows 2000 do not come with choice
533 rem echo is used for @or_broken@ formatting
534 choice /C:ABC /M "Example message" /D A /T:0
535 if %ERRORLEVEL% EQU 9009 (
536 echo choice unavailable
538 echo %ERRORLEVEL%
539 choice /C ABC "/M:Example message" /D:B /T 0
540 if %ERRORLEVEL% EQU 9009 (
541 echo choice unavailable
543 echo %ERRORLEVEL%
544 choice /C def /D:f /T:0
545 if %ERRORLEVEL% EQU 9009 (
546 echo choice unavailable
548 echo %ERRORLEVEL%
549 REM If a pipe fails due to a nonexistent command
550 REM it will stop the whole program's execution
551 if %ERRORLEVEL% NEQ 9009 (
552 echo Y | choice /C ABCXYZ /D A /T 2
554 if %ERRORLEVEL% EQU 9009 (
555 echo choice unavailable
557 echo %ERRORLEVEL%
558 choice /C ABC /N /D A /T 0
559 if %ERRORLEVEL% EQU 9009 (
560 echo choice unavailable
562 echo %ERRORLEVEL%
563 choice /C abcABC /CS /D:A /T:0
564 if %ERRORLEVEL% EQU 9009 (
565 echo choice unavailable
567 echo %ERRORLEVEL%
568 rem intentional error
569 choice /C abcABC /D:A /T:0 >NUL 2>NUL
570 echo %ERRORLEVEL%
572 echo ------------ Testing variable expansion ------------
573 call :setError 0
574 echo ~p0 should be path containing batch file
575 echo %~p0
576 mkdir dummydir
577 cd dummydir
578 echo %~p0
579 cd ..
580 rmdir dummydir
581 echo ~dp0 should be directory containing batch file
582 echo %~dp0
583 mkdir dummydir
584 cd dummydir
585 echo %~dp0
586 cd ..
587 rmdir dummydir
588 echo CD value %CD%
589 echo %%
590 echo P%
591 echo %P
592 echo %WINE_UNKNOWN%S
593 echo P%WINE_UNKNOWN%
594 echo P%WINE_UNKNOWN%S
595 echo %ERRORLEVEL
596 echo %ERRORLEVEL%
597 echo %ERRORLEVEL%%ERRORLEVEL%
598 echo %ERRORLEVEL%ERRORLEVEL%
599 echo %ERRORLEVEL%%
600 echo %ERRORLEVEL%%%
601 echo P%ERRORLEVEL%
602 echo %ERRORLEVEL%S
603 echo P%ERRORLEVEL%S
605 echo ------------ Testing variable substrings ------------
606 set WINE_VAR=qwerty
607 echo %WINE_VAR:~0,1%
608 echo %WINE_VAR:~0,3%
609 echo %WINE_VAR:~2,2%
610 echo '%WINE_VAR:~-2,3%'
611 echo '%WINE_VAR:~-2,1%'
612 echo %WINE_VAR:~2,-1%
613 echo %WINE_VAR:~2,-3%
614 echo '%WINE_VAR:~-2,-4%'
615 echo %WINE_VAR:~-3,-2%
616 set WINE_VAR=
618 echo ------------ Testing variable substitution ------------
619 echo --- in FOR variables
620 for %%i in ("A B" C) do echo %%i
621 rem check works when prefix with @
622 @for %%i in ("A B" C) do echo %%i
623 rem quotes removal
624 for %%i in ("A B" C) do echo '%%~i'
625 rem fully qualified path
626 for %%f in ("C D" E) do echo %%~ff
627 rem drive letter
628 for %%i in ("F G" H) do echo %%~di
629 rem path
630 for %%d in ("I J" K) do echo %%~pd
631 rem filename
632 for %%i in ("L M" N) do echo %%~ni
633 rem file extension
634 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
635 rem path with short path names
636 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
637 rem file attribute
638 for %%i in ("U V" W) do echo '%%~ai'
639 echo foo> foo
640 for %%i in (foo) do echo '%%~ai'
641 for %%i in (foo) do echo '%%~zi'
642 del foo
643 rem file date/time
644 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
645 for %%i in ("a b" c) do echo '%%~ti'
646 rem file size
647 rem Similar issues as above
648 for %%i in ("a b" c) do echo '%%~zi'
649 rem combined options
650 for %%i in ("d e" f) do echo %%~dpi
651 for %%i in ("g h" i) do echo %%~sdi
652 for %%i in ("g h" i) do echo %%~dsi
653 for %%i in ("j k" l.eh) do echo '%%~xsi'
654 for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
656 echo --- in parameters
657 for %%i in ("A B" C) do call :echoFun %%i
658 rem quotes removal
659 for %%i in ("A B" C) do call :echoFunQ %%i
660 rem fully qualified path
661 for %%f in ("C D" E) do call :echoFunF %%f
662 rem drive letter
663 for %%i in ("F G" H) do call :echoFunD %%i
664 rem path
665 for %%d in ("I J" K) do call :echoFunP %%d
666 rem filename
667 for %%i in ("L M" N) do call :echoFunN %%i
668 rem file extension
669 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
670 rem path with short path names
671 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
672 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
673 rem combined options
674 for %%i in ("d e" f) do call :echoFunDP %%i
675 for %%i in ("g h" i) do call :echoFunSD %%i
676 for %%i in ("g h" i) do call :echoFunDS %%i
677 for %%i in ("j k" l.eh) do call :echoFunXS %%i
679 goto :endEchoFuns
680 :echoFun
681 echo %1
682 goto :eof
684 :echoFunQ
685 echo '%~1'
686 goto :eof
688 :echoFunF
689 echo %~f1
690 goto :eof
692 :echoFunD
693 echo %~d1
694 goto :eof
696 :echoFunP
697 echo %~p1
698 goto :eof
700 :echoFunN
701 echo %~n1
702 goto :eof
704 :echoFunX
705 echo '%~x1'
706 goto :eof
708 :echoFunS
709 rem some NT4 workaround
710 set WINE_VAR='%~s1'
711 echo %WINE_VAR%
712 set WINE_VAR=
713 goto :eof
715 :echoFunDP
716 echo %~dp1
717 goto :eof
719 :echoFunSD
720 echo %~sd1
721 goto :eof
723 :echoFunDS
724 echo %~ds1
725 goto :eof
727 :echoFunXS
728 echo '%~xs1'
729 goto :eof
730 :endEchoFuns
732 echo ------------ Testing parameter zero ------------
733 call :func parm1 parm2
734 goto :endParm0
735 :func
736 echo %~0 %~1
737 echo [%0] [%~d0] [%~p0] [%~n0] [%~x0] [%~s0]
738 goto :EOF
739 :endParm0
741 echo ------------ Testing variable delayed expansion ------------
742 rem NT4 doesn't support this
743 echo --- default mode (load-time expansion)
744 set WINE_FOO=foo
745 echo %WINE_FOO%
746 echo !WINE_FOO!
747 if %WINE_FOO% == foo (
748 set WINE_FOO=bar
749 if %WINE_FOO% == bar (echo bar) else echo foo
752 set WINE_FOO=foo
753 if %WINE_FOO% == foo (
754 set WINE_FOO=bar
755 if !WINE_FOO! == bar (echo bar) else echo foo
758 echo --- runtime (delayed) expansion mode
759 setlocal EnableDelayedExpansion
760 set WINE_FOO=foo
761 echo %WINE_FOO%
762 echo !WINE_FOO!
763 if %WINE_FOO% == foo (
764 set WINE_FOO=bar
765 if %WINE_FOO% == bar (echo bar) else echo foo
768 set WINE_FOO=foo
769 if %WINE_FOO% == foo (
770 set WINE_FOO=bar
771 if !WINE_FOO! == bar (echo bar) else echo foo
773 echo %ErrorLevel%
774 setlocal DisableDelayedExpansion
775 echo %ErrorLevel%
776 set WINE_FOO=foo
777 echo %WINE_FOO%
778 echo !WINE_FOO!
779 set WINE_FOO=
780 echo --- using /V cmd flag
781 echo @echo off> tmp.cmd
782 echo set WINE_FOO=foo>> tmp.cmd
783 echo echo %%WINE_FOO%%>> tmp.cmd
784 echo echo !WINE_FOO!>> tmp.cmd
785 echo set WINE_FOO=>> tmp.cmd
786 cmd /V:ON /C tmp.cmd
787 cmd /V:OfF /C tmp.cmd
788 del tmp.cmd
790 echo ------------ Testing conditional execution ------------
791 echo --- unconditional ampersand
792 call :setError 123 & echo foo1
793 echo bar2 & echo foo2
794 mkdir foobar & cd foobar
795 echo > foobazbar
796 cd .. & rd /s/q foobar
797 if exist foobazbar (
798 echo foobar not deleted!
799 cd ..
800 rd /s/q foobar
801 ) else echo foobar deleted
802 echo --- on success conditional and
803 call :setError 456 && echo foo3 > foo3
804 if exist foo3 (
805 echo foo3 created
806 del foo3
807 ) else echo foo3 not created
808 echo bar4 && echo foo4
809 echo --- on failure conditional or
810 call :setError 789 || echo foo5
811 echo foo6 || echo bar6 > bar6
812 if exist bar6 (
813 echo bar6 created
814 del bar6
817 echo ------------ Testing cd ------------
818 mkdir foobar
819 cd foobar
820 echo blabla > singleFile
821 dir /b
822 echo Current dir: %CD%
824 cd ..
826 cd foobar@space@
828 cd ..
830 cd @space@foobar
832 cd..
834 cd foobar
835 cd..@space@
837 if not exist foobar (cd ..)
838 cd foobar
839 cd@tab@..@tab@@space@@tab@
841 if not exist foobar (cd ..)
842 cd foobar
843 mkdir "bar bak"
844 cd "bar bak"
846 cd ..
847 cd ".\bar bak"
849 cd ..
850 cd .\"bar bak"
852 cd ..
853 cd bar bak
855 cd "bar bak@space@"@tab@@space@
857 cd ..\..
859 rd /Q/s foobar
860 mkdir foobar
861 cd /d@tab@foobar
863 cd ..
864 rd /q/s foobar
866 echo ------------ Testing type ------------
867 echo bar> foobaz
868 @echo on
869 type foobaz
870 echo ---
871 @echo off
872 type foobaz@tab@
873 echo ---1
874 type ."\foobaz"
875 echo ---2
876 type ".\foobaz"
877 echo ---3
878 echo foo> foobay
879 echo ---4
880 type foobaz foobay > foobax 2> foobaw
881 echo ---5
882 type foobax
883 echo ---6
884 type foobaw
885 echo ---7
886 del foobaz foobay foobax foobaw
888 echo ------------ Testing NUL ------------
889 md foobar & cd foobar
890 rem NUL file (non) creation + case insensitivity
891 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
892 echo > bar
893 echo foo > NUL
894 dir /b /a-d
895 echo foo > nul
896 dir /b /a-d
897 echo foo > NuL
898 @tab@dir /b@tab@/a-d
899 del bar
900 rem NUL not special everywhere
901 call :setError 123
902 echo NUL> foo
903 if not exist foo (echo foo should have been created) else (
904 type foo
905 del foo
907 rem Empty file creation
908 copy nul foo > nul
909 if exist foo (
910 echo foo created
911 del foo
912 type foo
913 ) else (
914 echo ***
916 echo 1234 >a.a
917 copy a.a+NUL b.b >nul
918 call :CheckFileSize a.a 7 b.b 8
919 copy NUL+a.a b.b >nul
920 call :CheckFileSize a.a 7 b.b 8
921 mkdir subdir
922 copy a.a+NUL subdir\ >nul
923 call :CheckFileSize a.a 7 subdir\a.a 8
924 del subdir\a.a
925 cd subdir
926 copy ..\a.a NUL >nul
927 if exist a.a echo Failed
928 cd ..
929 rd subdir /s /q
930 del a.a b.b
931 cd .. & rd foobar /s /q
933 echo ------------ Testing if/else ------------
934 echo --- if/else should work with blocks
935 if 0 == 0 (
936 echo if seems to work
937 ) else (
938 echo if seems to be broken
940 if 1 == 0 (
941 echo else seems to be broken
942 ) else (
943 echo else seems to work
945 if /c==/c (
946 echo if seems not to detect /c as parameter
947 ) else (
948 echo parameter detection seems to be broken
950 SET elseIF=0
951 if 1 == 1 (
952 SET /a elseIF=%elseIF%+1
953 ) else if 1 == 1 (
954 SET /a elseIF=%elseIF%+2
955 ) else (
956 SET /a elseIF=%elseIF%+2
958 if %elseIF% == 1 (
959 echo else if seems to work
960 ) else (
961 echo else if seems to be broken
963 SET elseIF=0
964 if 1 == 2 (
965 SET /a elseIF=%elseIF%+2
966 ) else if 1 == 1 (
967 SET /a elseIF=%elseIF%+1
968 ) else (
969 SET /a elseIF=%elseIF%+2
971 if %elseIF% == 1 (
972 echo else if seems to work
973 ) else (
974 echo else if seems to be broken
976 SET elseIF=0
977 if 1 == 2 (
978 SET /a elseIF=%elseIF%+2
979 ) else if 1 == 2 (
980 SET /a elseIF=%elseIF%+2
981 ) else (
982 SET /a elseIF=%elseIF%+1
984 if %elseIF% == 1 (
985 echo else if seems to work
986 ) else (
987 echo else if seems to be broken
989 if "x" == "a" (
990 echo broken1
991 ) else (
992 echo expected1
993 if "y" == "b" echo broken2
994 echo expected post-embedded if
996 if ()==() (
997 echo comparison operators surrounded by brackets seem to work
998 ) else (
999 echo comparison operators surrounded by brackets seem to be broken
1001 if 1(==1( (
1002 echo comparison operators surrounded by brackets seem to work
1003 ) else (
1004 echo comparison operators surrounded by brackets seem to be broken
1006 if )==) (
1007 echo comparison operators surrounded by brackets seem to work
1008 ) else (
1009 echo comparison operators surrounded by brackets seem to be broken
1011 if /i not (a)==(b) (
1012 echo comparison operators surrounded by brackets seem to work
1013 ) else (
1014 echo comparison operators surrounded by brackets seem to be broken
1016 if defined windir echo windir is defined
1017 if not defined windir echo windir is defined
1018 if not exist %windir% (
1019 echo windir does not exist
1020 ) else (
1021 echo windir does exist
1023 echo --- case sensitivity with and without /i option
1024 if bar==BAR echo if does not default to case sensitivity
1025 if not bar==BAR echo if seems to default to case sensitivity
1026 if /i foo==FOO echo if /i seems to work
1027 if /i not foo==FOO echo if /i seems to be broken
1028 if /I foo==FOO echo if /I seems to work
1029 if /I not foo==FOO echo if /I seems to be broken
1031 echo --- string comparisons
1032 if abc == abc (echo equal) else echo non equal
1033 if abc =="abc" (echo equal) else echo non equal
1034 if "abc"== abc (echo equal) else echo non equal
1035 if "abc"== "abc" (echo equal) else echo non equal
1037 echo --- tabs handling
1038 if@tab@1==1 echo doom
1039 if @tab@1==1 echo doom
1040 if 1==1 (echo doom) else@tab@echo quake
1041 if@tab@not @tab@1==@tab@0 @tab@echo lol
1042 if 1==0@tab@(echo doom) else echo quake
1043 if 1==0 (echo doom)@tab@else echo quake
1044 if 1==0 (echo doom) else@tab@echo quake
1046 echo --- comparison operators
1047 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
1048 echo ------ for strings
1049 rem NT4 stops processing of the whole batch file as soon as it finds a
1050 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
1051 rem can't test those here.
1052 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
1053 if LSS LSS LSS (echo bar)
1054 if 1.1 LSS 1.10 (echo floats are handled as strings)
1055 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
1056 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
1057 if /i foo LSS FoOc echo if /i seems to work for LSS
1058 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
1059 set WINE_STR_PARMS=A B AB BA AA
1060 for %%i in (%WINE_STR_PARMS%) do (
1061 for %%j in (%WINE_STR_PARMS%) do (
1062 call :LSStest %%i %%j))
1063 if b LSS B (echo b LSS B) else echo NT4
1064 if /I b LSS B echo b LSS B insensitive
1065 if b LSS A echo b LSS A
1066 if /I b LSS A echo b LSS A insensitive
1067 if a LSS B (echo a LSS B) else echo NT4
1068 if /I a LSS B echo a LSS B insensitive
1069 if A LSS b echo A LSS b
1070 if /I A LSS b echo A LSS b insensitive
1071 for %%i in (%WINE_STR_PARMS%) do (
1072 for %%j in (%WINE_STR_PARMS%) do (
1073 call :LEQtest %%i %%j))
1074 if b LEQ B (echo b LEQ B) else echo NT4
1075 if /I b LEQ B echo b LEQ B insensitive
1076 if b LEQ A echo b LEQ A
1077 if /I b LEQ A echo b LEQ A insensitive
1078 if a LEQ B (echo a LEQ B) else echo NT4
1079 if /I a LEQ B echo a LEQ B insensitive
1080 if A LEQ b echo A LEQ b
1081 if /I A LEQ b echo A LEQ b insensitive
1082 for %%i in (%WINE_STR_PARMS%) do (
1083 for %%j in (%WINE_STR_PARMS%) do (
1084 call :EQUtest %%i %%j))
1085 if /I A EQU a echo A EQU a insensitive
1086 for %%i in (%WINE_STR_PARMS%) do (
1087 for %%j in (%WINE_STR_PARMS%) do (
1088 call :NEQtest %%i %%j))
1089 for %%i in (%WINE_STR_PARMS%) do (
1090 for %%j in (%WINE_STR_PARMS%) do (
1091 call :GEQtest %%i %%j))
1092 for %%i in (%WINE_STR_PARMS%) do (
1093 for %%j in (%WINE_STR_PARMS%) do (
1094 call :GTRtest %%i %%j))
1096 echo ------------ Testing if/exist ------------
1097 mkdir subdir
1098 echo something>subdir\bar
1099 echo something else>foo
1100 if exist foo (
1101 echo exist explicit works
1102 ) else (
1103 echo ERROR exist explicit broken
1105 if exist bar (
1106 echo ERROR exist explicit unknown file broken
1107 ) else (
1108 echo exist explicit unknown file works
1110 if exist subdir\bar (
1111 echo exist explicit in subdir works
1112 ) else (
1113 echo ERROR exist explicit in subdir broken
1115 if exist fo* (
1116 echo exist simple wildcard works
1117 ) else (
1118 echo ERROR exist simple wildcard broken
1120 if exist subdir\ba* (
1121 echo exist wildcard works
1122 ) else (
1123 echo ERROR exist wildcard broken
1125 if not exist subdir\ba* (
1126 echo ERROR negate exist wildcard broken
1127 ) else (
1128 echo negate exist wildcard works
1130 if exist idontexist\ba* (
1131 echo ERROR exist wildcard bad subdir broken
1132 ) else (
1133 echo exist wildcard bad subdir broken works
1135 if exist subdir (
1136 echo exist subdir ok
1137 ) else (
1138 echo ERROR exist subdir not working
1140 if exist subdir\. (
1141 echo exist subdir with . ok
1142 ) else (
1143 echo ERROR exist subdir with . not working
1145 if exist subdir\ (
1146 echo exist subdir with \ ok
1147 ) else (
1148 echo ERROR exist subdir with \ not working
1150 if exist "subdir\" (
1151 echo exist subdir with \ and quotes ok
1152 ) else (
1153 echo ERROR exist subdir with \ and quotes not working
1155 del foo subdir\bar
1156 rd subdir
1158 echo ------ for numbers
1159 if -1 LSS 1 (echo negative numbers handled)
1160 if not -1 LSS -10 (echo negative numbers handled)
1161 if not 9 LSS 010 (echo octal handled)
1162 if not -010 LSS -8 (echo also in negative form)
1163 if 4 LSS 0x5 (echo hexa handled)
1164 if not -1 LSS -0x1A (echo also in negative form)
1165 if 11 LSS 101 (echo 11 LSS 101)
1166 set WINE_INT_PARMS=0 1 10 9
1167 for %%i in (%WINE_INT_PARMS%) do (
1168 for %%j in (%WINE_INT_PARMS%) do (
1169 call :LSStest %%i %%j))
1170 for %%i in (%WINE_INT_PARMS%) do (
1171 for %%j in (%WINE_INT_PARMS%) do (
1172 call :LEQtest %%i %%j))
1173 for %%i in (%WINE_INT_PARMS%) do (
1174 for %%j in (%WINE_INT_PARMS%) do (
1175 call :EQUtest %%i %%j))
1176 if 011 EQU 9 (echo octal ok)
1177 if 0xA1 EQU 161 (echo hexa ok)
1178 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
1179 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
1180 for %%i in (%WINE_INT_PARMS%) do (
1181 for %%j in (%WINE_INT_PARMS%) do (
1182 call :NEQtest %%i %%j))
1183 for %%i in (%WINE_INT_PARMS%) do (
1184 for %%j in (%WINE_INT_PARMS%) do (
1185 call :GEQtest %%i %%j))
1186 for %%i in (%WINE_INT_PARMS%) do (
1187 for %%j in (%WINE_INT_PARMS%) do (
1188 call :GTRtest %%i %%j))
1189 echo ------ for numbers and stringified numbers
1190 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
1191 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
1192 if '1' EQU 1 echo '1' EQU 1
1193 if 1 EQU '1' echo 1 EQU '1'
1194 if not "1" GEQ 1 (echo foo) else echo bar
1195 if "10" GEQ "1" echo "10" GEQ "1"
1196 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
1197 if 1 GEQ "1" echo 1 GEQ "1"
1198 if "1" GEQ "1" echo "1" GEQ "1"
1199 if '1' GEQ "1" echo '1' GEQ "1"
1200 if "10" GEQ "1" echo "10" GEQ "1"
1201 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
1202 for %%i in ("1" '1') do call :GEQtest %%i '1'
1203 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
1204 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
1205 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
1206 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
1207 if "10" GEQ "10" (echo "10" GEQ "10")
1208 echo --- unconditional ampersand after if one line
1209 if "0"=="0" echo 1 & echo 2 & echo 3 else echo 4
1210 echo ---
1211 echo x & if "0"=="1" echo 1 & echo 2
1212 echo ---
1213 echo x & if "0"=="1" echo 1 & echo 2 & echo 3
1214 echo ---
1215 echo x & if "0"=="1" (echo 1 & echo 2 & echo 3)
1216 echo ---
1217 echo x & if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
1218 echo ---
1219 goto :endIfCompOpsSubroutines
1221 rem IF subroutines helpers
1222 :LSStest
1223 if %1 LSS %2 echo %1 LSS %2
1224 goto :eof
1225 :LEQtest
1226 if %1 LEQ %2 echo %1 LEQ %2
1227 goto :eof
1228 :EQUtest
1229 if %1 EQU %2 echo %1 EQU %2
1230 goto :eof
1231 :NEQtest
1232 if %1 NEQ %2 echo %1 NEQ %2
1233 goto :eof
1234 :GEQtest
1235 if %1 GEQ %2 echo %1 GEQ %2
1236 goto :eof
1237 :GTRtest
1238 if %1 GTR %2 echo %1 GTR %2
1239 goto :eof
1241 :endIfCompOpsSubroutines
1242 set WINE_STR_PARMS=
1243 set WINE_INT_PARMS=
1245 echo ------------ Testing if/for ------------
1246 if ""=="" for %%i in (A) DO (echo %%i)
1247 if not ""=="" for %%i in (B) DO (echo %%i)
1249 echo ------------ Testing if/set ------------
1250 set x=C:\Program Files (x86)
1251 if ""=="" set y=%x%\dummy
1252 echo %y%
1254 echo ------------ Testing for ------------
1255 echo --- plain FOR
1256 for %%i in (A B C) do echo %%i
1257 for %%i in (A B C) do echo %%I
1258 for %%i in (A B C) do echo %%j
1259 for %%i in (A B C) do call :forTestFun1 %%i
1260 for %%i in (1,4,1) do echo %%i
1261 for %%i in (A, B,C) do echo %%i
1262 for %%i in (X) do echo %%i
1263 for@tab@%%i in (X2) do echo %%i
1264 for %%i in@tab@(X3) do echo %%i
1265 for %%i in (@tab@ foo@tab@) do echo %%i
1266 for@tab@ %%i in@tab@(@tab@M) do echo %%i
1267 for %%i@tab@in (X)@tab@do@tab@echo %%i
1268 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
1269 for %%i in (`echo A B`) do echo %%i
1270 for %%i in ('echo A B') do echo %%i
1271 for %%i in ("echo A B") do echo %%i
1272 for %%i in ("A B" C) do echo %%i
1273 goto :endForTestFun1
1274 :forTestFun1
1275 echo %1
1276 goto :eof
1277 :endForTestFun1
1278 echo --- imbricated FORs
1279 for %%i in (X) do (
1280 for %%j in (Y) do (
1281 echo %%i %%j))
1282 for %%i in (X) do (
1283 for %%I in (Y) do (
1284 echo %%i %%I))
1285 for %%i in (A B) do (
1286 for %%j in (C D) do (
1287 echo %%i %%j))
1288 for %%i in (A B) do (
1289 for %%j in (C D) do (
1290 call :forTestFun2 %%i %%j ))
1291 goto :endForTestFun2
1292 :forTestFun2
1293 echo %1 %2
1294 goto :eof
1295 :endForTestFun2
1296 mkdir foobar & cd foobar
1297 mkdir foo
1298 mkdir bar
1299 mkdir baz
1300 mkdir pop
1301 echo > bazbaz
1302 echo --- basic wildcards
1303 for %%i in (ba*) do echo %%i
1304 echo --- wildcards in subdirs
1305 echo something>pop\bar1
1306 echo something>pop\bar2.txt
1307 echo something>pop\bar3
1308 for %%f in (pop\ba*) do ( call echo %%f )
1309 rmdir /s/q pop
1310 echo --- for /d
1311 for /d %%i in (baz foo bar) do echo %%i 2>&1
1312 rem Confirm we don't match files:
1313 for /d %%i in (bazb*) do echo %%i 2>&1
1314 for /d %%i in (bazb2*) do echo %%i 2>&1
1315 rem Show we pass through non wildcards
1316 for /d %%i in (PASSED) do echo %%i
1317 for /d %%i in (xxx) do (
1318 echo %%i - Should be xxx
1319 echo Expected second line
1321 rem Show we issue no messages on failures
1322 for /d %%i in (FAILED?) do echo %%i 2>&1
1323 for /d %%i in (FAILED?) do (
1324 echo %%i - Unexpected!
1325 echo FAILED Unexpected second line
1327 for /d %%i in (FAILED*) do echo %%i 2>&1
1328 for /d %%i in (FAILED*) do (
1329 echo %%i - Unexpected!
1330 echo FAILED Unexpected second line
1332 rem FIXME can't test wildcard expansion here since it's listed in directory
1333 rem order, and not in alphabetic order.
1334 rem Proper testing would need a currently missing "sort" program implementation.
1335 rem for /d %%i in (ba*) do echo %%i>> tmp
1336 rem sort < tmp
1337 rem del tmp
1338 rem for /d %%i in (?a*) do echo %%i>> tmp
1339 rem sort < tmp
1340 rem del tmp
1341 rem for /d %%i in (*) do echo %%i>> tmp
1342 rem sort < tmp
1343 rem del tmp
1344 echo > baz\bazbaz
1345 goto :TestForR
1347 :SetExpected
1348 del temp.bat 2>nul
1349 call :WriteLine set WINE_found=N
1350 for /l %%i in (1,1,%WINE_expectedresults%) do (
1351 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%~1" set WINE_found=Y
1352 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
1353 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
1355 call :WriteLine echo Got unexpected result: "%%%%~1"
1356 goto :eof
1358 :WriteLine
1359 echo %*>> temp.bat
1360 goto :EOF
1362 :ValidateExpected
1363 del temp.bat 2>nul
1364 for /l %%i in (1,1,%WINE_expectedresults%) do (
1365 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
1367 call temp.bat
1368 del temp.bat 2>nul
1369 goto :eof
1371 :TestForR
1372 rem %CD% does not work on NT4 so use the following workaround
1373 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
1375 echo --- for /R
1376 echo Plain directory enumeration
1377 set WINE_expectedresults=4
1378 set WINE_expectedresults.1=%WINE_CURDIR%\.
1379 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1380 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1381 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1382 call :SetExpected
1383 for /R %%i in (.) do call temp.bat "%%i"
1384 call :ValidateExpected
1386 echo Plain directory enumeration from provided root
1387 set WINE_expectedresults=4
1388 set WINE_expectedresults.1=%WINE_CURDIR%\.
1389 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1390 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1391 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1392 if "%CD%"=="" goto :SkipBrokenNT4
1393 call :SetExpected
1394 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat "%%i"
1395 call :ValidateExpected
1396 :SkipBrokenNT4
1398 echo File enumeration
1399 set WINE_expectedresults=2
1400 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1401 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1402 call :SetExpected
1403 for /R %%i in (baz*) do call temp.bat "%%i"
1404 call :ValidateExpected
1406 echo File enumeration from provided root
1407 set WINE_expectedresults=2
1408 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1409 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1410 call :SetExpected
1411 for /R %%i in (baz*) do call temp.bat "%%i"
1412 call :ValidateExpected
1414 echo Mixed enumeration
1415 set WINE_expectedresults=6
1416 set WINE_expectedresults.1=%WINE_CURDIR%\.
1417 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1418 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1419 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1420 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1421 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1422 call :SetExpected
1423 for /R %%i in (. baz*) do call temp.bat "%%i"
1424 call :ValidateExpected
1426 echo Mixed enumeration from provided root
1427 set WINE_expectedresults=6
1428 set WINE_expectedresults.1=%WINE_CURDIR%\.
1429 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1430 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1431 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1432 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1433 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1434 call :SetExpected
1435 for /R %%i in (. baz*) do call temp.bat "%%i"
1436 call :ValidateExpected
1438 echo With duplicates enumeration
1439 set WINE_expectedresults=12
1440 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
1441 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
1442 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
1443 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1444 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
1445 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
1446 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
1447 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
1448 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1449 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1450 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1451 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1452 call :SetExpected
1453 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat "%%i"
1454 call :ValidateExpected
1456 echo Strip missing wildcards, keep unwildcarded names
1457 set WINE_expectedresults=6
1458 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1459 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1460 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1461 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1462 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1463 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1464 call :SetExpected
1465 for /R %%i in (baz* fred* jim) do call temp.bat "%%i"
1466 call :ValidateExpected
1468 echo for /R passed
1469 echo --- Complex wildcards unix and windows slash
1470 cd ..
1471 echo Windows slashes, valid path
1472 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1473 for %%f in (foobar\baz\*) do echo WC : %%f
1474 echo Windows slashes, invalid path
1475 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1476 for %%f in (foobar\jim\*) do echo WC : %%f
1477 echo Unix slashes, valid path
1478 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1479 for %%f in (foobar/baz/*) do echo WC : %%f
1480 echo Unix slashes, invalid path
1481 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1482 for %%f in (foobar/jim/*) do echo WC : %%f
1483 echo Done
1484 rd /s/Q foobar
1485 echo --- for /L
1486 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
1487 for /L %%i in (1,2,0) do echo %%i
1488 for@tab@/L %%i in (1,2,0) do echo %%i
1489 for /L %%i in (1,2,6) do echo %%i
1490 for /l %%i in (1 ,2,6) do echo %%i
1491 for /L %%i in (a,2,3) do echo %%i
1492 for /L %%i in (1,2,-1) do echo %%i
1493 for /L %%i in (-4,-1,-1) do echo %%i
1494 for /L %%i in (1,-2,-2) do echo %%i
1495 for /L %%i in (1,2,a) do echo %%i
1496 echo ErrorLevel %ErrorLevel%
1497 for /L %%i in (1,a,b) do echo %%i
1498 echo ErrorLevel %ErrorLevel%
1499 rem Test boundaries
1500 for /l %%i in (1,1,4) do echo %%i
1501 for /l %%i in (1,2,4) do echo %%i
1502 for /l %%i in (4,-1,1) do echo %%i
1503 for /l %%i in (4,-2,1) do echo %%i
1504 for /l %%i in (1,-1,4) do echo %%i
1505 for /l %%i in (4,1,1) do echo %%i
1506 for /L %%i in (a,2,b) do echo %%i
1507 for /L %%i in (1,1,1) do echo %%i
1508 for /L %%i in (1,-2,-1) do echo %%i
1509 for /L %%i in (-1,-1,-1) do echo %%i
1510 for /L %%i in (1,2, 3) do echo %%i
1511 rem Test zero iteration skips the body of the for
1512 for /L %%i in (2,2,1) do (
1513 echo %%i
1514 echo FAILED
1516 echo --- rems inside for loops
1517 for /f %%i IN ("hello") DO (
1518 REM foo|echo ERROR unexpected execution 1
1519 @REM foo|echo ERROR unexpected execution 2
1520 @ REM foo|echo ERROR unexpected execution 3
1522 echo --- ifs inside for loops
1523 for %%i in (test) do (
1524 echo a1
1525 if 1==1 (
1526 echo b1
1527 ) else (
1528 echo c1
1530 echo d1
1532 for %%i in (test) do (
1533 echo a2
1534 if 1==1 (
1535 echo b2
1536 ) else echo c2
1537 echo d2
1539 for %%i in (test) do (
1540 echo a3
1541 if 1==0 (
1542 echo b3
1543 ) else echo c3
1544 echo d3
1546 for %%i in (test) do (
1547 echo a4
1548 if 1==0 (
1549 echo b4
1550 ) else (
1551 echo c4
1553 echo d4
1555 echo --- set /a
1556 goto :testseta
1558 Rem Ideally for /f can be used rather than building a command to execute
1559 rem but that does not work on NT4
1560 :checkenvvars
1561 if "%1"=="" goto :eof
1562 call :executecmd set wine_result=%%%1%%
1563 if "%wine_result%"=="%2" (
1564 echo %1 correctly %2
1565 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1566 set %1=
1567 shift
1568 shift
1569 rem shift
1570 goto :checkenvvars
1571 :executecmd
1573 goto :eof
1575 :testseta
1576 rem No output when using "set expr" syntax, unless in interactive mode
1577 rem Need to use "set envvar=expr" to use in a batch script
1578 echo ------ individual operations
1579 set WINE_foo=0
1580 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1581 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1582 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1583 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1584 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1585 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1586 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1587 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1588 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1589 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1590 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1591 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1592 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1593 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1594 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1595 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1596 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1597 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1598 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1599 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1600 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1601 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1602 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1603 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1604 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1605 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1606 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1607 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1608 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1609 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1610 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1611 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1612 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1613 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1614 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1615 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1616 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1617 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1618 echo ------ precedence and grouping
1619 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1620 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1621 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1622 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1623 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1624 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1625 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1626 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1627 echo ------ octal and hexadecimal
1628 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1629 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1630 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1631 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1632 echo ------ variables
1633 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1634 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1635 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
1636 set WINE_bar=3
1637 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1638 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1639 set WINE_bar=4
1640 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1641 set WINE_bar=4
1642 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1643 set WINE_bar=-7
1644 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1645 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1646 set WINE_bar=1
1647 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1648 set WINE_bar=4
1649 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1650 set WINE_bar=1
1651 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1652 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1653 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1654 set WINE_baz=4
1655 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1656 echo --- quotes
1657 set /a WINE_foo=1
1658 call :checkenvvars WINE_foo 1
1659 set /a "WINE_foo=1"
1660 call :checkenvvars WINE_foo 1
1661 set /a WINE_foo=1,WINE_bar=2
1662 call :checkenvvars WINE_foo 1 WINE_bar 2
1663 set /a "WINE_foo=1,WINE_bar=2"
1664 call :checkenvvars WINE_foo 1 WINE_bar 2
1665 set /a "WINE_foo=1","WINE_bar=2"
1666 call :checkenvvars WINE_foo 1 WINE_bar 2
1667 set /a ""WINE_foo=1","WINE_bar=2""
1668 call :checkenvvars WINE_foo 1 WINE_bar 2
1669 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1670 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1671 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
1672 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1673 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
1674 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1675 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1676 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1677 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
1678 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1679 set /a """"""WINE_foo=1""""""
1680 call :checkenvvars WINE_foo 1
1681 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1682 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1683 set /a WINE_foo="3"+"4"+"5+6"
1684 call :checkenvvars WINE_foo 18
1685 set WINE_foo=3
1686 set /a WINE_bar="WINE_""foo"+4
1687 call :checkenvvars WINE_foo 3 WINE_bar 7
1688 echo --- whitespace are ignored between double char operators
1689 set WINE_foo=4
1690 set WINE_bar=5
1691 set /a WINE_foo + = 6
1692 set /a WINE_bar * = WINE_foo
1693 call :checkenvvars WINE_foo 10 WINE_bar 50
1694 set WINE_foo=4
1695 set WINE_bar=5
1696 set /a WINE_foo + = "6 < < 7"
1697 set /a WINE_bar * = WINE_foo + WINE_foo
1698 call :checkenvvars WINE_foo 772 WINE_bar 7720
1699 set /a WINE_foo=6 7
1700 set /a WINE_ var1=8
1701 set WINE_foo=
1702 echo --- invalid operator sequence
1703 set WINE_foo=4
1704 set /a =4
1705 set /a *=4
1706 set /a ^>=4"
1707 set /a ^<=4"
1708 set /a WINE_foo^>^<=4
1709 echo %WINE_foo%
1710 set /a WINE_foo^>^>^>=4
1711 echo %WINE_foo%
1712 echo ----- negative prefix
1713 set /a WINE_foo=-1
1714 call :checkenvvars WINE_foo -1
1715 set /a WINE_foo=--1
1716 call :checkenvvars WINE_foo 1
1717 set /a WINE_foo=3--3
1718 call :checkenvvars WINE_foo 6
1719 set /a WINE_foo=3---3
1720 call :checkenvvars WINE_foo 0
1721 set /a WINE_foo=3----3
1722 call :checkenvvars WINE_foo 6
1723 set /a WINE_foo=-~1
1724 call :checkenvvars WINE_foo 2
1725 set /a WINE_foo=~-1
1726 call :checkenvvars WINE_foo 0
1727 set /a WINE_foo=3+-~1
1728 call :checkenvvars WINE_foo 5
1729 set /a WINE_foo=3+~-1
1730 call :checkenvvars WINE_foo 3
1731 echo ----- assignment tests involving the end destination
1732 set WINE_foo=3
1733 set /a WINE_foo+=3+(WINE_foo=4)
1734 call :checkenvvars WINE_foo 11
1735 set WINE_foo=2
1736 set /a WINE_bar=3+(WINE_foo=6)
1737 call :checkenvvars WINE_foo 6 WINE_bar 9
1738 set WINE_foo=2
1739 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1740 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1741 set WINE_foo=2
1742 set /a WINE_bar=WINE_foo=7
1743 call :checkenvvars WINE_foo 7 WINE_bar 7
1744 echo ----- equal precedence on stack
1745 rem Unary - don't reduce if precedence is equal
1746 set /a WINE_foo=!!1
1747 call :checkenvvars WINE_foo 1
1748 set /a WINE_foo=!!0
1749 call :checkenvvars WINE_foo 0
1750 set /a WINE_foo=~~1
1751 call :checkenvvars WINE_foo 1
1752 set /a WINE_foo=~~0
1753 call :checkenvvars WINE_foo 0
1754 set /a WINE_foo=--1
1755 call :checkenvvars WINE_foo 1
1756 set /a WINE_foo=+-1
1757 call :checkenvvars WINE_foo -1
1758 set /a WINE_foo=-+1
1759 call :checkenvvars WINE_foo -1
1760 set /a WINE_foo=++1
1761 call :checkenvvars WINE_foo 1
1762 set /a WINE_foo=!~1
1763 call :checkenvvars WINE_foo 0
1764 set /a WINE_foo=~!1
1765 call :checkenvvars WINE_foo -1
1766 set /a WINE_foo=!-1
1767 call :checkenvvars WINE_foo 0
1768 set /a WINE_foo=-!1
1769 call :checkenvvars WINE_foo 0
1770 set /a WINE_foo=!-0
1771 call :checkenvvars WINE_foo 1
1772 set /a WINE_foo=-!0
1773 call :checkenvvars WINE_foo -1
1774 rem Aritmatic - Reduce if precedence is equal
1775 set /a WINE_foo=10*5/2
1776 call :checkenvvars WINE_foo 25
1777 set /a WINE_foo=5/2*10
1778 call :checkenvvars WINE_foo 20
1779 set /a WINE_foo=10/5/2
1780 call :checkenvvars WINE_foo 1
1781 set /a WINE_foo=5%%2*4
1782 call :checkenvvars WINE_foo 4
1783 set /a WINE_foo=10-5+2
1784 call :checkenvvars WINE_foo 7
1785 set /a WINE_foo=1^<^<4^>^>1
1786 call :checkenvvars WINE_foo 8
1787 rem Assignment - don't reduce if precedence is equal
1788 set /a WINE_foo=5
1789 set /a WINE_bar=WINE_foo=6
1790 call :checkenvvars WINE_foo 6 WINE_bar 6
1792 echo --- for /F
1793 mkdir foobar & cd foobar
1794 echo ------ string argument
1795 rem NT4 does not support usebackq
1796 for /F %%i in ("a b c") do echo %%i
1797 for /F %%i in ( "a b c" ) do echo X%%iX
1798 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1799 if not exist output_file (echo no output) else (type output_file & del output_file)
1800 for /f usebackq %%i in ( 'a b c' ) do echo X%%iX>output_file
1801 if not exist output_file (echo no output) else (type output_file & del output_file)
1802 for /f %%i in ("a ") do echo %%i
1803 for /f usebackq %%i in ('a ') do echo %%i>output_file
1804 if not exist output_file (echo no output) else (type output_file & del output_file)
1805 for /f %%i in ("a") do echo %%i
1806 for /f usebackq %%i in ('a') do echo %%i>output_file
1807 if not exist output_file (echo no output) else (type output_file & del output_file)
1808 fOr /f %%i in (" a") do echo %%i
1809 for /f usebackq %%i in (' a') do echo %%i>output_file
1810 if not exist output_file (echo no output) else (type output_file & del output_file)
1811 for /f %%i in (" a ") do echo %%i
1812 for /f usebackq %%i in (' a ') do echo %%i>output_file
1813 if not exist output_file (echo no output) else (type output_file & del output_file)
1814 echo ------ fileset argument
1815 echo --------- basic blank handling
1816 echo a b c>foo
1817 for /f %%i in (foo) do echo %%i
1818 echo a >foo
1819 for /f %%i in (foo) do echo %%i
1820 echo a>foo
1821 for /f %%i in (foo) do echo %%i
1822 echo a>foo
1823 for /f %%i in (foo) do echo %%i
1824 echo a >foo
1825 for /f %%i in (foo) do echo %%i
1826 echo. > foo
1827 for /f %%i in (foo) do echo %%i
1828 echo. >> foo
1829 echo b > foo
1830 for /f %%i in (foo) do echo %%i
1831 echo --------- multi-line with empty lines
1832 echo a Z f> foo
1833 echo. >> foo
1834 echo.>> foo
1835 echo b bC>> foo
1836 echo c>> foo
1837 echo. >> foo
1838 for /f %%b in (foo) do echo %%b
1839 echo --------- multiple files
1840 echo q w > bar
1841 echo.>> bar
1842 echo kkk>>bar
1843 for /f %%k in (foo bar) do echo %%k
1844 for /f %%k in (bar foo) do echo %%k
1845 echo ------ command argument
1846 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1847 if "%CD%"=="" goto :SkipFORFcmdNT4
1848 for /f %%i in ('echo.Passed1') do echo %%i
1849 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
1850 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1851 for /f "usebackq" %%i in (`"c:\windows\system32\cmd.exe" /C echo Passed4`) do echo %%i
1852 for /f "usebackq" %%i in (`""c:\windows\system32\cmd.exe" /C echo Passed5"`) do echo %%i
1853 for /f %%i in ( 'echo.Passed6' ) do echo %%i
1854 for /f "usebackq" %%i in ( `echo.Passed7` ) do echo %%i
1855 goto :ContinueFORF
1856 :SkipFORFcmdNT4
1857 for /l %%i in (1,1,7) do echo Missing functionality - Broken%%i
1858 :ContinueFORF
1859 rem FIXME: Rest not testable right now in wine: not implemented and would need
1860 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1861 rem for a simple todo_wine test
1862 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1863 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1864 echo ------ eol option
1865 if "%CD%"=="" goto :SkipFORFeolNT4
1866 echo Line one>foo
1867 echo and Line two>>foo
1868 echo Line three>>foo
1869 for /f "eol=L" %%i in (foo) do echo %%i
1870 for /f "eol=a" %%i in (foo) do echo %%i
1871 del foo
1872 goto :ContinueFORFeol
1873 :SkipFORFeolNT4
1874 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1875 :ContinueFORFeol
1876 for /f "eol=@" %%i in (" ad") do echo %%i
1877 for /f "eol=@" %%i in (" z@y") do echo %%i
1878 for /f "eol=|" %%i in ("a|d") do echo %%i
1879 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
1880 if not exist output_file (echo no output) else (del output_file)
1881 for /f "eol==" %%i in ("=y") do echo %%i > output_file
1882 if not exist output_file (echo no output) else (del output_file)
1883 echo ------ delims option
1884 for /f "delims=|" %%i in ("a|d") do echo %%i
1885 for /f "delims=|" %%i in ("a |d") do echo %%i
1886 for /f "delims=|" %%i in ("a d|") do echo %%i
1887 for /f "delims=| " %%i in ("a d|") do echo %%i
1888 for /f "delims==" %%i in ("C r=d|") do echo %%i
1889 for /f "delims=" %%i in ("foo bar baz") do echo %%i
1890 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
1891 echo ------ skip option
1892 echo a > foo
1893 echo b >> foo
1894 echo c >> foo
1895 for /f "skip=2" %%i in (foo) do echo %%i
1896 for /f "skip=3" %%i in (foo) do echo %%i > output_file
1897 if not exist output_file (echo no output) else (del output_file)
1898 for /f "skip=4" %%i in (foo) do echo %%i > output_file
1899 if not exist output_file (echo no output) else (del output_file)
1900 for /f "skip=02" %%i in (foo) do echo %%i
1901 for /f "skip=0x2" %%i in (foo) do echo %%i
1902 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
1903 if not exist output_file (echo no output) else (del output_file)
1904 echo ------ tokens= option
1905 rem Basic
1906 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
1907 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
1908 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
1909 rem Show * means the rest
1910 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
1911 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
1912 rem Show * means the rest (not tokenized and rebuilt)
1913 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
1914 rem Order is irrelevant
1915 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
1916 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
1917 rem Duplicates are ignored
1918 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
1919 rem Large tokens are allowed
1920 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
1921 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1922 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
1923 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
1924 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1925 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
1926 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
1927 rem Show negative ranges have no effect
1928 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
1929 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
1930 rem Show duplicates stop * from working
1931 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
1932 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
1933 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
1934 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
1935 rem Special case tokens=* or tokens=n,*
1936 echo 3.14>testfile
1937 FOR /F "tokens=*" %%A IN (testfile) DO @echo 1:%%A,%%B
1938 FOR /F "tokens=1*" %%A IN (testfile) DO @echo 2:%%A,%%B
1939 FOR /F "tokens=2*" %%A IN (testfile) DO @echo 3:%%A,%%B
1940 FOR /F "tokens=1,* delims=." %%A IN (testfile) DO @echo 4:%%A,%%B
1941 del testfile
1942 cd ..
1943 rd /s/q foobar
1944 echo ------ parameter splitting
1945 echo forFParameterSplittingFunc "myparam1=myvalue1 myparam2=myparam2" mytest> foo
1946 for /f "tokens=1 delims=;" %%i in (foo) do (call :%%i)
1947 del foo
1948 for /f "tokens=1 delims=;" %%i in ("forFParameterSplittingFunc "myparam1^=myvalue1 myparam2^=myparam2" mytest") do (call :%%i)
1949 goto :forFParameterSplittingEnd
1950 :forFParameterSplittingFunc
1951 echo %~0 %~1 %~2 %~3 %~4 %~5
1952 goto :eof
1953 :forFParameterSplittingEnd
1954 echo 3.14>testfile
1955 FOR /F "delims=. tokens=*" %%A IN (testfile) DO @echo 4:%%A,%%B
1956 FOR /F "delims=. tokens=1*" %%A IN (testfile) DO @echo 5:%%A,%%B
1957 FOR /F "delims=. tokens=2*" %%A IN (testfile) DO @echo 6:%%A,%%B
1958 FOR /F "delims=. tokens=3*" %%A IN (testfile) DO @echo 7:%%A,%%B
1959 del testfile
1960 rem file contains NUL, created by the .exe
1961 for /f %%A in (nul_test_file) DO echo %%A
1962 for /f "tokens=*" %%A in (nul_test_file) DO echo %%A
1964 echo ------------ Testing del ------------
1965 echo abc > file
1966 echo deleting 'file'
1967 del file
1968 if errorlevel 0 (
1969 echo errorlevel is 0, good
1970 ) else (
1971 echo unexpected errorlevel, got %errorlevel%
1973 if not exist file (
1974 echo successfully deleted 'file'
1975 ) else (
1976 echo error deleting 'file'
1978 echo attempting to delete 'file', even though it is not present
1979 del file
1980 if errorlevel 0 (
1981 echo errorlevel is 0, good
1982 ) else (
1983 echo unexpected errorlevel, got %errorlevel%
1986 echo ------------ Testing del /a ------------
1987 del /f/q *.test > nul
1988 echo r > r.test
1989 attrib +r r.test
1990 echo not-r > not-r.test
1992 if not exist not-r.test echo not-r.test not found before delete, bad
1993 del /a:-r *.test
1994 if not exist not-r.test echo not-r.test not found after delete, good
1996 if not exist r.test echo r.test not found before delete, bad
1997 if exist r.test echo r.test found before delete, good
1998 del /a:r *.test
1999 if not exist r.test echo r.test not found after delete, good
2000 if exist r.test echo r.test found after delete, bad
2002 echo ------------ Testing del /q ------------
2003 mkdir del_q_dir
2004 cd del_q_dir
2005 echo abc > file1
2006 echo abc > file2.dat
2007 rem If /q doesn't work, cmd will prompt and the test case should hang
2008 del /q * > nul
2009 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
2010 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
2011 cd ..
2012 rmdir del_q_dir
2014 echo ------------ Testing del /s ------------
2015 mkdir "foo bar"
2016 cd "foo bar"
2017 mkdir "foo:"
2018 echo hi > file1.dat
2019 echo there > file2.dat
2020 echo bub > file3.dat
2021 echo bye > "file with spaces.dat"
2022 cd ..
2023 del /s file1.dat > nul
2024 del file2.dat /s > nul
2025 del "file3.dat" /s > nul
2026 del "file with spaces.dat" /s > nul
2027 cd "foo bar"
2028 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
2029 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
2030 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
2031 if exist "file with spaces.dat" del "file with spaces.dat"
2032 rmdir "foo:"
2033 cd ..
2034 rmdir "foo bar"
2036 echo ------------ Testing rename ------------
2037 mkdir foobar & cd foobar
2038 echo --- ren and rename are synonymous
2039 echo > foo
2040 rename foo bar
2041 if exist foo echo foo should be renamed!
2042 if exist bar echo foo renamed to bar
2043 ren bar foo
2044 if exist bar echo bar should be renamed!
2045 if exist foo echo bar renamed to foo
2046 echo --- name collision
2047 echo foo>foo
2048 echo bar>bar
2049 ren foo bar 2> nul
2050 type foo
2051 type bar
2052 rem no-op
2053 ren foo foo
2054 mkdir baz
2055 ren foo baz\abc
2056 echo --- rename read-only files
2057 echo > file1
2058 attrib +r file1
2059 ren file1 file2
2060 if not exist file1 (
2061 if exist file2 (
2062 echo read-only file renamed
2064 ) else (
2065 echo read-only file not renamed!
2067 echo --- rename directories
2068 mkdir rep1
2069 ren rep1 rep2
2070 if not exist rep1 (
2071 if exist rep2 (
2072 echo dir renamed
2075 attrib +r rep2
2076 ren rep2 rep1
2077 if not exist rep2 (
2078 if exist rep1 (
2079 echo read-only dir renamed
2082 echo --- rename in other directory
2083 if not exist baz\abc (
2084 echo rename impossible in other directory
2085 if exist foo echo original file still present
2086 ) else (
2087 echo shouldn't rename in other directory!
2088 if not exist foo echo original file not present anymore
2090 cd .. & rd /s/q foobar
2092 echo ------------ Testing move ------------
2093 mkdir foobar & cd foobar
2094 echo --- file move
2095 echo >foo
2096 move foo bar > nul 2>&1
2097 if not exist foo (
2098 if exist bar (
2099 echo file move succeeded
2102 echo bar>bar
2103 echo baz> baz
2104 move /Y bar baz > nul 2>&1
2105 if not exist bar (
2106 if exist baz (
2107 echo file move with overwrite succeeded
2109 ) else (
2110 echo file overwrite impossible!
2111 del bar
2113 type baz
2115 attrib +r baz
2116 move baz bazro > nul 2>&1
2117 if not exist baz (
2118 if exist bazro (
2119 echo read-only files are moveable
2120 move bazro baz > nul 2>&1
2122 ) else (
2123 echo read-only file not moved!
2125 attrib -r baz
2126 mkdir rep
2127 move baz rep > nul 2>&1
2128 if not exist baz (
2129 if exist rep\baz (
2130 echo file moved in subdirectory
2133 call :setError 0
2134 move rep\baz . > nul 2>&1
2135 move /Y baz baz > nul 2>&1
2136 if errorlevel 1 (
2137 echo moving a file to itself should be a no-op!
2138 ) else (
2139 echo moving a file to itself is a no-op
2141 echo ErrorLevel: %ErrorLevel%
2142 call :setError 0
2143 del baz
2144 echo --- directory move
2145 mkdir foo\bar
2146 mkdir baz
2147 echo baz2>baz\baz2
2148 move baz foo\bar > nul 2>&1
2149 if not exist baz (
2150 if exist foo\bar\baz\baz2 (
2151 echo simple directory move succeeded
2154 call :setError 0
2155 mkdir baz
2156 move baz baz > nul 2>&1
2157 echo moving a directory to itself gives error; errlevel %ErrorLevel%
2158 echo ------ dir in dir move
2159 rd /s/q foo
2160 mkdir foo bar
2161 echo foo2>foo\foo2
2162 echo bar2>bar\bar2
2163 move foo bar > nul 2>&1
2164 if not exist foo (
2165 if exist bar (
2166 dir /b /ad bar
2167 dir /b /a-d bar
2168 dir /b bar\foo
2171 cd .. & rd /s/q foobar
2173 echo ------------ Testing mkdir ------------
2174 call :setError 0
2175 echo --- md and mkdir are synonymous
2176 mkdir foobar
2177 echo %ErrorLevel%
2178 rmdir foobar
2179 md foobar
2180 echo %ErrorLevel%
2181 rmdir foobar
2182 echo --- creating an already existing directory/file must fail
2183 mkdir foobar
2184 md foobar
2185 echo %ErrorLevel%
2186 rmdir foobar
2187 echo > foobar
2188 mkdir foobar
2189 echo %ErrorLevel%
2190 del foobar
2191 echo --- multilevel path creation
2192 mkdir foo
2193 echo %ErrorLevel%
2194 mkdir foo\bar\baz
2195 echo %ErrorLevel%
2196 cd foo
2197 echo %ErrorLevel%
2198 cd bar
2199 echo %ErrorLevel%
2200 cd baz
2201 echo %ErrorLevel%
2202 echo > ..\..\bar2
2203 mkdir ..\..\..\foo\bar2
2204 echo %ErrorLevel%
2205 del ..\..\bar2
2206 mkdir ..\..\..\foo\bar2
2207 echo %ErrorLevel%
2208 rmdir ..\..\..\foo\bar2
2209 cd ..
2210 rmdir baz
2211 cd ..
2212 rmdir bar
2213 cd ..
2214 rmdir foo
2215 echo %ErrorLevel%
2216 echo --- trailing backslashes
2217 mkdir foo\\\\
2218 echo %ErrorLevel%
2219 if exist foo (rmdir foo & echo dir created
2220 ) else ( echo dir not created )
2221 echo %ErrorLevel%
2222 echo --- invalid chars
2223 mkdir ?
2224 echo mkdir ? gives errorlevel %ErrorLevel%
2225 call :setError 0
2226 mkdir ?\foo
2227 echo mkdir ?\foo gives errorlevel %ErrorLevel%
2228 call :setError 0
2229 mkdir foo\?
2230 echo mkdir foo\? gives errorlevel %ErrorLevel%
2231 if exist foo (rmdir foo & echo ok, foo created
2232 ) else ( echo foo not created )
2233 call :setError 0
2234 mkdir foo\bar\?
2235 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
2236 call :setError 0
2237 if not exist foo (
2238 echo bad, foo not created
2239 ) else (
2240 cd foo
2241 if exist bar (
2242 echo ok, foo\bar created
2243 rmdir bar
2245 cd ..
2246 rmdir foo
2248 echo --- multiple directories at once
2249 mkdir foobaz & cd foobaz
2250 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
2251 if exist foo (echo foo created) else echo foo not created!
2252 if exist bar (echo bar created) else echo bar not created!
2253 if exist foobar (echo foobar created) else echo foobar not created!
2254 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
2255 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
2256 if exist zabzab (echo zabzab created) else echo zabzab not created!
2257 cd .. & rd /s/q foobaz
2258 call :setError 0
2259 mkdir foo\*
2260 echo mkdir foo\* errorlevel %ErrorLevel%
2261 if exist foo (rmdir foo & echo ok, foo created
2262 ) else ( echo bad, foo not created )
2264 echo ------------ Testing rmdir ------------
2265 call :setError 0
2266 rem rd and rmdir are synonymous
2267 mkdir foobar
2268 rmdir foobar
2269 echo %ErrorLevel%
2270 if not exist foobar echo dir removed
2271 mkdir foobar
2272 rd foobar
2273 echo %ErrorLevel%
2274 if not exist foobar echo dir removed
2275 rem Removing nonexistent directory
2276 rmdir foobar
2277 echo %ErrorLevel%
2278 rem Removing single-level directories
2279 echo > foo
2280 rmdir foo
2281 echo %ErrorLevel%
2282 if exist foo echo file not removed
2283 del foo
2284 mkdir foo
2285 echo > foo\bar
2286 rmdir foo
2287 echo %ErrorLevel%
2288 if exist foo echo non-empty dir not removed
2289 del foo\bar
2290 mkdir foo\bar
2291 rmdir foo
2292 echo %ErrorLevel%
2293 if exist foo echo non-empty dir not removed
2294 rmdir foo\bar
2295 rmdir foo
2296 rem Recursive rmdir
2297 mkdir foo\bar\baz
2298 rmdir /s /Q foo
2299 if not exist foo (
2300 echo recursive rmdir succeeded
2301 ) else (
2302 rd foo\bar\baz
2303 rd foo\bar
2304 rd foo
2306 mkdir foo\bar\baz
2307 echo foo > foo\bar\brol
2308 rmdir /s /Q foo 2>&1
2309 if not exist foo (
2310 echo recursive rmdir succeeded
2311 ) else (
2312 rd foo\bar\baz
2313 del foo\bar\brol
2314 rd foo\bar
2315 rd foo
2317 rem multiples directories at once
2318 mkdir foobaz & cd foobaz
2319 mkdir foo
2320 mkdir bar\baz
2321 mkdir foobar
2322 rd /s/q foo bar foobar
2323 if not exist foo (echo foo removed) else echo foo not removed!
2324 if not exist bar (echo bar removed) else echo bar not removed!
2325 if not exist foobar (echo foobar removed) else echo foobar not removed!
2326 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
2327 cd .. & rd /s/q foobaz
2329 echo ------------ Testing pushd/popd ------------
2331 echo --- popd is no-op when dir stack is empty
2332 popd
2334 echo --- pushing non-existing dir
2335 pushd foobar
2337 echo --- basic behaviour
2338 mkdir foobar\baz
2339 pushd foobar
2341 popd
2343 pushd foobar
2344 pushd baz
2346 popd
2348 pushd baz
2349 popd
2351 popd
2353 pushd .
2354 cd foobar\baz
2355 pushd ..
2357 popd
2358 popd
2360 rd /s/q foobar
2362 echo ------------ Testing attrib ------------
2363 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
2364 mkdir foobar & cd foobar
2365 echo foo original contents> foo
2366 attrib
2367 attrib foo
2368 echo > bar
2369 echo --- read-only attribute
2370 rem Read-only files cannot be altered or deleted, unless forced
2371 attrib +R foo
2372 attrib foo
2373 dir /Ar /B
2374 echo bar>> foo
2375 type foo
2376 del foo > NUL 2>&1
2377 if exist foo (
2378 echo Read-only file not deleted
2379 ) else (
2380 echo Should not delete read-only file!
2382 del /F foo
2383 if not exist foo (
2384 echo Read-only file forcibly deleted
2385 ) else (
2386 echo Should delete read-only file with del /F!
2387 attrib -r foo
2388 del foo
2390 cd .. & rd /s/q foobar
2391 echo --- recursive behaviour
2392 mkdir foobar\baz & cd foobar
2393 echo > level1
2394 echo > whatever
2395 echo > baz\level2
2396 attrib baz\level2
2397 cd ..
2398 attrib +R l*vel? /S > nul 2>&1
2399 cd foobar
2400 attrib level1
2401 attrib baz\level2
2402 echo > bar
2403 attrib bar
2404 cd .. & rd /s/q foobar
2405 echo --- folders processing
2406 mkdir foobar
2407 attrib foobar
2408 cd foobar
2409 mkdir baz
2410 echo toto> baz\toto
2411 attrib +r baz /s /d > nul 2>&1
2412 attrib baz
2413 attrib baz\toto
2414 echo lulu>>baz\toto
2415 type baz\toto
2416 echo > baz\lala
2417 rem Oddly windows allows file creation in a read-only directory...
2418 if exist baz\lala (echo file created in read-only dir) else echo file not created
2419 cd .. & rd /s/q foobar
2421 echo ------------ Testing assoc ------------
2422 rem Modifying associations requires some privileges...
2423 net session >nul 2>&1
2424 if errorlevel 1 goto :SkipAssoc
2426 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2427 rem FIXME Revise once || conditional execution is fixed
2428 mkdir foobar & cd foobar
2429 echo --- setting association
2430 assoc .foo > baz
2431 type baz
2432 echo ---
2434 assoc .foo=bar
2435 assoc .foo
2437 rem association set system-wide
2438 echo @echo off> tmp.cmd
2439 echo echo +++>> tmp.cmd
2440 echo assoc .foo>> tmp.cmd
2441 cmd /c tmp.cmd
2443 echo --- resetting association
2444 assoc .foo=
2445 assoc .foo > baz
2446 type baz
2447 echo ---
2449 rem association removal set system-wide
2450 cmd /c tmp.cmd > baz
2451 type baz
2452 echo ---
2453 cd .. & rd /s/q foobar
2454 goto ContinueFType
2455 :SkipAssoc
2456 echo --- setting association
2457 echo ---
2458 echo .foo=bar
2459 echo .foo=bar
2460 echo +++
2461 echo .foo=bar
2462 echo --- resetting association
2463 echo ---
2464 echo +++
2465 echo ---
2468 :ContinueFType
2469 echo ------------ Testing ftype ------------
2470 rem Modifying associations requires some privileges...
2471 net session >nul 2>&1
2472 if errorlevel 1 goto :SkipFType
2473 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2474 rem FIXME Revise once || conditional execution is fixed
2475 mkdir foobar & cd foobar
2476 echo --- setting association
2477 ftype footype> baz
2478 type baz
2479 echo ---
2481 ftype footype=foo_opencmd
2482 assoc .foo=footype
2483 ftype footype
2485 rem association set system-wide
2486 echo @echo off> tmp.cmd
2487 echo echo +++>> tmp.cmd
2488 echo ftype footype>> tmp.cmd
2489 cmd /c tmp.cmd
2491 echo --- resetting association
2492 assoc .foo=
2494 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2495 setlocal EnableDelayedExpansion
2496 set WINE_FOO=original value
2497 ftype footype=
2498 ftype footype > baz
2499 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
2500 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2501 rem FIXME Revisit once a grep-like program like ftype is implemented
2502 rem (e.g. to check baz's size using dir /b instead)
2503 echo !WINE_FOO!
2505 rem cleanup registry
2506 echo REGEDIT4> regCleanup.reg
2507 echo.>> regCleanup.reg
2508 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
2509 regedit /s regCleanup.reg
2510 set WINE_FOO=
2511 endlocal
2512 cd .. & rd /s/q foobar
2513 goto ContinueCall
2514 :SkipFType
2515 echo --- setting association
2516 echo ---
2517 echo footype=foo_opencmd
2518 echo .foo=footype
2519 echo footype=foo_opencmd
2520 echo +++
2521 echo footype=foo_opencmd
2522 echo --- resetting association
2523 echo original value
2525 :ContinueCall
2526 echo ------------ Testing CALL ------------
2527 mkdir foobar & cd foobar
2528 echo --- external script
2529 echo echo foo %%1> foo.cmd
2530 call foo
2531 call foo.cmd 8
2532 echo echo %%1 %%2 > foo.cmd
2533 call foo.cmd foo
2534 call foo.cmd foo bar
2535 call foo.cmd foo ""
2536 call foo.cmd "" bar
2537 call foo.cmd foo ''
2538 call foo.cmd '' bar
2539 del foo.cmd
2541 echo --- internal routines
2542 call :testRoutine :testRoutine
2543 goto :endTestRoutine
2544 :testRoutine
2545 echo bar %1
2546 goto :eof
2547 :endTestRoutine
2549 call :testRoutineArgs foo
2550 call :testRoutineArgs foo bar
2551 call :testRoutineArgs foo ""
2552 call :testRoutineArgs "" bar
2553 call :testRoutineArgs foo ''
2554 call :testRoutineArgs '' bar
2555 goto :endTestRoutineArgs
2556 :testRoutineArgs
2557 echo %1 %2
2558 goto :eof
2559 :endTestRoutineArgs
2561 echo --- with builtins
2562 call mkdir foo
2563 echo %ErrorLevel%
2564 if exist foo (echo foo created) else echo foo should exist!
2565 rmdir foo
2566 set WINE_FOOBAZ_VAR=foobaz
2567 call echo Should expand %WINE_FOOBAZ_VAR%
2568 set WINE_FOOBAZ_VAR=
2569 echo>batfile
2570 call dir /b
2571 echo>robinfile
2572 if 1==1 call del batfile
2573 dir /b
2574 if exist batfile echo batfile shouldn't exist
2575 rem ... but not for 'if' or 'for'
2576 call if 1==1 echo bar 2> nul
2577 echo %ErrorLevel%
2578 call :setError 0
2579 call for %%i in (foo bar baz) do echo %%i 2> nul
2580 echo %ErrorLevel%
2581 rem First look for programs in the path before trying a builtin
2582 echo echo non-builtin dir> dir.cmd
2583 call dir /b
2584 del dir.cmd
2585 rem The below line equates to call (, which does nothing, then the
2586 rem subsequent lines are executed.
2587 call (
2588 echo Line one
2589 echo Line two
2591 rem The below line equates to call if, which always fails, then the
2592 rem subsequent lines are executed. Note cmd.exe swallows all lines
2593 rem starting with )
2594 call if 1==1 (
2595 echo Get if
2596 ) else (
2597 echo ... and else!
2599 call call call echo passed
2600 cd .. & rd /s/q foobar
2602 echo ------------ Testing SHIFT ------------
2604 call :shiftFun p1 p2 p3 p4 p5
2605 goto :endShiftFun
2607 :shiftFun
2608 echo '%1' '%2' '%3' '%4' '%5'
2609 shift
2610 echo '%1' '%2' '%3' '%4' '%5'
2611 shift@tab@ /1
2612 echo '%1' '%2' '%3' '%4' '%5'
2613 shift /2
2614 echo '%1' '%2' '%3' '%4' '%5'
2615 shift /-1
2616 echo '%1' '%2' '%3' '%4' '%5'
2617 shift /0
2618 echo '%1' '%2' '%3' '%4' '%5'
2619 goto :eof
2620 :endShiftFun
2622 echo ------------ Testing cmd invocation ------------
2623 rem FIXME: only a stub ATM
2624 echo --- a batch file can delete itself
2625 echo del foo.cmd>foo.cmd
2626 cmd /q /c foo.cmd
2627 if not exist foo.cmd (
2628 echo file correctly deleted
2629 ) else (
2630 echo file should be deleted!
2631 del foo.cmd
2633 echo --- a batch file can alter itself
2634 echo echo bar^>foo.cmd>foo.cmd
2635 cmd /q /c foo.cmd > NUL 2>&1
2636 if exist foo.cmd (
2637 type foo.cmd
2638 del foo.cmd
2639 ) else (
2640 echo file not created!
2643 echo ---------- Testing copy
2644 md foobar2
2645 cd foobar2
2646 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2647 echo AAA> file1
2648 echo BBBBBB> file2
2649 echo CCCCCCCCC> file3
2650 md dir1
2651 goto :testcopy
2653 :CheckExist
2654 if exist "%1" (
2655 echo Passed: Found expected %1
2656 ) else (
2657 echo Failed: Did not find expected %1
2659 del /q "%1" >nul 2>&1
2660 shift
2661 if not "%1"=="" goto :CheckExist
2662 goto :eof
2664 :CheckNotExist
2665 if not exist "%1" (
2666 echo Passed: Did not find %1
2667 ) else (
2668 echo Failed: Unexpectedly found %1
2669 del /q "%1" >nul 2>&1
2671 shift
2672 if not "%1"=="" goto :CheckNotExist
2673 goto :eof
2675 rem Note: No way to check file size on NT4 so skip the test
2676 :CheckFileSize
2677 if not exist "%1" (
2678 echo Failed: File missing when requested filesize check [%2]
2679 goto :ContinueFileSizeChecks
2681 for %%i in (%1) do set WINE_filesize=%%~zi
2682 if "%WINE_filesize%"=="%2" (
2683 echo Passed: file size check on %1 [%WINE_filesize%]
2684 ) else (
2685 if "%WINE_filesize%"=="%%~zi" (
2686 echo Skipping file size check on NT4
2687 ) else (
2688 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2691 :ContinueFileSizeChecks
2692 shift
2693 shift
2694 if not "%1"=="" goto :CheckFileSize
2695 goto :eof
2697 :testcopy
2699 rem -----------------------
2700 rem Simple single file copy
2701 rem -----------------------
2702 rem Simple single file copy, normally used syntax
2703 copy file1 dummy.file >nul 2>&1
2704 if errorlevel 1 echo Incorrect errorlevel
2705 call :CheckExist dummy.file
2707 rem Simple single file copy, destination supplied as two forms of directory
2708 copy file1 dir1 >nul 2>&1
2709 if errorlevel 1 echo Incorrect errorlevel
2710 call :CheckExist dir1\file1
2712 copy file1 dir1\ >nul 2>&1
2713 if errorlevel 1 echo Incorrect errorlevel
2714 call :CheckExist dir1\file1
2716 rem Simple single file copy, destination supplied as fully qualified destination
2717 copy file1 dir1\file99 >nul 2>&1
2718 if errorlevel 1 echo Incorrect errorlevel
2719 call :CheckExist dir1\file99
2721 rem Simple single file copy, destination not supplied
2722 cd dir1
2723 copy ..\file1 >nul 2>&1
2724 if errorlevel 1 echo Incorrect errorlevel
2725 call :CheckExist file1
2726 cd ..
2728 rem Simple single file copy, destination supplied as nonexistent directory
2729 copy file1 dir2\ >nul 2>&1
2730 if not errorlevel 1 echo Incorrect errorlevel
2731 call :CheckNotExist dir2 dir2\file1
2733 rem -----------------------
2734 rem Wildcarded copy
2735 rem -----------------------
2736 rem Simple single file copy, destination supplied as two forms of directory
2737 copy file? dir1 >nul 2>&1
2738 if errorlevel 1 echo Incorrect errorlevel
2739 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2741 copy file* dir1\ >nul 2>&1
2742 if errorlevel 1 echo Incorrect errorlevel
2743 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2745 rem Simple single file copy, destination not supplied
2746 cd dir1
2747 copy ..\file*.* >nul 2>&1
2748 if errorlevel 1 echo Incorrect errorlevel
2749 call :CheckExist file1 file2 file3
2750 cd ..
2752 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2753 copy file? dir2\ >nul 2>&1
2754 if not errorlevel 1 echo Incorrect errorlevel
2755 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2757 rem ------------------------------------------------
2758 rem Confirm overwrite works (cannot test prompting!)
2759 rem ------------------------------------------------
2760 copy file1 testfile >nul 2>&1
2761 copy /y file2 testfile >nul 2>&1
2762 call :CheckExist testfile
2764 rem ------------------------------------------------
2765 rem Test concatenation
2766 rem ------------------------------------------------
2767 rem simple case, no wildcards
2768 copy file1+file2 testfile >nul 2>&1
2769 if errorlevel 1 echo Incorrect errorlevel
2770 call :CheckExist testfile
2772 rem simple case, wildcards, no concatenation
2773 copy file* testfile >nul 2>&1
2774 if errorlevel 1 echo Incorrect errorlevel
2775 call :CheckExist testfile
2777 rem simple case, wildcards, and concatenation
2778 echo ddddd > fred
2779 copy file*+fred testfile >nul 2>&1
2780 if errorlevel 1 echo Incorrect errorlevel
2781 call :CheckExist testfile
2783 rem simple case, wildcards, and concatenation
2784 copy fred+file* testfile >nul 2>&1
2785 if errorlevel 1 echo Incorrect errorlevel
2786 call :CheckExist testfile
2788 rem Calculate destination name
2789 copy fred+file* dir1 >nul 2>&1
2790 if errorlevel 1 echo Incorrect errorlevel
2791 call :CheckExist dir1\fred
2793 rem Calculate destination name
2794 copy fred+file* dir1\ >nul 2>&1
2795 if errorlevel 1 echo Incorrect errorlevel
2796 call :CheckExist dir1\fred
2798 rem Calculate destination name (none supplied)
2799 cd dir1
2800 copy ..\fred+..\file* >nul 2>&1
2801 if errorlevel 1 echo Incorrect errorlevel
2802 call :CheckExist fred
2804 copy ..\fr*+..\file1 >nul 2>&1
2805 if errorlevel 1 echo Incorrect errorlevel
2806 call :CheckExist fred
2807 cd ..
2809 rem ******************************************************************
2810 rem ASCII and BINARY tests
2811 rem Note: hard coded numbers deliberate because need to ensure whether
2812 rem an additional EOF has been added or not. There is no way to handle
2813 rem EOFs in batch, so assume if a single byte appears, it's an EOF!
2814 rem ******************************************************************
2816 rem Confirm original sizes of file1,2,3
2817 call :CheckFileSize file1 5 file2 8 file3 11
2819 cd dir1
2821 rem ----------------------------------------------
2822 rem Show concatenation defaults copy to ascii mode
2823 rem ----------------------------------------------
2824 rem Simple default copy source to destination (should not append EOF 5)
2825 copy ..\file1 file1_default >nul 2>&1
2826 call :CheckFileSize file1_default 5
2828 rem Simple binary copy source to destination (should not append EOF 5)
2829 copy /b ..\file1 file1_default2 >nul 2>&1
2830 call :CheckFileSize file1_default2 5
2832 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2833 copy /a ..\file1 file1_plus_eof >nul 2>&1
2834 call :CheckFileSize file1_plus_eof 6
2835 copy /a ..\file2 file2_plus_eof >nul 2>&1
2836 call :CheckFileSize file2_plus_eof 9
2837 copy /a ..\file3 file3_plus_eof >nul 2>&1
2838 call :CheckFileSize file3_plus_eof 12
2840 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2841 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2842 call :CheckFileSize file12_plus_eof 14
2844 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2845 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2846 call :CheckFileSize file12_no_eof 13
2848 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2849 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2850 call :CheckFileSize file12_eof2 14
2852 rem Test copying when destination is one of the sources.
2853 rem Concat file1+file2+file3 into file1, should produce file1+file2+file3 = 24
2854 copy /y ..\file? .\ >nul 2>&1
2855 copy /y /b file1+file2+file3 file1 >nul 2>&1
2856 call :CheckFileSize file1 24
2858 rem Concat file1+file2+file3 into file2, should produce file1+file3 = 16
2859 copy /y ..\file? .\ >nul 2>&1
2860 copy /y /b file1+file2+file3 file2 >nul 2>&1
2861 call :CheckFileSize file2 16
2863 rem Concat file1+file2+file3 into file3, should produce file1+file2 = 13
2864 copy /y ..\file? .\ >nul 2>&1
2865 copy /y /b file1+file2+file3 file3 >nul 2>&1
2866 call :CheckFileSize file3 13
2868 rem --------------------------------------------------------------
2869 rem Show ascii source copy stops at first EOF, binary does the lot
2870 rem --------------------------------------------------------------
2871 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2872 call :CheckFileSize file1_binary_srccopy 6
2874 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2875 call :CheckFileSize file1_ascii_srccopy 5
2877 rem --------------------------------------------------------------
2878 rem Show results of concatenating files (ending in EOFs) and /a /b
2879 rem --------------------------------------------------------------
2881 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2882 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2883 call :CheckFileSize file123_default_copy 25
2884 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2885 call :CheckFileSize file123_ascii_copy 25
2887 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2888 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2889 call :CheckFileSize file123_binary_copy 27
2891 rem We can select which we want the eofs from by postfixing it with /a or /b
2892 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2893 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2894 call :CheckFileSize file123_mixed_copy1 26
2896 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2897 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2898 rem Note the delta between this and the previous one also shows that the destination
2899 rem ascii/binary is inherited from the last /a or /b on the line
2900 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2901 call :CheckFileSize file123_mixed_copy2 27
2903 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2904 rem Note the delta between the next two also shows that the destination ascii/binary is
2905 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2906 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2907 call :CheckFileSize file123_mixed_copy3 26
2908 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2909 call :CheckFileSize file123_mixed_copy4 25
2911 rem -------------------------------------------------------------------------------------------
2912 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2913 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2914 rem -------------------------------------------------------------------------------------------
2916 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2917 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2918 call :CheckFileSize file123_mixed_copy5 28
2920 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2921 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2922 call :CheckFileSize file123_mixed_copy6 19
2924 rem One file has EOF, but doesn't get an extra one, i.e. 6
2925 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2926 call :CheckFileSize file123_mixed_copy7 6
2928 rem Syntax means concatenate so ascii destination kicks in
2929 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2930 call :CheckFileSize file123_mixed_copy8 7
2932 del *.* /q
2933 cd ..
2935 rem ---------------------------------------
2936 rem Error combinations
2937 rem ---------------------------------------
2938 rem Specify source directory but name is a file
2939 call :setError 0
2940 copy file1\ dir1\ >NUL 2>&1
2941 if errorlevel 1 echo Passed: errorlevel invalid check 1
2942 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2943 call :CheckNotExist dir1\file1
2945 rem Overwrite same file
2946 call :setError 0
2947 copy file1 file1 >NUL 2>&1
2948 if errorlevel 1 echo Passed: errorlevel invalid check 2
2949 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2951 rem Supply same file identified as a directory
2952 call :setError 0
2953 copy file1 file1\ >NUL 2>&1
2954 if errorlevel 1 echo Passed: errorlevel invalid check 3
2955 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2957 cd ..
2958 rd foobar2 /s /q
2960 echo ------------ Testing setlocal/endlocal ------------
2961 call :setError 0
2962 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2963 mkdir foobar & cd foobar
2964 echo --- enable/disable extensions
2965 setlocal DisableEXTensions
2966 echo ErrLev: %ErrorLevel%
2967 endlocal
2968 echo ErrLev: %ErrorLevel%
2969 echo @echo off> tmp.cmd
2970 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2971 rem Enabled by default
2972 cmd /C tmp.cmd
2973 cmd /E:OfF /C tmp.cmd
2974 cmd /e:oN /C tmp.cmd
2976 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2977 echo --- setlocal with corresponding endlocal
2978 rem %CD% does not work on NT4 so use the following workaround
2979 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2980 echo @echo off> test.cmd
2981 echo echo %%WINE_VAR%%>> test.cmd
2982 echo setlocal>> test.cmd
2983 echo set WINE_VAR=localval>> test.cmd
2984 echo md foobar2>> test.cmd
2985 echo cd foobar2>> test.cmd
2986 echo echo %%WINE_VAR%%>> test.cmd
2987 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2988 echo endlocal>> test.cmd
2989 echo echo %%WINE_VAR%%>> test.cmd
2990 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2991 set WINE_VAR=globalval
2992 call test.cmd
2993 echo %WINE_VAR%
2994 for /d %%i in (.) do echo %%~dpnxi
2995 cd /d %WINE_CURDIR%
2996 rd foobar2
2997 set WINE_VAR=
2998 echo --- setlocal with no corresponding endlocal
2999 echo @echo off> test.cmd
3000 echo echo %%WINE_VAR%%>> test.cmd
3001 echo setlocal>> test.cmd
3002 echo set WINE_VAR=localval>> test.cmd
3003 echo md foobar2>> test.cmd
3004 echo cd foobar2>> test.cmd
3005 echo echo %%WINE_VAR%%>> test.cmd
3006 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
3007 set WINE_VAR=globalval
3008 rem %CD% does not work on NT4 so use the following workaround
3009 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
3010 call test.cmd
3011 echo %WINE_VAR%
3012 for /d %%i in (.) do echo %%~dpnxi
3013 cd /d %WINE_CURDIR%
3014 rd foobar2
3015 set WINE_VAR=
3016 echo --- setlocal within same batch program
3017 set WINE_var1=one
3018 set WINE_var2=
3019 set WINE_var3=
3020 rem %CD% does not work on NT4 so use the following workaround
3021 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
3022 setlocal
3023 set WINE_var2=two
3024 mkdir foobar2
3025 cd foobar2
3026 setlocal
3027 set WINE_var3=three
3028 if "%WINE_var1%"=="one" echo Var1 ok 1
3029 if "%WINE_var2%"=="two" echo Var2 ok 2
3030 if "%WINE_var3%"=="three" echo Var3 ok 3
3031 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
3032 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
3033 endlocal
3034 if "%WINE_var1%"=="one" echo Var1 ok 1
3035 if "%WINE_var2%"=="two" echo Var2 ok 2
3036 if "%WINE_var3%"=="" echo Var3 ok 3
3037 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
3038 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
3039 endlocal
3040 if "%WINE_var1%"=="one" echo Var1 ok 1
3041 if "%WINE_var2%"=="" echo Var2 ok 2
3042 if "%WINE_var3%"=="" echo Var3 ok 3
3043 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
3044 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
3045 rd foobar2 /s /q
3046 set WINE_var1=
3048 echo --- Mismatched set and end locals
3049 mkdir foodir2 2>nul
3050 mkdir foodir3 2>nul
3051 mkdir foodir4 2>nul
3052 rem %CD% does not work on NT4 so use the following workaround
3053 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
3055 echo @echo off> 2set1end.cmd
3056 echo echo %%WINE_var%%>> 2set1end.cmd
3057 echo setlocal>> 2set1end.cmd
3058 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
3059 echo cd ..\foodir3>> 2set1end.cmd
3060 echo setlocal>> 2set1end.cmd
3061 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
3062 echo cd ..\foodir4>> 2set1end.cmd
3063 echo endlocal>> 2set1end.cmd
3064 echo echo %%WINE_var%%>> 2set1end.cmd
3065 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
3067 echo @echo off> 1set2end.cmd
3068 echo echo %%WINE_var%%>> 1set2end.cmd
3069 echo setlocal>> 1set2end.cmd
3070 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
3071 echo cd ..\foodir3>> 1set2end.cmd
3072 echo endlocal>> 1set2end.cmd
3073 echo echo %%WINE_var%%>> 1set2end.cmd
3074 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
3075 echo endlocal>> 1set2end.cmd
3076 echo echo %%WINE_var%%>> 1set2end.cmd
3077 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
3079 echo --- Extra setlocal in called batch
3080 set WINE_VAR=value1
3081 rem -- setlocal1 == this batch, should never be used inside a called routine
3082 setlocal
3083 set WINE_var=value2
3084 cd foodir2
3085 call "%WINE_CURDIR%\2set1end.cmd"
3086 echo Finished:
3087 echo %WINE_VAR%
3088 for /d %%i in (.) do echo %%~dpnxi
3089 endlocal
3090 echo %WINE_VAR%
3091 for /d %%i in (.) do echo %%~dpnxi
3092 cd /d %WINE_CURDIR%
3094 echo --- Extra endlocal in called batch
3095 set WINE_VAR=value1
3096 rem -- setlocal1 == this batch, should never be used inside a called routine
3097 setlocal
3098 set WINE_var=value2
3099 cd foodir2
3100 call "%WINE_CURDIR%\1set2end.cmd"
3101 echo Finished:
3102 echo %WINE_VAR%
3103 for /d %%i in (.) do echo %%~dpnxi
3104 endlocal
3105 echo %WINE_VAR%
3106 for /d %%i in (.) do echo %%~dpnxi
3107 cd /d %WINE_CURDIR%
3109 echo --- endlocal in called function rather than batch pgm is ineffective
3110 @echo off
3111 set WINE_var=1
3112 set WINE_var2=1
3113 setlocal
3114 set WINE_var=2
3115 call :endlocalroutine
3116 echo %WINE_var%
3117 endlocal
3118 echo %WINE_var%
3119 goto :endlocalfinished
3120 :endlocalroutine
3121 echo %WINE_var%
3122 endlocal
3123 echo %WINE_var%
3124 setlocal
3125 set WINE_var2=2
3126 endlocal
3127 echo %WINE_var2%
3128 endlocal
3129 echo %WINE_var%
3130 echo %WINE_var2%
3131 goto :eof
3132 :endlocalfinished
3133 echo %WINE_var%
3135 set WINE_var=
3136 set WINE_var2=
3137 cd .. & rd /q/s foobar
3139 echo ------------ Testing Errorlevel ------------
3140 rem WARNING: Do *not* add tests using ErrorLevel after this section
3141 should_not_exist 2> nul > nul
3142 echo %ErrorLevel%
3143 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
3144 rem See http://www.robvanderwoude.com/exit.php
3145 call :setError 1
3146 echo %ErrorLevel%
3147 if errorlevel 2 echo errorlevel too high, bad
3148 if errorlevel 1 echo errorlevel just right, good
3149 if errorlevel 01 echo errorlevel with leading zero just right, good
3150 if errorlevel -1 echo errorlevel with negative number OK
3151 if errorlevel 0x1 echo hexa should not be recognized!
3152 if errorlevel 1a echo invalid error level recognized!
3153 call :setError 0
3154 echo abc%ErrorLevel%def
3155 if errorlevel 1 echo errorlevel nonzero, bad
3156 if not errorlevel 1 echo errorlevel zero, good
3157 if not errorlevel 0x1 echo hexa should not be recognized!
3158 if not errorlevel 1a echo invalid error level recognized!
3159 rem Now verify that setting a real variable hides its magic variable
3160 set errorlevel=7
3161 echo %ErrorLevel% should be 7
3162 if errorlevel 7 echo setting var worked too well, bad
3163 call :setError 3
3164 echo %ErrorLevel% should still be 7
3165 rem Verify that (call ) sets errorlevel to 0
3166 (call )
3167 if errorlevel 1 echo errorlevel should have been 0
3169 echo ------------ Testing GOTO ------------
3170 if a==a goto dest1
3171 echo FAILURE at dest 1
3172 :dest1
3173 echo goto with no leading space worked
3174 if a==a goto :dest1b
3175 echo FAILURE at dest 1b
3176 :dest1b
3177 echo goto with colon and no leading space worked
3178 if b==b goto dest2
3179 echo FAILURE at dest 2
3180 :dest2
3181 echo goto with a leading space worked
3182 if c==c goto dest3
3183 echo FAILURE at dest 3
3184 :dest3
3185 echo goto with a leading tab worked
3186 if d==d goto dest4
3187 echo FAILURE at dest 4
3188 :dest4@space@
3189 echo goto with a following space worked
3190 if e==e goto dest5
3191 echo FAILURE at dest 5
3192 :dest5&& echo FAILURE
3193 echo goto with following amphersands worked
3195 del failure.txt >nul 2>&1
3196 if f==f goto dest6
3197 echo FAILURE at dest 6
3198 :dest6>FAILURE.TXT
3199 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
3200 echo goto with redirections worked
3201 del FAILURE.TXT >nul 2>&1
3203 :: some text that is ignored | dir >cmd_output | another test
3204 if exist cmd_output echo FAILURE at dest 6 as file exists
3205 echo Ignoring double colons worked
3206 del cmd_output >nul 2>&1
3208 rem goto a label which does not exist issues an error message and
3209 rem acts the same as goto :EOF, and ensure ::label is never matched
3210 del testgoto.bat >nul 2>&1
3211 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
3212 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
3213 echo ::dest7>> testgoto.bat
3214 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
3215 call testgoto.bat
3216 del testgoto.bat >nul 2>&1
3218 del testgoto.bat >nul 2>&1
3219 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
3220 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
3221 echo ::dest8>> testgoto.bat
3222 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
3223 call testgoto.bat
3224 del testgoto.bat >nul 2>&1
3226 if g==g goto dest9
3227 echo FAILURE at dest 9
3228 :dest91
3229 echo FAILURE at dest 91
3230 @ : dest9>rubbish
3231 echo label with mixed whitespace and no echo worked
3233 if h==h goto :dest10:this is ignored
3234 echo FAILURE at dest 10
3235 :dest10:this is also ignored
3236 echo Correctly ignored trailing information
3238 rem Testing which label is reached when there are many options
3239 echo Begin:
3240 set nextlabel=
3241 call :sub
3242 set nextlabel=middle
3243 goto :sub
3245 :sub
3246 echo ..First sub
3247 if not "%nextlabel%"=="" goto :%nextlabel%
3248 goto :EOF
3250 :sub
3251 echo ..Second sub
3252 if not "%nextlabel%"=="" goto :%nextlabel%
3253 goto :EOF
3255 :middle
3256 echo Middle:
3257 set nextlabel=
3258 call :sub
3259 set nextlabel=nearend
3260 goto :sub
3262 :sub
3263 echo ..Third sub
3264 if not "%nextlabel%"=="" goto :%nextlabel%
3265 goto :EOF
3267 :nearend
3268 echo Near end:
3269 set nextlabel=
3270 call :sub
3271 set nextlabel=end
3272 goto :sub
3274 :sub
3275 echo ..Fourth sub
3276 if not "%nextlabel%"=="" goto :%nextlabel%
3277 goto :EOF
3279 :end
3280 echo At end:
3281 set nextlabel=
3282 call :sub
3283 set nextlabel=done
3284 goto :sub
3286 :done
3287 echo Finished
3289 echo ------------ Testing PATH ------------
3290 set WINE_backup_path=%path%
3291 set path=original
3292 path
3293 path try2
3294 path
3295 path=try3
3296 path
3297 set path=%WINE_backup_path%
3298 set WINE_backup_path=
3300 echo ------------ Testing start /W ------------
3301 echo start /W failed to wait>foobar.txt
3302 start /W "" cmd /C "ping -n1 & echo start /W seems to really wait>foobar.txt"& type foobar.txt& del foobar.txt
3304 echo ------------ Testing changing the drive letter ----------
3305 pushd C:\
3307 echo Normal:
3308 call :setError 0
3310 if errorlevel 1 echo Normal drive change failed
3312 echo Normal+space
3313 call :setError 0
3314 C:@space@
3315 if errorlevel 1 echo Normal+space drive change failed
3317 echo Normal+space+garbage
3318 call :setError 0
3319 C: garbage
3320 if errorlevel 1 echo Normal+space+garbage drive change failed
3322 call :setError 0
3323 echo Quoted should fail
3324 "C:"
3325 if not errorlevel 1 echo quoted drive change unexpectedly worked
3327 echo Normal+tab
3328 call :setError 0
3329 C:@tab@
3330 if errorlevel 1 echo Normal+tab drive change failed
3332 echo Normal+tab+garbage
3333 call :setError 0
3334 C:@tab@garbagetab
3335 if errorlevel 1 echo Normal+tab+garbage drive change failed
3337 popd
3339 echo ------------ Testing length wrt. MAX_PATH ------------
3340 rem native cmd limits all path lengths to MAX_PATH=260
3341 pushd c:\
3342 set depth=25
3343 for /L %%d in (0,1,25) do (
3344 mkdir abcdefghij > NUL 2>&1
3345 if exist abcdefghij (
3346 cd abcdefghij
3347 set depth=%%d
3350 echo %depth%
3351 rem even relative paths are transformed to absolute, and tested against MAX_PATH
3352 echo abc > 01234567890123
3353 if exist 01234567890123 (echo Success) else echo Failure
3354 echo abc > 012345678901234
3355 if exist 012345678901234 (echo Failure) else echo Success
3356 popd
3357 rmdir /s /q c:\abcdefghij
3358 echo ------------ Testing combined CALLs/GOTOs ------------
3359 echo @echo off>foo.cmd
3360 echo goto :eof>>foot.cmd
3361 echo :eof>>foot.cmd
3362 echo echo world>>foo.cmd
3364 echo @echo off>foot.cmd
3365 echo echo cheball>>foot.cmd
3366 echo.>>foot.cmd
3367 echo call :bar>>foot.cmd
3368 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
3369 echo goto :eof>>foot.cmd
3370 echo.>>foot.cmd
3371 echo :bar>>foot.cmd
3372 echo echo barbare>>foot.cmd
3373 echo goto :eof>>foot.cmd
3375 call foo.cmd
3376 call foot
3377 call :bar
3378 del foo.cmd
3379 rem Script execution stops after the following line
3380 foot deleteMe
3381 call :foo
3382 call :foot
3383 goto :endFuns
3385 :foot
3386 echo foot
3388 :foo
3389 echo foo
3390 goto :eof
3392 :endFuns
3394 :bar
3395 echo bar
3396 call :foo
3398 :baz
3399 echo baz
3400 goto :eof
3402 echo Final message is not output since earlier 'foot' processing stops script execution
3403 echo Do NOT add any tests below this line
3405 echo ------------ Done, jumping to EOF -----------
3406 goto :eof
3407 rem Subroutine to set errorlevel and return
3408 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
3409 :setError
3410 exit /B %1
3411 rem This line runs under cmd in windows NT 4, but not in more modern versions.