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

Martin Wilck mwilck at arcor.de
Mon Sep 19 18:51:11 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.
---
 programs/cmd/tests/rsrc.rc              |    6 +
 programs/cmd/tests/test_cmdline.cmd     |  159 ++++++++++++++++++++++
 programs/cmd/tests/test_cmdline.cmd.exp |  219 +++++++++++++++++++++++++++++++
 3 files changed, 384 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..d415c9b
--- /dev/null
+++ b/programs/cmd/tests/test_cmdline.cmd
@@ -0,0 +1,159 @@
+ at prompt $G
+ at echo @echo 0 > "say.bat"
+ at echo @echo 1 > "say one.bat"
+ at echo @echo 2 > "saytwo.bat"
+ at echo @echo 3 > "say (3).bat"
+ at echo @echo 4 > "say .bat"
+ at echo ------ Testing invocation of batch files ----------
+call say one
+call "say one"
+call "say"" one"
+call "say one
+ at call :setError 0
+call say" one"
+ at if errorlevel 1 echo error %ErrorLevel%
+call say "one"
+ at call :setError 0
+call s"ay one
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call s"aytwo
+ at if errorlevel 1 echo error %ErrorLevel%
+call say (3)
+call "say (3)"
+ at call :setError 0
+call say" (3)"
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call say" "(3) prints 4?!
+ at if errorlevel 1 echo error %ErrorLevel%
+ at echo ------ Testing invocation with CMD /C -------------
+cmd /c say one
+cmd /c "say one"
+ at call :setError 0
+cmd /c "say"" one"
+ at if errorlevel 1 echo error %ErrorLevel%
+cmd /c "say one
+ at call :setError 0
+cmd /c say" one"
+ at if errorlevel 1 echo error %ErrorLevel%
+cmd /c say "one"
+ at call :setError 0
+cmd /c s"ay one
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+cmd /c s"aytwo
+ at if errorlevel 1 echo error %ErrorLevel%
+cmd /c say (3)
+ at call :setError 0
+cmd /c say" (3)"
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+cmd /c say" "(3) prints 4?!
+ at if errorlevel 1 echo error %ErrorLevel%
+ at echo ---------- Testing CMD /C quoting -----------------
+cmd /c @echo "hi"
+ at call :setError 0
+cmd /c say" "one
+ at if errorlevel 1 echo error %ErrorLevel%
+cmd /c @echo "\"\\"\\\"\\\\" "\"\\"\\\"\\\\"
+ at rem ---- all 5 conditions met, quotes preserved 
+cmd /c "say one"
+ at rem cond 1 - /s
+cmd /s/c "say one"
+cmd /s/c ""say one""
+ at rem cond 2 - not 2 quotes
+cmd /c "say one
+ at call :setError 0
+cmd /c "say"" one"
+ at if errorlevel 1 echo error %ErrorLevel%
+ at rem cond 3 - special char - first test fails on Vista, W2K8!
+cmd /c "say (3)"
+cmd /c ""say (3)""
+ at rem cond 4 - no spaces (quotes make no difference here)
+cmd /c saytwo
+cmd /c "saytwo"
+cmd /c "saytwo
+ at rem cond 5 - string between quotes must be name of executable 
+cmd /c "say five"
+ at echo @echo 5 >"say five.bat"
+cmd /c "say five"
+ at echo ------- Testing CMD /C qualifier treatment ------------
+ at rem no need for space after /c
+cmd /csay one
+cmd /c"say one"
+ at rem ignore quote before qualifier
+cmd "/c"say one
+ at rem ignore anything before /c
+ at rem FIXME the next command in wine starts a sub-CMD
+echo THIS FAILS: cmd ignoreme/c say one
+ at echo --------- Testing special characters --------------
+ at echo @echo amp > "say&.bat"
+call say&
+ at echo @echo ( > "say(.bat"
+call say(
+ at echo @echo ) > "say).bat"
+call say)
+ at echo @echo [ > "say[.bat"
+call say[
+ at echo @echo ] > "say].bat"
+call say]
+ at echo @echo { > "say{.bat"
+call say{
+ at echo @echo } > "say}.bat"
+call say}
+ at echo @echo = > "say=.bat"
+call say=
+ at echo @echo sem > "say;.bat"
+call say;
+ at setlocal DisableDelayedExpansion
+ at echo @echo ! > "say!.bat"
+call say!
+ at endlocal
+ at setlocal EnableDelayedExpansion
+call say!
+ at endlocal
+ at echo @echo %%%% > "say%%.bat"
+call say%%
+ at echo @echo ' > "say'.bat"
+call say'
+ at echo @echo + > "say+.bat"
+call say+
+ at echo @echo com > "say,.bat"
+call say,
+ at echo @echo ` > "say`.bat"
+call say'
+ at echo @echo ~ > "say~.bat"
+call say~
+ at echo --------- Testing parameter passing  --------------
+ at echo @echo 1:%%1,2:%%2 > tell.bat
+call tell 1
+call tell (1)
+call tell 1(2)
+ at call :setError 0
+call tell(1)
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call tell((1))
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call tell(1)(2)
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call tell(1);,;(2)
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call tell;1 2
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call tell; 1, ;2
+ at if errorlevel 1 echo error %ErrorLevel%
+ at call :setError 0
+call tell;1;;2
+ at if errorlevel 1 echo error %ErrorLevel%
+call tell "p "1 p" "2
+call tell p"1 p";2
+ at del tell.bat say*.*
+ at exit
+:setError
+ at 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..9ddd939
--- /dev/null
+++ b/programs/cmd/tests/test_cmdline.cmd.exp
@@ -0,0 +1,219 @@
+------ Testing invocation of batch files ----------
+
+>call say one 
+0 at space@
+
+>call "say one" 
+1 at space@
+
+>call "say"" one" 
+ at todo_wine@1 at space@
+
+>call "say one 
+1 at space@
+
+>call say" one" 
+ at todo_wine@1 at space@
+
+>call say "one" 
+0 at space@
+
+>call s"ay one 
+ at todo_wine@1 at space@
+
+>call s"aytwo 
+ at todo_wine@2 at space@
+
+>call say (3) 
+0 at space@
+
+>call "say (3)" 
+3 at space@
+
+>call say" (3)" 
+ at todo_wine@3 at space@
+
+>call say" "(3) prints 4?! 
+ at todo_wine@4 at space@
+------ Testing invocation with CMD /C -------------
+
+>cmd /c say one 
+0 at space@
+
+>cmd /c "say one" 
+1 at space@
+
+>cmd /c "say"" one" 
+ at todo_wine@0 at space@
+
+>cmd /c "say one 
+ at todo_wine@0 at space@
+
+>cmd /c say" one" 
+1 at space@
+
+>cmd /c say "one" 
+0 at space@
+
+>cmd /c s"ay one 
+1 at space@
+
+>cmd /c s"aytwo 
+2 at space@
+
+>cmd /c say (3) 
+0 at space@
+
+>cmd /c say" (3)" 
+ at todo_wine@3 at space@
+
+>cmd /c say" "(3) prints 4?! 
+ at todo_wine@4 at space@
+---------- Testing CMD /C quoting -----------------
+
+>cmd /c @echo "hi" 
+ at todo_wine@"hi"
+
+>cmd /c say" "one 
+1 at space@
+
+>cmd /c @echo "\"\\"\\\"\\\\" "\"\\"\\\"\\\\" 
+ at todo_wine@"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\"
+
+>cmd /c "say one" 
+1 at space@
+
+>cmd /s/c "say one" 
+0 at space@
+
+>cmd /s/c ""say one"" 
+ at todo_wine@1 at space@
+
+>cmd /c "say one 
+ at todo_wine@0 at space@
+
+>cmd /c "say"" one" 
+ at todo_wine@0 at space@
+
+>cmd /c "say (3)" 
+0 at space@@or_broken at 3@space@
+
+>cmd /c ""say (3)"" 
+ at todo_wine@3 at space@
+
+>cmd /c saytwo 
+2 at space@
+
+>cmd /c "saytwo" 
+2 at space@
+
+>cmd /c "saytwo 
+2 at space@
+
+>cmd /c "say five" 
+0 at space@
+
+>cmd /c "say five" 
+5 at space@
+------- Testing CMD /C qualifier treatment ------------
+
+>cmd /csay one 
+0 at space@
+
+>cmd /c"say one" 
+1 at space@
+
+>cmd "/c"say one 
+0 at space@
+
+ at todo_wine@>cmd ignoreme/c say one 
+ at todo_wine@0 at space@
+--------- Testing special characters --------------
+
+ at todo_wine@>call say 
+0 at space@
+
+>call say( 
+ at todo_wine@0 at space@
+
+>call say) 
+)@space@
+
+>call say[ 
+[@space@
+
+>call say] 
+]@space@
+
+>call say{ 
+{@space@
+
+>call say} 
+}@space@
+
+>call say= 
+0 at space@
+
+>call say; 
+ at todo_wine@0 at space@
+
+>call say! 
+!@space@
+
+>call say! 
+ at todo_wine@0 at space@
+
+>call say% 
+ at todo_wine@0 at space@
+
+>call say' 
+'@space@
+
+>call say+ 
++ at space@
+
+>call say, 
+0 at space@
+
+>call say' 
+'@space@
+
+>call say~ 
+~@space@
+--------- Testing parameter passing  --------------
+
+>call tell 1 
+1:1,2:@space@
+
+>call tell (1) 
+1:(1),2:@space@
+
+>call tell 1(2) 
+1:1(2),2:@space@
+
+>call tell(1) 
+ at todo_wine@1:(1),2:@space@
+
+>call tell((1)) 
+ at todo_wine@1:((1)),2:@space@
+
+>call tell(1)(2) 
+ at todo_wine@1:(1)(2),2:@space@
+
+>call tell(1);,;(2) 
+ at todo_wine@1:(1),2:(2)@space@
+
+>call tell;1 2 
+ at todo_wine@1:1,2:2 at space@
+
+>call tell; 1, ;2 
+ at todo_wine@1:1,2:2 at space@
+
+>call tell;1;;2 
+ at todo_wine@1:1,2:2 at space@
+
+>call tell "p "1 p" "2 
+ at todo_wine@1:"p at space@"1,2:p"@space@"2 at space@
+
+>call tell p"1 p";2 
+ 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