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