[PATCH 1/5] cmd/tests: add tests for command line parsing

Martin Wilck mwilck at arcor.de
Sun Sep 25 08:19:40 CDT 2011


This patch adds some tests for command line parsing and treatment
of quotes and special characters in the command line and in program
names and parameters. The .exp file was created using Win XP.

Changed the test to run with @echo off.
---
 programs/cmd/tests/rsrc.rc              |    6 +
 programs/cmd/tests/test_cmdline.cmd     |  159 +++++++++++++++++++++++++++++++
 programs/cmd/tests/test_cmdline.cmd.exp |   77 +++++++++++++++
 3 files changed, 242 insertions(+), 0 deletions(-)
 create mode 100755 programs/cmd/tests/test_cmdline.cmd
 create mode 100755 programs/cmd/tests/test_cmdline.cmd.exp

diff --git a/programs/cmd/tests/rsrc.rc b/programs/cmd/tests/rsrc.rc
index bcb738d..affe04c 100644
--- a/programs/cmd/tests/rsrc.rc
+++ b/programs/cmd/tests/rsrc.rc
@@ -21,3 +21,9 @@ test_builtins.cmd TESTCMD "test_builtins.cmd"
 
 /* @makedep: test_builtins.cmd.exp */
 test_builtins.cmd.exp TESTOUT "test_builtins.cmd.exp"
+
+/* @makedep: test_cmdline.cmd */
+test_cmdline.cmd TESTCMD "test_cmdline.cmd"
+
+/* @makedep: test_cmdline.cmd.exp */
+test_cmdline.cmd.exp TESTOUT "test_cmdline.cmd.exp"
diff --git a/programs/cmd/tests/test_cmdline.cmd b/programs/cmd/tests/test_cmdline.cmd
new file mode 100755
index 0000000..16855e1
--- /dev/null
+++ b/programs/cmd/tests/test_cmdline.cmd
@@ -0,0 +1,159 @@
+ at echo off
+echo @echo 0 > "say.bat"
+echo @echo 1 > "say one.bat"
+echo @echo 2 > "saytwo.bat"
+echo @echo 3 > "say (3).bat"
+echo @echo 4 > "say .bat"
+echo ------ Testing invocation of batch files ----------
+call say one
+call "say one"
+call "say"" one"
+call "say one
+call :setError 0
+call say" one"
+if errorlevel 1 echo error %ErrorLevel%
+call say "one"
+call :setError 0
+call s"ay one
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call s"aytwo
+if errorlevel 1 echo error %ErrorLevel%
+call say (3)
+call "say (3)"
+call :setError 0
+call say" (3)"
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call say" "(3) prints 4?!
+if errorlevel 1 echo error %ErrorLevel%
+echo ------ Testing invocation with CMD /C -------------
+cmd /c say one
+cmd /c "say one"
+call :setError 0
+cmd /c "say"" one"
+if errorlevel 1 echo error %ErrorLevel%
+cmd /c "say one
+call :setError 0
+cmd /c say" one"
+if errorlevel 1 echo error %ErrorLevel%
+cmd /c say "one"
+call :setError 0
+cmd /c s"ay one
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+cmd /c s"aytwo
+if errorlevel 1 echo error %ErrorLevel%
+cmd /c say (3)
+call :setError 0
+cmd /c say" (3)"
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+cmd /c say" "(3) prints 4?!
+if errorlevel 1 echo error %ErrorLevel%
+echo ---------- Testing CMD /C quoting -----------------
+cmd /c @echo "hi"
+call :setError 0
+cmd /c say" "one
+if errorlevel 1 echo error %ErrorLevel%
+cmd /c @echo "\"\\"\\\"\\\\" "\"\\"\\\"\\\\"
+rem ---- all 5 conditions met, quotes preserved
+cmd /c "say one"
+rem cond 1 - /s
+cmd /s/c "say one"
+cmd /s/c ""say one""
+rem cond 2 - not 2 quotes
+cmd /c "say one
+call :setError 0
+cmd /c "say"" one"
+if errorlevel 1 echo error %ErrorLevel%
+rem cond 3 - special char - first test fails on Vista, W2K8!
+cmd /c "say (3)"
+cmd /c ""say (3)""
+rem cond 4 - no spaces (quotes make no difference here)
+cmd /c saytwo
+cmd /c "saytwo"
+cmd /c "saytwo
+rem cond 5 - string between quotes must be name of executable
+cmd /c "say five"
+echo @echo 5 >"say five.bat"
+cmd /c "say five"
+echo ------- Testing CMD /C qualifier treatment ------------
+rem no need for space after /c
+cmd /csay one
+cmd /c"say one"
+rem ignore quote before qualifier
+cmd "/c"say one
+rem ignore anything before /c
+rem FIXME the next command in wine starts a sub-CMD
+echo THIS FAILS: cmd ignoreme/c say one
+echo --------- Testing special characters --------------
+echo @echo amp > "say&.bat"
+call say&
+echo @echo ( > "say(.bat"
+call say(
+echo @echo ) > "say).bat"
+call say)
+echo @echo [ > "say[.bat"
+call say[
+echo @echo ] > "say].bat"
+call say]
+echo @echo { > "say{.bat"
+call say{
+echo @echo } > "say}.bat"
+call say}
+echo @echo = > "say=.bat"
+call say=
+echo @echo sem > "say;.bat"
+call say;
+setlocal DisableDelayedExpansion
+echo @echo ! > "say!.bat"
+call say!
+endlocal
+setlocal EnableDelayedExpansion
+call say!
+endlocal
+echo @echo %%%% > "say%%.bat"
+call say%%
+echo @echo ' > "say'.bat"
+call say'
+echo @echo + > "say+.bat"
+call say+
+echo @echo com > "say,.bat"
+call say,
+echo @echo ` > "say`.bat"
+call say'
+echo @echo ~ > "say~.bat"
+call say~
+echo --------- Testing parameter passing  --------------
+echo @echo 1:%%1,2:%%2 > tell.bat
+call tell 1
+call tell (1)
+call tell 1(2)
+call :setError 0
+call tell(1)
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell((1))
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell(1)(2)
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell(1);,;(2)
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell;1 2
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell; 1, ;2
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell;1;;2
+if errorlevel 1 echo error %ErrorLevel%
+call tell "p "1 p" "2
+call tell p"1 p";2
+del tell.bat say*.*
+exit
+:setError
+exit /B %1
diff --git a/programs/cmd/tests/test_cmdline.cmd.exp b/programs/cmd/tests/test_cmdline.cmd.exp
new file mode 100755
index 0000000..fd6b151
--- /dev/null
+++ b/programs/cmd/tests/test_cmdline.cmd.exp
@@ -0,0 +1,77 @@
+------ Testing invocation of batch files ----------
+0 at space@
+1 at space@
+ at todo_wine@1 at space@
+1 at space@
+ at todo_wine@1 at space@
+0 at space@
+ at todo_wine@1 at space@
+ at todo_wine@2 at space@
+0 at space@
+3 at space@
+ at todo_wine@3 at space@
+ at todo_wine@4 at space@
+------ Testing invocation with CMD /C -------------
+0 at space@
+1 at space@
+ at todo_wine@0 at space@
+ at todo_wine@0 at space@
+1 at space@
+0 at space@
+1 at space@
+2 at space@
+0 at space@
+ at todo_wine@3 at space@
+ at todo_wine@4 at space@
+---------- Testing CMD /C quoting -----------------
+ at todo_wine@"hi"
+1 at space@
+ at todo_wine@"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\"
+1 at space@
+0 at space@
+ at todo_wine@1 at space@
+ at todo_wine@0 at space@
+ at todo_wine@0 at space@
+0 at space@@or_broken at 3@space@
+ at todo_wine@3 at space@
+2 at space@
+2 at space@
+2 at space@
+0 at space@
+5 at space@
+------- Testing CMD /C qualifier treatment ------------
+0 at space@
+1 at space@
+0 at space@
+ at todo_wine@0 at space@
+--------- Testing special characters --------------
+0 at space@
+ at todo_wine@0 at space@
+)@space@
+[@space@
+]@space@
+{@space@
+}@space@
+0 at space@
+ at todo_wine@0 at space@
+!@space@
+ at todo_wine@0 at space@
+ at todo_wine@0 at space@
+'@space@
++ at space@
+0 at space@
+'@space@
+~@space@
+--------- Testing parameter passing  --------------
+1:1,2:@space@
+1:(1),2:@space@
+1:1(2),2:@space@
+ at todo_wine@1:(1),2:@space@
+ at todo_wine@1:((1)),2:@space@
+ at todo_wine@1:(1)(2),2:@space@
+ at todo_wine@1:(1),2:(2)@space@
+ at todo_wine@1:1,2:2 at space@
+ at todo_wine@1:1,2:2 at space@
+ at todo_wine@1:1,2:2 at space@
+ at todo_wine@1:"p at space@"1,2:p"@space@"2 at space@
+ at todo_wine@1:p"1 at space@p",2:2 at space@
-- 
1.7.3.4



More information about the wine-patches mailing list