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