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