Commit 2e928530 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd: Prevent external env vars causing tests to fail.

parent 47b35d55
......@@ -223,67 +223,70 @@ echo foo ^> foo
echo ^<> foo
type foo
del foo
set FOO=oof
echo ff^%FOO%
set FOO=bar ^| baz
set FOO
rem FIXME: echoing %FOO% gives an error (baz not recognized) but prematurely
set WINE_FOO=oof
echo ff^%WINE_FOO%
set WINE_FOO=bar ^| baz
set WINE_FOO
rem FIXME: echoing %WINE_FOO% gives an error (baz not recognized) but prematurely
rem exits the script on windows; redirecting stdout and/or stderr doesn't help
echo %ErrorLevel%
call :setError 0
set FOO=bar ^^^| baz
set FOO
echo %FOO%
set WINE_FOO=bar ^^^| baz
set WINE_FOO
echo %WINE_FOO%
echo %ErrorLevel%
set FOO=
set WINE_FOO=
echo ------------ Testing 'set' ------------
call :setError 0
set FOOBAR 2> nul > nul
rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
for /f "delims==" %%i in ('set WINE_ba') do set %%i=
for /f "delims==" %%i in ('set WINE_foo') do set %%i=
set WINE_FOOBAR 2> nul > nul
echo %ErrorLevel%
set FOOBAR = baz
set WINE_FOOBAR = baz
echo %ErrorLevel%
echo %FOOBAR%FOOBAR not defined
echo %FOOBAR %
set FOOBAR 2> nul
set FOOBAR = baz2
echo %WINE_FOOBAR%WINE_FOOBAR not defined
echo %WINE_FOOBAR %
set WINE_FOOBAR 2> nul
set WINE_FOOBAR = baz2
echo %ErrorLevel%
echo %fOObAr %
set FOOBAR= bar
echo %WINE_fOObAr %
set WINE_FOOBAR= bar
echo %ErrorLevel%
echo %FOOBAR%
set FOO
set FOOBAR=
set FOOB
echo %FOOBAR%FOOBAR not defined
set FOOBAR =
set FOOBA 2> nul > nul
echo %WINE_FOOBAR%
set WINE_FOO
set WINE_FOOBAR=
set WINE_FOOB
echo %WINE_FOOBAR%WINE_FOOBAR not defined
set WINE_FOOBAR =
set WINE_FOOBA 2> nul > nul
echo %ErrorLevel%
set FOO=bar
echo %FOO%
set FOO=foo
set BAR=bar
echo %FOO%%BAR%
set BAR=
set FOO=
set FOO=%FOO%
echo %FOO%FOO not defined
set BAZ%=bazbaz
set BA
echo %BAZ%%
set BAZ%=
echo set "FOO=bar" should not include the quotes in the variable value
set "FOO=bar"
echo %FOO%
set@tab@FOO=foo
echo %FOO%
set@tab@FOO=
echo '%FOO%'
set FOO=foo@space@
echo '%FOO%'
set FOO=foo@tab@
echo '%FOO%'
set FOO=
set WINE_FOO=bar
echo %WINE_FOO%
set WINE_FOO=foo
set WINE_BAR=bar
echo %WINE_FOO%%WINE_BAR%
set WINE_BAR=
set WINE_FOO=
set WINE_FOO=%WINE_FOO%
echo %WINE_FOO%WINE_FOO not defined
set WINE_BAZ%=bazbaz
set WINE_BA
echo %WINE_BAZ%%
set WINE_BAZ%=
echo set "WINE_FOO=bar" should not include the quotes in the variable value
set "WINE_FOO=bar"
echo %WINE_FOO%
set@tab@WINE_FOO=foo
echo %WINE_FOO%
set@tab@WINE_FOO=
echo '%WINE_FOO%'
set WINE_FOO=foo@space@
echo '%WINE_FOO%'
set WINE_FOO=foo@tab@
echo '%WINE_FOO%'
set WINE_FOO=
echo ------------ Testing variable expansion ------------
call :setError 0
......@@ -298,9 +301,9 @@ echo CD value %CD%
echo %%
echo P%
echo %P
echo %UNKNOWN%S
echo P%UNKNOWN%
echo P%UNKNOWN%S
echo %WINE_UNKNOWN%S
echo P%WINE_UNKNOWN%
echo P%WINE_UNKNOWN%S
echo %ERRORLEVEL
echo %ERRORLEVEL%
echo %ERRORLEVEL%%ERRORLEVEL%
......@@ -312,17 +315,17 @@ echo %ERRORLEVEL%S
echo P%ERRORLEVEL%S
echo ------------ Testing variable substrings ------------
set VAR=qwerty
echo %VAR:~0,1%
echo %VAR:~0,3%
echo %VAR:~2,2%
echo '%VAR:~-2,3%'
echo '%VAR:~-2,1%'
echo %VAR:~2,-1%
echo %VAR:~2,-3%
echo '%VAR:~-2,-4%'
echo %VAR:~-3,-2%
set VAR=
set WINE_VAR=qwerty
echo %WINE_VAR:~0,1%
echo %WINE_VAR:~0,3%
echo %WINE_VAR:~2,2%
echo '%WINE_VAR:~-2,3%'
echo '%WINE_VAR:~-2,1%'
echo %WINE_VAR:~2,-1%
echo %WINE_VAR:~2,-3%
echo '%WINE_VAR:~-2,-4%'
echo %WINE_VAR:~-3,-2%
set WINE_VAR=
echo ------------ Testing variable substitution ------------
echo --- in FOR variables
......@@ -415,9 +418,9 @@ goto :eof
:echoFunS
rem some NT4 workaround
set VAR='%~s1'
echo %VAR%
set VAR=
set WINE_VAR='%~s1'
echo %WINE_VAR%
set WINE_VAR=
goto :eof
:echoFunDP
......@@ -440,48 +443,48 @@ goto :eof
echo ------------ Testing variable delayed expansion ------------
rem NT4 doesn't support this
echo --- default mode (load-time expansion)
set FOO=foo
echo %FOO%
echo !FOO!
if %FOO% == foo (
set FOO=bar
if %FOO% == bar (echo bar) else echo foo
set WINE_FOO=foo
echo %WINE_FOO%
echo !WINE_FOO!
if %WINE_FOO% == foo (
set WINE_FOO=bar
if %WINE_FOO% == bar (echo bar) else echo foo
)
set FOO=foo
if %FOO% == foo (
set FOO=bar
if !FOO! == bar (echo bar) else echo foo
set WINE_FOO=foo
if %WINE_FOO% == foo (
set WINE_FOO=bar
if !WINE_FOO! == bar (echo bar) else echo foo
)
echo --- runtime (delayed) expansion mode
setlocal EnableDelayedExpansion
set FOO=foo
echo %FOO%
echo !FOO!
if %FOO% == foo (
set FOO=bar
if %FOO% == bar (echo bar) else echo foo
set WINE_FOO=foo
echo %WINE_FOO%
echo !WINE_FOO!
if %WINE_FOO% == foo (
set WINE_FOO=bar
if %WINE_FOO% == bar (echo bar) else echo foo
)
set FOO=foo
if %FOO% == foo (
set FOO=bar
if !FOO! == bar (echo bar) else echo foo
set WINE_FOO=foo
if %WINE_FOO% == foo (
set WINE_FOO=bar
if !WINE_FOO! == bar (echo bar) else echo foo
)
echo %ErrorLevel%
setlocal DisableDelayedExpansion
echo %ErrorLevel%
set FOO=foo
echo %FOO%
echo !FOO!
set FOO=
set WINE_FOO=foo
echo %WINE_FOO%
echo !WINE_FOO!
set WINE_FOO=
echo --- using /V cmd flag
echo @echo off> tmp.cmd
echo set FOO=foo>> tmp.cmd
echo echo %%FOO%%>> tmp.cmd
echo echo !FOO!>> tmp.cmd
echo set FOO=>> tmp.cmd
echo set WINE_FOO=foo>> tmp.cmd
echo echo %%WINE_FOO%%>> tmp.cmd
echo echo !WINE_FOO!>> tmp.cmd
echo set WINE_FOO=>> tmp.cmd
cmd /V:ON /C tmp.cmd
cmd /V:OfF /C tmp.cmd
del tmp.cmd
......@@ -660,9 +663,9 @@ if "9" LSS "10" (echo numbers in quotes recognized!) else echo numbers in quotes
if not "-1" LSS "1" (echo negative numbers as well) else echo NT4
if /i foo LSS FoOc echo if /i seems to work for LSS
if /I not foo LSS FOOb echo if /I seems to be broken for LSS
set STR_PARMS=A B AB BA AA
for %%i in (%STR_PARMS%) do (
for %%j in (%STR_PARMS%) do (
set WINE_STR_PARMS=A B AB BA AA
for %%i in (%WINE_STR_PARMS%) do (
for %%j in (%WINE_STR_PARMS%) do (
call :LSStest %%i %%j))
if b LSS B (echo b LSS B) else echo NT4
if /I b LSS B echo b LSS B insensitive
......@@ -672,8 +675,8 @@ if a LSS B (echo a LSS B) else echo NT4
if /I a LSS B echo a LSS B insensitive
if A LSS b echo A LSS b
if /I A LSS b echo A LSS b insensitive
for %%i in (%STR_PARMS%) do (
for %%j in (%STR_PARMS%) do (
for %%i in (%WINE_STR_PARMS%) do (
for %%j in (%WINE_STR_PARMS%) do (
call :LEQtest %%i %%j))
if b LEQ B (echo b LEQ B) else echo NT4
if /I b LEQ B echo b LEQ B insensitive
......@@ -683,18 +686,18 @@ if a LEQ B (echo a LEQ B) else echo NT4
if /I a LEQ B echo a LEQ B insensitive
if A LEQ b echo A LEQ b
if /I A LEQ b echo A LEQ b insensitive
for %%i in (%STR_PARMS%) do (
for %%j in (%STR_PARMS%) do (
for %%i in (%WINE_STR_PARMS%) do (
for %%j in (%WINE_STR_PARMS%) do (
call :EQUtest %%i %%j))
if /I A EQU a echo A EQU a insensitive
for %%i in (%STR_PARMS%) do (
for %%j in (%STR_PARMS%) do (
for %%i in (%WINE_STR_PARMS%) do (
for %%j in (%WINE_STR_PARMS%) do (
call :NEQtest %%i %%j))
for %%i in (%STR_PARMS%) do (
for %%j in (%STR_PARMS%) do (
for %%i in (%WINE_STR_PARMS%) do (
for %%j in (%WINE_STR_PARMS%) do (
call :GEQtest %%i %%j))
for %%i in (%STR_PARMS%) do (
for %%j in (%STR_PARMS%) do (
for %%i in (%WINE_STR_PARMS%) do (
for %%j in (%WINE_STR_PARMS%) do (
call :GTRtest %%i %%j))
echo ------ for numbers
if -1 LSS 1 (echo negative numbers handled)
......@@ -704,28 +707,28 @@ if not -010 LSS -8 (echo also in negative form)
if 4 LSS 0x5 (echo hexa handled)
if not -1 LSS -0x1A (echo also in negative form)
if 11 LSS 101 (echo 11 LSS 101)
set INT_PARMS=0 1 10 9
for %%i in (%INT_PARMS%) do (
for %%j in (%INT_PARMS%) do (
set WINE_INT_PARMS=0 1 10 9
for %%i in (%WINE_INT_PARMS%) do (
for %%j in (%WINE_INT_PARMS%) do (
call :LSStest %%i %%j))
for %%i in (%INT_PARMS%) do (
for %%j in (%INT_PARMS%) do (
for %%i in (%WINE_INT_PARMS%) do (
for %%j in (%WINE_INT_PARMS%) do (
call :LEQtest %%i %%j))
for %%i in (%INT_PARMS%) do (
for %%j in (%INT_PARMS%) do (
for %%i in (%WINE_INT_PARMS%) do (
for %%j in (%WINE_INT_PARMS%) do (
call :EQUtest %%i %%j))
if 011 EQU 9 (echo octal ok)
if 0xA1 EQU 161 (echo hexa ok)
if 0xA1 EQU "161" (echo hexa should be recognized) else (echo string/hexa compare ok)
if "0xA1" EQU 161 (echo hexa should be recognized) else (echo string/hexa compare ok)
for %%i in (%INT_PARMS%) do (
for %%j in (%INT_PARMS%) do (
for %%i in (%WINE_INT_PARMS%) do (
for %%j in (%WINE_INT_PARMS%) do (
call :NEQtest %%i %%j))
for %%i in (%INT_PARMS%) do (
for %%j in (%INT_PARMS%) do (
for %%i in (%WINE_INT_PARMS%) do (
for %%j in (%WINE_INT_PARMS%) do (
call :GEQtest %%i %%j))
for %%i in (%INT_PARMS%) do (
for %%j in (%INT_PARMS%) do (
for %%i in (%WINE_INT_PARMS%) do (
for %%j in (%WINE_INT_PARMS%) do (
call :GTRtest %%i %%j))
echo ------ for numbers and stringified numbers
if not "1" EQU 1 (echo strings and integers not equal) else echo foo
......@@ -769,8 +772,8 @@ if %1 GTR %2 echo %1 GTR %2
goto :eof
:endIfCompOpsSubroutines
set STR_PARMS=
set INT_PARMS=
set WINE_STR_PARMS=
set WINE_INT_PARMS=
echo ------------ Testing for ------------
echo --- plain FOR
......@@ -860,11 +863,11 @@ goto :TestForR
:SetExpected
del temp.bat 2>nul
call :WriteLine set found=N
for /l %%i in (1,1,%expectedresults%) do (
call :WriteLine if "%%%%expectedresults.%%i%%%%"=="%%%%1" set found=Y
call :WriteLine if "%%%%found%%%%"=="Y" set expectedresults.%%i=
call :WriteLine if "%%%%found%%%%"=="Y" goto :eof
call :WriteLine set WINE_found=N
for /l %%i in (1,1,%WINE_expectedresults%) do (
call :WriteLine if "%%%%WINE_expectedresults.%%i%%%%"=="%%%%1" set WINE_found=Y
call :WriteLine if "%%%%WINE_found%%%%"=="Y" set WINE_expectedresults.%%i=
call :WriteLine if "%%%%WINE_found%%%%"=="Y" goto :eof
)
call :WriteLine echo Got unexpected result: "%%%%1"
goto :eof
......@@ -875,104 +878,106 @@ goto :EOF
:ValidateExpected
del temp.bat 2>nul
for /l %%i in (1,1,%expectedresults%) do call :WriteLine if not "%%%%expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%expectedresults.%%i%%%%"
for /l %%i in (1,1,%WINE_expectedresults%) do (
call :WriteLine if not "%%%%WINE_expectedresults.%%i%%%%"=="" echo Found missing result: "%%%%WINE_expectedresults.%%i%%%%"
)
call temp.bat
del temp.bat 2>nul
goto :eof
:TestForR
rem %CD% does not tork on NT4 so use the following workaround
for /d %%i in (.) do set CURDIR=%%~dpnxi
for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
echo --- for /R
echo Plain directory enumeration
set expectedresults=4
set expectedresults.1=%CURDIR%\.
set expectedresults.2=%CURDIR%\bar\.
set expectedresults.3=%CURDIR%\baz\.
set expectedresults.4=%CURDIR%\foo\.
set WINE_expectedresults=4
set WINE_expectedresults.1=%WINE_CURDIR%\.
set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
call :SetExpected
for /R %%i in (.) do call temp.bat %%i
call :ValidateExpected
echo Plain directory enumeration from provided root
set expectedresults=4
set expectedresults.1=%CURDIR%\.
set expectedresults.2=%CURDIR%\bar\.
set expectedresults.3=%CURDIR%\baz\.
set expectedresults.4=%CURDIR%\foo\.
set WINE_expectedresults=4
set WINE_expectedresults.1=%WINE_CURDIR%\.
set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
set WINE_expectedresults.4=%WINE_CURDIR%\foo\.
if "%CD%"=="" goto :SkipBrokenNT4
call :SetExpected
for /R "%CURDIR%" %%i in (.) do call temp.bat %%i
for /R "%WINE_CURDIR%" %%i in (.) do call temp.bat %%i
call :ValidateExpected
:SkipBrokenNT4
echo File enumeration
set expectedresults=2
set expectedresults.1=%CURDIR%\baz\bazbaz
set expectedresults.2=%CURDIR%\bazbaz
set WINE_expectedresults=2
set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
call :SetExpected
for /R %%i in (baz*) do call temp.bat %%i
call :ValidateExpected
echo File enumeration from provided root
set expectedresults=2
set expectedresults.1=%CURDIR%\baz\bazbaz
set expectedresults.2=%CURDIR%\bazbaz
set WINE_expectedresults=2
set WINE_expectedresults.1=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.2=%WINE_CURDIR%\bazbaz
call :SetExpected
for /R %%i in (baz*) do call temp.bat %%i
call :ValidateExpected
echo Mixed enumeration
set expectedresults=6
set expectedresults.1=%CURDIR%\.
set expectedresults.2=%CURDIR%\bar\.
set expectedresults.3=%CURDIR%\baz\.
set expectedresults.4=%CURDIR%\baz\bazbaz
set expectedresults.5=%CURDIR%\bazbaz
set expectedresults.6=%CURDIR%\foo\.
set WINE_expectedresults=6
set WINE_expectedresults.1=%WINE_CURDIR%\.
set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
call :SetExpected
for /R %%i in (. baz*) do call temp.bat %%i
call :ValidateExpected
echo Mixed enumeration from provided root
set expectedresults=6
set expectedresults.1=%CURDIR%\.
set expectedresults.2=%CURDIR%\bar\.
set expectedresults.3=%CURDIR%\baz\.
set expectedresults.4=%CURDIR%\baz\bazbaz
set expectedresults.5=%CURDIR%\bazbaz
set expectedresults.6=%CURDIR%\foo\.
set WINE_expectedresults=6
set WINE_expectedresults.1=%WINE_CURDIR%\.
set WINE_expectedresults.2=%WINE_CURDIR%\bar\.
set WINE_expectedresults.3=%WINE_CURDIR%\baz\.
set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.5=%WINE_CURDIR%\bazbaz
set WINE_expectedresults.6=%WINE_CURDIR%\foo\.
call :SetExpected
for /R %%i in (. baz*) do call temp.bat %%i
call :ValidateExpected
echo With duplicates enumeration
set expectedresults=12
set expectedresults.1=%CURDIR%\bar\bazbaz
set expectedresults.2=%CURDIR%\bar\fred
set expectedresults.3=%CURDIR%\baz\bazbaz
set expectedresults.4=%CURDIR%\baz\bazbaz
set expectedresults.5=%CURDIR%\baz\bazbaz
set expectedresults.6=%CURDIR%\baz\fred
set expectedresults.7=%CURDIR%\bazbaz
set expectedresults.8=%CURDIR%\bazbaz
set expectedresults.9=%CURDIR%\bazbaz
set expectedresults.10=%CURDIR%\foo\bazbaz
set expectedresults.11=%CURDIR%\foo\fred
set expectedresults.12=%CURDIR%\fred
set WINE_expectedresults=12
set WINE_expectedresults.1=%WINE_CURDIR%\bar\bazbaz
set WINE_expectedresults.2=%WINE_CURDIR%\bar\fred
set WINE_expectedresults.3=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.4=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.5=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.6=%WINE_CURDIR%\baz\fred
set WINE_expectedresults.7=%WINE_CURDIR%\bazbaz
set WINE_expectedresults.8=%WINE_CURDIR%\bazbaz
set WINE_expectedresults.9=%WINE_CURDIR%\bazbaz
set WINE_expectedresults.10=%WINE_CURDIR%\foo\bazbaz
set WINE_expectedresults.11=%WINE_CURDIR%\foo\fred
set WINE_expectedresults.12=%WINE_CURDIR%\fred
call :SetExpected
for /R %%i in (baz* bazbaz fred ba*) do call temp.bat %%i
call :ValidateExpected
echo Strip missing wildcards, keep unwildcarded names
set expectedresults=6
set expectedresults.1=%CURDIR%\bar\jim
set expectedresults.2=%CURDIR%\baz\bazbaz
set expectedresults.3=%CURDIR%\baz\jim
set expectedresults.4=%CURDIR%\bazbaz
set expectedresults.5=%CURDIR%\foo\jim
set expectedresults.6=%CURDIR%\jim
set WINE_expectedresults=6
set WINE_expectedresults.1=%WINE_CURDIR%\bar\jim
set WINE_expectedresults.2=%WINE_CURDIR%\baz\bazbaz
set WINE_expectedresults.3=%WINE_CURDIR%\baz\jim
set WINE_expectedresults.4=%WINE_CURDIR%\bazbaz
set WINE_expectedresults.5=%WINE_CURDIR%\foo\jim
set WINE_expectedresults.6=%WINE_CURDIR%\jim
call :SetExpected
for /R %%i in (baz* fred* jim) do call temp.bat %%i
call :ValidateExpected
......@@ -1014,81 +1019,81 @@ echo --- for /a
rem No output when using "set expr" syntax, unless in interactive mode
rem Need to use "set envvar=expr" to use in a batch script
echo ------ individual operations
set var=0
set /a var=1 +2 & echo %var%
set /a var=1 +-2 & echo %var%
set /a var=1 --2 & echo %var%
set /a var=2* 3 & echo %var%
set /a var=-2* -5 & echo %var%
set /a var=12/3 & echo %var%
set /a var=13/3 & echo %var%
set /a var=-13/3 & echo %var%
set WINE_var=0
set /a WINE_var=1 +2 & echo %WINE_var%
set /a WINE_var=1 +-2 & echo %WINE_var%
set /a WINE_var=1 --2 & echo %WINE_var%
set /a WINE_var=2* 3 & echo %WINE_var%
set /a WINE_var=-2* -5 & echo %WINE_var%
set /a WINE_var=12/3 & echo %WINE_var%
set /a WINE_var=13/3 & echo %WINE_var%
set /a WINE_var=-13/3 & echo %WINE_var%
rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
set /a var=5 %% 5 & echo %var%
set /a var=5 %% 3 & echo %var%
set /a var=5 %% -3 & echo %var%
set /a var=-5 %% -3 & echo %var%
set /a var=1 ^<^< 0 & echo %var%
set /a var=1 ^<^< 2 & echo %var%
set /a var=1 ^<^< -2 & echo %var%
set /a var=-1 ^<^< -2 & echo %var%
set /a var=-1 ^<^< 2 & echo %var%
set /a var=9 ^>^> 0 & echo %var%
set /a var=9 ^>^> 2 & echo %var%
set /a var=9 ^>^> -2 & echo %var%
set /a var=-9 ^>^> -2 & echo %var%
set /a var=-9 ^>^> 2 & echo %var%
set /a var=5 ^& 0 & echo %var%
set /a var=5 ^& 1 & echo %var%
set /a var=5 ^& 3 & echo %var%
set /a var=5 ^& 4 & echo %var%
set /a var=5 ^& 1 & echo %var%
set /a var=5 ^| 0 & echo %var%
set /a var=5 ^| 1 & echo %var%
set /a var=5 ^| 3 & echo %var%
set /a var=5 ^| 4 & echo %var%
set /a var=5 ^| 1 & echo %var%
set /a var=5 ^^ 0 & echo %var%
set /a var=5 ^^ 1 & echo %var%
set /a var=5 ^^ 3 & echo %var%
set /a var=5 ^^ 4 & echo %var%
set /a var=5 ^^ 1 & echo %var%
set /a WINE_var=5 %% 5 & echo %WINE_var%
set /a WINE_var=5 %% 3 & echo %WINE_var%
set /a WINE_var=5 %% -3 & echo %WINE_var%
set /a WINE_var=-5 %% -3 & echo %WINE_var%
set /a WINE_var=1 ^<^< 0 & echo %WINE_var%
set /a WINE_var=1 ^<^< 2 & echo %WINE_var%
set /a WINE_var=1 ^<^< -2 & echo %WINE_var%
set /a WINE_var=-1 ^<^< -2 & echo %WINE_var%
set /a WINE_var=-1 ^<^< 2 & echo %WINE_var%
set /a WINE_var=9 ^>^> 0 & echo %WINE_var%
set /a WINE_var=9 ^>^> 2 & echo %WINE_var%
set /a WINE_var=9 ^>^> -2 & echo %WINE_var%
set /a WINE_var=-9 ^>^> -2 & echo %WINE_var%
set /a WINE_var=-9 ^>^> 2 & echo %WINE_var%
set /a WINE_var=5 ^& 0 & echo %WINE_var%
set /a WINE_var=5 ^& 1 & echo %WINE_var%
set /a WINE_var=5 ^& 3 & echo %WINE_var%
set /a WINE_var=5 ^& 4 & echo %WINE_var%
set /a WINE_var=5 ^& 1 & echo %WINE_var%
set /a WINE_var=5 ^| 0 & echo %WINE_var%
set /a WINE_var=5 ^| 1 & echo %WINE_var%
set /a WINE_var=5 ^| 3 & echo %WINE_var%
set /a WINE_var=5 ^| 4 & echo %WINE_var%
set /a WINE_var=5 ^| 1 & echo %WINE_var%
set /a WINE_var=5 ^^ 0 & echo %WINE_var%
set /a WINE_var=5 ^^ 1 & echo %WINE_var%
set /a WINE_var=5 ^^ 3 & echo %WINE_var%
set /a WINE_var=5 ^^ 4 & echo %WINE_var%
set /a WINE_var=5 ^^ 1 & echo %WINE_var%
echo ------ precedence and grouping
set /a var=4 + 2*3 & echo %var%
set /a var=(4+2)*3 & echo %var%
set /a var=4 * 3/5 & echo %var%
set /a var=(4 * 3)/5 & echo %var%
set /a var=4 * 5 %% 4 & echo %var%
set /a var=4 * (5 %% 4) & echo %var%
set /a var=3 %% (5 + 8 %% 3 ^^ 2) & echo %var%
set /a var=3 %% (5 + 8 %% 3 ^^ -2) & echo %var%
set /a WINE_var=4 + 2*3 & echo %WINE_var%
set /a WINE_var=(4+2)*3 & echo %WINE_var%
set /a WINE_var=4 * 3/5 & echo %WINE_var%
set /a WINE_var=(4 * 3)/5 & echo %WINE_var%
set /a WINE_var=4 * 5 %% 4 & echo %WINE_var%
set /a WINE_var=4 * (5 %% 4) & echo %WINE_var%
set /a WINE_var=3 %% (5 + 8 %% 3 ^^ 2) & echo %WINE_var%
set /a WINE_var=3 %% (5 + 8 %% 3 ^^ -2) & echo %WINE_var%
echo ------ octal and hexadecimal
set /a var=0xf + 3 & echo %var%
set /a var=0xF + 3 & echo %var%
set /a var=015 + 2 & echo %var%
set /a var=3, 8+3,0 & echo %var%
set /a WINE_var=0xf + 3 & echo %WINE_var%
set /a WINE_var=0xF + 3 & echo %WINE_var%
set /a WINE_var=015 + 2 & echo %WINE_var%
set /a WINE_var=3, 8+3,0 & echo %WINE_var%
echo ------ variables
set /a var=foo=3, foo+1 & echo %var%
if defined foo (echo %foo%) else (
echo foo not defined
set /a WINE_var=WINE_foo=3, WINE_foo+1 & echo %WINE_var%
if defined WINE_foo (echo %WINE_foo%) else (
echo WINE_foo not defined
)
set /a var=foo=3, foo+=1 & echo %var%
set /a var=foo=3, bar=1, bar+=foo, bar & echo %var%
set /a var=foo*= foo & echo %var%
set /a var=whateverNonExistingVar & echo %var%
set /a var=whateverNonExistingVar + bar & echo %var%
set /a var=foo -= foo + 7 & echo %var%
set /a var=foo /= 3 + 2 & echo %var%
set /a var=foo=5, foo %%=2 & echo %var%
set /a var=foo ^<^<= 2 & echo %var%
set /a var=foo ^>^>= 2 & echo %var%
set /a var=foo ^&= 2 & echo %var%
set /a var=foo=5, foo ^|= 2 & echo %var%
set /a var=foo=5, foo ^^= 2 & echo %var%
set /a var=foo=19, foo %%= 4 + (bar %%= 7) & echo.
set foo=
set bar=
set var=
set /a WINE_var=WINE_foo=3, WINE_foo+=1 & echo %WINE_var%
set /a WINE_var=WINE_foo=3, WINE_bar=1, WINE_bar+=WINE_foo, WINE_bar & echo %WINE_var%
set /a WINE_var=WINE_foo*= WINE_foo & echo %WINE_var%
set /a WINE_var=WINE_whateverNonExistingVar & echo %WINE_var%
set /a WINE_var=WINE_whateverNonExistingVar + WINE_bar & echo %WINE_var%
set /a WINE_var=WINE_foo -= WINE_foo + 7 & echo %WINE_var%
set /a WINE_var=WINE_foo /= 3 + 2 & echo %WINE_var%
set /a WINE_var=WINE_foo=5, WINE_foo %%=2 & echo %WINE_var%
set /a WINE_var=WINE_foo ^<^<= 2 & echo %WINE_var%
set /a WINE_var=WINE_foo ^>^>= 2 & echo %WINE_var%
set /a WINE_var=WINE_foo ^&= 2 & echo %WINE_var%
set /a WINE_var=WINE_foo=5, WINE_foo ^|= 2 & echo %WINE_var%
set /a WINE_var=WINE_foo=5, WINE_foo ^^= 2 & echo %WINE_var%
set /a WINE_var=WINE_foo=19, WINE_foo %%= 4 + (WINE_bar %%= 7) & echo.
set WINE_foo=
set WINE_bar=
set WINE_var=
echo --- for /F
mkdir foobar & cd foobar
echo ------ string argument
......@@ -1716,21 +1721,21 @@ assoc .foo=
rem Removing a file type association doesn't work on XP due to a bug, so a workaround is needed
setlocal EnableDelayedExpansion
set FOO=original value
set WINE_FOO=original value
ftype footype=
ftype footype > baz
for /F %%i in ('type baz') do (set FOO=buggyXP)
for /F %%i in ('type baz') do (set WINE_FOO=buggyXP)
rem Resetting actually works on wine/NT4, but is reported as failing due to the peculiar test (and non-support for EnabledDelayedExpansion)
rem FIXME Revisit once a grep-like program like ftype is implemented
rem (e.g. to check baz's size using dir /b instead)
echo !FOO!
echo !WINE_FOO!
rem cleanup registry
echo REGEDIT4> regCleanup.reg
echo.>> regCleanup.reg
echo [-HKEY_CLASSES_ROOT\footype]>> regCleanup.reg
regedit /s regCleanup.reg
set FOO=
set WINE_FOO=
endlocal
cd .. & rd /s/q foobar
......@@ -1774,9 +1779,9 @@ call mkdir foo
echo %ErrorLevel%
if exist foo (echo foo created) else echo foo should exist!
rmdir foo
set FOOBAZ_VAR=foobaz
call echo Should expand %FOOBAZ_VAR%
set FOOBAZ_VAR=
set WINE_FOOBAZ_VAR=foobaz
call echo Should expand %WINE_FOOBAZ_VAR%
set WINE_FOOBAZ_VAR=
echo>batfile
call dir /b
echo>robinfile
......@@ -1889,14 +1894,14 @@ if not exist "%1" (
echo Failed: File missing when requested filesize check [%2]
goto :ContinueFileSizeChecks
)
for %%i in (%1) do set filesize=%%~zi
if "%filesize%"=="%2" (
echo Passed: file size check on %1 [%filesize%]
for %%i in (%1) do set WINE_filesize=%%~zi
if "%WINE_filesize%"=="%2" (
echo Passed: file size check on %1 [%WINE_filesize%]
) else (
if "%filesize%"=="%%~zi" (
if "%WINE_filesize%"=="%%~zi" (
echo Skipping file size check on NT4
) else (
echo Failed: file size check on %1 [%filesize% != %2]
echo Failed: file size check on %1 [%WINE_filesize% != %2]
)
)
:ContinueFileSizeChecks
......@@ -2171,164 +2176,164 @@ cmd /e:oN /C tmp.cmd
rem FIXME: creating file before setting envvar value to prevent parsing-time evaluation (due to EnableDelayedExpansion not being implemented/available yet)
echo --- setlocal with corresponding endlocal
rem %CD% does not tork on NT4 so use the following workaround
for /d %%i in (.) do set CURDIR=%%~dpnxi
for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
echo @echo off> test.cmd
echo echo %%VAR%%>> test.cmd
echo echo %%WINE_VAR%%>> test.cmd
echo setlocal>> test.cmd
echo set VAR=localval>> test.cmd
echo set WINE_VAR=localval>> test.cmd
echo md foobar2>> test.cmd
echo cd foobar2>> test.cmd
echo echo %%VAR%%>> test.cmd
echo echo %%WINE_VAR%%>> test.cmd
echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
echo endlocal>> test.cmd
echo echo %%VAR%%>> test.cmd
echo echo %%WINE_VAR%%>> test.cmd
echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
set VAR=globalval
set WINE_VAR=globalval
call test.cmd
echo %VAR%
echo %WINE_VAR%
for /d %%i in (.) do echo %%~dpnxi
cd /d %curdir%
cd /d %WINE_CURDIR%
rd foobar2
set VAR=
set WINE_VAR=
echo --- setlocal with no corresponding endlocal
echo @echo off> test.cmd
echo echo %%VAR%%>> test.cmd
echo echo %%WINE_VAR%%>> test.cmd
echo setlocal>> test.cmd
echo set VAR=localval>> test.cmd
echo set WINE_VAR=localval>> test.cmd
echo md foobar2>> test.cmd
echo cd foobar2>> test.cmd
echo echo %%VAR%%>> test.cmd
echo echo %%WINE_VAR%%>> test.cmd
echo for /d %%%%i in (.) do echo %%%%~dpnxi>> test.cmd
set VAR=globalval
set WINE_VAR=globalval
rem %CD% does not tork on NT4 so use the following workaround
for /d %%i in (.) do set CURDIR=%%~dpnxi
for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
call test.cmd
echo %VAR%
echo %WINE_VAR%
for /d %%i in (.) do echo %%~dpnxi
cd /d %curdir%
cd /d %WINE_CURDIR%
rd foobar2
set VAR=
set WINE_VAR=
echo --- setlocal within same batch program
set var1=one
set var2=
set var3=
set WINE_var1=one
set WINE_var2=
set WINE_var3=
rem %CD% does not tork on NT4 so use the following workaround
for /d %%i in (.) do set CURDIR=%%~dpnxi
for /d %%i in (.) do set WINE_CURDIR=%%~dpnxi
setlocal
set var2=two
set WINE_var2=two
mkdir foobar2
cd foobar2
setlocal
set var3=three
if "%var1%"=="one" echo Var1 ok 1
if "%var2%"=="two" echo Var2 ok 2
if "%var3%"=="three" echo Var3 ok 3
for /d %%i in (.) do set curdir2=%%~dpnxi
if "%curdir2%"=="%curdir%\foobar2" echo Directory is ok 1
set WINE_var3=three
if "%WINE_var1%"=="one" echo Var1 ok 1
if "%WINE_var2%"=="two" echo Var2 ok 2
if "%WINE_var3%"=="three" echo Var3 ok 3
for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 1
endlocal
if "%var1%"=="one" echo Var1 ok 1
if "%var2%"=="two" echo Var2 ok 2
if "%var3%"=="" echo Var3 ok 3
for /d %%i in (.) do set curdir2=%%~dpnxi
if "%curdir2%"=="%curdir%\foobar2" echo Directory is ok 2
if "%WINE_var1%"=="one" echo Var1 ok 1
if "%WINE_var2%"=="two" echo Var2 ok 2
if "%WINE_var3%"=="" echo Var3 ok 3
for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
if "%WINE_curdir2%"=="%WINE_CURDIR%\foobar2" echo Directory is ok 2
endlocal
if "%var1%"=="one" echo Var1 ok 1
if "%var2%"=="" echo Var2 ok 2
if "%var3%"=="" echo Var3 ok 3
for /d %%i in (.) do set curdir2=%%~dpnxi
if "%curdir2%"=="%curdir%" echo Directory is ok 3
if "%WINE_var1%"=="one" echo Var1 ok 1
if "%WINE_var2%"=="" echo Var2 ok 2
if "%WINE_var3%"=="" echo Var3 ok 3
for /d %%i in (.) do set WINE_curdir2=%%~dpnxi
if "%WINE_curdir2%"=="%WINE_CURDIR%" echo Directory is ok 3
rd foobar2 /s /q
set var1=
set WINE_var1=
echo --- Mismatched set and end locals
mkdir foodir2 2>nul
mkdir foodir3 2>nul
mkdir foodir4 2>nul
rem %CD% does not tork on NT4 so use the following workaround
for /d %%i in (.) do set curdir=%%~dpnxi
for /d %%i in (.) do set WINE_curdir=%%~dpnxi
echo @echo off> 2set1end.cmd
echo echo %%VAR%%>> 2set1end.cmd
echo echo %%WINE_var%%>> 2set1end.cmd
echo setlocal>> 2set1end.cmd
echo set VAR=2set1endvalue1>> 2set1end.cmd
echo set WINE_VAR=2set1endvalue1>> 2set1end.cmd
echo cd ..\foodir3>> 2set1end.cmd
echo setlocal>> 2set1end.cmd
echo set VAR=2set1endvalue2>> 2set1end.cmd
echo set WINE_VAR=2set1endvalue2>> 2set1end.cmd
echo cd ..\foodir4>> 2set1end.cmd
echo endlocal>> 2set1end.cmd
echo echo %%VAR%%>> 2set1end.cmd
echo echo %%WINE_var%%>> 2set1end.cmd
echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 2set1end.cmd
echo @echo off> 1set2end.cmd
echo echo %%VAR%%>> 1set2end.cmd
echo echo %%WINE_var%%>> 1set2end.cmd
echo setlocal>> 1set2end.cmd
echo set VAR=1set2endvalue1>> 1set2end.cmd
echo set WINE_VAR=1set2endvalue1>> 1set2end.cmd
echo cd ..\foodir3>> 1set2end.cmd
echo endlocal>> 1set2end.cmd
echo echo %%VAR%%>> 1set2end.cmd
echo echo %%WINE_var%%>> 1set2end.cmd
echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
echo endlocal>> 1set2end.cmd
echo echo %%VAR%%>> 1set2end.cmd
echo echo %%WINE_var%%>> 1set2end.cmd
echo for /d %%%%i in (.) do echo %%%%~dpnxi>> 1set2end.cmd
echo --- Extra setlocal in called batch
set VAR=value1
set WINE_VAR=value1
rem -- setlocal1 == this batch, should never be used inside a called routine
setlocal
set var=value2
set WINE_var=value2
cd foodir2
call %curdir%\2set1end.cmd
call %WINE_CURDIR%\2set1end.cmd
echo Finished:
echo %VAR%
echo %WINE_VAR%
for /d %%i in (.) do echo %%~dpnxi
endlocal
echo %VAR%
echo %WINE_VAR%
for /d %%i in (.) do echo %%~dpnxi
cd /d %curdir%
cd /d %WINE_CURDIR%
echo --- Extra endlocal in called batch
set VAR=value1
set WINE_VAR=value1
rem -- setlocal1 == this batch, should never be used inside a called routine
setlocal
set var=value2
set WINE_var=value2
cd foodir2
call %curdir%\1set2end.cmd
call %WINE_CURDIR%\1set2end.cmd
echo Finished:
echo %VAR%
echo %WINE_VAR%
for /d %%i in (.) do echo %%~dpnxi
endlocal
echo %VAR%
echo %WINE_VAR%
for /d %%i in (.) do echo %%~dpnxi
cd /d %curdir%
cd /d %WINE_CURDIR%
echo --- endlocal in called function rather than batch pgm is ineffective
@echo off
set var=1
set var2=1
set WINE_var=1
set WINE_var2=1
setlocal
set var=2
set WINE_var=2
call :endlocalroutine
echo %var%
echo %WINE_var%
endlocal
echo %var%
echo %WINE_var%
goto :endlocalfinished
:endlocalroutine
echo %var%
echo %WINE_var%
endlocal
echo %var%
echo %WINE_var%
setlocal
set var2=2
set WINE_var2=2
endlocal
echo %var2%
echo %WINE_var2%
endlocal
echo %var%
echo %var2%
echo %WINE_var%
echo %WINE_var2%
goto :eof
:endlocalfinished
echo %var%
echo %WINE_var%
set var=
set var2=
set WINE_var=
set WINE_var2=
cd .. & rd /q/s foobar
echo ------------ Testing Errorlevel ------------
......@@ -2373,15 +2378,15 @@ if d==d goto dest4
echo goto with a following space worked
echo ------------ Testing PATH ------------
set backup_path=%path%
set WINE_backup_path=%path%
set path=original
path
path try2
path
path=try3
path
set path=%backup_path%
set backup_path=
set path=%WINE_backup_path%
set WINE_backup_path=
echo ------------ Testing combined CALLs/GOTOs ------------
echo @echo off>foo.cmd
......
......@@ -220,32 +220,32 @@ baz@space@
foo > foo
<
ffoof
FOO=bar | baz
WINE_FOO=bar | baz
0
FOO=bar ^| baz
WINE_FOO=bar ^| baz
bar | baz
0
------------ Testing 'set' ------------
1
0
FOOBAR not defined
WINE_FOOBAR not defined
baz
FOOBAR = baz
WINE_FOOBAR = baz
0
baz2
0
bar
FOOBAR= bar
FOOBAR = baz2
FOOBAR = baz2
FOOBAR not defined
WINE_FOOBAR= bar
WINE_FOOBAR = baz2
WINE_FOOBAR = baz2
WINE_FOOBAR not defined
1
bar
foobar
FOO not defined
BAZ=bazbaz
WINE_FOO not defined
WINE_BAZ=bazbaz
bazbaz
set "FOO=bar" should not include the quotes in the variable value
set "WINE_FOO=bar" should not include the quotes in the variable value
bar
foo
''
......@@ -349,23 +349,23 @@ N
------------ Testing variable delayed expansion ------------
--- default mode (load-time expansion)
foo
!FOO!
!WINE_FOO!
foo
foo
--- runtime (delayed) expansion mode
foo
@todo_wine@foo@or_broken@!FOO!
@todo_wine@foo@or_broken@!WINE_FOO!
foo
@todo_wine@bar@or_broken@foo
0
0@or_broken@1
foo
!FOO!
!WINE_FOO!
--- using /V cmd flag
foo
@todo_wine@foo@or_broken@!FOO!
@todo_wine@foo@or_broken@!WINE_FOO!
foo
!FOO!
!WINE_FOO!
------------ Testing conditional execution ------------
--- unconditional ampersand
foo1
......@@ -764,7 +764,7 @@ ErrorLevel 0
@todo_wine@15
------ variables
@todo_wine@3
@todo_wine@3@or_broken@foo not defined
@todo_wine@3@or_broken@WINE_foo not defined
@todo_wine@3@or_broken@0
@todo_wine@3@or_broken@0
@todo_wine@3@or_broken@0
......@@ -1011,7 +1011,7 @@ footype=foo_opencmd
+++
footype=foo_opencmd
--- resetting association
@todo_wine@original value@or_broken@buggyXP@or_broken@!FOO!
@todo_wine@original value@or_broken@buggyXP@or_broken@!WINE_FOO!
------------ Testing CALL ------------
--- external script
foo@space@
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment