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