cmd/tests: Add variable substitution tests.

This commit is contained in:
Frédéric Delanoy 2011-08-26 01:19:28 +02:00 committed by Alexandre Julliard
parent c85be8aecc
commit 9b79fd5777
2 changed files with 172 additions and 0 deletions

View File

@ -227,6 +227,116 @@ echo '%VAR:~-2,-4%'
echo %VAR:~-3,-2% echo %VAR:~-3,-2%
set VAR= set VAR=
echo ------------ Testing variable substitution --------------
echo ...in FOR variables
for %%i in ("A B" C) do echo %%i
rem quotes removal
for %%i in ("A B" C) do echo '%%~i'
rem fully qualified path
for %%f in ("C D" E) do echo %%~ff
rem drive letter
for %%i in ("F G" H) do echo %%~di
rem path
for %%d in ("I J" K) do echo %%~pd
rem filename
for %%i in ("L M" N) do echo %%~ni
rem file extension
for %%i in ("O. P.OOL" Q.TABC hello) do echo '%%~xi'
rem path with short path names
for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do echo '%%~sI'
rem file attribute
for %%i in ("U V" W) do echo '%%~ai'
echo foo> foo
for %%i in (foo) do echo '%%~ai'
del foo
rem file date/time
rem Not fully testable, until we can grep dir's output to get foo's creation time in an envvar...
for %%i in ("a b" c) do echo '%%~ti'
rem file size
rem Similar issues as above
for %%i in ("a b" c) do echo '%%~zi'
rem combined options
for %%i in ("d e" f) do echo %%~dpi
for %%i in ("g h" i) do echo %%~sdi
for %%i in ("g h" i) do echo %%~dsi
for %%i in ("j k" l.eh) do echo '%%~xsi'
echo ...in parameters
for %%i in ("A B" C) do call :echoFun %%i
rem quotes removal
for %%i in ("A B" C) do call :echoFunQ %%i
rem fully qualified path
for %%f in ("C D" E) do call :echoFunF %%f
rem drive letter
for %%i in ("F G" H) do call :echoFunD %%i
rem path
for %%d in ("I J" K) do call :echoFunP %%d
rem filename
for %%i in ("L M" N) do call :echoFunN %%i
rem file extension
for %%i in ("O. P.OOL" Q.TABC hello) do call :echoFunX %%i
rem path with short path names
for %%I in ("R S" T ABCDEFGHIJK.LMNOP) do call :echoFunS %%I
rem NT4 aborts whole script execution when encountering ~a, ~t and ~z substitutions, preventing full testing
rem combined options
for %%i in ("d e" f) do call :echoFunDP %%i
for %%i in ("g h" i) do call :echoFunSD %%i
for %%i in ("g h" i) do call :echoFunDS %%i
for %%i in ("j k" l.eh) do call :echoFunXS %%i
goto :endEchoFuns
:echoFun
echo %1
goto :eof
:echoFunQ
echo '%~1'
goto :eof
:echoFunF
echo %~f1
goto :eof
:echoFunD
echo %~d1
goto :eof
:echoFunP
echo %~p1
goto :eof
:echoFunN
echo %~n1
goto :eof
:echoFunX
echo '%~x1'
goto :eof
:echoFunS
rem some NT4 workaround
set VAR='%~s1'
echo %VAR%
set VAR=
goto :eof
:echoFunDP
echo %~dp1
goto :eof
:echoFunSD
echo %~sd1
goto :eof
:echoFunDS
echo %~ds1
goto :eof
:echoFunXS
echo '%~xs1'
goto :eof
:endEchoFuns
echo ------------ Testing variable delayed expansion -------------- echo ------------ Testing variable delayed expansion --------------
rem NT4 doesn't support this rem NT4 doesn't support this
echo ...default mode (load-time expansion) echo ...default mode (load-time expansion)

View File

@ -213,6 +213,68 @@ ert@or_broken@qwerty
e@or_broken@qwerty e@or_broken@qwerty
''@or_broken@'qwerty' ''@or_broken@'qwerty'
r@or_broken@qwerty r@or_broken@qwerty
------------ Testing variable substitution --------------
...in FOR variables
@todo_wine@"A B"
C
'A B'@or_broken@''
'C'@or_broken@''
@pwd@\C D@or_broken@%~ff
@pwd@\E@or_broken@%~ff
@drive@
@drive@
@path@@or_broken@%~pd
@path@@or_broken@%~pd
L M
N
'.OOL'
'.TABC'
''
@todo_wine@'@drive@@shortpath@R S'@or_broken@''
@todo_wine@'@drive@@shortpath@T'@or_broken@''
@todo_wine@'@drive@@shortpath@ABCDEFGHIJK.LMNOP'@or_broken@''
@todo_wine@''@or_broken@'%~ai'
@todo_wine@''@or_broken@'%~ai'
@todo_wine@'--a------'@or_broken@'%~ai'
@todo_wine@''@or_broken@'%~ti'
@todo_wine@''@or_broken@'%~ti'
@todo_wine@''@or_broken@'%~zi'
@todo_wine@''@or_broken@'%~zi'
@drive@@path@
@drive@@path@
@drive@
@drive@
@drive@
@drive@
''
'.eh'
...in parameters
@todo_wine@"A B"
C
@todo_wine@'A B'@or_broken@''
'C'@or_broken@''
@todo_wine@@pwd@\C D
@pwd@\E
@drive@
@drive@
@path@
@path@
@todo_wine@L M
N
@todo_wine@'.OOL'
'.TABC'
''
@todo_wine@'@drive@@shortpath@R S'@or_broken@''
@todo_wine@'@drive@@shortpath@T'@or_broken@''
@todo_wine@'@drive@@shortpath@ABCDEFGHIJK.LMNOP'@or_broken@''
@drive@@path@
@drive@@path@
@drive@
@drive@
@drive@
@drive@
''
'.eh'@or_broken@''
------------ Testing variable delayed expansion -------------- ------------ Testing variable delayed expansion --------------
...default mode (load-time expansion) ...default mode (load-time expansion)
foo foo