cmd: Handle "for" loop handling of tokens, where * does not follow a number.
[wine.git] / programs / cmd / tests / test_builtins.cmd
blobbed395091e265b6f4a378bc3fe6d6f73c08d7bba
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 gready 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 variable expansion ------------
531 call :setError 0
532 echo ~p0 should be path containing batch file
533 echo %~p0
534 mkdir dummydir
535 cd dummydir
536 echo %~p0
537 cd ..
538 rmdir dummydir
539 echo ~dp0 should be directory containing batch file
540 echo %~dp0
541 mkdir dummydir
542 cd dummydir
543 echo %~dp0
544 cd ..
545 rmdir dummydir
546 echo CD value %CD%
547 echo %%
548 echo P%
549 echo %P
550 echo %WINE_UNKNOWN%S
551 echo P%WINE_UNKNOWN%
552 echo P%WINE_UNKNOWN%S
553 echo %ERRORLEVEL
554 echo %ERRORLEVEL%
555 echo %ERRORLEVEL%%ERRORLEVEL%
556 echo %ERRORLEVEL%ERRORLEVEL%
557 echo %ERRORLEVEL%%
558 echo %ERRORLEVEL%%%
559 echo P%ERRORLEVEL%
560 echo %ERRORLEVEL%S
561 echo P%ERRORLEVEL%S
563 echo ------------ Testing variable substrings ------------
564 set WINE_VAR=qwerty
565 echo %WINE_VAR:~0,1%
566 echo %WINE_VAR:~0,3%
567 echo %WINE_VAR:~2,2%
568 echo '%WINE_VAR:~-2,3%'
569 echo '%WINE_VAR:~-2,1%'
570 echo %WINE_VAR:~2,-1%
571 echo %WINE_VAR:~2,-3%
572 echo '%WINE_VAR:~-2,-4%'
573 echo %WINE_VAR:~-3,-2%
574 set WINE_VAR=
576 echo ------------ Testing variable substitution ------------
577 echo --- in FOR variables
578 for %%i in ("A B" C) do echo %%i
579 rem check works when prefix with @
580 @for %%i in ("A B" C) do echo %%i
581 rem quotes removal
582 for %%i in ("A B" C) do echo '%%~i'
583 rem fully qualified path
584 for %%f in ("C D" E) do echo %%~ff
585 rem drive letter
586 for %%i in ("F G" H) do echo %%~di
587 rem path
588 for %%d in ("I J" K) do echo %%~pd
589 rem filename
590 for %%i in ("L M" N) do echo %%~ni
591 rem file extension
592 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
593 rem path with short path names
594 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
595 rem file attribute
596 for %%i in ("U V" W) do echo '%%~ai'
597 echo foo> foo
598 for %%i in (foo) do echo '%%~ai'
599 for %%i in (foo) do echo '%%~zi'
600 del foo
601 rem file date/time
602 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
603 for %%i in ("a b" c) do echo '%%~ti'
604 rem file size
605 rem Similar issues as above
606 for %%i in ("a b" c) do echo '%%~zi'
607 rem combined options
608 for %%i in ("d e" f) do echo %%~dpi
609 for %%i in ("g h" i) do echo %%~sdi
610 for %%i in ("g h" i) do echo %%~dsi
611 for %%i in ("j k" l.eh) do echo '%%~xsi'
612 for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
614 echo --- in parameters
615 for %%i in ("A B" C) do call :echoFun %%i
616 rem quotes removal
617 for %%i in ("A B" C) do call :echoFunQ %%i
618 rem fully qualified path
619 for %%f in ("C D" E) do call :echoFunF %%f
620 rem drive letter
621 for %%i in ("F G" H) do call :echoFunD %%i
622 rem path
623 for %%d in ("I J" K) do call :echoFunP %%d
624 rem filename
625 for %%i in ("L M" N) do call :echoFunN %%i
626 rem file extension
627 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
628 rem path with short path names
629 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
630 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
631 rem combined options
632 for %%i in ("d e" f) do call :echoFunDP %%i
633 for %%i in ("g h" i) do call :echoFunSD %%i
634 for %%i in ("g h" i) do call :echoFunDS %%i
635 for %%i in ("j k" l.eh) do call :echoFunXS %%i
637 goto :endEchoFuns
638 :echoFun
639 echo %1
640 goto :eof
642 :echoFunQ
643 echo '%~1'
644 goto :eof
646 :echoFunF
647 echo %~f1
648 goto :eof
650 :echoFunD
651 echo %~d1
652 goto :eof
654 :echoFunP
655 echo %~p1
656 goto :eof
658 :echoFunN
659 echo %~n1
660 goto :eof
662 :echoFunX
663 echo '%~x1'
664 goto :eof
666 :echoFunS
667 rem some NT4 workaround
668 set WINE_VAR='%~s1'
669 echo %WINE_VAR%
670 set WINE_VAR=
671 goto :eof
673 :echoFunDP
674 echo %~dp1
675 goto :eof
677 :echoFunSD
678 echo %~sd1
679 goto :eof
681 :echoFunDS
682 echo %~ds1
683 goto :eof
685 :echoFunXS
686 echo '%~xs1'
687 goto :eof
688 :endEchoFuns
690 echo ------------ Testing parameter zero ------------
691 call :func parm1 parm2
692 goto :endParm0
693 :func
694 echo %~0 %~1
695 echo [%0] [%~d0] [%~p0] [%~n0] [%~x0] [%~s0]
696 goto :EOF
697 :endParm0
699 echo ------------ Testing variable delayed expansion ------------
700 rem NT4 doesn't support this
701 echo --- default mode (load-time expansion)
702 set WINE_FOO=foo
703 echo %WINE_FOO%
704 echo !WINE_FOO!
705 if %WINE_FOO% == foo (
706 set WINE_FOO=bar
707 if %WINE_FOO% == bar (echo bar) else echo foo
710 set WINE_FOO=foo
711 if %WINE_FOO% == foo (
712 set WINE_FOO=bar
713 if !WINE_FOO! == bar (echo bar) else echo foo
716 echo --- runtime (delayed) expansion mode
717 setlocal EnableDelayedExpansion
718 set WINE_FOO=foo
719 echo %WINE_FOO%
720 echo !WINE_FOO!
721 if %WINE_FOO% == foo (
722 set WINE_FOO=bar
723 if %WINE_FOO% == bar (echo bar) else echo foo
726 set WINE_FOO=foo
727 if %WINE_FOO% == foo (
728 set WINE_FOO=bar
729 if !WINE_FOO! == bar (echo bar) else echo foo
731 echo %ErrorLevel%
732 setlocal DisableDelayedExpansion
733 echo %ErrorLevel%
734 set WINE_FOO=foo
735 echo %WINE_FOO%
736 echo !WINE_FOO!
737 set WINE_FOO=
738 echo --- using /V cmd flag
739 echo @echo off> tmp.cmd
740 echo set WINE_FOO=foo>> tmp.cmd
741 echo echo %%WINE_FOO%%>> tmp.cmd
742 echo echo !WINE_FOO!>> tmp.cmd
743 echo set WINE_FOO=>> tmp.cmd
744 cmd /V:ON /C tmp.cmd
745 cmd /V:OfF /C tmp.cmd
746 del tmp.cmd
748 echo ------------ Testing conditional execution ------------
749 echo --- unconditional ampersand
750 call :setError 123 & echo foo1
751 echo bar2 & echo foo2
752 mkdir foobar & cd foobar
753 echo > foobazbar
754 cd .. & rd /s/q foobar
755 if exist foobazbar (
756 echo foobar not deleted!
757 cd ..
758 rd /s/q foobar
759 ) else echo foobar deleted
760 echo --- on success conditional and
761 call :setError 456 && echo foo3 > foo3
762 if exist foo3 (
763 echo foo3 created
764 del foo3
765 ) else echo foo3 not created
766 echo bar4 && echo foo4
767 echo --- on failure conditional or
768 call :setError 789 || echo foo5
769 echo foo6 || echo bar6 > bar6
770 if exist bar6 (
771 echo bar6 created
772 del bar6
775 echo ------------ Testing cd ------------
776 mkdir foobar
777 cd foobar
778 echo blabla > singleFile
779 dir /b
780 echo Current dir: %CD%
782 cd ..
784 cd foobar@space@
786 cd ..
788 cd @space@foobar
790 cd..
792 cd foobar
793 cd..@space@
795 if not exist foobar (cd ..)
796 cd foobar
797 cd@tab@..@tab@@space@@tab@
799 if not exist foobar (cd ..)
800 cd foobar
801 mkdir "bar bak"
802 cd "bar bak"
804 cd ..
805 cd ".\bar bak"
807 cd ..
808 cd .\"bar bak"
810 cd ..
811 cd bar bak
813 cd "bar bak@space@"@tab@@space@
815 cd ..\..
817 rd /Q/s foobar
818 mkdir foobar
819 cd /d@tab@foobar
821 cd ..
822 rd /q/s foobar
824 echo ------------ Testing type ------------
825 echo bar> foobaz
826 @echo on
827 type foobaz
828 echo ---
829 @echo off
830 type foobaz@tab@
831 echo ---1
832 type ."\foobaz"
833 echo ---2
834 type ".\foobaz"
835 echo ---3
836 del foobaz
838 echo ------------ Testing NUL ------------
839 md foobar & cd foobar
840 rem NUL file (non) creation + case insensitivity
841 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
842 echo > bar
843 echo foo > NUL
844 dir /b /a-d
845 echo foo > nul
846 dir /b /a-d
847 echo foo > NuL
848 @tab@dir /b@tab@/a-d
849 del bar
850 rem NUL not special everywhere
851 call :setError 123
852 echo NUL> foo
853 if not exist foo (echo foo should have been created) else (
854 type foo
855 del foo
857 rem Empty file creation
858 copy nul foo > nul
859 if exist foo (
860 echo foo created
861 del foo
862 type foo
863 ) else (
864 echo ***
866 echo 1234 >a.a
867 copy a.a+NUL b.b >nul
868 call :CheckFileSize a.a 7 b.b 8
869 copy NUL+a.a b.b >nul
870 call :CheckFileSize a.a 7 b.b 8
871 mkdir subdir
872 copy a.a+NUL subdir\ >nul
873 call :CheckFileSize a.a 7 subdir\a.a 8
874 del subdir\a.a
875 cd subdir
876 copy ..\a.a NUL >nul
877 if exist a.a echo Failed
878 cd ..
879 rd subdir /s /q
880 del a.a b.b
881 cd .. & rd foobar /s /q
883 echo ------------ Testing if/else ------------
884 echo --- if/else should work with blocks
885 if 0 == 0 (
886 echo if seems to work
887 ) else (
888 echo if seems to be broken
890 if 1 == 0 (
891 echo else seems to be broken
892 ) else (
893 echo else seems to work
895 if /c==/c (
896 echo if seems not to detect /c as parameter
897 ) else (
898 echo parameter detection seems to be broken
900 SET elseIF=0
901 if 1 == 1 (
902 SET /a elseIF=%elseIF%+1
903 ) else if 1 == 1 (
904 SET /a elseIF=%elseIF%+2
905 ) else (
906 SET /a elseIF=%elseIF%+2
908 if %elseIF% == 1 (
909 echo else if seems to work
910 ) else (
911 echo else if seems to be broken
913 SET elseIF=0
914 if 1 == 2 (
915 SET /a elseIF=%elseIF%+2
916 ) else if 1 == 1 (
917 SET /a elseIF=%elseIF%+1
918 ) else (
919 SET /a elseIF=%elseIF%+2
921 if %elseIF% == 1 (
922 echo else if seems to work
923 ) else (
924 echo else if seems to be broken
926 SET elseIF=0
927 if 1 == 2 (
928 SET /a elseIF=%elseIF%+2
929 ) else if 1 == 2 (
930 SET /a elseIF=%elseIF%+2
931 ) else (
932 SET /a elseIF=%elseIF%+1
934 if %elseIF% == 1 (
935 echo else if seems to work
936 ) else (
937 echo else if seems to be broken
939 if "x" == "a" (
940 echo broken1
941 ) else (
942 echo expected1
943 if "y" == "b" echo broken2
944 echo expected post-embedded if
946 echo --- case sensitivity with and without /i option
947 if bar==BAR echo if does not default to case sensitivity
948 if not bar==BAR echo if seems to default to case sensitivity
949 if /i foo==FOO echo if /i seems to work
950 if /i not foo==FOO echo if /i seems to be broken
951 if /I foo==FOO echo if /I seems to work
952 if /I not foo==FOO echo if /I seems to be broken
954 echo --- string comparisons
955 if abc == abc (echo equal) else echo non equal
956 if abc =="abc" (echo equal) else echo non equal
957 if "abc"== abc (echo equal) else echo non equal
958 if "abc"== "abc" (echo equal) else echo non equal
960 echo --- tabs handling
961 if@tab@1==1 echo doom
962 if @tab@1==1 echo doom
963 if 1==1 (echo doom) else@tab@echo quake
964 if@tab@not @tab@1==@tab@0 @tab@echo lol
965 if 1==0@tab@(echo doom) else echo quake
966 if 1==0 (echo doom)@tab@else echo quake
967 if 1==0 (echo doom) else@tab@echo quake
969 echo --- comparison operators
970 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
971 echo ------ for strings
972 rem NT4 stops processing of the whole batch file as soon as it finds a
973 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
974 rem can't test those here.
975 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
976 if LSS LSS LSS (echo bar)
977 if 1.1 LSS 1.10 (echo floats are handled as strings)
978 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
979 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
980 if /i foo LSS FoOc echo if /i seems to work for LSS
981 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
982 set WINE_STR_PARMS=A B AB BA AA
983 for %%i in (%WINE_STR_PARMS%) do (
984 for %%j in (%WINE_STR_PARMS%) do (
985 call :LSStest %%i %%j))
986 if b LSS B (echo b LSS B) else echo NT4
987 if /I b LSS B echo b LSS B insensitive
988 if b LSS A echo b LSS A
989 if /I b LSS A echo b LSS A insensitive
990 if a LSS B (echo a LSS B) else echo NT4
991 if /I a LSS B echo a LSS B insensitive
992 if A LSS b echo A LSS b
993 if /I A LSS b echo A LSS b insensitive
994 for %%i in (%WINE_STR_PARMS%) do (
995 for %%j in (%WINE_STR_PARMS%) do (
996 call :LEQtest %%i %%j))
997 if b LEQ B (echo b LEQ B) else echo NT4
998 if /I b LEQ B echo b LEQ B insensitive
999 if b LEQ A echo b LEQ A
1000 if /I b LEQ A echo b LEQ A insensitive
1001 if a LEQ B (echo a LEQ B) else echo NT4
1002 if /I a LEQ B echo a LEQ B insensitive
1003 if A LEQ b echo A LEQ b
1004 if /I A LEQ b echo A LEQ b insensitive
1005 for %%i in (%WINE_STR_PARMS%) do (
1006 for %%j in (%WINE_STR_PARMS%) do (
1007 call :EQUtest %%i %%j))
1008 if /I A EQU a echo A EQU a insensitive
1009 for %%i in (%WINE_STR_PARMS%) do (
1010 for %%j in (%WINE_STR_PARMS%) do (
1011 call :NEQtest %%i %%j))
1012 for %%i in (%WINE_STR_PARMS%) do (
1013 for %%j in (%WINE_STR_PARMS%) do (
1014 call :GEQtest %%i %%j))
1015 for %%i in (%WINE_STR_PARMS%) do (
1016 for %%j in (%WINE_STR_PARMS%) do (
1017 call :GTRtest %%i %%j))
1019 echo ------------ Testing if/exist ------------
1020 mkdir subdir
1021 echo something>subdir\bar
1022 echo something else>foo
1023 if exist foo (
1024 echo exist explicit works
1025 ) else (
1026 echo ERROR exist explicit broken
1028 if exist bar (
1029 echo ERROR exist explicit unknown file broken
1030 ) else (
1031 echo exist explicit unknown file works
1033 if exist subdir\bar (
1034 echo exist explicit in subdir works
1035 ) else (
1036 echo ERROR exist explicit in subdir broken
1038 if exist fo* (
1039 echo exist simple wildcard works
1040 ) else (
1041 echo ERROR exist simple wildcard broken
1043 if exist subdir\ba* (
1044 echo exist wildcard works
1045 ) else (
1046 echo ERROR exist wildcard broken
1048 if not exist subdir\ba* (
1049 echo ERROR negate exist wildcard broken
1050 ) else (
1051 echo negate exist wildcard works
1053 if exist idontexist\ba* (
1054 echo ERROR exist wildcard bad subdir broken
1055 ) else (
1056 echo exist wildcard bad subdir broken works
1058 if exist subdir (
1059 echo exist subdir ok
1060 ) else (
1061 echo ERROR exist subdir not working
1063 if exist subdir\. (
1064 echo exist subdir with . ok
1065 ) else (
1066 echo ERROR exist subdir with . not working
1068 if exist subdir\ (
1069 echo exist subdir with \ ok
1070 ) else (
1071 echo ERROR exist subdir with \ not working
1073 if exist "subdir\" (
1074 echo exist subdir with \ and quotes ok
1075 ) else (
1076 echo ERROR exist subdir with \ and quotes not working
1078 del foo subdir\bar
1079 rd subdir
1081 echo ------ for numbers
1082 if -1 LSS 1 (echo negative numbers handled)
1083 if not -1 LSS -10 (echo negative numbers handled)
1084 if not 9 LSS 010 (echo octal handled)
1085 if not -010 LSS -8 (echo also in negative form)
1086 if 4 LSS 0x5 (echo hexa handled)
1087 if not -1 LSS -0x1A (echo also in negative form)
1088 if 11 LSS 101 (echo 11 LSS 101)
1089 set WINE_INT_PARMS=0 1 10 9
1090 for %%i in (%WINE_INT_PARMS%) do (
1091 for %%j in (%WINE_INT_PARMS%) do (
1092 call :LSStest %%i %%j))
1093 for %%i in (%WINE_INT_PARMS%) do (
1094 for %%j in (%WINE_INT_PARMS%) do (
1095 call :LEQtest %%i %%j))
1096 for %%i in (%WINE_INT_PARMS%) do (
1097 for %%j in (%WINE_INT_PARMS%) do (
1098 call :EQUtest %%i %%j))
1099 if 011 EQU 9 (echo octal ok)
1100 if 0xA1 EQU 161 (echo hexa ok)
1101 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
1102 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
1103 for %%i in (%WINE_INT_PARMS%) do (
1104 for %%j in (%WINE_INT_PARMS%) do (
1105 call :NEQtest %%i %%j))
1106 for %%i in (%WINE_INT_PARMS%) do (
1107 for %%j in (%WINE_INT_PARMS%) do (
1108 call :GEQtest %%i %%j))
1109 for %%i in (%WINE_INT_PARMS%) do (
1110 for %%j in (%WINE_INT_PARMS%) do (
1111 call :GTRtest %%i %%j))
1112 echo ------ for numbers and stringified numbers
1113 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
1114 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
1115 if '1' EQU 1 echo '1' EQU 1
1116 if 1 EQU '1' echo 1 EQU '1'
1117 if not "1" GEQ 1 (echo foo) else echo bar
1118 if "10" GEQ "1" echo "10" GEQ "1"
1119 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
1120 if 1 GEQ "1" echo 1 GEQ "1"
1121 if "1" GEQ "1" echo "1" GEQ "1"
1122 if '1' GEQ "1" echo '1' GEQ "1"
1123 if "10" GEQ "1" echo "10" GEQ "1"
1124 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
1125 for %%i in ("1" '1') do call :GEQtest %%i '1'
1126 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
1127 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
1128 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
1129 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
1130 if "10" GEQ "10" (echo "10" GEQ "10")
1131 echo --- unconditional ampersand after if one line
1132 if "0"=="0" echo 1 & echo 2 & echo 3 else echo 4
1133 echo ---
1134 echo x & if "0"=="1" echo 1 & echo 2
1135 echo ---
1136 echo x & if "0"=="1" echo 1 & echo 2 & echo 3
1137 echo ---
1138 echo x & if "0"=="1" (echo 1 & echo 2 & echo 3)
1139 echo ---
1140 echo x & if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
1141 echo ---
1142 goto :endIfCompOpsSubroutines
1144 rem IF subroutines helpers
1145 :LSStest
1146 if %1 LSS %2 echo %1 LSS %2
1147 goto :eof
1148 :LEQtest
1149 if %1 LEQ %2 echo %1 LEQ %2
1150 goto :eof
1151 :EQUtest
1152 if %1 EQU %2 echo %1 EQU %2
1153 goto :eof
1154 :NEQtest
1155 if %1 NEQ %2 echo %1 NEQ %2
1156 goto :eof
1157 :GEQtest
1158 if %1 GEQ %2 echo %1 GEQ %2
1159 goto :eof
1160 :GTRtest
1161 if %1 GTR %2 echo %1 GTR %2
1162 goto :eof
1164 :endIfCompOpsSubroutines
1165 set WINE_STR_PARMS=
1166 set WINE_INT_PARMS=
1168 echo ------------ Testing for ------------
1169 echo --- plain FOR
1170 for %%i in (A B C) do echo %%i
1171 for %%i in (A B C) do echo %%I
1172 for %%i in (A B C) do echo %%j
1173 for %%i in (A B C) do call :forTestFun1 %%i
1174 for %%i in (1,4,1) do echo %%i
1175 for %%i in (A, B,C) do echo %%i
1176 for %%i in (X) do echo %%i
1177 for@tab@%%i in (X2) do echo %%i
1178 for %%i in@tab@(X3) do echo %%i
1179 for %%i in (@tab@ foo@tab@) do echo %%i
1180 for@tab@ %%i in@tab@(@tab@M) do echo %%i
1181 for %%i@tab@in (X)@tab@do@tab@echo %%i
1182 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
1183 for %%i in (`echo A B`) do echo %%i
1184 for %%i in ('echo A B') do echo %%i
1185 for %%i in ("echo A B") do echo %%i
1186 for %%i in ("A B" C) do echo %%i
1187 goto :endForTestFun1
1188 :forTestFun1
1189 echo %1
1190 goto :eof
1191 :endForTestFun1
1192 echo --- imbricated FORs
1193 for %%i in (X) do (
1194 for %%j in (Y) do (
1195 echo %%i %%j))
1196 for %%i in (X) do (
1197 for %%I in (Y) do (
1198 echo %%i %%I))
1199 for %%i in (A B) do (
1200 for %%j in (C D) do (
1201 echo %%i %%j))
1202 for %%i in (A B) do (
1203 for %%j in (C D) do (
1204 call :forTestFun2 %%i %%j ))
1205 goto :endForTestFun2
1206 :forTestFun2
1207 echo %1 %2
1208 goto :eof
1209 :endForTestFun2
1210 mkdir foobar & cd foobar
1211 mkdir foo
1212 mkdir bar
1213 mkdir baz
1214 mkdir pop
1215 echo > bazbaz
1216 echo --- basic wildcards
1217 for %%i in (ba*) do echo %%i
1218 echo --- wildcards in subdirs
1219 echo something>pop\bar1
1220 echo something>pop\bar2.txt
1221 echo something>pop\bar3
1222 for %%f in (pop\ba*) do ( call echo %%f )
1223 rmdir /s/q pop
1224 echo --- for /d
1225 for /d %%i in (baz foo bar) do echo %%i 2>&1
1226 rem Confirm we don't match files:
1227 for /d %%i in (bazb*) do echo %%i 2>&1
1228 for /d %%i in (bazb2*) do echo %%i 2>&1
1229 rem Show we pass through non wildcards
1230 for /d %%i in (PASSED) do echo %%i
1231 for /d %%i in (xxx) do (
1232 echo %%i - Should be xxx
1233 echo Expected second line
1235 rem Show we issue no messages on failures
1236 for /d %%i in (FAILED?) do echo %%i 2>&1
1237 for /d %%i in (FAILED?) do (
1238 echo %%i - Unexpected!
1239 echo FAILED Unexpected second line
1241 for /d %%i in (FAILED*) do echo %%i 2>&1
1242 for /d %%i in (FAILED*) do (
1243 echo %%i - Unexpected!
1244 echo FAILED Unexpected second line
1246 rem FIXME can't test wildcard expansion here since it's listed in directory
1247 rem order, and not in alphabetic order.
1248 rem Proper testing would need a currently missing "sort" program implementation.
1249 rem for /d %%i in (ba*) do echo %%i>> tmp
1250 rem sort < tmp
1251 rem del tmp
1252 rem for /d %%i in (?a*) do echo %%i>> tmp
1253 rem sort < tmp
1254 rem del tmp
1255 rem for /d %%i in (*) do echo %%i>> tmp
1256 rem sort < tmp
1257 rem del tmp
1258 echo > baz\bazbaz
1259 goto :TestForR
1261 :SetExpected
1262 del temp.bat 2>nul
1263 call :WriteLine set WINE_found=N
1264 for /l %%i in (1,1,%WINE_expectedresults%) do (
1265 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%~1" set WINE_found=Y
1266 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
1267 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
1269 call :WriteLine echo Got unexpected result: "%%%%~1"
1270 goto :eof
1272 :WriteLine
1273 echo %*>> temp.bat
1274 goto :EOF
1276 :ValidateExpected
1277 del temp.bat 2>nul
1278 for /l %%i in (1,1,%WINE_expectedresults%) do (
1279 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
1281 call temp.bat
1282 del temp.bat 2>nul
1283 goto :eof
1285 :TestForR
1286 rem %CD% does not work on NT4 so use the following workaround
1287 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
1289 echo --- for /R
1290 echo Plain directory enumeration
1291 set WINE_expectedresults=4
1292 set WINE_expectedresults.1=%WINE_CURDIR%\.
1293 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1294 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1295 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1296 call :SetExpected
1297 for /R %%i in (.) do call temp.bat "%%i"
1298 call :ValidateExpected
1300 echo Plain directory enumeration from provided root
1301 set WINE_expectedresults=4
1302 set WINE_expectedresults.1=%WINE_CURDIR%\.
1303 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1304 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1305 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
1306 if "%CD%"=="" goto :SkipBrokenNT4
1307 call :SetExpected
1308 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat "%%i"
1309 call :ValidateExpected
1310 :SkipBrokenNT4
1312 echo File enumeration
1313 set WINE_expectedresults=2
1314 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1315 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1316 call :SetExpected
1317 for /R %%i in (baz*) do call temp.bat "%%i"
1318 call :ValidateExpected
1320 echo File enumeration from provided root
1321 set WINE_expectedresults=2
1322 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
1323 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
1324 call :SetExpected
1325 for /R %%i in (baz*) do call temp.bat "%%i"
1326 call :ValidateExpected
1328 echo Mixed enumeration
1329 set WINE_expectedresults=6
1330 set WINE_expectedresults.1=%WINE_CURDIR%\.
1331 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1332 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1333 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1334 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1335 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1336 call :SetExpected
1337 for /R %%i in (. baz*) do call temp.bat "%%i"
1338 call :ValidateExpected
1340 echo Mixed enumeration from provided root
1341 set WINE_expectedresults=6
1342 set WINE_expectedresults.1=%WINE_CURDIR%\.
1343 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
1344 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
1345 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1346 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
1347 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
1348 call :SetExpected
1349 for /R %%i in (. baz*) do call temp.bat "%%i"
1350 call :ValidateExpected
1352 echo With duplicates enumeration
1353 set WINE_expectedresults=12
1354 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
1355 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
1356 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
1357 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
1358 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
1359 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
1360 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
1361 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
1362 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1363 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1364 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1365 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1366 call :SetExpected
1367 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat "%%i"
1368 call :ValidateExpected
1370 echo Strip missing wildcards, keep unwildcarded names
1371 set WINE_expectedresults=6
1372 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1373 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1374 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1375 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1376 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1377 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1378 call :SetExpected
1379 for /R %%i in (baz* fred* jim) do call temp.bat "%%i"
1380 call :ValidateExpected
1382 echo for /R passed
1383 echo --- Complex wildcards unix and windows slash
1384 cd ..
1385 echo Windows slashes, valid path
1386 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1387 for %%f in (foobar\baz\*) do echo WC : %%f
1388 echo Windows slashes, invalid path
1389 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1390 for %%f in (foobar\jim\*) do echo WC : %%f
1391 echo Unix slashes, valid path
1392 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1393 for %%f in (foobar/baz/*) do echo WC : %%f
1394 echo Unix slashes, invalid path
1395 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1396 for %%f in (foobar/jim/*) do echo WC : %%f
1397 echo Done
1398 rd /s/Q foobar
1399 echo --- for /L
1400 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
1401 for /L %%i in (1,2,0) do echo %%i
1402 for@tab@/L %%i in (1,2,0) do echo %%i
1403 for /L %%i in (1,2,6) do echo %%i
1404 for /l %%i in (1 ,2,6) do echo %%i
1405 for /L %%i in (a,2,3) do echo %%i
1406 for /L %%i in (1,2,-1) do echo %%i
1407 for /L %%i in (-4,-1,-1) do echo %%i
1408 for /L %%i in (1,-2,-2) do echo %%i
1409 for /L %%i in (1,2,a) do echo %%i
1410 echo ErrorLevel %ErrorLevel%
1411 for /L %%i in (1,a,b) do echo %%i
1412 echo ErrorLevel %ErrorLevel%
1413 rem Test boundaries
1414 for /l %%i in (1,1,4) do echo %%i
1415 for /l %%i in (1,2,4) do echo %%i
1416 for /l %%i in (4,-1,1) do echo %%i
1417 for /l %%i in (4,-2,1) do echo %%i
1418 for /l %%i in (1,-1,4) do echo %%i
1419 for /l %%i in (4,1,1) do echo %%i
1420 for /L %%i in (a,2,b) do echo %%i
1421 for /L %%i in (1,1,1) do echo %%i
1422 for /L %%i in (1,-2,-1) do echo %%i
1423 for /L %%i in (-1,-1,-1) do echo %%i
1424 for /L %%i in (1,2, 3) do echo %%i
1425 rem Test zero iteration skips the body of the for
1426 for /L %%i in (2,2,1) do (
1427 echo %%i
1428 echo FAILED
1430 echo --- ifs inside for loops
1431 for %%i in (test) do (
1432 echo a1
1433 if 1==1 (
1434 echo b1
1435 ) else (
1436 echo c1
1438 echo d1
1440 for %%i in (test) do (
1441 echo a2
1442 if 1==1 (
1443 echo b2
1444 ) else echo c2
1445 echo d2
1447 for %%i in (test) do (
1448 echo a3
1449 if 1==0 (
1450 echo b3
1451 ) else echo c3
1452 echo d3
1454 for %%i in (test) do (
1455 echo a4
1456 if 1==0 (
1457 echo b4
1458 ) else (
1459 echo c4
1461 echo d4
1463 echo --- set /a
1464 goto :testseta
1466 Rem Ideally for /f can be used rather than building a command to execute
1467 rem but that does not work on NT4
1468 :checkenvvars
1469 if "%1"=="" goto :eof
1470 call :executecmd set wine_result=%%%1%%
1471 if "%wine_result%"=="%2" (
1472 echo %1 correctly %2
1473 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1474 set %1=
1475 shift
1476 shift
1477 rem shift
1478 goto :checkenvvars
1479 :executecmd
1481 goto :eof
1483 :testseta
1484 rem No output when using "set expr" syntax, unless in interactive mode
1485 rem Need to use "set envvar=expr" to use in a batch script
1486 echo ------ individual operations
1487 set WINE_foo=0
1488 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1489 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1490 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1491 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1492 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1493 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1494 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1495 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1496 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1497 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1498 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1499 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1500 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1501 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1502 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1503 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1504 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1505 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1506 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1507 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1508 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1509 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1510 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1511 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1512 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1513 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1514 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1515 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1516 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1517 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1518 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1519 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1520 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1521 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1522 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1523 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1524 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1525 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1526 echo ------ precedence and grouping
1527 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1528 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1529 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1530 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1531 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1532 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1533 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1534 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1535 echo ------ octal and hexadecimal
1536 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1537 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1538 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1539 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1540 echo ------ variables
1541 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1542 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1543 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
1544 set WINE_bar=3
1545 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1546 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1547 set WINE_bar=4
1548 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1549 set WINE_bar=4
1550 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1551 set WINE_bar=-7
1552 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1553 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1554 set WINE_bar=1
1555 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1556 set WINE_bar=4
1557 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1558 set WINE_bar=1
1559 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1560 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1561 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1562 set WINE_baz=4
1563 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1564 echo --- quotes
1565 set /a WINE_foo=1
1566 call :checkenvvars WINE_foo 1
1567 set /a "WINE_foo=1"
1568 call :checkenvvars WINE_foo 1
1569 set /a WINE_foo=1,WINE_bar=2
1570 call :checkenvvars WINE_foo 1 WINE_bar 2
1571 set /a "WINE_foo=1,WINE_bar=2"
1572 call :checkenvvars WINE_foo 1 WINE_bar 2
1573 set /a "WINE_foo=1","WINE_bar=2"
1574 call :checkenvvars WINE_foo 1 WINE_bar 2
1575 set /a ""WINE_foo=1","WINE_bar=2""
1576 call :checkenvvars WINE_foo 1 WINE_bar 2
1577 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1578 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1579 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
1580 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1581 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
1582 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1583 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1584 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1585 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
1586 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1587 set /a """"""WINE_foo=1""""""
1588 call :checkenvvars WINE_foo 1
1589 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1590 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1591 set /a WINE_foo="3"+"4"+"5+6"
1592 call :checkenvvars WINE_foo 18
1593 set WINE_foo=3
1594 set /a WINE_bar="WINE_""foo"+4
1595 call :checkenvvars WINE_foo 3 WINE_bar 7
1596 echo --- whitespace are ignored between double char operators
1597 set WINE_foo=4
1598 set WINE_bar=5
1599 set /a WINE_foo + = 6
1600 set /a WINE_bar * = WINE_foo
1601 call :checkenvvars WINE_foo 10 WINE_bar 50
1602 set WINE_foo=4
1603 set WINE_bar=5
1604 set /a WINE_foo + = "6 < < 7"
1605 set /a WINE_bar * = WINE_foo + WINE_foo
1606 call :checkenvvars WINE_foo 772 WINE_bar 7720
1607 set /a WINE_foo=6 7
1608 set /a WINE_ var1=8
1609 set WINE_foo=
1610 echo --- invalid operator sequence
1611 set WINE_foo=4
1612 set /a =4
1613 set /a *=4
1614 set /a ^>=4"
1615 set /a ^<=4"
1616 set /a WINE_foo^>^<=4
1617 echo %WINE_foo%
1618 set /a WINE_foo^>^>^>=4
1619 echo %WINE_foo%
1620 echo ----- negative prefix
1621 set /a WINE_foo=-1
1622 call :checkenvvars WINE_foo -1
1623 set /a WINE_foo=--1
1624 call :checkenvvars WINE_foo 1
1625 set /a WINE_foo=3--3
1626 call :checkenvvars WINE_foo 6
1627 set /a WINE_foo=3---3
1628 call :checkenvvars WINE_foo 0
1629 set /a WINE_foo=3----3
1630 call :checkenvvars WINE_foo 6
1631 set /a WINE_foo=-~1
1632 call :checkenvvars WINE_foo 2
1633 set /a WINE_foo=~-1
1634 call :checkenvvars WINE_foo 0
1635 set /a WINE_foo=3+-~1
1636 call :checkenvvars WINE_foo 5
1637 set /a WINE_foo=3+~-1
1638 call :checkenvvars WINE_foo 3
1639 echo ----- assignment tests involving the end destination
1640 set WINE_foo=3
1641 set /a WINE_foo+=3+(WINE_foo=4)
1642 call :checkenvvars WINE_foo 11
1643 set WINE_foo=2
1644 set /a WINE_bar=3+(WINE_foo=6)
1645 call :checkenvvars WINE_foo 6 WINE_bar 9
1646 set WINE_foo=2
1647 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1648 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1649 set WINE_foo=2
1650 set /a WINE_bar=WINE_foo=7
1651 call :checkenvvars WINE_foo 7 WINE_bar 7
1652 echo ----- equal precedence on stack
1653 rem Unary - don't reduce if precedence is equal
1654 set /a WINE_foo=!!1
1655 call :checkenvvars WINE_foo 1
1656 set /a WINE_foo=!!0
1657 call :checkenvvars WINE_foo 0
1658 set /a WINE_foo=~~1
1659 call :checkenvvars WINE_foo 1
1660 set /a WINE_foo=~~0
1661 call :checkenvvars WINE_foo 0
1662 set /a WINE_foo=--1
1663 call :checkenvvars WINE_foo 1
1664 set /a WINE_foo=+-1
1665 call :checkenvvars WINE_foo -1
1666 set /a WINE_foo=-+1
1667 call :checkenvvars WINE_foo -1
1668 set /a WINE_foo=++1
1669 call :checkenvvars WINE_foo 1
1670 set /a WINE_foo=!~1
1671 call :checkenvvars WINE_foo 0
1672 set /a WINE_foo=~!1
1673 call :checkenvvars WINE_foo -1
1674 set /a WINE_foo=!-1
1675 call :checkenvvars WINE_foo 0
1676 set /a WINE_foo=-!1
1677 call :checkenvvars WINE_foo 0
1678 set /a WINE_foo=!-0
1679 call :checkenvvars WINE_foo 1
1680 set /a WINE_foo=-!0
1681 call :checkenvvars WINE_foo -1
1682 rem Aritmatic - Reduce if precedence is equal
1683 set /a WINE_foo=10*5/2
1684 call :checkenvvars WINE_foo 25
1685 set /a WINE_foo=5/2*10
1686 call :checkenvvars WINE_foo 20
1687 set /a WINE_foo=10/5/2
1688 call :checkenvvars WINE_foo 1
1689 set /a WINE_foo=5%%2*4
1690 call :checkenvvars WINE_foo 4
1691 set /a WINE_foo=10-5+2
1692 call :checkenvvars WINE_foo 7
1693 set /a WINE_foo=1^<^<4^>^>1
1694 call :checkenvvars WINE_foo 8
1695 rem Assignment - don't reduce if precedence is equal
1696 set /a WINE_foo=5
1697 set /a WINE_bar=WINE_foo=6
1698 call :checkenvvars WINE_foo 6 WINE_bar 6
1700 echo --- for /F
1701 mkdir foobar & cd foobar
1702 echo ------ string argument
1703 rem NT4 does not support usebackq
1704 for /F %%i in ("a b c") do echo %%i
1705 for /F %%i in ( "a b c" ) do echo X%%iX
1706 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1707 if not exist output_file (echo no output) else (type output_file & del output_file)
1708 for /f usebackq %%i in ( 'a b c' ) do echo X%%iX>output_file
1709 if not exist output_file (echo no output) else (type output_file & del output_file)
1710 for /f %%i in ("a ") do echo %%i
1711 for /f usebackq %%i in ('a ') do echo %%i>output_file
1712 if not exist output_file (echo no output) else (type output_file & del output_file)
1713 for /f %%i in ("a") do echo %%i
1714 for /f usebackq %%i in ('a') do echo %%i>output_file
1715 if not exist output_file (echo no output) else (type output_file & del output_file)
1716 fOr /f %%i in (" a") do echo %%i
1717 for /f usebackq %%i in (' a') do echo %%i>output_file
1718 if not exist output_file (echo no output) else (type output_file & del output_file)
1719 for /f %%i in (" a ") do echo %%i
1720 for /f usebackq %%i in (' a ') do echo %%i>output_file
1721 if not exist output_file (echo no output) else (type output_file & del output_file)
1722 echo ------ fileset argument
1723 echo --------- basic blank handling
1724 echo a b c>foo
1725 for /f %%i in (foo) do echo %%i
1726 echo a >foo
1727 for /f %%i in (foo) do echo %%i
1728 echo a>foo
1729 for /f %%i in (foo) do echo %%i
1730 echo a>foo
1731 for /f %%i in (foo) do echo %%i
1732 echo a >foo
1733 for /f %%i in (foo) do echo %%i
1734 echo. > foo
1735 for /f %%i in (foo) do echo %%i
1736 echo. >> foo
1737 echo b > foo
1738 for /f %%i in (foo) do echo %%i
1739 echo --------- multi-line with empty lines
1740 echo a Z f> foo
1741 echo. >> foo
1742 echo.>> foo
1743 echo b bC>> foo
1744 echo c>> foo
1745 echo. >> foo
1746 for /f %%b in (foo) do echo %%b
1747 echo --------- multiple files
1748 echo q w > bar
1749 echo.>> bar
1750 echo kkk>>bar
1751 for /f %%k in (foo bar) do echo %%k
1752 for /f %%k in (bar foo) do echo %%k
1753 echo ------ command argument
1754 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1755 if "%CD%"=="" goto :SkipFORFcmdNT4
1756 for /f %%i in ('echo.Passed1') do echo %%i
1757 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
1758 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1759 for /f "usebackq" %%i in (`"c:\windows\system32\cmd.exe" /C echo Passed4`) do echo %%i
1760 for /f "usebackq" %%i in (`""c:\windows\system32\cmd.exe" /C echo Passed5"`) do echo %%i
1761 for /f %%i in ( 'echo.Passed6' ) do echo %%i
1762 for /f "usebackq" %%i in ( `echo.Passed7` ) do echo %%i
1763 goto :ContinueFORF
1764 :SkipFORFcmdNT4
1765 for /l %%i in (1,1,7) do echo Missing functionality - Broken%%i
1766 :ContinueFORF
1767 rem FIXME: Rest not testable right now in wine: not implemented and would need
1768 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1769 rem for a simple todo_wine test
1770 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1771 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1772 echo ------ eol option
1773 if "%CD%"=="" goto :SkipFORFeolNT4
1774 echo Line one>foo
1775 echo and Line two>>foo
1776 echo Line three>>foo
1777 for /f "eol=L" %%i in (foo) do echo %%i
1778 for /f "eol=a" %%i in (foo) do echo %%i
1779 del foo
1780 goto :ContinueFORFeol
1781 :SkipFORFeolNT4
1782 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1783 :ContinueFORFeol
1784 for /f "eol=@" %%i in (" ad") do echo %%i
1785 for /f "eol=@" %%i in (" z@y") do echo %%i
1786 for /f "eol=|" %%i in ("a|d") do echo %%i
1787 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
1788 if not exist output_file (echo no output) else (del output_file)
1789 for /f "eol==" %%i in ("=y") do echo %%i > output_file
1790 if not exist output_file (echo no output) else (del output_file)
1791 echo ------ delims option
1792 for /f "delims=|" %%i in ("a|d") do echo %%i
1793 for /f "delims=|" %%i in ("a |d") do echo %%i
1794 for /f "delims=|" %%i in ("a d|") do echo %%i
1795 for /f "delims=| " %%i in ("a d|") do echo %%i
1796 for /f "delims==" %%i in ("C r=d|") do echo %%i
1797 for /f "delims=" %%i in ("foo bar baz") do echo %%i
1798 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
1799 echo ------ skip option
1800 echo a > foo
1801 echo b >> foo
1802 echo c >> foo
1803 for /f "skip=2" %%i in (foo) do echo %%i
1804 for /f "skip=3" %%i in (foo) do echo %%i > output_file
1805 if not exist output_file (echo no output) else (del output_file)
1806 for /f "skip=4" %%i in (foo) do echo %%i > output_file
1807 if not exist output_file (echo no output) else (del output_file)
1808 for /f "skip=02" %%i in (foo) do echo %%i
1809 for /f "skip=0x2" %%i in (foo) do echo %%i
1810 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
1811 if not exist output_file (echo no output) else (del output_file)
1812 echo ------ tokens= option
1813 rem Basic
1814 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
1815 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
1816 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
1817 rem Show * means the rest
1818 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
1819 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
1820 rem Show * means the rest (not tokenized and rebuilt)
1821 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
1822 rem Order is irrelevant
1823 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
1824 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
1825 rem Duplicates are ignored
1826 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
1827 rem Large tokens are allowed
1828 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
1829 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1830 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
1831 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
1832 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1833 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
1834 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
1835 rem Show negative ranges have no effect
1836 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
1837 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
1838 rem Show duplicates stop * from working
1839 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
1840 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
1841 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
1842 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
1843 rem Special case tokens=* or tokens=n,*
1844 echo 3.14>testfile
1845 FOR /F "tokens=*" %%A IN (testfile) DO @echo 1:%%A,%%B
1846 FOR /F "tokens=1*" %%A IN (testfile) DO @echo 2:%%A,%%B
1847 FOR /F "tokens=2*" %%A IN (testfile) DO @echo 3:%%A,%%B
1848 FOR /F "tokens=1,* delims=." %%A IN (testfile) DO @echo 4:%%A,%%B
1849 del testfile
1850 cd ..
1851 rd /s/q foobar
1852 echo ------ parameter splitting
1853 echo forFParameterSplittingFunc "myparam1=myvalue1 myparam2=myparam2" mytest> foo
1854 for /f "tokens=1 delims=;" %%i in (foo) do (call :%%i)
1855 del foo
1856 for /f "tokens=1 delims=;" %%i in ("forFParameterSplittingFunc "myparam1^=myvalue1 myparam2^=myparam2" mytest") do (call :%%i)
1857 goto :forFParameterSplittingEnd
1858 :forFParameterSplittingFunc
1859 echo %~0 %~1 %~2 %~3 %~4 %~5
1860 goto :eof
1861 :forFParameterSplittingEnd
1862 echo 3.14>testfile
1863 FOR /F "delims=. tokens=*" %%A IN (testfile) DO @echo 4:%%A,%%B
1864 FOR /F "delims=. tokens=1*" %%A IN (testfile) DO @echo 5:%%A,%%B
1865 FOR /F "delims=. tokens=2*" %%A IN (testfile) DO @echo 6:%%A,%%B
1866 FOR /F "delims=. tokens=3*" %%A IN (testfile) DO @echo 7:%%A,%%B
1867 del testfile
1869 echo ------------ Testing del ------------
1870 echo abc > file
1871 echo deleting 'file'
1872 del file
1873 if errorlevel 0 (
1874 echo errorlevel is 0, good
1875 ) else (
1876 echo unexpected errorlevel, got %errorlevel%
1878 if not exist file (
1879 echo successfully deleted 'file'
1880 ) else (
1881 echo error deleting 'file'
1883 echo attempting to delete 'file', even though it is not present
1884 del file
1885 if errorlevel 0 (
1886 echo errorlevel is 0, good
1887 ) else (
1888 echo unexpected errorlevel, got %errorlevel%
1891 echo ------------ Testing del /a ------------
1892 del /f/q *.test > nul
1893 echo r > r.test
1894 attrib +r r.test
1895 echo not-r > not-r.test
1897 if not exist not-r.test echo not-r.test not found before delete, bad
1898 del /a:-r *.test
1899 if not exist not-r.test echo not-r.test not found after delete, good
1901 if not exist r.test echo r.test not found before delete, bad
1902 if exist r.test echo r.test found before delete, good
1903 del /a:r *.test
1904 if not exist r.test echo r.test not found after delete, good
1905 if exist r.test echo r.test found after delete, bad
1907 echo ------------ Testing del /q ------------
1908 mkdir del_q_dir
1909 cd del_q_dir
1910 echo abc > file1
1911 echo abc > file2.dat
1912 rem If /q doesn't work, cmd will prompt and the test case should hang
1913 del /q * > nul
1914 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1915 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1916 cd ..
1917 rmdir del_q_dir
1919 echo ------------ Testing del /s ------------
1920 mkdir "foo bar"
1921 cd "foo bar"
1922 mkdir "foo:"
1923 echo hi > file1.dat
1924 echo there > file2.dat
1925 echo bub > file3.dat
1926 echo bye > "file with spaces.dat"
1927 cd ..
1928 del /s file1.dat > nul
1929 del file2.dat /s > nul
1930 del "file3.dat" /s > nul
1931 del "file with spaces.dat" /s > nul
1932 cd "foo bar"
1933 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1934 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1935 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
1936 if exist "file with spaces.dat" del "file with spaces.dat"
1937 rmdir "foo:"
1938 cd ..
1939 rmdir "foo bar"
1941 echo ------------ Testing rename ------------
1942 mkdir foobar & cd foobar
1943 echo --- ren and rename are synonymous
1944 echo > foo
1945 rename foo bar
1946 if exist foo echo foo should be renamed!
1947 if exist bar echo foo renamed to bar
1948 ren bar foo
1949 if exist bar echo bar should be renamed!
1950 if exist foo echo bar renamed to foo
1951 echo --- name collision
1952 echo foo>foo
1953 echo bar>bar
1954 ren foo bar 2> nul
1955 type foo
1956 type bar
1957 rem no-op
1958 ren foo foo
1959 mkdir baz
1960 ren foo baz\abc
1961 echo --- rename read-only files
1962 echo > file1
1963 attrib +r file1
1964 ren file1 file2
1965 if not exist file1 (
1966 if exist file2 (
1967 echo read-only file renamed
1969 ) else (
1970 echo read-only file not renamed!
1972 echo --- rename directories
1973 mkdir rep1
1974 ren rep1 rep2
1975 if not exist rep1 (
1976 if exist rep2 (
1977 echo dir renamed
1980 attrib +r rep2
1981 ren rep2 rep1
1982 if not exist rep2 (
1983 if exist rep1 (
1984 echo read-only dir renamed
1987 echo --- rename in other directory
1988 if not exist baz\abc (
1989 echo rename impossible in other directory
1990 if exist foo echo original file still present
1991 ) else (
1992 echo shouldn't rename in other directory!
1993 if not exist foo echo original file not present anymore
1995 cd .. & rd /s/q foobar
1997 echo ------------ Testing move ------------
1998 mkdir foobar & cd foobar
1999 echo --- file move
2000 echo >foo
2001 move foo bar > nul 2>&1
2002 if not exist foo (
2003 if exist bar (
2004 echo file move succeeded
2007 echo bar>bar
2008 echo baz> baz
2009 move /Y bar baz > nul 2>&1
2010 if not exist bar (
2011 if exist baz (
2012 echo file move with overwrite succeeded
2014 ) else (
2015 echo file overwrite impossible!
2016 del bar
2018 type baz
2020 attrib +r baz
2021 move baz bazro > nul 2>&1
2022 if not exist baz (
2023 if exist bazro (
2024 echo read-only files are moveable
2025 move bazro baz > nul 2>&1
2027 ) else (
2028 echo read-only file not moved!
2030 attrib -r baz
2031 mkdir rep
2032 move baz rep > nul 2>&1
2033 if not exist baz (
2034 if exist rep\baz (
2035 echo file moved in subdirectory
2038 call :setError 0
2039 move rep\baz . > nul 2>&1
2040 move /Y baz baz > nul 2>&1
2041 if errorlevel 1 (
2042 echo moving a file to itself should be a no-op!
2043 ) else (
2044 echo moving a file to itself is a no-op
2046 echo ErrorLevel: %ErrorLevel%
2047 call :setError 0
2048 del baz
2049 echo --- directory move
2050 mkdir foo\bar
2051 mkdir baz
2052 echo baz2>baz\baz2
2053 move baz foo\bar > nul 2>&1
2054 if not exist baz (
2055 if exist foo\bar\baz\baz2 (
2056 echo simple directory move succeeded
2059 call :setError 0
2060 mkdir baz
2061 move baz baz > nul 2>&1
2062 echo moving a directory to itself gives error; errlevel %ErrorLevel%
2063 echo ------ dir in dir move
2064 rd /s/q foo
2065 mkdir foo bar
2066 echo foo2>foo\foo2
2067 echo bar2>bar\bar2
2068 move foo bar > nul 2>&1
2069 if not exist foo (
2070 if exist bar (
2071 dir /b /ad bar
2072 dir /b /a-d bar
2073 dir /b bar\foo
2076 cd .. & rd /s/q foobar
2078 echo ------------ Testing mkdir ------------
2079 call :setError 0
2080 echo --- md and mkdir are synonymous
2081 mkdir foobar
2082 echo %ErrorLevel%
2083 rmdir foobar
2084 md foobar
2085 echo %ErrorLevel%
2086 rmdir foobar
2087 echo --- creating an already existing directory/file must fail
2088 mkdir foobar
2089 md foobar
2090 echo %ErrorLevel%
2091 rmdir foobar
2092 echo > foobar
2093 mkdir foobar
2094 echo %ErrorLevel%
2095 del foobar
2096 echo --- multilevel path creation
2097 mkdir foo
2098 echo %ErrorLevel%
2099 mkdir foo\bar\baz
2100 echo %ErrorLevel%
2101 cd foo
2102 echo %ErrorLevel%
2103 cd bar
2104 echo %ErrorLevel%
2105 cd baz
2106 echo %ErrorLevel%
2107 echo > ..\..\bar2
2108 mkdir ..\..\..\foo\bar2
2109 echo %ErrorLevel%
2110 del ..\..\bar2
2111 mkdir ..\..\..\foo\bar2
2112 echo %ErrorLevel%
2113 rmdir ..\..\..\foo\bar2
2114 cd ..
2115 rmdir baz
2116 cd ..
2117 rmdir bar
2118 cd ..
2119 rmdir foo
2120 echo %ErrorLevel%
2121 echo --- trailing backslashes
2122 mkdir foo\\\\
2123 echo %ErrorLevel%
2124 if exist foo (rmdir foo & echo dir created
2125 ) else ( echo dir not created )
2126 echo %ErrorLevel%
2127 echo --- invalid chars
2128 mkdir ?
2129 echo mkdir ? gives errorlevel %ErrorLevel%
2130 call :setError 0
2131 mkdir ?\foo
2132 echo mkdir ?\foo gives errorlevel %ErrorLevel%
2133 call :setError 0
2134 mkdir foo\?
2135 echo mkdir foo\? gives errorlevel %ErrorLevel%
2136 if exist foo (rmdir foo & echo ok, foo created
2137 ) else ( echo foo not created )
2138 call :setError 0
2139 mkdir foo\bar\?
2140 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
2141 call :setError 0
2142 if not exist foo (
2143 echo bad, foo not created
2144 ) else (
2145 cd foo
2146 if exist bar (
2147 echo ok, foo\bar created
2148 rmdir bar
2150 cd ..
2151 rmdir foo
2153 echo --- multiple directories at once
2154 mkdir foobaz & cd foobaz
2155 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
2156 if exist foo (echo foo created) else echo foo not created!
2157 if exist bar (echo bar created) else echo bar not created!
2158 if exist foobar (echo foobar created) else echo foobar not created!
2159 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
2160 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
2161 if exist zabzab (echo zabzab created) else echo zabzab not created!
2162 cd .. & rd /s/q foobaz
2163 call :setError 0
2164 mkdir foo\*
2165 echo mkdir foo\* errorlevel %ErrorLevel%
2166 if exist foo (rmdir foo & echo ok, foo created
2167 ) else ( echo bad, foo not created )
2169 echo ------------ Testing rmdir ------------
2170 call :setError 0
2171 rem rd and rmdir are synonymous
2172 mkdir foobar
2173 rmdir foobar
2174 echo %ErrorLevel%
2175 if not exist foobar echo dir removed
2176 mkdir foobar
2177 rd foobar
2178 echo %ErrorLevel%
2179 if not exist foobar echo dir removed
2180 rem Removing nonexistent directory
2181 rmdir foobar
2182 echo %ErrorLevel%
2183 rem Removing single-level directories
2184 echo > foo
2185 rmdir foo
2186 echo %ErrorLevel%
2187 if exist foo echo file not removed
2188 del foo
2189 mkdir foo
2190 echo > foo\bar
2191 rmdir foo
2192 echo %ErrorLevel%
2193 if exist foo echo non-empty dir not removed
2194 del foo\bar
2195 mkdir foo\bar
2196 rmdir foo
2197 echo %ErrorLevel%
2198 if exist foo echo non-empty dir not removed
2199 rmdir foo\bar
2200 rmdir foo
2201 rem Recursive rmdir
2202 mkdir foo\bar\baz
2203 rmdir /s /Q foo
2204 if not exist foo (
2205 echo recursive rmdir succeeded
2206 ) else (
2207 rd foo\bar\baz
2208 rd foo\bar
2209 rd foo
2211 mkdir foo\bar\baz
2212 echo foo > foo\bar\brol
2213 rmdir /s /Q foo 2>&1
2214 if not exist foo (
2215 echo recursive rmdir succeeded
2216 ) else (
2217 rd foo\bar\baz
2218 del foo\bar\brol
2219 rd foo\bar
2220 rd foo
2222 rem multiples directories at once
2223 mkdir foobaz & cd foobaz
2224 mkdir foo
2225 mkdir bar\baz
2226 mkdir foobar
2227 rd /s/q foo bar foobar
2228 if not exist foo (echo foo removed) else echo foo not removed!
2229 if not exist bar (echo bar removed) else echo bar not removed!
2230 if not exist foobar (echo foobar removed) else echo foobar not removed!
2231 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
2232 cd .. & rd /s/q foobaz
2234 echo ------------ Testing pushd/popd ------------
2236 echo --- popd is no-op when dir stack is empty
2237 popd
2239 echo --- pushing non-existing dir
2240 pushd foobar
2242 echo --- basic behaviour
2243 mkdir foobar\baz
2244 pushd foobar
2246 popd
2248 pushd foobar
2249 pushd baz
2251 popd
2253 pushd baz
2254 popd
2256 popd
2258 pushd .
2259 cd foobar\baz
2260 pushd ..
2262 popd
2263 popd
2265 rd /s/q foobar
2267 echo ------------ Testing attrib ------------
2268 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
2269 mkdir foobar & cd foobar
2270 echo foo original contents> foo
2271 attrib foo
2272 echo > bar
2273 echo --- read-only attribute
2274 rem Read-only files cannot be altered or deleted, unless forced
2275 attrib +R foo
2276 attrib foo
2277 dir /Ar /B
2278 echo bar>> foo
2279 type foo
2280 del foo > NUL 2>&1
2281 if exist foo (
2282 echo Read-only file not deleted
2283 ) else (
2284 echo Should not delete read-only file!
2286 del /F foo
2287 if not exist foo (
2288 echo Read-only file forcibly deleted
2289 ) else (
2290 echo Should delete read-only file with del /F!
2291 attrib -r foo
2292 del foo
2294 cd .. & rd /s/q foobar
2295 echo --- recursive behaviour
2296 mkdir foobar\baz & cd foobar
2297 echo > level1
2298 echo > whatever
2299 echo > baz\level2
2300 attrib baz\level2
2301 cd ..
2302 attrib +R l*vel? /S > nul 2>&1
2303 cd foobar
2304 attrib level1
2305 attrib baz\level2
2306 echo > bar
2307 attrib bar
2308 cd .. & rd /s/q foobar
2309 echo --- folders processing
2310 mkdir foobar
2311 attrib foobar
2312 cd foobar
2313 mkdir baz
2314 echo toto> baz\toto
2315 attrib +r baz /s /d > nul 2>&1
2316 attrib baz
2317 attrib baz\toto
2318 echo lulu>>baz\toto
2319 type baz\toto
2320 echo > baz\lala
2321 rem Oddly windows allows file creation in a read-only directory...
2322 if exist baz\lala (echo file created in read-only dir) else echo file not created
2323 cd .. & rd /s/q foobar
2325 echo ------------ Testing assoc ------------
2326 rem Modifying associations requires some privileges...
2327 net session >nul 2>&1
2328 if errorlevel 1 goto :SkipAssoc
2330 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2331 rem FIXME Revise once || conditional execution is fixed
2332 mkdir foobar & cd foobar
2333 echo --- setting association
2334 assoc .foo > baz
2335 type baz
2336 echo ---
2338 assoc .foo=bar
2339 assoc .foo
2341 rem association set system-wide
2342 echo @echo off> tmp.cmd
2343 echo echo +++>> tmp.cmd
2344 echo assoc .foo>> tmp.cmd
2345 cmd /c tmp.cmd
2347 echo --- resetting association
2348 assoc .foo=
2349 assoc .foo > baz
2350 type baz
2351 echo ---
2353 rem association removal set system-wide
2354 cmd /c tmp.cmd > baz
2355 type baz
2356 echo ---
2357 cd .. & rd /s/q foobar
2358 goto ContinueFType
2359 :SkipAssoc
2360 echo --- setting association
2361 echo ---
2362 echo .foo=bar
2363 echo .foo=bar
2364 echo +++
2365 echo .foo=bar
2366 echo --- resetting association
2367 echo ---
2368 echo +++
2369 echo ---
2372 :ContinueFType
2373 echo ------------ Testing ftype ------------
2374 rem Modifying associations requires some privileges...
2375 net session >nul 2>&1
2376 if errorlevel 1 goto :SkipFType
2377 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
2378 rem FIXME Revise once || conditional execution is fixed
2379 mkdir foobar & cd foobar
2380 echo --- setting association
2381 ftype footype> baz
2382 type baz
2383 echo ---
2385 ftype footype=foo_opencmd
2386 assoc .foo=footype
2387 ftype footype
2389 rem association set system-wide
2390 echo @echo off> tmp.cmd
2391 echo echo +++>> tmp.cmd
2392 echo ftype footype>> tmp.cmd
2393 cmd /c tmp.cmd
2395 echo --- resetting association
2396 assoc .foo=
2398 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
2399 setlocal EnableDelayedExpansion
2400 set WINE_FOO=original value
2401 ftype footype=
2402 ftype footype > baz
2403 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
2404 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
2405 rem FIXME Revisit once a grep-like program like ftype is implemented
2406 rem (e.g. to check baz's size using dir /b instead)
2407 echo !WINE_FOO!
2409 rem cleanup registry
2410 echo REGEDIT4> regCleanup.reg
2411 echo.>> regCleanup.reg
2412 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
2413 regedit /s regCleanup.reg
2414 set WINE_FOO=
2415 endlocal
2416 cd .. & rd /s/q foobar
2417 goto ContinueCall
2418 :SkipFType
2419 echo --- setting association
2420 echo ---
2421 echo footype=foo_opencmd
2422 echo .foo=footype
2423 echo footype=foo_opencmd
2424 echo +++
2425 echo footype=foo_opencmd
2426 echo --- resetting association
2427 echo original value
2429 :ContinueCall
2430 echo ------------ Testing CALL ------------
2431 mkdir foobar & cd foobar
2432 echo --- external script
2433 echo echo foo %%1> foo.cmd
2434 call foo
2435 call foo.cmd 8
2436 echo echo %%1 %%2 > foo.cmd
2437 call foo.cmd foo
2438 call foo.cmd foo bar
2439 call foo.cmd foo ""
2440 call foo.cmd "" bar
2441 call foo.cmd foo ''
2442 call foo.cmd '' bar
2443 del foo.cmd
2445 echo --- internal routines
2446 call :testRoutine :testRoutine
2447 goto :endTestRoutine
2448 :testRoutine
2449 echo bar %1
2450 goto :eof
2451 :endTestRoutine
2453 call :testRoutineArgs foo
2454 call :testRoutineArgs foo bar
2455 call :testRoutineArgs foo ""
2456 call :testRoutineArgs "" bar
2457 call :testRoutineArgs foo ''
2458 call :testRoutineArgs '' bar
2459 goto :endTestRoutineArgs
2460 :testRoutineArgs
2461 echo %1 %2
2462 goto :eof
2463 :endTestRoutineArgs
2465 echo --- with builtins
2466 call mkdir foo
2467 echo %ErrorLevel%
2468 if exist foo (echo foo created) else echo foo should exist!
2469 rmdir foo
2470 set WINE_FOOBAZ_VAR=foobaz
2471 call echo Should expand %WINE_FOOBAZ_VAR%
2472 set WINE_FOOBAZ_VAR=
2473 echo>batfile
2474 call dir /b
2475 echo>robinfile
2476 if 1==1 call del batfile
2477 dir /b
2478 if exist batfile echo batfile shouldn't exist
2479 rem ... but not for 'if' or 'for'
2480 call if 1==1 echo bar 2> nul
2481 echo %ErrorLevel%
2482 call :setError 0
2483 call for %%i in (foo bar baz) do echo %%i 2> nul
2484 echo %ErrorLevel%
2485 rem First look for programs in the path before trying a builtin
2486 echo echo non-builtin dir> dir.cmd
2487 call dir /b
2488 del dir.cmd
2489 rem The below line equates to call (, which does nothing, then the
2490 rem subsequent lines are executed.
2491 call (
2492 echo Line one
2493 echo Line two
2495 rem The below line equates to call if, which always fails, then the
2496 rem subsequent lines are executed. Note cmd.exe swallows all lines
2497 rem starting with )
2498 call if 1==1 (
2499 echo Get if
2500 ) else (
2501 echo ... and else!
2503 call call call echo passed
2504 cd .. & rd /s/q foobar
2506 echo ------------ Testing SHIFT ------------
2508 call :shiftFun p1 p2 p3 p4 p5
2509 goto :endShiftFun
2511 :shiftFun
2512 echo '%1' '%2' '%3' '%4' '%5'
2513 shift
2514 echo '%1' '%2' '%3' '%4' '%5'
2515 shift@tab@ /1
2516 echo '%1' '%2' '%3' '%4' '%5'
2517 shift /2
2518 echo '%1' '%2' '%3' '%4' '%5'
2519 shift /-1
2520 echo '%1' '%2' '%3' '%4' '%5'
2521 shift /0
2522 echo '%1' '%2' '%3' '%4' '%5'
2523 goto :eof
2524 :endShiftFun
2526 echo ------------ Testing cmd invocation ------------
2527 rem FIXME: only a stub ATM
2528 echo --- a batch file can delete itself
2529 echo del foo.cmd>foo.cmd
2530 cmd /q /c foo.cmd
2531 if not exist foo.cmd (
2532 echo file correctly deleted
2533 ) else (
2534 echo file should be deleted!
2535 del foo.cmd
2537 echo --- a batch file can alter itself
2538 echo echo bar^>foo.cmd>foo.cmd
2539 cmd /q /c foo.cmd > NUL 2>&1
2540 if exist foo.cmd (
2541 type foo.cmd
2542 del foo.cmd
2543 ) else (
2544 echo file not created!
2547 echo ---------- Testing copy
2548 md foobar2
2549 cd foobar2
2550 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2551 echo AAA> file1
2552 echo BBBBBB> file2
2553 echo CCCCCCCCC> file3
2554 md dir1
2555 goto :testcopy
2557 :CheckExist
2558 if exist "%1" (
2559 echo Passed: Found expected %1
2560 ) else (
2561 echo Failed: Did not find expected %1
2563 del /q "%1" >nul 2>&1
2564 shift
2565 if not "%1"=="" goto :CheckExist
2566 goto :eof
2568 :CheckNotExist
2569 if not exist "%1" (
2570 echo Passed: Did not find %1
2571 ) else (
2572 echo Failed: Unexpectedly found %1
2573 del /q "%1" >nul 2>&1
2575 shift
2576 if not "%1"=="" goto :CheckNotExist
2577 goto :eof
2579 rem Note: No way to check file size on NT4 so skip the test
2580 :CheckFileSize
2581 if not exist "%1" (
2582 echo Failed: File missing when requested filesize check [%2]
2583 goto :ContinueFileSizeChecks
2585 for %%i in (%1) do set WINE_filesize=%%~zi
2586 if "%WINE_filesize%"=="%2" (
2587 echo Passed: file size check on %1 [%WINE_filesize%]
2588 ) else (
2589 if "%WINE_filesize%"=="%%~zi" (
2590 echo Skipping file size check on NT4
2591 ) else (
2592 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2595 :ContinueFileSizeChecks
2596 shift
2597 shift
2598 if not "%1"=="" goto :CheckFileSize
2599 goto :eof
2601 :testcopy
2603 rem -----------------------
2604 rem Simple single file copy
2605 rem -----------------------
2606 rem Simple single file copy, normally used syntax
2607 copy file1 dummy.file >nul 2>&1
2608 if errorlevel 1 echo Incorrect errorlevel
2609 call :CheckExist dummy.file
2611 rem Simple single file copy, destination supplied as two forms of directory
2612 copy file1 dir1 >nul 2>&1
2613 if errorlevel 1 echo Incorrect errorlevel
2614 call :CheckExist dir1\file1
2616 copy file1 dir1\ >nul 2>&1
2617 if errorlevel 1 echo Incorrect errorlevel
2618 call :CheckExist dir1\file1
2620 rem Simple single file copy, destination supplied as fully qualified destination
2621 copy file1 dir1\file99 >nul 2>&1
2622 if errorlevel 1 echo Incorrect errorlevel
2623 call :CheckExist dir1\file99
2625 rem Simple single file copy, destination not supplied
2626 cd dir1
2627 copy ..\file1 >nul 2>&1
2628 if errorlevel 1 echo Incorrect errorlevel
2629 call :CheckExist file1
2630 cd ..
2632 rem Simple single file copy, destination supplied as nonexistent directory
2633 copy file1 dir2\ >nul 2>&1
2634 if not errorlevel 1 echo Incorrect errorlevel
2635 call :CheckNotExist dir2 dir2\file1
2637 rem -----------------------
2638 rem Wildcarded copy
2639 rem -----------------------
2640 rem Simple single file copy, destination supplied as two forms of directory
2641 copy file? dir1 >nul 2>&1
2642 if errorlevel 1 echo Incorrect errorlevel
2643 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2645 copy file* dir1\ >nul 2>&1
2646 if errorlevel 1 echo Incorrect errorlevel
2647 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2649 rem Simple single file copy, destination not supplied
2650 cd dir1
2651 copy ..\file*.* >nul 2>&1
2652 if errorlevel 1 echo Incorrect errorlevel
2653 call :CheckExist file1 file2 file3
2654 cd ..
2656 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2657 copy file? dir2\ >nul 2>&1
2658 if not errorlevel 1 echo Incorrect errorlevel
2659 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2661 rem ------------------------------------------------
2662 rem Confirm overwrite works (cannot test prompting!)
2663 rem ------------------------------------------------
2664 copy file1 testfile >nul 2>&1
2665 copy /y file2 testfile >nul 2>&1
2666 call :CheckExist testfile
2668 rem ------------------------------------------------
2669 rem Test concatenation
2670 rem ------------------------------------------------
2671 rem simple case, no wildcards
2672 copy file1+file2 testfile >nul 2>&1
2673 if errorlevel 1 echo Incorrect errorlevel
2674 call :CheckExist testfile
2676 rem simple case, wildcards, no concatenation
2677 copy file* testfile >nul 2>&1
2678 if errorlevel 1 echo Incorrect errorlevel
2679 call :CheckExist testfile
2681 rem simple case, wildcards, and concatenation
2682 echo ddddd > fred
2683 copy file*+fred testfile >nul 2>&1
2684 if errorlevel 1 echo Incorrect errorlevel
2685 call :CheckExist testfile
2687 rem simple case, wildcards, and concatenation
2688 copy fred+file* testfile >nul 2>&1
2689 if errorlevel 1 echo Incorrect errorlevel
2690 call :CheckExist testfile
2692 rem Calculate destination name
2693 copy fred+file* dir1 >nul 2>&1
2694 if errorlevel 1 echo Incorrect errorlevel
2695 call :CheckExist dir1\fred
2697 rem Calculate destination name
2698 copy fred+file* dir1\ >nul 2>&1
2699 if errorlevel 1 echo Incorrect errorlevel
2700 call :CheckExist dir1\fred
2702 rem Calculate destination name (none supplied)
2703 cd dir1
2704 copy ..\fred+..\file* >nul 2>&1
2705 if errorlevel 1 echo Incorrect errorlevel
2706 call :CheckExist fred
2708 copy ..\fr*+..\file1 >nul 2>&1
2709 if errorlevel 1 echo Incorrect errorlevel
2710 call :CheckExist fred
2711 cd ..
2713 rem ******************************************************************
2714 rem ASCII and BINARY tests
2715 rem Note: hard coded numbers deliberate because need to ensure whether
2716 rem an additional EOF has been added or not. There is no way to handle
2717 rem EOFs in batch, so assume if a single byte appears, it's an EOF!
2718 rem ******************************************************************
2720 rem Confirm original sizes of file1,2,3
2721 call :CheckFileSize file1 5 file2 8 file3 11
2723 cd dir1
2725 rem ----------------------------------------------
2726 rem Show concatenation defaults copy to ascii mode
2727 rem ----------------------------------------------
2728 rem Simple default copy source to destination (should not append EOF 5)
2729 copy ..\file1 file1_default >nul 2>&1
2730 call :CheckFileSize file1_default 5
2732 rem Simple binary copy source to destination (should not append EOF 5)
2733 copy /b ..\file1 file1_default2 >nul 2>&1
2734 call :CheckFileSize file1_default2 5
2736 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2737 copy /a ..\file1 file1_plus_eof >nul 2>&1
2738 call :CheckFileSize file1_plus_eof 6
2739 copy /a ..\file2 file2_plus_eof >nul 2>&1
2740 call :CheckFileSize file2_plus_eof 9
2741 copy /a ..\file3 file3_plus_eof >nul 2>&1
2742 call :CheckFileSize file3_plus_eof 12
2744 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2745 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2746 call :CheckFileSize file12_plus_eof 14
2748 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2749 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2750 call :CheckFileSize file12_no_eof 13
2752 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2753 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2754 call :CheckFileSize file12_eof2 14
2756 rem Test copying when destination is one of the sources.
2757 rem Concat file1+file2+file3 into file1, should produce file1+file2+file3 = 24
2758 copy /y ..\file? .\ >nul 2>&1
2759 copy /y /b file1+file2+file3 file1 >nul 2>&1
2760 call :CheckFileSize file1 24
2762 rem Concat file1+file2+file3 into file2, should produce file1+file3 = 16
2763 copy /y ..\file? .\ >nul 2>&1
2764 copy /y /b file1+file2+file3 file2 >nul 2>&1
2765 call :CheckFileSize file2 16
2767 rem Concat file1+file2+file3 into file3, should produce file1+file2 = 13
2768 copy /y ..\file? .\ >nul 2>&1
2769 copy /y /b file1+file2+file3 file3 >nul 2>&1
2770 call :CheckFileSize file3 13
2772 rem --------------------------------------------------------------
2773 rem Show ascii source copy stops at first EOF, binary does the lot
2774 rem --------------------------------------------------------------
2775 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2776 call :CheckFileSize file1_binary_srccopy 6
2778 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2779 call :CheckFileSize file1_ascii_srccopy 5
2781 rem --------------------------------------------------------------
2782 rem Show results of concatenating files (ending in EOFs) and /a /b
2783 rem --------------------------------------------------------------
2785 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2786 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2787 call :CheckFileSize file123_default_copy 25
2788 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2789 call :CheckFileSize file123_ascii_copy 25
2791 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2792 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2793 call :CheckFileSize file123_binary_copy 27
2795 rem We can select which we want the eofs from by postfixing it with /a or /b
2796 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2797 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2798 call :CheckFileSize file123_mixed_copy1 26
2800 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2801 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2802 rem Note the delta between this and the previous one also shows that the destination
2803 rem ascii/binary is inherited from the last /a or /b on the line
2804 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2805 call :CheckFileSize file123_mixed_copy2 27
2807 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2808 rem Note the delta between the next two also shows that the destination ascii/binary is
2809 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2810 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2811 call :CheckFileSize file123_mixed_copy3 26
2812 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2813 call :CheckFileSize file123_mixed_copy4 25
2815 rem -------------------------------------------------------------------------------------------
2816 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2817 rem are not concatenating, it's a direct copy regardless of destination if being read as binary
2818 rem -------------------------------------------------------------------------------------------
2820 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2821 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2822 call :CheckFileSize file123_mixed_copy5 28
2824 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2825 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2826 call :CheckFileSize file123_mixed_copy6 19
2828 rem One file has EOF, but doesn't get an extra one, i.e. 6
2829 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2830 call :CheckFileSize file123_mixed_copy7 6
2832 rem Syntax means concatenate so ascii destination kicks in
2833 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2834 call :CheckFileSize file123_mixed_copy8 7
2836 del *.* /q
2837 cd ..
2839 rem ---------------------------------------
2840 rem Error combinations
2841 rem ---------------------------------------
2842 rem Specify source directory but name is a file
2843 call :setError 0
2844 copy file1\ dir1\ >NUL 2>&1
2845 if errorlevel 1 echo Passed: errorlevel invalid check 1
2846 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2847 call :CheckNotExist dir1\file1
2849 rem Overwrite same file
2850 call :setError 0
2851 copy file1 file1 >NUL 2>&1
2852 if errorlevel 1 echo Passed: errorlevel invalid check 2
2853 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2855 rem Supply same file identified as a directory
2856 call :setError 0
2857 copy file1 file1\ >NUL 2>&1
2858 if errorlevel 1 echo Passed: errorlevel invalid check 3
2859 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2861 cd ..
2862 rd foobar2 /s /q
2864 echo ------------ Testing setlocal/endlocal ------------
2865 call :setError 0
2866 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2867 mkdir foobar & cd foobar
2868 echo --- enable/disable extensions
2869 setlocal DisableEXTensions
2870 echo ErrLev: %ErrorLevel%
2871 endlocal
2872 echo ErrLev: %ErrorLevel%
2873 echo @echo off> tmp.cmd
2874 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2875 rem Enabled by default
2876 cmd /C tmp.cmd
2877 cmd /E:OfF /C tmp.cmd
2878 cmd /e:oN /C tmp.cmd
2880 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2881 echo --- setlocal with corresponding endlocal
2882 rem %CD% does not work on NT4 so use the following workaround
2883 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2884 echo @echo off> test.cmd
2885 echo echo %%WINE_VAR%%>> test.cmd
2886 echo setlocal>> test.cmd
2887 echo set WINE_VAR=localval>> test.cmd
2888 echo md foobar2>> test.cmd
2889 echo cd foobar2>> test.cmd
2890 echo echo %%WINE_VAR%%>> test.cmd
2891 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2892 echo endlocal>> test.cmd
2893 echo echo %%WINE_VAR%%>> test.cmd
2894 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2895 set WINE_VAR=globalval
2896 call test.cmd
2897 echo %WINE_VAR%
2898 for /d %%i in (.) do echo %%~dpnxi
2899 cd /d %WINE_CURDIR%
2900 rd foobar2
2901 set WINE_VAR=
2902 echo --- setlocal with no corresponding endlocal
2903 echo @echo off> test.cmd
2904 echo echo %%WINE_VAR%%>> test.cmd
2905 echo setlocal>> test.cmd
2906 echo set WINE_VAR=localval>> test.cmd
2907 echo md foobar2>> test.cmd
2908 echo cd foobar2>> test.cmd
2909 echo echo %%WINE_VAR%%>> test.cmd
2910 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2911 set WINE_VAR=globalval
2912 rem %CD% does not work on NT4 so use the following workaround
2913 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2914 call test.cmd
2915 echo %WINE_VAR%
2916 for /d %%i in (.) do echo %%~dpnxi
2917 cd /d %WINE_CURDIR%
2918 rd foobar2
2919 set WINE_VAR=
2920 echo --- setlocal within same batch program
2921 set WINE_var1=one
2922 set WINE_var2=
2923 set WINE_var3=
2924 rem %CD% does not work on NT4 so use the following workaround
2925 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2926 setlocal
2927 set WINE_var2=two
2928 mkdir foobar2
2929 cd foobar2
2930 setlocal
2931 set WINE_var3=three
2932 if "%WINE_var1%"=="one" echo Var1 ok 1
2933 if "%WINE_var2%"=="two" echo Var2 ok 2
2934 if "%WINE_var3%"=="three" echo Var3 ok 3
2935 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2936 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
2937 endlocal
2938 if "%WINE_var1%"=="one" echo Var1 ok 1
2939 if "%WINE_var2%"=="two" echo Var2 ok 2
2940 if "%WINE_var3%"=="" echo Var3 ok 3
2941 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2942 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
2943 endlocal
2944 if "%WINE_var1%"=="one" echo Var1 ok 1
2945 if "%WINE_var2%"=="" echo Var2 ok 2
2946 if "%WINE_var3%"=="" echo Var3 ok 3
2947 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2948 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
2949 rd foobar2 /s /q
2950 set WINE_var1=
2952 echo --- Mismatched set and end locals
2953 mkdir foodir2 2>nul
2954 mkdir foodir3 2>nul
2955 mkdir foodir4 2>nul
2956 rem %CD% does not work on NT4 so use the following workaround
2957 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
2959 echo @echo off> 2set1end.cmd
2960 echo echo %%WINE_var%%>> 2set1end.cmd
2961 echo setlocal>> 2set1end.cmd
2962 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
2963 echo cd ..\foodir3>> 2set1end.cmd
2964 echo setlocal>> 2set1end.cmd
2965 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
2966 echo cd ..\foodir4>> 2set1end.cmd
2967 echo endlocal>> 2set1end.cmd
2968 echo echo %%WINE_var%%>> 2set1end.cmd
2969 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
2971 echo @echo off> 1set2end.cmd
2972 echo echo %%WINE_var%%>> 1set2end.cmd
2973 echo setlocal>> 1set2end.cmd
2974 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
2975 echo cd ..\foodir3>> 1set2end.cmd
2976 echo endlocal>> 1set2end.cmd
2977 echo echo %%WINE_var%%>> 1set2end.cmd
2978 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2979 echo endlocal>> 1set2end.cmd
2980 echo echo %%WINE_var%%>> 1set2end.cmd
2981 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2983 echo --- Extra setlocal in called batch
2984 set WINE_VAR=value1
2985 rem -- setlocal1 == this batch, should never be used inside a called routine
2986 setlocal
2987 set WINE_var=value2
2988 cd foodir2
2989 call "%WINE_CURDIR%\2set1end.cmd"
2990 echo Finished:
2991 echo %WINE_VAR%
2992 for /d %%i in (.) do echo %%~dpnxi
2993 endlocal
2994 echo %WINE_VAR%
2995 for /d %%i in (.) do echo %%~dpnxi
2996 cd /d %WINE_CURDIR%
2998 echo --- Extra endlocal in called batch
2999 set WINE_VAR=value1
3000 rem -- setlocal1 == this batch, should never be used inside a called routine
3001 setlocal
3002 set WINE_var=value2
3003 cd foodir2
3004 call "%WINE_CURDIR%\1set2end.cmd"
3005 echo Finished:
3006 echo %WINE_VAR%
3007 for /d %%i in (.) do echo %%~dpnxi
3008 endlocal
3009 echo %WINE_VAR%
3010 for /d %%i in (.) do echo %%~dpnxi
3011 cd /d %WINE_CURDIR%
3013 echo --- endlocal in called function rather than batch pgm is ineffective
3014 @echo off
3015 set WINE_var=1
3016 set WINE_var2=1
3017 setlocal
3018 set WINE_var=2
3019 call :endlocalroutine
3020 echo %WINE_var%
3021 endlocal
3022 echo %WINE_var%
3023 goto :endlocalfinished
3024 :endlocalroutine
3025 echo %WINE_var%
3026 endlocal
3027 echo %WINE_var%
3028 setlocal
3029 set WINE_var2=2
3030 endlocal
3031 echo %WINE_var2%
3032 endlocal
3033 echo %WINE_var%
3034 echo %WINE_var2%
3035 goto :eof
3036 :endlocalfinished
3037 echo %WINE_var%
3039 set WINE_var=
3040 set WINE_var2=
3041 cd .. & rd /q/s foobar
3043 echo ------------ Testing Errorlevel ------------
3044 rem WARNING: Do *not* add tests using ErrorLevel after this section
3045 should_not_exist 2> nul > nul
3046 echo %ErrorLevel%
3047 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
3048 rem See http://www.robvanderwoude.com/exit.php
3049 call :setError 1
3050 echo %ErrorLevel%
3051 if errorlevel 2 echo errorlevel too high, bad
3052 if errorlevel 1 echo errorlevel just right, good
3053 if errorlevel 01 echo errorlevel with leading zero just right, good
3054 if errorlevel -1 echo errorlevel with negative number OK
3055 if errorlevel 0x1 echo hexa should not be recognized!
3056 if errorlevel 1a echo invalid error level recognized!
3057 call :setError 0
3058 echo abc%ErrorLevel%def
3059 if errorlevel 1 echo errorlevel nonzero, bad
3060 if not errorlevel 1 echo errorlevel zero, good
3061 if not errorlevel 0x1 echo hexa should not be recognized!
3062 if not errorlevel 1a echo invalid error level recognized!
3063 rem Now verify that setting a real variable hides its magic variable
3064 set errorlevel=7
3065 echo %ErrorLevel% should be 7
3066 if errorlevel 7 echo setting var worked too well, bad
3067 call :setError 3
3068 echo %ErrorLevel% should still be 7
3070 echo ------------ Testing GOTO ------------
3071 if a==a goto dest1
3072 echo FAILURE at dest 1
3073 :dest1
3074 echo goto with no leading space worked
3075 if a==a goto :dest1b
3076 echo FAILURE at dest 1b
3077 :dest1b
3078 echo goto with colon and no leading space worked
3079 if b==b goto dest2
3080 echo FAILURE at dest 2
3081 :dest2
3082 echo goto with a leading space worked
3083 if c==c goto dest3
3084 echo FAILURE at dest 3
3085 :dest3
3086 echo goto with a leading tab worked
3087 if d==d goto dest4
3088 echo FAILURE at dest 4
3089 :dest4@space@
3090 echo goto with a following space worked
3091 if e==e goto dest5
3092 echo FAILURE at dest 5
3093 :dest5&& echo FAILURE
3094 echo goto with following amphersands worked
3096 del failure.txt >nul 2>&1
3097 if f==f goto dest6
3098 echo FAILURE at dest 6
3099 :dest6>FAILURE.TXT
3100 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
3101 echo goto with redirections worked
3102 del FAILURE.TXT >nul 2>&1
3104 :: some text that is ignored | dir >cmd_output | another test
3105 if exist cmd_output echo FAILURE at dest 6 as file exists
3106 echo Ignoring double colons worked
3107 del cmd_output >nul 2>&1
3109 rem goto a label which does not exist issues an error message and
3110 rem acts the same as goto :EOF, and ensure ::label is never matched
3111 del testgoto.bat >nul 2>&1
3112 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
3113 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
3114 echo ::dest7>> testgoto.bat
3115 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
3116 call testgoto.bat
3117 del testgoto.bat >nul 2>&1
3119 del testgoto.bat >nul 2>&1
3120 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
3121 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
3122 echo ::dest8>> testgoto.bat
3123 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
3124 call testgoto.bat
3125 del testgoto.bat >nul 2>&1
3127 if g==g goto dest9
3128 echo FAILURE at dest 9
3129 :dest91
3130 echo FAILURE at dest 91
3131 @ : dest9>rubbish
3132 echo label with mixed whitespace and no echo worked
3134 if h==h goto :dest10:this is ignored
3135 echo FAILURE at dest 10
3136 :dest10:this is also ignored
3137 echo Correctly ignored trailing information
3139 rem Testing which label is reached when there are many options
3140 echo Begin:
3141 set nextlabel=
3142 call :sub
3143 set nextlabel=middle
3144 goto :sub
3146 :sub
3147 echo ..First sub
3148 if not "%nextlabel%"=="" goto :%nextlabel%
3149 goto :EOF
3151 :sub
3152 echo ..Second sub
3153 if not "%nextlabel%"=="" goto :%nextlabel%
3154 goto :EOF
3156 :middle
3157 echo Middle:
3158 set nextlabel=
3159 call :sub
3160 set nextlabel=nearend
3161 goto :sub
3163 :sub
3164 echo ..Third sub
3165 if not "%nextlabel%"=="" goto :%nextlabel%
3166 goto :EOF
3168 :nearend
3169 echo Near end:
3170 set nextlabel=
3171 call :sub
3172 set nextlabel=end
3173 goto :sub
3175 :sub
3176 echo ..Fourth sub
3177 if not "%nextlabel%"=="" goto :%nextlabel%
3178 goto :EOF
3180 :end
3181 echo At end:
3182 set nextlabel=
3183 call :sub
3184 set nextlabel=done
3185 goto :sub
3187 :done
3188 echo Finished
3190 echo ------------ Testing PATH ------------
3191 set WINE_backup_path=%path%
3192 set path=original
3193 path
3194 path try2
3195 path
3196 path=try3
3197 path
3198 set path=%WINE_backup_path%
3199 set WINE_backup_path=
3201 echo ------------ Testing start /W ------------
3202 echo start /W failed to wait>foobar.txt
3203 start /W "" cmd /C "ping -n1 & echo start /W seems to really wait>foobar.txt"& type foobar.txt& del foobar.txt
3205 echo ------------ Testing changing the drive letter ----------
3206 pushd C:\
3208 echo Normal:
3209 call :setError 0
3211 if errorlevel 1 echo Normal drive change failed
3213 echo Normal+space
3214 call :setError 0
3215 C:@space@
3216 if errorlevel 1 echo Normal+space drive change failed
3218 echo Normal+space+garbage
3219 call :setError 0
3220 C: garbage
3221 if errorlevel 1 echo Normal+space+garbage drive change failed
3223 call :setError 0
3224 echo Quoted should fail
3225 "C:"
3226 if not errorlevel 1 echo quoted drive change unexpectedly worked
3228 echo Normal+tab
3229 call :setError 0
3230 C:@tab@
3231 if errorlevel 1 echo Normal+tab drive change failed
3233 echo Normal+tab+garbage
3234 call :setError 0
3235 C:@tab@garbagetab
3236 if errorlevel 1 echo Normal+tab+garbage drive change failed
3238 popd
3240 echo ------------ Testing combined CALLs/GOTOs ------------
3241 echo @echo off>foo.cmd
3242 echo goto :eof>>foot.cmd
3243 echo :eof>>foot.cmd
3244 echo echo world>>foo.cmd
3246 echo @echo off>foot.cmd
3247 echo echo cheball>>foot.cmd
3248 echo.>>foot.cmd
3249 echo call :bar>>foot.cmd
3250 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
3251 echo goto :eof>>foot.cmd
3252 echo.>>foot.cmd
3253 echo :bar>>foot.cmd
3254 echo echo barbare>>foot.cmd
3255 echo goto :eof>>foot.cmd
3257 call foo.cmd
3258 call foot
3259 call :bar
3260 del foo.cmd
3261 rem Script execution stops after the following line
3262 foot deleteMe
3263 call :foo
3264 call :foot
3265 goto :endFuns
3267 :foot
3268 echo foot
3270 :foo
3271 echo foo
3272 goto :eof
3274 :endFuns
3276 :bar
3277 echo bar
3278 call :foo
3280 :baz
3281 echo baz
3282 goto :eof
3284 echo Final message is not output since earlier 'foot' processing stops script execution
3285 echo Do NOT add any tests below this line
3287 echo ------------ Done, jumping to EOF -----------
3288 goto :eof
3289 rem Subroutine to set errorlevel and return
3290 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
3291 :setError
3292 exit /B %1
3293 rem This line runs under cmd in windows NT 4, but not in more modern versions.