[NTVDM]: Reorganize code.
[reactos.git] / rostests / winetests / cmd / test_cmdline.cmd
1 @echo off
2 mkdir foobar
3 cd foobar
4 echo file1 > file1
5
6 rem Basic test of command line. Note a section prefix per command
7 rem to resync, as wine does not output anything in these cases yet.
8 echo --- Test 1
9 cmd.exe /c echo Line1
10 cmd.exe /c echo "Line2"
11 echo --- Test 2
12 cmd.exe /c echo Test quotes "&" work
13 echo --- Test 3
14 cmd.exe /c echo "&"
15 echo --- Test 4
16 cmd.exe /c echo "<"
17 echo --- Test 5
18 cmd.exe /c echo ">"
19 echo --- Test 6
20 cmd.exe /c echo "\"
21 echo --- Test 7
22 cmd.exe /c echo "|"
23 echo --- Test 8
24 cmd.exe /c echo "`"
25 echo --- Test 9
26 cmd.exe /c echo """
27 echo --- Test 10
28 echo on > file3
29 @type file3
30 @echo off
31 echo --- Test 11
32 cmd.exe /c echo on >file3
33 @type file3
34 @echo off
35 echo --- Test 12
36 cmd.exe /c "echo passed1"
37 echo --- Test 13
38 cmd.exe /c " echo passed2 "
39 echo --- Test 14
40 cmd.exe /c "dir /ad ..\fooba* /b"
41 echo --- Test 15
42 cmd.exe /cecho No whitespace
43 echo --- Test 16
44 cmd.exe /c
45 echo --- Test 17
46 cmd.exe /c@space@
47 echo --- Test 18
48 rem Ensure no interactive prompting when cmd.exe /c or /k
49 echo file2 > file2
50 cmd.exe /c copy file1 file2 >nul
51 echo No prompts or I would not get here1
52 rem - Try cmd.exe /k as well
53 cmd.exe /k "copy file1 file2 >nul && exit"
54 echo No prompts or I would not get here2
55
56 rem Nonexistent variable expansion is as per command line, i.e. left as-is
57 cmd.exe /c echo %%hello1%%
58 cmd.exe /c echo %%hello2
59 cmd.exe /c echo %%hello3^:h=t%%
60 cmd.exe /c echo %%hello4%%%%
61
62 rem Cannot issue a call from cmd.exe /c
63 cmd.exe /c call :hello5
64
65 rem %1-9 has no meaning
66 cmd.exe /c echo one = %%1
67
68 rem for loop vars need expanding
69 cmd.exe /c for /L %%i in (1,1,5) do @echo %%i
70
71 rem goto's are ineffective
72 cmd.exe /c goto :fred
73 cmd.exe /c goto eof
74
75 rem - %var% is expanded at read time, not execute time
76 set var=11
77 cmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && echo var contents: %%var%%"
78
79 rem - endlocal ineffective on cmd.exe /c lines
80 cmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && set var"
81 set var=99
82
83 rem - Environment is inherited ok
84 cmd.exe /c ECHO %%VAR%%
85
86 rem - Exit works
87 cmd.exe /c exit
88
89 cd ..
90 rd foobar /s /q
91
92 rem - Temporary batch files
93 echo @echo 0 > "say.bat"
94 echo @echo 1 > "say one.bat"
95 echo @echo 2 > "saytwo.bat"
96 echo @echo 3 > "say (3).bat"
97 echo @echo 4 > "say .bat"
98
99 echo ------ Testing invocation of batch files ----------
100 call say one
101 call "say one"
102 call "say"" one"
103 call "say one
104 call :setError 0
105 call say" one"
106 if errorlevel 2 echo error %ErrorLevel%
107 call say "one"
108 call :setError 0
109 call s"ay one
110 if errorlevel 2 echo error %ErrorLevel%
111 call :setError 0
112 call s"aytwo
113 if errorlevel 2 echo error %ErrorLevel%
114 call say (3)
115 call "say (3)"
116 call :setError 0
117 call say" (3)"
118 if errorlevel 2 echo error %ErrorLevel%
119 call :setError 0
120 call say" "(3) prints 4?!
121 if errorlevel 2 echo error %ErrorLevel%
122
123 echo ------ Testing invocation with CMD /C -------------
124 cmd /c say one
125 cmd /c "say one"
126 call :setError 0
127 cmd /c "say"" one"
128 if errorlevel 2 echo error %ErrorLevel%
129 cmd /c "say one
130 call :setError 0
131 cmd /c say" one"
132 if errorlevel 2 echo error %ErrorLevel%
133 cmd /c say "one"
134 call :setError 0
135 cmd /c s"ay one
136 if errorlevel 2 echo error %ErrorLevel%
137 call :setError 0
138 cmd /c s"aytwo
139 if errorlevel 2 echo error %ErrorLevel%
140 cmd /c say (3)
141 call :setError 0
142 cmd /c say" (3)"
143 if errorlevel 2 echo error %ErrorLevel%
144 call :setError 0
145 cmd /c say" "(3) prints 4?!
146 if errorlevel 2 echo error %ErrorLevel%
147
148 echo ---------- Testing CMD /C quoting -----------------
149 cmd /c @echo "hi"
150 call :setError 0
151 cmd /c say" "one
152 if errorlevel 2 echo error %ErrorLevel%
153 cmd /c @echo "\"\\"\\\"\\\\" "\"\\"\\\"\\\\"
154 rem ---- all 5 conditions met, quotes preserved
155 cmd /c "say one"
156 rem cond 1 - /s
157 cmd /s/c "say one"
158 cmd /s/c ""say one""
159 rem cond 2 - not 2 quotes
160 cmd /c "say one
161 call :setError 0
162 cmd /c "say"" one"
163 if errorlevel 2 echo error %ErrorLevel%
164 rem cond 3 - special char - first test fails on Vista, W2K8!
165 cmd /c "say (3)"
166 cmd /c ""say (3)""
167 rem cond 4 - no spaces (quotes make no difference here)
168 cmd /c saytwo
169 cmd /c "saytwo"
170 cmd /c "saytwo
171 rem cond 5 - string between quotes must be name of executable
172 cmd /c "say five"
173 echo @echo 5 >"say five.bat"
174 cmd /c "say five"
175
176 echo ------- Testing CMD /C qualifier treatment ------------
177 rem no need for space after /c
178 cmd /csay one
179 cmd /c"say one"
180 rem ignore quote before qualifier
181 rem FIXME the next command in wine starts a sub-CMD
182 echo THIS FAILS: cmd "/c"say one
183 rem ignore anything before /c
184 rem FIXME the next command in wine starts a sub-CMD
185 echo THIS FAILS: cmd ignoreme/c say one
186
187 echo --------- Testing special characters --------------
188 echo @echo amp > "say&.bat"
189 call say&
190 echo @echo ( > "say(.bat"
191 call say(
192 echo @echo ) > "say).bat"
193 call say)
194 echo @echo [ > "say[.bat"
195 call say[
196 echo @echo ] > "say].bat"
197 call say]
198 echo @echo { > "say{.bat"
199 call say{
200 echo @echo } > "say}.bat"
201 call say}
202 echo @echo = > "say=.bat"
203 call say=
204 echo @echo sem > "say;.bat"
205 call say;
206 setlocal DisableDelayedExpansion
207 echo @echo ! > "say!.bat"
208 call say!
209 endlocal
210 setlocal EnableDelayedExpansion
211 call say!
212 endlocal
213 echo @echo %%%% > "say%%.bat"
214 call say%%
215 echo @echo ' > "say'.bat"
216 call say'
217 echo @echo + > "say+.bat"
218 call say+
219 echo @echo com > "say,.bat"
220 call say,
221 echo @echo ` > "say`.bat"
222 call say'
223 echo @echo ~ > "say~.bat"
224 call say~
225
226 echo --------- Testing parameter passing --------------
227 echo @echo 1:%%1,2:%%2 > tell.bat
228 call tell 1
229 call tell (1)
230 call tell 1(2)
231 call :setError 0
232 call tell(1)
233 if errorlevel 2 echo error %ErrorLevel%
234 call :setError 0
235 call tell((1))
236 if errorlevel 2 echo error %ErrorLevel%
237 call :setError 0
238 call tell(1)(2)
239 if errorlevel 2 echo error %ErrorLevel%
240 call :setError 0
241 call tell(1);,;(2)
242 if errorlevel 2 echo error %ErrorLevel%
243 call :setError 0
244 call tell;1 2
245 if errorlevel 2 echo error %ErrorLevel%
246 call :setError 0
247 call tell; 1, ;2
248 if errorlevel 2 echo error %ErrorLevel%
249 call :setError 0
250 call tell;1;;2
251 if errorlevel 2 echo error %ErrorLevel%
252 call tell "p "1 p" "2
253 call tell p"1 p";2
254
255 echo --------- Testing delimiters and parameter passing --------------
256 echo @echo 0:%%0,1:%%1,2:%%2,All:'%%*'> tell.bat
257 call;tell 1 2
258 call tell 1 2
259 ==call==tell==1==2
260 call tell(1234)
261 call tell(12(34)
262 call tell(12;34)
263 echo --------- Finished --------------
264 del tell.bat say*.*
265 exit
266 :setError
267 exit /B %1