Release 1.6-rc2.
[wine/testsucceed.git] / programs / cmd / tests / test_builtins.cmd
blob78f7cdcb9d62311d75f9f3efbd6ac46505a16d0f
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 off now
19 echo word@space@
20 echo word@space@@space@
21 echo word
22 echo@tab@word
23 echo@tab@word @tab@
24 echo@tab@word@tab@@space@
25 @tab@echo word
26 echo @tab@word
27 echo @tab@word
28 echo@tab@@tab@word
29 echo @tab@ on @space@
31 @echo off
32 echo off@tab@@space@
33 @echo noecho1
34 @echo noecho2
35 @@@@@echo echo3
36 echo ------------ Testing 'echo' [OFF] ------------
37 echo word
38 echo 'singlequotedword'
39 echo "doublequotedword"
40 @echo at-echoed-word
41 echo "/?"
42 echo.
43 echo .
44 echo.word
45 echo .word
46 echo:
47 echo :
48 echo:word
49 echo :word
50 echo on again
51 echo word@space@
52 echo word@space@@space@
53 echo word
54 echo@tab@word
55 echo@tab@word @tab@
56 echo@tab@word@tab@@space@
57 @tab@echo word
58 echo @tab@word
59 echo @tab@word
60 echo@tab@@tab@word
62 echo ------------ Testing mixed echo modes ------------
63 echo @echo on> mixedEchoModes.cmd
64 echo if 1==1 echo foo>> mixedEchoModes.cmd
65 echo if 1==1 @echo bar>> mixedEchoModes.cmd
66 echo @echo off>> mixedEchoModes.cmd
67 echo if 1==1 echo foo2>> mixedEchoModes.cmd
68 echo if 1==1 @echo bar2>> mixedEchoModes.cmd
69 type mixedEchoModes.cmd
70 cmd /c mixedEchoModes.cmd
71 del mixedEchoModes.cmd
73 echo ------------ Testing parameterization ------------
74 call :TestParm a b c
75 call :TestParm "a b c"
76 call :TestParm "a b"\c
77 call :TestParm a=~`+,.{}!+b
78 call :TestParm a;b
79 call :TestParm "a;b"
80 call :TestParm a^;b
81 call :TestParm a[b]{c}(d)e
82 call :TestParm a&echo second line
83 call :TestParm a b,,,c
84 call :TestParm a==b;;c
85 call :TestParm a,,, b
86 goto :TestRem
88 :TestParm
89 echo '%1', '%2', '%3'
90 goto :eof
92 :TestRem
93 echo ------------ Testing rem ------------
94 rem Hello
95 rem Hello
96 rem Hello || foo
97 rem echo lol
98 rem echo foo & echo bar
99 rem @tab@ Hello
100 rem@tab@ Hello
101 rem@tab@echo foo & echo bar
102 @echo on
103 rem Hello
104 rem Hello
105 rem Hello || foo
106 rem echo lol
107 rem echo foo & echo bar
108 rem @tab@ Hello
109 rem@tab@ Hello
110 rem@tab@echo foo & echo bar
111 @echo off
113 echo ------------ Testing redirection operators ------------
114 mkdir foobar & cd foobar
115 echo --- stdout redirection
116 echo foo>foo
117 type foo
118 echo foo 1> foo
119 type foo
120 echo foo@tab@1> foo
121 type foo
122 echo foo 1>@tab@foo
123 type foo
124 echo foo@tab@1>@tab@foo
125 type foo
126 echo foo7 7> foo
127 type foo
128 echo foo9 9> foo
129 type foo
130 echo foo1> foo
131 type foo
132 echo foo11> foo
133 type foo
134 echo foo12> foo
135 type foo
136 echo foo13>"foo"
137 type foo
138 echo foo14>."\foo"
139 type foo
140 echo foo15>."\f"oo
141 type foo
142 del foo
143 echo1>foo
144 type foo
145 echo --- stdout appending
146 echo foo>foo
147 echo foo >>foo
148 type foo
149 del foo
150 echo foob >> foo
151 type foo
152 echo fooc 1>>foo
153 type foo
154 echo food1>>foo
155 type foo
156 echo food2>>"foo"
157 type foo
158 del foo
159 echo food21>>foo
160 type foo
161 del foo
162 echo foo> foo
163 echo foo7 7>> foo || (echo not supported & del foo)
164 if exist foo (type foo) else echo not supported
165 echo --- redirections within IF statements
166 if 1==1 echo foo1>bar
167 type bar & del bar
168 echo -----
169 if 1==1 (echo foo2>bar) else echo baz2>bar
170 type bar & del bar
171 if 1==1 (echo foo3) else echo baz3>bar
172 type bar || echo file does not exist, ok
173 if 1==1 (echo foo4>bar) else echo baz4>bar
174 type bar & del bar
175 if 1==0 (echo foo5>bar) else echo baz5>bar
176 type bar & del bar
177 if 1==0 (echo foo6) else echo baz6 1>bar
178 type bar & del bar
179 if 1==0 (echo foo7 1>bar) else echo baz7>bar
180 type bar & del bar
181 if 1==0 (echo foo8 1>bar) else echo baz8>bak
182 type bak
183 if 1==1 (echo foo>bar & echo baz)
184 type bar
185 if 1==1 (
186 echo foo>bar
187 echo baz
189 type bar
190 (if 1==1 (echo A) else echo B) > C
191 type C
192 (if 1==0 (echo A) else echo B) > C
193 type C
194 (if 1==0 (echo A > B) else echo C)
195 cd .. & rd /s/q foobar
197 echo ------------ Testing circumflex escape character ------------
198 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
199 echo ^hell^o, world
200 echo hell^o, world
201 echo hell^^o, world
202 echo hell^^^o, world
203 echo hello^
204 world
205 echo hello^
207 world
208 echo hello^
211 echo finished
212 mkdir foobar
213 echo baz> foobar\baz
214 type foobar\baz
215 type foobar^\baz
216 rd /s/q foobar
217 echo foo ^| echo bar
218 echo foo ^& echo bar
219 call :setError 0
220 echo bak ^&& echo baz 2> nul
221 echo %ErrorLevel%
222 echo foo ^> foo
223 echo ^<> foo
224 type foo
225 del foo
226 set WINE_FOO=oof
227 echo ff^%WINE_FOO%
228 set WINE_FOO=bar ^| baz
229 set WINE_FOO
230 rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
231 rem exits the script on windows; redirecting stdout and/or stderr doesn't help
232 echo %ErrorLevel%
233 call :setError 0
234 set WINE_FOO=bar ^^^| baz
235 set WINE_FOO
236 echo %WINE_FOO%
237 echo %ErrorLevel%
238 set WINE_FOO=
240 echo ------------ Testing 'set' ------------
241 call :setError 0
242 rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
243 for /f "delims==" %%i in ('set WINE_ba') do set %%i=
244 for /f "delims==" %%i in ('set WINE_foo') do set %%i=
245 set WINE_FOOBAR 2> nul > nul
246 echo %ErrorLevel%
247 set WINE_FOOBAR = baz
248 echo %ErrorLevel%
249 echo %WINE_FOOBAR%WINE_FOOBAR not defined
250 echo %WINE_FOOBAR %
251 set WINE_FOOBAR 2> nul
252 set WINE_FOOBAR = baz2
253 echo %ErrorLevel%
254 echo %WINE_fOObAr %
255 set WINE_FOOBAR= bar
256 echo %ErrorLevel%
257 echo %WINE_FOOBAR%
258 set WINE_FOO
259 set WINE_FOOBAR=
260 set WINE_FOOB
261 echo %WINE_FOOBAR%WINE_FOOBAR not defined
262 set WINE_FOOBAR =
263 set WINE_FOOBA 2> nul > nul
264 echo %ErrorLevel%
265 set WINE_FOO=bar
266 echo %WINE_FOO%
267 set WINE_FOO=foo
268 set WINE_BAR=bar
269 echo %WINE_FOO%%WINE_BAR%
270 set WINE_BAR=
271 set WINE_FOO=
272 set WINE_FOO=%WINE_FOO%
273 echo %WINE_FOO%WINE_FOO not defined
274 set WINE_BAZ%=bazbaz
275 set WINE_BA
276 echo %WINE_BAZ%%
277 set WINE_BAZ%=
278 echo set "WINE_FOO=bar" should not include the quotes in the variable value
279 set "WINE_FOO=bar"
280 echo %WINE_FOO%
281 set@tab@WINE_FOO=foo
282 echo %WINE_FOO%
283 set@tab@WINE_FOO=
284 echo '%WINE_FOO%'
285 set WINE_FOO=foo@space@
286 echo '%WINE_FOO%'
287 set WINE_FOO=foo@tab@
288 echo '%WINE_FOO%'
289 rem Space symbol must appear in `var`
290 set WINE_FOO=value@space@
291 echo '%WINE_FOO%'
292 rem Space symbol must NOT appear in `var`
293 set "WINE_FOO=value"@space@
294 echo '%WINE_FOO%'
295 rem Mixed examples:
296 set WINE_FOO=jim fred
297 echo '%WINE_FOO%'
298 set WINE_FOO="jim" fred
299 echo '%WINE_FOO%'
300 set "WINE_FOO=jim fred"
301 echo '%WINE_FOO%'
302 set "WINE_FOO=jim" fred
303 echo '%WINE_FOO%'
304 rem Only the final quote ends the string
305 set "WINE_FOO=apple"banana"grape"orange
306 echo '%WINE_FOO%'
307 set WINE_FOO=
309 echo ------------ Testing variable expansion ------------
310 call :setError 0
311 echo ~dp0 should be directory containing batch file
312 echo %~dp0
313 mkdir dummydir
314 cd dummydir
315 echo %~dp0
316 cd ..
317 rmdir dummydir
318 echo CD value %CD%
319 echo %%
320 echo P%
321 echo %P
322 echo %WINE_UNKNOWN%S
323 echo P%WINE_UNKNOWN%
324 echo P%WINE_UNKNOWN%S
325 echo %ERRORLEVEL
326 echo %ERRORLEVEL%
327 echo %ERRORLEVEL%%ERRORLEVEL%
328 echo %ERRORLEVEL%ERRORLEVEL%
329 echo %ERRORLEVEL%%
330 echo %ERRORLEVEL%%%
331 echo P%ERRORLEVEL%
332 echo %ERRORLEVEL%S
333 echo P%ERRORLEVEL%S
335 echo ------------ Testing variable substrings ------------
336 set WINE_VAR=qwerty
337 echo %WINE_VAR:~0,1%
338 echo %WINE_VAR:~0,3%
339 echo %WINE_VAR:~2,2%
340 echo '%WINE_VAR:~-2,3%'
341 echo '%WINE_VAR:~-2,1%'
342 echo %WINE_VAR:~2,-1%
343 echo %WINE_VAR:~2,-3%
344 echo '%WINE_VAR:~-2,-4%'
345 echo %WINE_VAR:~-3,-2%
346 set WINE_VAR=
348 echo ------------ Testing variable substitution ------------
349 echo --- in FOR variables
350 for %%i in ("A B" C) do echo %%i
351 rem check works when prefix with @
352 @for %%i in ("A B" C) do echo %%i
353 rem quotes removal
354 for %%i in ("A B" C) do echo '%%~i'
355 rem fully qualified path
356 for %%f in ("C D" E) do echo %%~ff
357 rem drive letter
358 for %%i in ("F G" H) do echo %%~di
359 rem path
360 for %%d in ("I J" K) do echo %%~pd
361 rem filename
362 for %%i in ("L M" N) do echo %%~ni
363 rem file extension
364 for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
365 rem path with short path names
366 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
367 rem file attribute
368 for %%i in ("U V" W) do echo '%%~ai'
369 echo foo> foo
370 for %%i in (foo) do echo '%%~ai'
371 for %%i in (foo) do echo '%%~zi'
372 del foo
373 rem file date/time
374 rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
375 for %%i in ("a b" c) do echo '%%~ti'
376 rem file size
377 rem Similar issues as above
378 for %%i in ("a b" c) do echo '%%~zi'
379 rem combined options
380 for %%i in ("d e" f) do echo %%~dpi
381 for %%i in ("g h" i) do echo %%~sdi
382 for %%i in ("g h" i) do echo %%~dsi
383 for %%i in ("j k" l.eh) do echo '%%~xsi'
384 for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
386 echo --- in parameters
387 for %%i in ("A B" C) do call :echoFun %%i
388 rem quotes removal
389 for %%i in ("A B" C) do call :echoFunQ %%i
390 rem fully qualified path
391 for %%f in ("C D" E) do call :echoFunF %%f
392 rem drive letter
393 for %%i in ("F G" H) do call :echoFunD %%i
394 rem path
395 for %%d in ("I J" K) do call :echoFunP %%d
396 rem filename
397 for %%i in ("L M" N) do call :echoFunN %%i
398 rem file extension
399 for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
400 rem path with short path names
401 for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
402 rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
403 rem combined options
404 for %%i in ("d e" f) do call :echoFunDP %%i
405 for %%i in ("g h" i) do call :echoFunSD %%i
406 for %%i in ("g h" i) do call :echoFunDS %%i
407 for %%i in ("j k" l.eh) do call :echoFunXS %%i
409 goto :endEchoFuns
410 :echoFun
411 echo %1
412 goto :eof
414 :echoFunQ
415 echo '%~1'
416 goto :eof
418 :echoFunF
419 echo %~f1
420 goto :eof
422 :echoFunD
423 echo %~d1
424 goto :eof
426 :echoFunP
427 echo %~p1
428 goto :eof
430 :echoFunN
431 echo %~n1
432 goto :eof
434 :echoFunX
435 echo '%~x1'
436 goto :eof
438 :echoFunS
439 rem some NT4 workaround
440 set WINE_VAR='%~s1'
441 echo %WINE_VAR%
442 set WINE_VAR=
443 goto :eof
445 :echoFunDP
446 echo %~dp1
447 goto :eof
449 :echoFunSD
450 echo %~sd1
451 goto :eof
453 :echoFunDS
454 echo %~ds1
455 goto :eof
457 :echoFunXS
458 echo '%~xs1'
459 goto :eof
460 :endEchoFuns
462 echo ------------ Testing variable delayed expansion ------------
463 rem NT4 doesn't support this
464 echo --- default mode (load-time expansion)
465 set WINE_FOO=foo
466 echo %WINE_FOO%
467 echo !WINE_FOO!
468 if %WINE_FOO% == foo (
469 set WINE_FOO=bar
470 if %WINE_FOO% == bar (echo bar) else echo foo
473 set WINE_FOO=foo
474 if %WINE_FOO% == foo (
475 set WINE_FOO=bar
476 if !WINE_FOO! == bar (echo bar) else echo foo
479 echo --- runtime (delayed) expansion mode
480 setlocal EnableDelayedExpansion
481 set WINE_FOO=foo
482 echo %WINE_FOO%
483 echo !WINE_FOO!
484 if %WINE_FOO% == foo (
485 set WINE_FOO=bar
486 if %WINE_FOO% == bar (echo bar) else echo foo
489 set WINE_FOO=foo
490 if %WINE_FOO% == foo (
491 set WINE_FOO=bar
492 if !WINE_FOO! == bar (echo bar) else echo foo
494 echo %ErrorLevel%
495 setlocal DisableDelayedExpansion
496 echo %ErrorLevel%
497 set WINE_FOO=foo
498 echo %WINE_FOO%
499 echo !WINE_FOO!
500 set WINE_FOO=
501 echo --- using /V cmd flag
502 echo @echo off> tmp.cmd
503 echo set WINE_FOO=foo>> tmp.cmd
504 echo echo %%WINE_FOO%%>> tmp.cmd
505 echo echo !WINE_FOO!>> tmp.cmd
506 echo set WINE_FOO=>> tmp.cmd
507 cmd /V:ON /C tmp.cmd
508 cmd /V:OfF /C tmp.cmd
509 del tmp.cmd
511 echo ------------ Testing conditional execution ------------
512 echo --- unconditional ampersand
513 call :setError 123 & echo foo1
514 echo bar2 & echo foo2
515 mkdir foobar & cd foobar
516 echo > foobazbar
517 cd .. & rd /s/q foobar
518 if exist foobazbar (
519 echo foobar not deleted!
520 cd ..
521 rd /s/q foobar
522 ) else echo foobar deleted
523 echo --- on success conditional and
524 call :setError 456 && echo foo3 > foo3
525 if exist foo3 (
526 echo foo3 created
527 del foo3
528 ) else echo foo3 not created
529 echo bar4 && echo foo4
530 echo --- on failure conditional or
531 call :setError 789 || echo foo5
532 echo foo6 || echo bar6 > bar6
533 if exist bar6 (
534 echo bar6 created
535 del bar6
538 echo ------------ Testing cd ------------
539 mkdir foobar
540 cd foobar
541 echo blabla > singleFile
542 dir /b
543 echo Current dir: %CD%
545 cd ..
547 cd foobar@space@
549 cd ..
551 cd @space@foobar
553 cd..
555 cd foobar
556 cd..@space@
558 if not exist foobar (cd ..)
559 cd foobar
560 cd@tab@..@tab@@space@@tab@
562 if not exist foobar (cd ..)
563 cd foobar
564 mkdir "bar bak"
565 cd "bar bak"
567 cd ..
568 cd ".\bar bak"
570 cd ..
571 cd .\"bar bak"
573 cd ..
574 cd bar bak
576 cd "bar bak@space@"@tab@@space@
578 cd ..\..
580 rd /Q/s foobar
581 mkdir foobar
582 cd /d@tab@foobar
584 cd ..
585 rd /q/s foobar
587 echo ------------ Testing type ------------
588 echo bar> foobaz
589 @echo on
590 type foobaz
591 echo ---
592 @echo off
593 type foobaz@tab@
594 echo ---1
595 type ."\foobaz"
596 echo ---2
597 type ".\foobaz"
598 echo ---3
599 del foobaz
601 echo ------------ Testing NUL ------------
602 md foobar & cd foobar
603 rem NUL file (non) creation + case insensitivity
604 rem Note: "if exist" does not work with NUL, so to check for file existence we use a kludgy workaround
605 echo > bar
606 echo foo > NUL
607 dir /b /a-d
608 echo foo > nul
609 dir /b /a-d
610 echo foo > NuL
611 @tab@dir /b@tab@/a-d
612 del bar
613 rem NUL not special everywhere
614 call :setError 123
615 echo NUL> foo
616 if not exist foo (echo foo should have been created) else (
617 type foo
618 del foo
620 rem Empty file creation
621 copy nul foo > nul
622 if exist foo (
623 echo foo created
624 del foo
625 type foo
626 ) else (
627 echo ***
629 echo 1234 >a.a
630 copy a.a+NUL b.b >nul
631 call :CheckFileSize a.a 7 b.b 8
632 copy NUL+a.a b.b >nul
633 call :CheckFileSize a.a 7 b.b 8
634 mkdir subdir
635 copy a.a+NUL subdir\ >nul
636 call :CheckFileSize a.a 7 subdir\a.a 8
637 del subdir\a.a
638 cd subdir
639 copy ..\a.a NUL >nul
640 if exist a.a echo Failed
641 cd ..
642 rd subdir /s /q
643 del a.a b.b
644 cd .. & rd foobar /s /q
646 echo ------------ Testing if/else ------------
647 echo --- if/else should work with blocks
648 if 0 == 0 (
649 echo if seems to work
650 ) else (
651 echo if seems to be broken
653 if 1 == 0 (
654 echo else seems to be broken
655 ) else (
656 echo else seems to work
658 if /c==/c (
659 echo if seems not to detect /c as parameter
660 ) else (
661 echo parameter detection seems to be broken
664 echo --- case sensitivity with and without /i option
665 if bar==BAR echo if does not default to case sensitivity
666 if not bar==BAR echo if seems to default to case sensitivity
667 if /i foo==FOO echo if /i seems to work
668 if /i not foo==FOO echo if /i seems to be broken
669 if /I foo==FOO echo if /I seems to work
670 if /I not foo==FOO echo if /I seems to be broken
672 echo --- string comparisons
673 if abc == abc (echo equal) else echo non equal
674 if abc =="abc" (echo equal) else echo non equal
675 if "abc"== abc (echo equal) else echo non equal
676 if "abc"== "abc" (echo equal) else echo non equal
678 echo --- tabs handling
679 if@tab@1==1 echo doom
680 if @tab@1==1 echo doom
681 if 1==1 (echo doom) else@tab@echo quake
682 if@tab@not @tab@1==@tab@0 @tab@echo lol
683 if 1==0@tab@(echo doom) else echo quake
684 if 1==0 (echo doom)@tab@else echo quake
685 if 1==0 (echo doom) else@tab@echo quake
687 echo --- comparison operators
688 rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
689 echo ------ for strings
690 rem NT4 stops processing of the whole batch file as soon as it finds a
691 rem comparison operator non fully uppercased, such as lss instead of LSS, so we
692 rem can't test those here.
693 if LSS LSS LSSfoo (echo LSS string can be used as operand for LSS comparison)
694 if LSS LSS LSS (echo bar)
695 if 1.1 LSS 1.10 (echo floats are handled as strings)
696 if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes are handled as strings
697 if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
698 if /i foo LSS FoOc echo if /i seems to work for LSS
699 if /I not foo LSS FOOb echo if /I seems to be broken for LSS
700 set WINE_STR_PARMS=A B AB BA AA
701 for %%i in (%WINE_STR_PARMS%) do (
702 for %%j in (%WINE_STR_PARMS%) do (
703 call :LSStest %%i %%j))
704 if b LSS B (echo b LSS B) else echo NT4
705 if /I b LSS B echo b LSS B insensitive
706 if b LSS A echo b LSS A
707 if /I b LSS A echo b LSS A insensitive
708 if a LSS B (echo a LSS B) else echo NT4
709 if /I a LSS B echo a LSS B insensitive
710 if A LSS b echo A LSS b
711 if /I A LSS b echo A LSS b insensitive
712 for %%i in (%WINE_STR_PARMS%) do (
713 for %%j in (%WINE_STR_PARMS%) do (
714 call :LEQtest %%i %%j))
715 if b LEQ B (echo b LEQ B) else echo NT4
716 if /I b LEQ B echo b LEQ B insensitive
717 if b LEQ A echo b LEQ A
718 if /I b LEQ A echo b LEQ A insensitive
719 if a LEQ B (echo a LEQ B) else echo NT4
720 if /I a LEQ B echo a LEQ B insensitive
721 if A LEQ b echo A LEQ b
722 if /I A LEQ b echo A LEQ b insensitive
723 for %%i in (%WINE_STR_PARMS%) do (
724 for %%j in (%WINE_STR_PARMS%) do (
725 call :EQUtest %%i %%j))
726 if /I A EQU a echo A EQU a insensitive
727 for %%i in (%WINE_STR_PARMS%) do (
728 for %%j in (%WINE_STR_PARMS%) do (
729 call :NEQtest %%i %%j))
730 for %%i in (%WINE_STR_PARMS%) do (
731 for %%j in (%WINE_STR_PARMS%) do (
732 call :GEQtest %%i %%j))
733 for %%i in (%WINE_STR_PARMS%) do (
734 for %%j in (%WINE_STR_PARMS%) do (
735 call :GTRtest %%i %%j))
736 echo ------ for numbers
737 if -1 LSS 1 (echo negative numbers handled)
738 if not -1 LSS -10 (echo negative numbers handled)
739 if not 9 LSS 010 (echo octal handled)
740 if not -010 LSS -8 (echo also in negative form)
741 if 4 LSS 0x5 (echo hexa handled)
742 if not -1 LSS -0x1A (echo also in negative form)
743 if 11 LSS 101 (echo 11 LSS 101)
744 set WINE_INT_PARMS=0 1 10 9
745 for %%i in (%WINE_INT_PARMS%) do (
746 for %%j in (%WINE_INT_PARMS%) do (
747 call :LSStest %%i %%j))
748 for %%i in (%WINE_INT_PARMS%) do (
749 for %%j in (%WINE_INT_PARMS%) do (
750 call :LEQtest %%i %%j))
751 for %%i in (%WINE_INT_PARMS%) do (
752 for %%j in (%WINE_INT_PARMS%) do (
753 call :EQUtest %%i %%j))
754 if 011 EQU 9 (echo octal ok)
755 if 0xA1 EQU 161 (echo hexa ok)
756 if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
757 if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
758 for %%i in (%WINE_INT_PARMS%) do (
759 for %%j in (%WINE_INT_PARMS%) do (
760 call :NEQtest %%i %%j))
761 for %%i in (%WINE_INT_PARMS%) do (
762 for %%j in (%WINE_INT_PARMS%) do (
763 call :GEQtest %%i %%j))
764 for %%i in (%WINE_INT_PARMS%) do (
765 for %%j in (%WINE_INT_PARMS%) do (
766 call :GTRtest %%i %%j))
767 echo ------ for numbers and stringified numbers
768 if not "1" EQU 1 (echo strings and integers not equal) else echo foo
769 if not 1 EQU "1" (echo strings and integers not equal) else echo foo
770 if '1' EQU 1 echo '1' EQU 1
771 if 1 EQU '1' echo 1 EQU '1'
772 if not "1" GEQ 1 (echo foo) else echo bar
773 if "10" GEQ "1" echo "10" GEQ "1"
774 if '1' GEQ 1 (echo '1' GEQ 1) else echo NT4
775 if 1 GEQ "1" echo 1 GEQ "1"
776 if "1" GEQ "1" echo "1" GEQ "1"
777 if '1' GEQ "1" echo '1' GEQ "1"
778 if "10" GEQ "1" echo "10" GEQ "1"
779 if not 1 GEQ '1' (echo non NT4) else echo 1 GEQ '1'
780 for %%i in ("1" '1') do call :GEQtest %%i '1'
781 if "10" GEQ '1' (echo "10" GEQ '1') else echo foo
782 if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
783 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
784 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
785 if "10" GEQ "10" (echo "10" GEQ "10")
786 goto :endIfCompOpsSubroutines
788 rem IF subroutines helpers
789 :LSStest
790 if %1 LSS %2 echo %1 LSS %2
791 goto :eof
792 :LEQtest
793 if %1 LEQ %2 echo %1 LEQ %2
794 goto :eof
795 :EQUtest
796 if %1 EQU %2 echo %1 EQU %2
797 goto :eof
798 :NEQtest
799 if %1 NEQ %2 echo %1 NEQ %2
800 goto :eof
801 :GEQtest
802 if %1 GEQ %2 echo %1 GEQ %2
803 goto :eof
804 :GTRtest
805 if %1 GTR %2 echo %1 GTR %2
806 goto :eof
808 :endIfCompOpsSubroutines
809 set WINE_STR_PARMS=
810 set WINE_INT_PARMS=
812 echo ------------ Testing for ------------
813 echo --- plain FOR
814 for %%i in (A B C) do echo %%i
815 for %%i in (A B C) do echo %%I
816 for %%i in (A B C) do echo %%j
817 for %%i in (A B C) do call :forTestFun1 %%i
818 for %%i in (1,4,1) do echo %%i
819 for %%i in (A, B,C) do echo %%i
820 for %%i in (X) do echo %%i
821 for@tab@%%i in (X2) do echo %%i
822 for %%i in@tab@(X3) do echo %%i
823 for %%i in (@tab@ foo@tab@) do echo %%i
824 for@tab@ %%i in@tab@(@tab@M) do echo %%i
825 for %%i@tab@in (X)@tab@do@tab@echo %%i
826 for@tab@ %%j in@tab@(@tab@M, N, O@tab@) do echo %%j
827 for %%i in (`echo A B`) do echo %%i
828 for %%i in ('echo A B') do echo %%i
829 for %%i in ("echo A B") do echo %%i
830 for %%i in ("A B" C) do echo %%i
831 goto :endForTestFun1
832 :forTestFun1
833 echo %1
834 goto :eof
835 :endForTestFun1
836 echo --- imbricated FORs
837 for %%i in (X) do (
838 for %%j in (Y) do (
839 echo %%i %%j))
840 for %%i in (X) do (
841 for %%I in (Y) do (
842 echo %%i %%I))
843 for %%i in (A B) do (
844 for %%j in (C D) do (
845 echo %%i %%j))
846 for %%i in (A B) do (
847 for %%j in (C D) do (
848 call :forTestFun2 %%i %%j ))
849 goto :endForTestFun2
850 :forTestFun2
851 echo %1 %2
852 goto :eof
853 :endForTestFun2
854 mkdir foobar & cd foobar
855 mkdir foo
856 mkdir bar
857 mkdir baz
858 echo > bazbaz
859 echo --- basic wildcards
860 for %%i in (ba*) do echo %%i
861 echo --- for /d
862 for /d %%i in (baz foo bar) do echo %%i 2>&1
863 rem Confirm we don't match files:
864 for /d %%i in (bazb*) do echo %%i 2>&1
865 for /d %%i in (bazb2*) do echo %%i 2>&1
866 rem Show we pass through non wildcards
867 for /d %%i in (PASSED) do echo %%i
868 for /d %%i in (xxx) do (
869 echo %%i - Should be xxx
870 echo Expected second line
872 rem Show we issue no messages on failures
873 for /d %%i in (FAILED?) do echo %%i 2>&1
874 for /d %%i in (FAILED?) do (
875 echo %%i - Unexpected!
876 echo FAILED Unexpected second line
878 for /d %%i in (FAILED*) do echo %%i 2>&1
879 for /d %%i in (FAILED*) do (
880 echo %%i - Unexpected!
881 echo FAILED Unexpected second line
883 rem FIXME can't test wildcard expansion here since it's listed in directory
884 rem order, and not in alphabetic order.
885 rem Proper testing would need a currently missing "sort" program implementation.
886 rem for /d %%i in (ba*) do echo %%i>> tmp
887 rem sort < tmp
888 rem del tmp
889 rem for /d %%i in (?a*) do echo %%i>> tmp
890 rem sort < tmp
891 rem del tmp
892 rem for /d %%i in (*) do echo %%i>> tmp
893 rem sort < tmp
894 rem del tmp
895 echo > baz\bazbaz
896 goto :TestForR
898 :SetExpected
899 del temp.bat 2>nul
900 call :WriteLine set WINE_found=N
901 for /l %%i in (1,1,%WINE_expectedresults%) do (
902 call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%1" set WINE_found=Y
903 call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
904 call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
906 call :WriteLine echo Got unexpected result: "%%%%1"
907 goto :eof
909 :WriteLine
910 echo %*>> temp.bat
911 goto :EOF
913 :ValidateExpected
914 del temp.bat 2>nul
915 for /l %%i in (1,1,%WINE_expectedresults%) do (
916 call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
918 call temp.bat
919 del temp.bat 2>nul
920 goto :eof
922 :TestForR
923 rem %CD% does not tork on NT4 so use the following workaround
924 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
926 echo --- for /R
927 echo Plain directory enumeration
928 set WINE_expectedresults=4
929 set WINE_expectedresults.1=%WINE_CURDIR%\.
930 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
931 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
932 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
933 call :SetExpected
934 for /R %%i in (.) do call temp.bat %%i
935 call :ValidateExpected
937 echo Plain directory enumeration from provided root
938 set WINE_expectedresults=4
939 set WINE_expectedresults.1=%WINE_CURDIR%\.
940 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
941 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
942 set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
943 if "%CD%"=="" goto :SkipBrokenNT4
944 call :SetExpected
945 for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat %%i
946 call :ValidateExpected
947 :SkipBrokenNT4
949 echo File enumeration
950 set WINE_expectedresults=2
951 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
952 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
953 call :SetExpected
954 for /R %%i in (baz*) do call temp.bat %%i
955 call :ValidateExpected
957 echo File enumeration from provided root
958 set WINE_expectedresults=2
959 set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
960 set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
961 call :SetExpected
962 for /R %%i in (baz*) do call temp.bat %%i
963 call :ValidateExpected
965 echo Mixed enumeration
966 set WINE_expectedresults=6
967 set WINE_expectedresults.1=%WINE_CURDIR%\.
968 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
969 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
970 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
971 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
972 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
973 call :SetExpected
974 for /R %%i in (. baz*) do call temp.bat %%i
975 call :ValidateExpected
977 echo Mixed enumeration from provided root
978 set WINE_expectedresults=6
979 set WINE_expectedresults.1=%WINE_CURDIR%\.
980 set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
981 set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
982 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
983 set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
984 set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
985 call :SetExpected
986 for /R %%i in (. baz*) do call temp.bat %%i
987 call :ValidateExpected
989 echo With duplicates enumeration
990 set WINE_expectedresults=12
991 set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
992 set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
993 set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
994 set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
995 set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
996 set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
997 set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
998 set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
999 set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
1000 set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
1001 set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
1002 set WINE_expectedresults.12=%WINE_CURDIR%\fred
1003 call :SetExpected
1004 for /R %%i in (baz* bazbaz fred ba*) do call temp.bat %%i
1005 call :ValidateExpected
1007 echo Strip missing wildcards, keep unwildcarded names
1008 set WINE_expectedresults=6
1009 set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
1010 set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
1011 set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
1012 set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
1013 set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
1014 set WINE_expectedresults.6=%WINE_CURDIR%\jim
1015 call :SetExpected
1016 for /R %%i in (baz* fred* jim) do call temp.bat %%i
1017 call :ValidateExpected
1019 echo for /R passed
1020 echo --- Complex wildcards unix and windows slash
1021 cd ..
1022 echo Windows slashs, valid path
1023 for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
1024 for %%f in (foobar\baz\*) do echo WC : %%f
1025 echo Windows slashs, invalid path
1026 for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
1027 for %%f in (foobar\jim\*) do echo WC : %%f
1028 echo Unix slashs, valid path
1029 for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
1030 for %%f in (foobar/baz/*) do echo WC : %%f
1031 echo Unix slashs, invalid path
1032 for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
1033 for %%f in (foobar/jim/*) do echo WC : %%f
1034 echo Done
1035 rd /s/Q foobar
1036 echo --- for /L
1037 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
1038 for /L %%i in (1,2,0) do echo %%i
1039 for@tab@/L %%i in (1,2,0) do echo %%i
1040 for /L %%i in (1,2,6) do echo %%i
1041 for /l %%i in (1 ,2,6) do echo %%i
1042 for /L %%i in (a,2,3) do echo %%i
1043 for /L %%i in (1,2,-1) do echo %%i
1044 for /L %%i in (-4,-1,-1) do echo %%i
1045 for /L %%i in (1,-2,-2) do echo %%i
1046 for /L %%i in (1,2,a) do echo %%i
1047 echo ErrorLevel %ErrorLevel%
1048 for /L %%i in (1,a,b) do echo %%i
1049 echo ErrorLevel %ErrorLevel%
1050 rem Test boundaries
1051 for /l %%i in (1,1,4) do echo %%i
1052 for /l %%i in (1,2,4) do echo %%i
1053 for /l %%i in (4,-1,1) do echo %%i
1054 for /l %%i in (4,-2,1) do echo %%i
1055 for /l %%i in (1,-1,4) do echo %%i
1056 for /l %%i in (4,1,1) do echo %%i
1057 for /L %%i in (a,2,b) do echo %%i
1058 for /L %%i in (1,1,1) do echo %%i
1059 for /L %%i in (1,-2,-1) do echo %%i
1060 for /L %%i in (-1,-1,-1) do echo %%i
1061 for /L %%i in (1,2, 3) do echo %%i
1062 rem Test zero iteration skips the body of the for
1063 for /L %%i in (2,2,1) do (
1064 echo %%i
1065 echo FAILED
1067 echo --- set /a
1068 goto :testseta
1070 Rem Ideally for /f can be used rather than building a command to execute
1071 rem but that does not work on NT4
1072 :checkenvvars
1073 if "%1"=="" goto :eof
1074 call :executecmd set wine_result=%%%1%%
1075 if "%wine_result%"=="%2" (
1076 echo %1 correctly %2
1077 ) else echo ERROR: %1 incorrectly %wine_result% [%2]
1078 set %1=
1079 shift
1080 shift
1081 rem shift
1082 goto :checkenvvars
1083 :executecmd
1085 goto :eof
1087 :testseta
1088 rem No output when using "set expr" syntax, unless in interactive mode
1089 rem Need to use "set envvar=expr" to use in a batch script
1090 echo ------ individual operations
1091 set WINE_foo=0
1092 set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
1093 set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
1094 set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
1095 set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
1096 set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
1097 set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
1098 set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
1099 set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
1100 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
1101 set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
1102 set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
1103 set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
1104 set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
1105 set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
1106 set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
1107 set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
1108 set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
1109 set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
1110 set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
1111 set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
1112 set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
1113 set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
1114 set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
1115 set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
1116 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1117 set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
1118 set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
1119 set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
1120 set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
1121 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1122 set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
1123 set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
1124 set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
1125 set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
1126 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1127 set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
1128 set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
1129 set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
1130 echo ------ precedence and grouping
1131 set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
1132 set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
1133 set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
1134 set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
1135 set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
1136 set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
1137 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
1138 set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
1139 echo ------ octal and hexadecimal
1140 set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
1141 set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
1142 set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
1143 set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
1144 echo ------ variables
1145 set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
1146 set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
1147 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
1148 set WINE_bar=3
1149 set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
1150 set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
1151 set WINE_bar=4
1152 set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
1153 set WINE_bar=4
1154 set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
1155 set WINE_bar=-7
1156 set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
1157 set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
1158 set WINE_bar=1
1159 set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
1160 set WINE_bar=4
1161 set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
1162 set WINE_bar=1
1163 set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
1164 set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1165 set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
1166 set WINE_baz=4
1167 set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
1168 echo --- quotes
1169 set /a WINE_foo=1
1170 call :checkenvvars WINE_foo 1
1171 set /a "WINE_foo=1"
1172 call :checkenvvars WINE_foo 1
1173 set /a WINE_foo=1,WINE_bar=2
1174 call :checkenvvars WINE_foo 1 WINE_bar 2
1175 set /a "WINE_foo=1,WINE_bar=2"
1176 call :checkenvvars WINE_foo 1 WINE_bar 2
1177 set /a "WINE_foo=1","WINE_bar=2"
1178 call :checkenvvars WINE_foo 1 WINE_bar 2
1179 set /a ""WINE_foo=1","WINE_bar=2""
1180 call :checkenvvars WINE_foo 1 WINE_bar 2
1181 set /a WINE_foo=1,WINE_bar=2,WINE_baz=3
1182 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1183 set /a "WINE_foo=1,WINE_bar=2,WINE_baz=3"
1184 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1185 set /a "WINE_foo=1","WINE_bar=2","WINE_baz=3"
1186 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1187 set /a ""WINE_foo=1","WINE_bar=2","WINE_baz=3""
1188 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1189 set /a ""WINE_foo=1","WINE_bar=2"","WINE_baz=3"
1190 call :checkenvvars WINE_foo 1 WINE_bar 2 WINE_baz 3
1191 set /a """"""WINE_foo=1""""""
1192 call :checkenvvars WINE_foo 1
1193 set /a """"""WINE_foo=1","WINE_bar=5""","WINE_baz=2""
1194 call :checkenvvars WINE_foo 1 WINE_bar 5 WINE_baz 2
1195 set /a WINE_foo="3"+"4"+"5+6"
1196 call :checkenvvars WINE_foo 18
1197 set WINE_foo=3
1198 set /a WINE_bar="WINE_""foo"+4
1199 call :checkenvvars WINE_foo 3 WINE_bar 7
1200 echo --- whitespace are ignored between double char operators
1201 set WINE_foo=4
1202 set WINE_bar=5
1203 set /a WINE_foo + = 6
1204 set /a WINE_bar * = WINE_foo
1205 call :checkenvvars WINE_foo 10 WINE_bar 50
1206 set WINE_foo=4
1207 set WINE_bar=5
1208 set /a WINE_foo + = "6 < < 7"
1209 set /a WINE_bar * = WINE_foo + WINE_foo
1210 call :checkenvvars WINE_foo 772 WINE_bar 7720
1211 set /a WINE_foo=6 7
1212 set /a WINE_ var1=8
1213 set WINE_foo=
1214 echo --- invalid operator sequence
1215 set WINE_foo=4
1216 set /a =4
1217 set /a *=4
1218 set /a ^>=4"
1219 set /a ^<=4"
1220 set /a WINE_foo^>^<=4
1221 echo %WINE_foo%
1222 set /a WINE_foo^>^>^>=4
1223 echo %WINE_foo%
1224 echo ----- negative prefix
1225 set /a WINE_foo=-1
1226 call :checkenvvars WINE_foo -1
1227 set /a WINE_foo=--1
1228 call :checkenvvars WINE_foo 1
1229 set /a WINE_foo=3--3
1230 call :checkenvvars WINE_foo 6
1231 set /a WINE_foo=3---3
1232 call :checkenvvars WINE_foo 0
1233 set /a WINE_foo=3----3
1234 call :checkenvvars WINE_foo 6
1235 set /a WINE_foo=-~1
1236 call :checkenvvars WINE_foo 2
1237 set /a WINE_foo=~-1
1238 call :checkenvvars WINE_foo 0
1239 set /a WINE_foo=3+-~1
1240 call :checkenvvars WINE_foo 5
1241 set /a WINE_foo=3+~-1
1242 call :checkenvvars WINE_foo 3
1243 echo ----- assignment tests involving the end destination
1244 set WINE_foo=3
1245 set /a WINE_foo+=3+(WINE_foo=4)
1246 call :checkenvvars WINE_foo 11
1247 set WINE_foo=2
1248 set /a WINE_bar=3+(WINE_foo=6)
1249 call :checkenvvars WINE_foo 6 WINE_bar 9
1250 set WINE_foo=2
1251 set /a WINE_bar=3+(WINE_foo=6,WINE_baz=7)
1252 call :checkenvvars WINE_foo 6 WINE_bar 10 WINE_baz 7
1253 set WINE_foo=2
1254 set /a WINE_bar=WINE_foo=7
1255 call :checkenvvars WINE_foo 7 WINE_bar 7
1256 echo ----- equal precedence on stack
1257 rem Unary - don't reduce if precedence is equal
1258 set /a WINE_foo=!!1
1259 call :checkenvvars WINE_foo 1
1260 set /a WINE_foo=!!0
1261 call :checkenvvars WINE_foo 0
1262 set /a WINE_foo=~~1
1263 call :checkenvvars WINE_foo 1
1264 set /a WINE_foo=~~0
1265 call :checkenvvars WINE_foo 0
1266 set /a WINE_foo=--1
1267 call :checkenvvars WINE_foo 1
1268 set /a WINE_foo=+-1
1269 call :checkenvvars WINE_foo -1
1270 set /a WINE_foo=-+1
1271 call :checkenvvars WINE_foo -1
1272 set /a WINE_foo=++1
1273 call :checkenvvars WINE_foo 1
1274 set /a WINE_foo=!~1
1275 call :checkenvvars WINE_foo 0
1276 set /a WINE_foo=~!1
1277 call :checkenvvars WINE_foo -1
1278 set /a WINE_foo=!-1
1279 call :checkenvvars WINE_foo 0
1280 set /a WINE_foo=-!1
1281 call :checkenvvars WINE_foo 0
1282 set /a WINE_foo=!-0
1283 call :checkenvvars WINE_foo 1
1284 set /a WINE_foo=-!0
1285 call :checkenvvars WINE_foo -1
1286 rem Aritmatic - Reduce if precedence is equal
1287 set /a WINE_foo=10*5/2
1288 call :checkenvvars WINE_foo 25
1289 set /a WINE_foo=5/2*10
1290 call :checkenvvars WINE_foo 20
1291 set /a WINE_foo=10/5/2
1292 call :checkenvvars WINE_foo 1
1293 set /a WINE_foo=5%%2*4
1294 call :checkenvvars WINE_foo 4
1295 set /a WINE_foo=10-5+2
1296 call :checkenvvars WINE_foo 7
1297 set /a WINE_foo=1^<^<4^>^>1
1298 call :checkenvvars WINE_foo 8
1299 rem Assignment - don't reduce if precedence is equal
1300 set /a WINE_foo=5
1301 set /a WINE_bar=WINE_foo=6
1302 call :checkenvvars WINE_foo 6 WINE_bar 6
1304 echo --- for /F
1305 mkdir foobar & cd foobar
1306 echo ------ string argument
1307 rem NT4 does not support usebackq
1308 for /F %%i in ("a b c") do echo %%i
1309 for /f usebackq %%i in ('a b c') do echo %%i>output_file
1310 if not exist output_file (echo no output) else (type output_file & del output_file)
1311 for /f %%i in ("a ") do echo %%i
1312 for /f usebackq %%i in ('a ') do echo %%i>output_file
1313 if not exist output_file (echo no output) else (type output_file & del output_file)
1314 for /f %%i in ("a") do echo %%i
1315 for /f usebackq %%i in ('a') do echo %%i>output_file
1316 if not exist output_file (echo no output) else (type output_file & del output_file)
1317 fOr /f %%i in (" a") do echo %%i
1318 for /f usebackq %%i in (' a') do echo %%i>output_file
1319 if not exist output_file (echo no output) else (type output_file & del output_file)
1320 for /f %%i in (" a ") do echo %%i
1321 for /f usebackq %%i in (' a ') do echo %%i>output_file
1322 if not exist output_file (echo no output) else (type output_file & del output_file)
1323 echo ------ fileset argument
1324 echo --------- basic blank handling
1325 echo a b c>foo
1326 for /f %%i in (foo) do echo %%i
1327 echo a >foo
1328 for /f %%i in (foo) do echo %%i
1329 echo a>foo
1330 for /f %%i in (foo) do echo %%i
1331 echo a>foo
1332 for /f %%i in (foo) do echo %%i
1333 echo a >foo
1334 for /f %%i in (foo) do echo %%i
1335 echo. > foo
1336 for /f %%i in (foo) do echo %%i
1337 echo. >> foo
1338 echo b > foo
1339 for /f %%i in (foo) do echo %%i
1340 echo --------- multi-line with empty lines
1341 echo a Z f> foo
1342 echo. >> foo
1343 echo.>> foo
1344 echo b bC>> foo
1345 echo c>> foo
1346 echo. >> foo
1347 for /f %%b in (foo) do echo %%b
1348 echo --------- multiple files
1349 echo q w > bar
1350 echo.>> bar
1351 echo kkk>>bar
1352 for /f %%k in (foo bar) do echo %%k
1353 for /f %%k in (bar foo) do echo %%k
1354 echo ------ command argument
1355 rem Not implemented on NT4, need to skip it as no way to get output otherwise
1356 if "%CD%"=="" goto :SkipFORFcmdNT4
1357 for /f %%i in ('echo.Passed1') do echo %%i
1358 for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
1359 for /f usebackq %%i in (`echo.Passed3`) do echo %%i
1360 goto :ContinueFORF
1361 :SkipFORFcmdNT4
1362 for /l %%i in (1,1,3) do echo Missing functionality - Broken%%i
1363 :ContinueFORF
1364 rem FIXME: Rest not testable right now in wine: not implemented and would need
1365 rem preliminary grep-like program implementation (e.g. like findstr or fc) even
1366 rem for a simple todo_wine test
1367 rem (for /f "usebackq" %%i in (`echo z a b`) do echo %%i) || echo not supported
1368 rem (for /f usebackq %%i in (`echo z a b`) do echo %%i) || echo not supported
1369 echo ------ eol option
1370 if "%CD%"=="" goto :SkipFORFeolNT4
1371 echo Line one>foo
1372 echo and Line two>>foo
1373 echo Line three>>foo
1374 for /f "eol=L" %%i in (foo) do echo %%i
1375 for /f "eol=a" %%i in (foo) do echo %%i
1376 del foo
1377 goto :ContinueFORFeol
1378 :SkipFORFeolNT4
1379 for /l %%i in (1,1,3) do echo Broken NT4 functionality%%i
1380 :ContinueFORFeol
1381 for /f "eol=@" %%i in (" ad") do echo %%i
1382 for /f "eol=@" %%i in (" z@y") do echo %%i
1383 for /f "eol=|" %%i in ("a|d") do echo %%i
1384 for /f "eol=@" %%i in ("@y") do echo %%i > output_file
1385 if not exist output_file (echo no output) else (del output_file)
1386 for /f "eol==" %%i in ("=y") do echo %%i > output_file
1387 if not exist output_file (echo no output) else (del output_file)
1388 echo ------ delims option
1389 for /f "delims=|" %%i in ("a|d") do echo %%i
1390 for /f "delims=|" %%i in ("a |d") do echo %%i
1391 for /f "delims=|" %%i in ("a d|") do echo %%i
1392 for /f "delims=| " %%i in ("a d|") do echo %%i
1393 for /f "delims==" %%i in ("C r=d|") do echo %%i
1394 for /f "delims=" %%i in ("foo bar baz") do echo %%i
1395 for /f "delims=" %%i in ("c:\foo bar baz\..") do echo %%~fi
1396 echo ------ skip option
1397 echo a > foo
1398 echo b >> foo
1399 echo c >> foo
1400 for /f "skip=2" %%i in (foo) do echo %%i
1401 for /f "skip=3" %%i in (foo) do echo %%i > output_file
1402 if not exist output_file (echo no output) else (del output_file)
1403 for /f "skip=4" %%i in (foo) do echo %%i > output_file
1404 if not exist output_file (echo no output) else (del output_file)
1405 for /f "skip=02" %%i in (foo) do echo %%i
1406 for /f "skip=0x2" %%i in (foo) do echo %%i
1407 for /f "skip=1" %%i in ("skipme") do echo %%i > output_file
1408 if not exist output_file (echo no output) else (del output_file)
1409 echo ------ tokens= option
1410 rem Basic
1411 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
1412 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
1413 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
1414 rem Show * means the rest
1415 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
1416 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
1417 rem Show * means the rest (not tokenized and rebuilt)
1418 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
1419 rem Order is irrelevant
1420 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
1421 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
1422 rem Duplicates are ignored
1423 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
1424 rem Large tokens are allowed
1425 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
1426 rem Show tokens blanked in advance regardless of uniqueness of requested tokens
1427 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
1428 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
1429 rem Show No wrapping from z to A BUT wrapping sort of occurs Z to a occurs
1430 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
1431 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
1432 rem Show negative ranges have no effect
1433 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
1434 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
1435 rem Show duplicates stop * from working
1436 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
1437 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
1438 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
1439 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
1440 cd ..
1441 rd /s/q foobar
1443 echo ------------ Testing del /a ------------
1444 del /f/q *.test > nul
1445 echo r > r.test
1446 attrib +r r.test
1447 echo not-r > not-r.test
1449 if not exist not-r.test echo not-r.test not found before delete, bad
1450 del /a:-r *.test
1451 if not exist not-r.test echo not-r.test not found after delete, good
1453 if not exist r.test echo r.test not found before delete, bad
1454 if exist r.test echo r.test found before delete, good
1455 del /a:r *.test
1456 if not exist r.test echo r.test not found after delete, good
1457 if exist r.test echo r.test found after delete, bad
1459 echo ------------ Testing del /q ------------
1460 mkdir del_q_dir
1461 cd del_q_dir
1462 echo abc > file1
1463 echo abc > file2.dat
1464 rem If /q doesn't work, cmd will prompt and the test case should hang
1465 del /q * > nul
1466 for %%a in (1 2.dat) do if exist file%%a echo del /q * failed on file%%a
1467 for %%a in (1 2.dat) do if not exist file%%a echo del /q * succeeded on file%%a
1468 cd ..
1469 rmdir del_q_dir
1471 echo ------------ Testing del /s ------------
1472 mkdir "foo bar"
1473 cd "foo bar"
1474 mkdir "foo:"
1475 echo hi > file1.dat
1476 echo there > file2.dat
1477 echo bub > file3.dat
1478 echo bye > "file with spaces.dat"
1479 cd ..
1480 del /s file1.dat > nul
1481 del file2.dat /s > nul
1482 del "file3.dat" /s > nul
1483 del "file with spaces.dat" /s > nul
1484 cd "foo bar"
1485 for %%f in (1 2 3) do if exist file%%f.dat echo Del /s failed on file%%f
1486 for %%f in (1 2 3) do if exist file%%f.dat del file%%f.dat
1487 if exist "file with spaces.dat" echo Del /s failed on "file with spaces.dat"
1488 if exist "file with spaces.dat" del "file with spaces.dat"
1489 rmdir "foo:"
1490 cd ..
1491 rmdir "foo bar"
1493 echo ------------ Testing rename ------------
1494 mkdir foobar & cd foobar
1495 echo --- ren and rename are synonymous
1496 echo > foo
1497 rename foo bar
1498 if exist foo echo foo should be renamed!
1499 if exist bar echo foo renamed to bar
1500 ren bar foo
1501 if exist bar echo bar should be renamed!
1502 if exist foo echo bar renamed to foo
1503 echo --- name collision
1504 echo foo>foo
1505 echo bar>bar
1506 ren foo bar 2> nul
1507 type foo
1508 type bar
1509 rem no-op
1510 ren foo foo
1511 mkdir baz
1512 ren foo baz\abc
1513 echo --- rename read-only files
1514 echo > file1
1515 attrib +r file1
1516 ren file1 file2
1517 if not exist file1 (
1518 if exist file2 (
1519 echo read-only file renamed
1521 ) else (
1522 echo read-only file not renamed!
1524 echo --- rename directories
1525 mkdir rep1
1526 ren rep1 rep2
1527 if not exist rep1 (
1528 if exist rep2 (
1529 echo dir renamed
1532 attrib +r rep2
1533 ren rep2 rep1
1534 if not exist rep2 (
1535 if exist rep1 (
1536 echo read-only dir renamed
1539 echo --- rename in other directory
1540 if not exist baz\abc (
1541 echo rename impossible in other directory
1542 if exist foo echo original file still present
1543 ) else (
1544 echo shouldn't rename in other directory!
1545 if not exist foo echo original file not present anymore
1547 cd .. & rd /s/q foobar
1549 echo ------------ Testing move ------------
1550 mkdir foobar & cd foobar
1551 echo --- file move
1552 echo >foo
1553 move foo bar > nul 2>&1
1554 if not exist foo (
1555 if exist bar (
1556 echo file move succeeded
1559 echo bar>bar
1560 echo baz> baz
1561 move /Y bar baz > nul 2>&1
1562 if not exist bar (
1563 if exist baz (
1564 echo file move with overwrite succeeded
1566 ) else (
1567 echo file overwrite impossible!
1568 del bar
1570 type baz
1572 attrib +r baz
1573 move baz bazro > nul 2>&1
1574 if not exist baz (
1575 if exist bazro (
1576 echo read-only files are moveable
1577 move bazro baz > nul 2>&1
1579 ) else (
1580 echo read-only file not moved!
1582 attrib -r baz
1583 mkdir rep
1584 move baz rep > nul 2>&1
1585 if not exist baz (
1586 if exist rep\baz (
1587 echo file moved in subdirectory
1590 call :setError 0
1591 move rep\baz . > nul 2>&1
1592 move /Y baz baz > nul 2>&1
1593 if errorlevel 1 (
1594 echo moving a file to itself should be a no-op!
1595 ) else (
1596 echo moving a file to itself is a no-op
1598 echo ErrorLevel: %ErrorLevel%
1599 call :setError 0
1600 del baz
1601 echo --- directory move
1602 mkdir foo\bar
1603 mkdir baz
1604 echo baz2>baz\baz2
1605 move baz foo\bar > nul 2>&1
1606 if not exist baz (
1607 if exist foo\bar\baz\baz2 (
1608 echo simple directory move succeeded
1611 call :setError 0
1612 mkdir baz
1613 move baz baz > nul 2>&1
1614 echo moving a directory to itself gives error; errlevel %ErrorLevel%
1615 echo ------ dir in dir move
1616 rd /s/q foo
1617 mkdir foo bar
1618 echo foo2>foo\foo2
1619 echo bar2>bar\bar2
1620 move foo bar > nul 2>&1
1621 if not exist foo (
1622 if exist bar (
1623 dir /b /ad bar
1624 dir /b /a-d bar
1625 dir /b bar\foo
1628 cd .. & rd /s/q foobar
1630 echo ------------ Testing mkdir ------------
1631 call :setError 0
1632 echo --- md and mkdir are synonymous
1633 mkdir foobar
1634 echo %ErrorLevel%
1635 rmdir foobar
1636 md foobar
1637 echo %ErrorLevel%
1638 rmdir foobar
1639 echo --- creating an already existing directory/file must fail
1640 mkdir foobar
1641 md foobar
1642 echo %ErrorLevel%
1643 rmdir foobar
1644 echo > foobar
1645 mkdir foobar
1646 echo %ErrorLevel%
1647 del foobar
1648 echo --- multilevel path creation
1649 mkdir foo
1650 echo %ErrorLevel%
1651 mkdir foo\bar\baz
1652 echo %ErrorLevel%
1653 cd foo
1654 echo %ErrorLevel%
1655 cd bar
1656 echo %ErrorLevel%
1657 cd baz
1658 echo %ErrorLevel%
1659 echo > ..\..\bar2
1660 mkdir ..\..\..\foo\bar2
1661 echo %ErrorLevel%
1662 del ..\..\bar2
1663 mkdir ..\..\..\foo\bar2
1664 echo %ErrorLevel%
1665 rmdir ..\..\..\foo\bar2
1666 cd ..
1667 rmdir baz
1668 cd ..
1669 rmdir bar
1670 cd ..
1671 rmdir foo
1672 echo %ErrorLevel%
1673 echo --- trailing backslashes
1674 mkdir foo\\\\
1675 echo %ErrorLevel%
1676 if exist foo (rmdir foo & echo dir created
1677 ) else ( echo dir not created )
1678 echo %ErrorLevel%
1679 echo --- invalid chars
1680 mkdir ?
1681 echo mkdir ? gives errorlevel %ErrorLevel%
1682 call :setError 0
1683 mkdir ?\foo
1684 echo mkdir ?\foo gives errorlevel %ErrorLevel%
1685 call :setError 0
1686 mkdir foo\?
1687 echo mkdir foo\? gives errorlevel %ErrorLevel%
1688 if exist foo (rmdir foo & echo ok, foo created
1689 ) else ( echo foo not created )
1690 call :setError 0
1691 mkdir foo\bar\?
1692 echo mkdir foo\bar\? gives errorlevel %ErrorLevel%
1693 call :setError 0
1694 if not exist foo (
1695 echo bad, foo not created
1696 ) else (
1697 cd foo
1698 if exist bar (
1699 echo ok, foo\bar created
1700 rmdir bar
1702 cd ..
1703 rmdir foo
1705 echo --- multiple directories at once
1706 mkdir foobaz & cd foobaz
1707 mkdir foo bar\baz foobar "bazbaz" .\"zabzab"
1708 if exist foo (echo foo created) else echo foo not created!
1709 if exist bar (echo bar created) else echo bar not created!
1710 if exist foobar (echo foobar created) else echo foobar not created!
1711 if exist bar\baz (echo bar\baz created) else echo bar\baz not created!
1712 if exist bazbaz (echo bazbaz created) else echo bazbaz not created!
1713 if exist zabzab (echo zabzab created) else echo zabzab not created!
1714 cd .. & rd /s/q foobaz
1715 call :setError 0
1716 mkdir foo\*
1717 echo mkdir foo\* errorlevel %ErrorLevel%
1718 if exist foo (rmdir foo & echo ok, foo created
1719 ) else ( echo bad, foo not created )
1721 echo ------------ Testing rmdir ------------
1722 call :setError 0
1723 rem rd and rmdir are synonymous
1724 mkdir foobar
1725 rmdir foobar
1726 echo %ErrorLevel%
1727 if not exist foobar echo dir removed
1728 mkdir foobar
1729 rd foobar
1730 echo %ErrorLevel%
1731 if not exist foobar echo dir removed
1732 rem Removing nonexistent directory
1733 rmdir foobar
1734 echo %ErrorLevel%
1735 rem Removing single-level directories
1736 echo > foo
1737 rmdir foo
1738 echo %ErrorLevel%
1739 if exist foo echo file not removed
1740 del foo
1741 mkdir foo
1742 echo > foo\bar
1743 rmdir foo
1744 echo %ErrorLevel%
1745 if exist foo echo non-empty dir not removed
1746 del foo\bar
1747 mkdir foo\bar
1748 rmdir foo
1749 echo %ErrorLevel%
1750 if exist foo echo non-empty dir not removed
1751 rmdir foo\bar
1752 rmdir foo
1753 rem Recursive rmdir
1754 mkdir foo\bar\baz
1755 rmdir /s /Q foo
1756 if not exist foo (
1757 echo recursive rmdir succeeded
1758 ) else (
1759 rd foo\bar\baz
1760 rd foo\bar
1761 rd foo
1763 mkdir foo\bar\baz
1764 echo foo > foo\bar\brol
1765 rmdir /s /Q foo 2>&1
1766 if not exist foo (
1767 echo recursive rmdir succeeded
1768 ) else (
1769 rd foo\bar\baz
1770 del foo\bar\brol
1771 rd foo\bar
1772 rd foo
1774 rem multiples directories at once
1775 mkdir foobaz & cd foobaz
1776 mkdir foo
1777 mkdir bar\baz
1778 mkdir foobar
1779 rd /s/q foo bar foobar
1780 if not exist foo (echo foo removed) else echo foo not removed!
1781 if not exist bar (echo bar removed) else echo bar not removed!
1782 if not exist foobar (echo foobar removed) else echo foobar not removed!
1783 if not exist bar\baz (echo bar\baz removed) else echo bar\baz not removed!
1784 cd .. & rd /s/q foobaz
1786 echo ------------ Testing pushd/popd ------------
1788 echo --- popd is no-op when dir stack is empty
1789 popd
1791 echo --- pushing non-existing dir
1792 pushd foobar
1794 echo --- basic behaviour
1795 mkdir foobar\baz
1796 pushd foobar
1798 popd
1800 pushd foobar
1801 pushd baz
1803 popd
1805 pushd baz
1806 popd
1808 popd
1810 pushd .
1811 cd foobar\baz
1812 pushd ..
1814 popd
1815 popd
1817 rd /s/q foobar
1819 echo ------------ Testing attrib ------------
1820 rem FIXME Add tests for archive, hidden and system attributes + mixed attributes modifications
1821 mkdir foobar & cd foobar
1822 echo foo original contents> foo
1823 attrib foo
1824 echo > bar
1825 echo --- read-only attribute
1826 rem Read-only files cannot be altered or deleted, unless forced
1827 attrib +R foo
1828 attrib foo
1829 dir /Ar /B
1830 echo bar>> foo
1831 type foo
1832 del foo > NUL 2>&1
1833 if exist foo (
1834 echo Read-only file not deleted
1835 ) else (
1836 echo Should not delete read-only file!
1838 del /F foo
1839 if not exist foo (
1840 echo Read-only file forcibly deleted
1841 ) else (
1842 echo Should delete read-only file with del /F!
1843 attrib -r foo
1844 del foo
1846 cd .. & rd /s/q foobar
1847 echo --- recursive behaviour
1848 mkdir foobar\baz & cd foobar
1849 echo > level1
1850 echo > whatever
1851 echo > baz\level2
1852 attrib baz\level2
1853 cd ..
1854 attrib +R l*vel? /S > nul 2>&1
1855 cd foobar
1856 attrib level1
1857 attrib baz\level2
1858 echo > bar
1859 attrib bar
1860 cd .. & rd /s/q foobar
1861 echo --- folders processing
1862 mkdir foobar
1863 attrib foobar
1864 cd foobar
1865 mkdir baz
1866 echo toto> baz\toto
1867 attrib +r baz /s /d > nul 2>&1
1868 attrib baz
1869 attrib baz\toto
1870 echo lulu>>baz\toto
1871 type baz\toto
1872 echo > baz\lala
1873 rem Oddly windows allows file creation in a read-only directory...
1874 if exist baz\lala (echo file created in read-only dir) else echo file not created
1875 cd .. & rd /s/q foobar
1877 echo ------------ Testing assoc ------------
1878 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1879 rem FIXME Revise once || conditional execution is fixed
1880 mkdir foobar & cd foobar
1881 echo --- setting association
1882 assoc .foo > baz
1883 type baz
1884 echo ---
1886 assoc .foo=bar
1887 assoc .foo
1889 rem association set system-wide
1890 echo @echo off> tmp.cmd
1891 echo echo +++>> tmp.cmd
1892 echo assoc .foo>> tmp.cmd
1893 cmd /c tmp.cmd
1895 echo --- resetting association
1896 assoc .foo=
1897 assoc .foo > baz
1898 type baz
1899 echo ---
1901 rem association removal set system-wide
1902 cmd /c tmp.cmd > baz
1903 type baz
1904 echo ---
1905 cd .. & rd /s/q foobar
1907 echo ------------ Testing ftype ------------
1908 rem FIXME Can't test error messages in the current test system, so we have to use some kludges
1909 rem FIXME Revise once || conditional execution is fixed
1910 mkdir foobar & cd foobar
1911 echo --- setting association
1912 ftype footype> baz
1913 type baz
1914 echo ---
1916 ftype footype=foo_opencmd
1917 assoc .foo=footype
1918 ftype footype
1920 rem association set system-wide
1921 echo @echo off> tmp.cmd
1922 echo echo +++>> tmp.cmd
1923 echo ftype footype>> tmp.cmd
1924 cmd /c tmp.cmd
1926 echo --- resetting association
1927 assoc .foo=
1929 rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
1930 setlocal EnableDelayedExpansion
1931 set WINE_FOO=original value
1932 ftype footype=
1933 ftype footype > baz
1934 for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
1935 rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
1936 rem FIXME Revisit once a grep-like program like ftype is implemented
1937 rem (e.g. to check baz's size using dir /b instead)
1938 echo !WINE_FOO!
1940 rem cleanup registry
1941 echo REGEDIT4> regCleanup.reg
1942 echo.>> regCleanup.reg
1943 echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
1944 regedit /s regCleanup.reg
1945 set WINE_FOO=
1946 endlocal
1947 cd .. & rd /s/q foobar
1949 echo ------------ Testing CALL ------------
1950 mkdir foobar & cd foobar
1951 echo --- external script
1952 echo echo foo %%1> foo.cmd
1953 call foo
1954 call foo.cmd 8
1955 echo echo %%1 %%2 > foo.cmd
1956 call foo.cmd foo
1957 call foo.cmd foo bar
1958 call foo.cmd foo ""
1959 call foo.cmd "" bar
1960 call foo.cmd foo ''
1961 call foo.cmd '' bar
1962 del foo.cmd
1964 echo --- internal routines
1965 call :testRoutine :testRoutine
1966 goto :endTestRoutine
1967 :testRoutine
1968 echo bar %1
1969 goto :eof
1970 :endTestRoutine
1972 call :testRoutineArgs foo
1973 call :testRoutineArgs foo bar
1974 call :testRoutineArgs foo ""
1975 call :testRoutineArgs "" bar
1976 call :testRoutineArgs foo ''
1977 call :testRoutineArgs '' bar
1978 goto :endTestRoutineArgs
1979 :testRoutineArgs
1980 echo %1 %2
1981 goto :eof
1982 :endTestRoutineArgs
1984 echo --- with builtins
1985 call mkdir foo
1986 echo %ErrorLevel%
1987 if exist foo (echo foo created) else echo foo should exist!
1988 rmdir foo
1989 set WINE_FOOBAZ_VAR=foobaz
1990 call echo Should expand %WINE_FOOBAZ_VAR%
1991 set WINE_FOOBAZ_VAR=
1992 echo>batfile
1993 call dir /b
1994 echo>robinfile
1995 if 1==1 call del batfile
1996 dir /b
1997 if exist batfile echo batfile shouldn't exist
1998 rem ... but not for 'if' or 'for'
1999 call if 1==1 echo bar 2> nul
2000 echo %ErrorLevel%
2001 call :setError 0
2002 call for %%i in (foo bar baz) do echo %%i 2> nul
2003 echo %ErrorLevel%
2004 rem First look for programs in the path before trying a builtin
2005 echo echo non-builtin dir> dir.cmd
2006 call dir /b
2007 del dir.cmd
2008 rem The below line equates to call (, which does nothing, then the
2009 rem subsequent lines are executed.
2010 call (
2011 echo Line one
2012 echo Line two
2014 rem The below line equates to call if, which always fails, then the
2015 rem subsequent lines are executed. Note cmd.exe swallows all lines
2016 rem starting with )
2017 call if 1==1 (
2018 echo Get if
2019 ) else (
2020 echo ... and else!
2022 call call call echo passed
2023 cd .. & rd /s/q foobar
2025 echo ------------ Testing SHIFT ------------
2027 call :shiftFun p1 p2 p3 p4 p5
2028 goto :endShiftFun
2030 :shiftFun
2031 echo '%1' '%2' '%3' '%4' '%5'
2032 shift
2033 echo '%1' '%2' '%3' '%4' '%5'
2034 shift@tab@ /1
2035 echo '%1' '%2' '%3' '%4' '%5'
2036 shift /2
2037 echo '%1' '%2' '%3' '%4' '%5'
2038 shift /-1
2039 echo '%1' '%2' '%3' '%4' '%5'
2040 shift /0
2041 echo '%1' '%2' '%3' '%4' '%5'
2042 goto :eof
2043 :endShiftFun
2045 echo ------------ Testing cmd invocation ------------
2046 rem FIXME: only a stub ATM
2047 echo --- a batch file can delete itself
2048 echo del foo.cmd>foo.cmd
2049 cmd /q /c foo.cmd
2050 if not exist foo.cmd (
2051 echo file correctly deleted
2052 ) else (
2053 echo file should be deleted!
2054 del foo.cmd
2056 echo --- a batch file can alter itself
2057 echo echo bar^>foo.cmd>foo.cmd
2058 cmd /q /c foo.cmd > NUL 2>&1
2059 if exist foo.cmd (
2060 type foo.cmd
2061 del foo.cmd
2062 ) else (
2063 echo file not created!
2066 echo ---------- Testing copy
2067 md foobar2
2068 cd foobar2
2069 rem Note echo adds 0x0d 0x0a on the end of the line in the file
2070 echo AAA> file1
2071 echo BBBBBB> file2
2072 echo CCCCCCCCC> file3
2073 md dir1
2074 goto :testcopy
2076 :CheckExist
2077 if exist "%1" (
2078 echo Passed: Found expected %1
2079 ) else (
2080 echo Failed: Did not find expected %1
2082 del /q "%1" >nul 2>&1
2083 shift
2084 if not "%1"=="" goto :CheckExist
2085 goto :eof
2087 :CheckNotExist
2088 if not exist "%1" (
2089 echo Passed: Did not find %1
2090 ) else (
2091 echo Failed: Unexpectedly found %1
2092 del /q "%1" >nul 2>&1
2094 shift
2095 if not "%1"=="" goto :CheckNotExist
2096 goto :eof
2098 rem Note: No way to check file size on NT4 so skip the test
2099 :CheckFileSize
2100 if not exist "%1" (
2101 echo Failed: File missing when requested filesize check [%2]
2102 goto :ContinueFileSizeChecks
2104 for %%i in (%1) do set WINE_filesize=%%~zi
2105 if "%WINE_filesize%"=="%2" (
2106 echo Passed: file size check on %1 [%WINE_filesize%]
2107 ) else (
2108 if "%WINE_filesize%"=="%%~zi" (
2109 echo Skipping file size check on NT4
2110 ) else (
2111 echo Failed: file size check on %1 [%WINE_filesize% != %2]
2114 :ContinueFileSizeChecks
2115 shift
2116 shift
2117 if not "%1"=="" goto :CheckFileSize
2118 goto :eof
2120 :testcopy
2122 rem -----------------------
2123 rem Simple single file copy
2124 rem -----------------------
2125 rem Simple single file copy, normally used syntax
2126 copy file1 dummy.file >nul 2>&1
2127 if errorlevel 1 echo Incorrect errorlevel
2128 call :CheckExist dummy.file
2130 rem Simple single file copy, destination supplied as two forms of directory
2131 copy file1 dir1 >nul 2>&1
2132 if errorlevel 1 echo Incorrect errorlevel
2133 call :CheckExist dir1\file1
2135 copy file1 dir1\ >nul 2>&1
2136 if errorlevel 1 echo Incorrect errorlevel
2137 call :CheckExist dir1\file1
2139 rem Simple single file copy, destination supplied as fully qualified destination
2140 copy file1 dir1\file99 >nul 2>&1
2141 if errorlevel 1 echo Incorrect errorlevel
2142 call :CheckExist dir1\file99
2144 rem Simple single file copy, destination not supplied
2145 cd dir1
2146 copy ..\file1 >nul 2>&1
2147 if errorlevel 1 echo Incorrect errorlevel
2148 call :CheckExist file1
2149 cd ..
2151 rem Simple single file copy, destination supplied as nonexistent directory
2152 copy file1 dir2\ >nul 2>&1
2153 if not errorlevel 1 echo Incorrect errorlevel
2154 call :CheckNotExist dir2 dir2\file1
2156 rem -----------------------
2157 rem Wildcarded copy
2158 rem -----------------------
2159 rem Simple single file copy, destination supplied as two forms of directory
2160 copy file? dir1 >nul 2>&1
2161 if errorlevel 1 echo Incorrect errorlevel
2162 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2164 copy file* dir1\ >nul 2>&1
2165 if errorlevel 1 echo Incorrect errorlevel
2166 call :CheckExist dir1\file1 dir1\file2 dir1\file3
2168 rem Simple single file copy, destination not supplied
2169 cd dir1
2170 copy ..\file*.* >nul 2>&1
2171 if errorlevel 1 echo Incorrect errorlevel
2172 call :CheckExist file1 file2 file3
2173 cd ..
2175 rem Simple wildcarded file copy, destination supplied as nonexistent directory
2176 copy file? dir2\ >nul 2>&1
2177 if not errorlevel 1 echo Incorrect errorlevel
2178 call :CheckNotExist dir2 dir2\file1 dir2\file2 dir2\file3
2180 rem ------------------------------------------------
2181 rem Confirm overwrite works (cannot test prompting!)
2182 rem ------------------------------------------------
2183 copy file1 testfile >nul 2>&1
2184 copy /y file2 testfile >nul 2>&1
2185 call :CheckExist testfile
2187 rem ------------------------------------------------
2188 rem Test concatenation
2189 rem ------------------------------------------------
2190 rem simple case, no wildcards
2191 copy file1+file2 testfile >nul 2>&1
2192 if errorlevel 1 echo Incorrect errorlevel
2193 call :CheckExist testfile
2195 rem simple case, wildcards, no concatenation
2196 copy file* testfile >nul 2>&1
2197 if errorlevel 1 echo Incorrect errorlevel
2198 call :CheckExist testfile
2200 rem simple case, wildcards, and concatenation
2201 echo ddddd > fred
2202 copy file*+fred testfile >nul 2>&1
2203 if errorlevel 1 echo Incorrect errorlevel
2204 call :CheckExist testfile
2206 rem simple case, wildcards, and concatenation
2207 copy fred+file* testfile >nul 2>&1
2208 if errorlevel 1 echo Incorrect errorlevel
2209 call :CheckExist testfile
2211 rem Calculate destination name
2212 copy fred+file* dir1 >nul 2>&1
2213 if errorlevel 1 echo Incorrect errorlevel
2214 call :CheckExist dir1\fred
2216 rem Calculate destination name
2217 copy fred+file* dir1\ >nul 2>&1
2218 if errorlevel 1 echo Incorrect errorlevel
2219 call :CheckExist dir1\fred
2221 rem Calculate destination name (none supplied)
2222 cd dir1
2223 copy ..\fred+..\file* >nul 2>&1
2224 if errorlevel 1 echo Incorrect errorlevel
2225 call :CheckExist fred
2227 copy ..\fr*+..\file1 >nul 2>&1
2228 if errorlevel 1 echo Incorrect errorlevel
2229 call :CheckExist fred
2230 cd ..
2232 rem ******************************************************************
2233 rem ASCII and BINARY tests
2234 rem Note: hard coded numbers deliberate because need to ensure whether
2235 rem an additional EOF has been added or not. There is no way to handle
2236 rem EOFs in batch, so assume if a single byte appears, its an EOF!
2237 rem ******************************************************************
2239 rem Confirm original sizes of file1,2,3
2240 call :CheckFileSize file1 5 file2 8 file3 11
2242 cd dir1
2244 rem ----------------------------------------------
2245 rem Show concatenation defaults copy to ascii mode
2246 rem ----------------------------------------------
2247 rem Simple default copy source to destination (should not append EOF 5)
2248 copy ..\file1 file1_default >nul 2>&1
2249 call :CheckFileSize file1_default 5
2251 rem Simple binary copy source to destination (should not append EOF 5)
2252 copy /b ..\file1 file1_default2 >nul 2>&1
2253 call :CheckFileSize file1_default2 5
2255 rem Simple ascii copy source to destination (should append EOF 5+1, 8+1, 11+1)
2256 copy /a ..\file1 file1_plus_eof >nul 2>&1
2257 call :CheckFileSize file1_plus_eof 6
2258 copy /a ..\file2 file2_plus_eof >nul 2>&1
2259 call :CheckFileSize file2_plus_eof 9
2260 copy /a ..\file3 file3_plus_eof >nul 2>&1
2261 call :CheckFileSize file3_plus_eof 12
2263 rem Concat 2 files, ascii mode - (only one EOF on the end 5+8+1)
2264 copy /a ..\file1+..\file2 file12_plus_eof >nul 2>&1
2265 call :CheckFileSize file12_plus_eof 14
2267 rem Concat 2 files, binary mode - (no EOF on the end 5+8)
2268 copy /b ..\file1+..\file2 file12_no_eof >nul 2>&1
2269 call :CheckFileSize file12_no_eof 13
2271 rem Concat 2 files, default mode - (one EOF on the end 5+8+1)
2272 copy ..\file1+..\file2 file12_eof2 >nul 2>&1
2273 call :CheckFileSize file12_eof2 14
2275 rem --------------------------------------------------------------
2276 rem Show ascii source copy stops at first EOF, binary does the lot
2277 rem --------------------------------------------------------------
2278 copy file1_plus_eof /b file1_binary_srccopy /b >nul 2>&1
2279 call :CheckFileSize file1_binary_srccopy 6
2281 copy file1_plus_eof /a file1_ascii_srccopy /b >nul 2>&1
2282 call :CheckFileSize file1_ascii_srccopy 5
2284 rem --------------------------------------------------------------
2285 rem Show results of concatenating files (ending in EOFs) and /a /b
2286 rem --------------------------------------------------------------
2288 rem Default and ascii copy reads as ascii, stripping EOFs, so 6-1 + 9-1 + 12-1 + 1
2289 copy file1_plus_eof+file2_plus_eof+file3_plus_eof file123_default_copy >nul 2>&1
2290 call :CheckFileSize file123_default_copy 25
2291 copy /a file1_plus_eof+file2_plus_eof+file3_plus_eof file123_ascii_copy >nul 2>&1
2292 call :CheckFileSize file123_ascii_copy 25
2294 rem In binary mode, we get 3 eofs, so 6 + 9 + 12 = 27
2295 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_binary_copy >nul 2>&1
2296 call :CheckFileSize file123_binary_copy 27
2298 rem We can select which we want the eofs from by postfixing it with /a or /b
2299 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12
2300 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy1 >nul 2>&1
2301 call :CheckFileSize file123_mixed_copy1 26
2303 rem By postfixing the destination with /a, we ask for an ascii destination which appends EOF
2304 rem so here have first and third with eof, second as ascii 6 + 9-1 + 12 + extra EOF
2305 rem Note the delta between this and the previous one also shows that the destination
2306 rem ascii/binary is inherited from the last /a or /b on the line
2307 copy file1_plus_eof /b + file2_plus_eof /a + file3_plus_eof /b file123_mixed_copy2 /a >nul 2>&1
2308 call :CheckFileSize file123_mixed_copy2 27
2310 rem so here have second with eof, first and third as ascii 6-1 + 9 + 12-1
2311 rem Note the delta between the next two also shows that the destination ascii/binary is
2312 rem inherited from the last /a or /b on the line, so the first has an extra EOF
2313 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy3 >nul 2>&1
2314 call :CheckFileSize file123_mixed_copy3 26
2315 copy file1_plus_eof /a + file2_plus_eof /b + file3_plus_eof /a file123_mixed_copy4 /b >nul 2>&1
2316 call :CheckFileSize file123_mixed_copy4 25
2318 rem -------------------------------------------------------------------------------------------
2319 rem This shows when concatenating, an ascii destination always adds on an EOF but when we
2320 rem are not concatenating, its a direct copy regardless of destination if being read as binary
2321 rem -------------------------------------------------------------------------------------------
2323 rem All 3 have eof's, plus an extra = 6 + 9 + 12 + eof
2324 copy /b file1_plus_eof + file2_plus_eof + file3_plus_eof file123_mixed_copy5 /a >nul 2>&1
2325 call :CheckFileSize file123_mixed_copy5 28
2327 rem All 2 have eof's, plus an extra = 6 + 12 + eof
2328 copy /b file1_plus_eof + file3_plus_eof file123_mixed_copy6 /a >nul 2>&1
2329 call :CheckFileSize file123_mixed_copy6 19
2331 rem One file has EOF, but doesn't get an extra one, i.e. 6
2332 copy /b file1_plus_eof file123_mixed_copy7 /a >nul 2>&1
2333 call :CheckFileSize file123_mixed_copy7 6
2335 rem Syntax means concatenate so ascii destination kicks in
2336 copy /b file1_plus_eof* file123_mixed_copy8 /a >nul 2>&1
2337 call :CheckFileSize file123_mixed_copy8 7
2339 del *.* /q
2340 cd ..
2342 rem ---------------------------------------
2343 rem Error combinations
2344 rem ---------------------------------------
2345 rem Specify source directory but name is a file
2346 call :setError 0
2347 copy file1\ dir1\ >NUL 2>&1
2348 if errorlevel 1 echo Passed: errorlevel invalid check 1
2349 if not errorlevel 1 echo Failed: errorlevel invalid check 1
2350 call :CheckNotExist dir1\file1
2352 rem Overwrite same file
2353 call :setError 0
2354 copy file1 file1 >NUL 2>&1
2355 if errorlevel 1 echo Passed: errorlevel invalid check 2
2356 if not errorlevel 1 echo Failed: errorlevel invalid check 2
2358 rem Supply same file identified as a directory
2359 call :setError 0
2360 copy file1 file1\ >NUL 2>&1
2361 if errorlevel 1 echo Passed: errorlevel invalid check 3
2362 if not errorlevel 1 echo Failed: errorlevel invalid check 3
2364 cd ..
2365 rd foobar2 /s /q
2367 echo ------------ Testing setlocal/endlocal ------------
2368 call :setError 0
2369 rem Note: setlocal EnableDelayedExpansion already tested in the variable delayed expansion test section
2370 mkdir foobar & cd foobar
2371 echo --- enable/disable extensions
2372 setlocal DisableEXTensions
2373 echo ErrLev: %ErrorLevel%
2374 endlocal
2375 echo ErrLev: %ErrorLevel%
2376 echo @echo off> tmp.cmd
2377 echo echo ErrLev: %%ErrorLevel%%>> tmp.cmd
2378 rem Enabled by default
2379 cmd /C tmp.cmd
2380 cmd /E:OfF /C tmp.cmd
2381 cmd /e:oN /C tmp.cmd
2383 rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
2384 echo --- setlocal with corresponding endlocal
2385 rem %CD% does not tork on NT4 so use the following workaround
2386 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2387 echo @echo off> test.cmd
2388 echo echo %%WINE_VAR%%>> test.cmd
2389 echo setlocal>> test.cmd
2390 echo set WINE_VAR=localval>> test.cmd
2391 echo md foobar2>> test.cmd
2392 echo cd foobar2>> test.cmd
2393 echo echo %%WINE_VAR%%>> test.cmd
2394 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2395 echo endlocal>> test.cmd
2396 echo echo %%WINE_VAR%%>> test.cmd
2397 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2398 set WINE_VAR=globalval
2399 call test.cmd
2400 echo %WINE_VAR%
2401 for /d %%i in (.) do echo %%~dpnxi
2402 cd /d %WINE_CURDIR%
2403 rd foobar2
2404 set WINE_VAR=
2405 echo --- setlocal with no corresponding endlocal
2406 echo @echo off> test.cmd
2407 echo echo %%WINE_VAR%%>> test.cmd
2408 echo setlocal>> test.cmd
2409 echo set WINE_VAR=localval>> test.cmd
2410 echo md foobar2>> test.cmd
2411 echo cd foobar2>> test.cmd
2412 echo echo %%WINE_VAR%%>> test.cmd
2413 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
2414 set WINE_VAR=globalval
2415 rem %CD% does not tork on NT4 so use the following workaround
2416 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2417 call test.cmd
2418 echo %WINE_VAR%
2419 for /d %%i in (.) do echo %%~dpnxi
2420 cd /d %WINE_CURDIR%
2421 rd foobar2
2422 set WINE_VAR=
2423 echo --- setlocal within same batch program
2424 set WINE_var1=one
2425 set WINE_var2=
2426 set WINE_var3=
2427 rem %CD% does not tork on NT4 so use the following workaround
2428 for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
2429 setlocal
2430 set WINE_var2=two
2431 mkdir foobar2
2432 cd foobar2
2433 setlocal
2434 set WINE_var3=three
2435 if "%WINE_var1%"=="one" echo Var1 ok 1
2436 if "%WINE_var2%"=="two" echo Var2 ok 2
2437 if "%WINE_var3%"=="three" echo Var3 ok 3
2438 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2439 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
2440 endlocal
2441 if "%WINE_var1%"=="one" echo Var1 ok 1
2442 if "%WINE_var2%"=="two" echo Var2 ok 2
2443 if "%WINE_var3%"=="" echo Var3 ok 3
2444 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2445 if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
2446 endlocal
2447 if "%WINE_var1%"=="one" echo Var1 ok 1
2448 if "%WINE_var2%"=="" echo Var2 ok 2
2449 if "%WINE_var3%"=="" echo Var3 ok 3
2450 for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
2451 if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
2452 rd foobar2 /s /q
2453 set WINE_var1=
2455 echo --- Mismatched set and end locals
2456 mkdir foodir2 2>nul
2457 mkdir foodir3 2>nul
2458 mkdir foodir4 2>nul
2459 rem %CD% does not tork on NT4 so use the following workaround
2460 for /d %%i in (.) do set WINE_curdir=%%~dpnxi
2462 echo @echo off> 2set1end.cmd
2463 echo echo %%WINE_var%%>> 2set1end.cmd
2464 echo setlocal>> 2set1end.cmd
2465 echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
2466 echo cd ..\foodir3>> 2set1end.cmd
2467 echo setlocal>> 2set1end.cmd
2468 echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
2469 echo cd ..\foodir4>> 2set1end.cmd
2470 echo endlocal>> 2set1end.cmd
2471 echo echo %%WINE_var%%>> 2set1end.cmd
2472 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
2474 echo @echo off> 1set2end.cmd
2475 echo echo %%WINE_var%%>> 1set2end.cmd
2476 echo setlocal>> 1set2end.cmd
2477 echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
2478 echo cd ..\foodir3>> 1set2end.cmd
2479 echo endlocal>> 1set2end.cmd
2480 echo echo %%WINE_var%%>> 1set2end.cmd
2481 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2482 echo endlocal>> 1set2end.cmd
2483 echo echo %%WINE_var%%>> 1set2end.cmd
2484 echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
2486 echo --- Extra setlocal in called batch
2487 set WINE_VAR=value1
2488 rem -- setlocal1 == this batch, should never be used inside a called routine
2489 setlocal
2490 set WINE_var=value2
2491 cd foodir2
2492 call %WINE_CURDIR%\2set1end.cmd
2493 echo Finished:
2494 echo %WINE_VAR%
2495 for /d %%i in (.) do echo %%~dpnxi
2496 endlocal
2497 echo %WINE_VAR%
2498 for /d %%i in (.) do echo %%~dpnxi
2499 cd /d %WINE_CURDIR%
2501 echo --- Extra endlocal in called batch
2502 set WINE_VAR=value1
2503 rem -- setlocal1 == this batch, should never be used inside a called routine
2504 setlocal
2505 set WINE_var=value2
2506 cd foodir2
2507 call %WINE_CURDIR%\1set2end.cmd
2508 echo Finished:
2509 echo %WINE_VAR%
2510 for /d %%i in (.) do echo %%~dpnxi
2511 endlocal
2512 echo %WINE_VAR%
2513 for /d %%i in (.) do echo %%~dpnxi
2514 cd /d %WINE_CURDIR%
2516 echo --- endlocal in called function rather than batch pgm is ineffective
2517 @echo off
2518 set WINE_var=1
2519 set WINE_var2=1
2520 setlocal
2521 set WINE_var=2
2522 call :endlocalroutine
2523 echo %WINE_var%
2524 endlocal
2525 echo %WINE_var%
2526 goto :endlocalfinished
2527 :endlocalroutine
2528 echo %WINE_var%
2529 endlocal
2530 echo %WINE_var%
2531 setlocal
2532 set WINE_var2=2
2533 endlocal
2534 echo %WINE_var2%
2535 endlocal
2536 echo %WINE_var%
2537 echo %WINE_var2%
2538 goto :eof
2539 :endlocalfinished
2540 echo %WINE_var%
2542 set WINE_var=
2543 set WINE_var2=
2544 cd .. & rd /q/s foobar
2546 echo ------------ Testing Errorlevel ------------
2547 rem WARNING: Do *not* add tests using ErrorLevel after this section
2548 should_not_exist 2> nul > nul
2549 echo %ErrorLevel%
2550 rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
2551 rem See http://www.robvanderwoude.com/exit.php
2552 call :setError 1
2553 echo %ErrorLevel%
2554 if errorlevel 2 echo errorlevel too high, bad
2555 if errorlevel 1 echo errorlevel just right, good
2556 if errorlevel 01 echo errorlevel with leading zero just right, good
2557 if errorlevel -1 echo errorlevel with negative number OK
2558 if errorlevel 0x1 echo hexa should not be recognized!
2559 if errorlevel 1a echo invalid error level recognized!
2560 call :setError 0
2561 echo abc%ErrorLevel%def
2562 if errorlevel 1 echo errorlevel nonzero, bad
2563 if not errorlevel 1 echo errorlevel zero, good
2564 if not errorlevel 0x1 echo hexa should not be recognized!
2565 if not errorlevel 1a echo invalid error level recognized!
2566 rem Now verify that setting a real variable hides its magic variable
2567 set errorlevel=7
2568 echo %ErrorLevel% should be 7
2569 if errorlevel 7 echo setting var worked too well, bad
2570 call :setError 3
2571 echo %ErrorLevel% should still be 7
2573 echo ------------ Testing GOTO ------------
2574 if a==a goto dest1
2575 echo FAILURE at dest 1
2576 :dest1
2577 echo goto with no leading space worked
2578 if a==a goto :dest1b
2579 echo FAILURE at dest 1b
2580 :dest1b
2581 echo goto with colon and no leading space worked
2582 if b==b goto dest2
2583 echo FAILURE at dest 2
2584 :dest2
2585 echo goto with a leading space worked
2586 if c==c goto dest3
2587 echo FAILURE at dest 3
2588 :dest3
2589 echo goto with a leading tab worked
2590 if d==d goto dest4
2591 echo FAILURE at dest 4
2592 :dest4@space@
2593 echo goto with a following space worked
2594 if e==e goto dest5
2595 echo FAILURE at dest 5
2596 :dest5&& echo FAILURE
2597 echo goto with following amphersands worked
2599 del failure.txt >nul 2>&1
2600 if f==f goto dest6
2601 echo FAILURE at dest 6
2602 :dest6>FAILURE.TXT
2603 if exist FAILURE.TXT echo FAILURE at dest 6 as file exists
2604 echo goto with redirections worked
2605 del FAILURE.TXT >nul 2>&1
2607 :: some text that is ignored | dir >cmd_output | another test
2608 if exist cmd_output echo FAILURE at dest 6 as file exists
2609 echo Ignoring double colons worked
2610 del cmd_output >nul 2>&1
2612 rem goto a label which does not exist issues an error message and
2613 rem acts the same as goto :EOF, and ensure ::label is never matched
2614 del testgoto.bat >nul 2>&1
2615 echo goto :dest7 ^>nul 2^>^&1 >> testgoto.bat
2616 echo echo FAILURE at dest 7 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2617 echo ::dest7>> testgoto.bat
2618 echo echo FAILURE at dest 7 - Incorrectly went to label >> testgoto.bat
2619 call testgoto.bat
2620 del testgoto.bat >nul 2>&1
2622 del testgoto.bat >nul 2>&1
2623 echo goto ::dest8 ^>nul 2^>^&1 >> testgoto.bat
2624 echo echo FAILURE at dest 8 - Should have not found label and issued an error plus ended the batch>> testgoto.bat
2625 echo ::dest8>> testgoto.bat
2626 echo echo FAILURE at dest 8 - Incorrectly went to label >> testgoto.bat
2627 call testgoto.bat
2628 del testgoto.bat >nul 2>&1
2630 if g==g goto dest9
2631 echo FAILURE at dest 9
2632 :dest91
2633 echo FAILURE at dest 91
2634 @ : dest9>rubbish
2635 echo label with mixed whitespace and no echo worked
2637 if h==h goto :dest10:this is ignored
2638 echo FAILURE at dest 10
2639 :dest10:this is also ignored
2640 echo Correctly ignored trailing information
2642 echo ------------ Testing PATH ------------
2643 set WINE_backup_path=%path%
2644 set path=original
2645 path
2646 path try2
2647 path
2648 path=try3
2649 path
2650 set path=%WINE_backup_path%
2651 set WINE_backup_path=
2653 echo ------------ Testing combined CALLs/GOTOs ------------
2654 echo @echo off>foo.cmd
2655 echo goto :eof>>foot.cmd
2656 echo :eof>>foot.cmd
2657 echo echo world>>foo.cmd
2659 echo @echo off>foot.cmd
2660 echo echo cheball>>foot.cmd
2661 echo.>>foot.cmd
2662 echo call :bar>>foot.cmd
2663 echo if "%%1"=="deleteMe" (del foot.cmd)>>foot.cmd
2664 echo goto :eof>>foot.cmd
2665 echo.>>foot.cmd
2666 echo :bar>>foot.cmd
2667 echo echo barbare>>foot.cmd
2668 echo goto :eof>>foot.cmd
2670 call foo.cmd
2671 call foot
2672 call :bar
2673 del foo.cmd
2674 rem Script execution stops after the following line
2675 foot deleteMe
2676 call :foo
2677 call :foot
2678 goto :endFuns
2680 :foot
2681 echo foot
2683 :foo
2684 echo foo
2685 goto :eof
2687 :endFuns
2689 :bar
2690 echo bar
2691 call :foo
2693 :baz
2694 echo baz
2695 goto :eof
2697 echo Final message is not output since earlier 'foot' processing stops script execution
2698 echo Do NOT add any tests below this line
2700 echo ------------ Done, jumping to EOF -----------
2701 goto :eof
2702 rem Subroutine to set errorlevel and return
2703 rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
2704 :setError
2705 exit /B %1
2706 rem This line runs under cmd in windows NT 4, but not in more modern versions.