Signed-off-by: Francois Gouget fgouget@codeweavers.com --- v2: - Some locales add the day-of-week before the date. Adjust the tests accordingly. - Add more for %cd%, %errorlevel%, defined, tests. - Compare date /t with %date%, and time /t with %time%. - Modify the tests so they work with @todo_wine@.
--- programs/cmd/tests/test_builtins.cmd | 39 +++++++++++++++++++++++- programs/cmd/tests/test_builtins.cmd.exp | 15 ++++++++- 2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 3f410e55166..f9e26da34b6 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -585,7 +585,6 @@ cd dummydir echo %~dp0 cd .. rmdir dummydir -echo CD value %CD% echo %% echo P% echo %P @@ -1789,6 +1788,44 @@ set /a WINE_foo=5 set /a WINE_bar=WINE_foo=6 call :checkenvvars WINE_foo 6 WINE_bar 6
+echo --- Magic environment variables +if defined cd (echo Has %%cd%%) else (echo Not defined) +echo CD value %CD% + +rem Some locales include the day-of-week either before or after the +rem day-month-year part. This makes it impossible to check the content of %date% +if defined date (echo Has %%date%%) else (echo Not defined) +set WINE_foo=%date:~9,1% +if defined WINE_foo (echo Good %%date%%) else (echo Too short) + +set WINE_before=%date% +for /f "usebackq tokens=*" %%i in (`date /t`) do set WINE_foo=%%i +set WINE_after=%date% +rem Use extra parentheses to work around a Wine bug +if not "%WINE_foo%"=="%WINE_before% " (if not "%WINE_foo%"=="%WINE_after% " (echo date /t != %%date%%) else (echo Match)) else (echo Match) + +if defined errorlevel (echo Has %%errorlevel%%) else (echo Not defined) + +if defined time (echo Has %%time%%) else (echo Not defined) +set WINE_foo=%time:~7,1% +if defined WINE_foo (echo %%time%% has seconds) else (echo Too short) +set WINE_foo=%time:~10,1% +if defined WINE_foo (echo %%time%% has 1/100s) else (echo Too short) +set WINE_foo=%time:~11,1% +if not defined WINE_foo (echo End of %%time%%) else (echo Too long) + +rem %time% has a leading space instead of a zero so ignore the first character +set WINE_before=%time:~1,4% +for /f "usebackq tokens=*" %%i in (`time /t`) do set WINE_foo=%%i +set WINE_after=%time:~1,4% +set WINE_foo=%WINE_foo:~1,99% +rem Use extra parentheses to work around a Wine bug +if not "%WINE_foo%"=="%WINE_before%" (if not "%WINE_foo%"=="%WINE_after%" (echo time /t != %%time:~1,4%%) else (echo Match)) else (echo Match) + +if defined random (echo Has %%random%%) else (echo Not defined) +set WINE_foo=%random% +if %WINE_foo% neq %random% (echo %%random%% looks random) else (echo Constant?) + echo --- for /F mkdir foobar & cd foobar echo ------ string argument diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 8b6e0914112..15fda131a5c 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -500,7 +500,6 @@ I'm here!@space@ ~dp0 should be directory containing batch file @drive@@path@ @drive@@path@ -CD value @pwd@@or_broken@CD value@space@ % P P @@ -1216,6 +1215,20 @@ WINE_foo correctly 7 WINE_foo correctly 8@or_broken@ERROR: WINE_foo incorrectly 4 [8] WINE_foo correctly 6@or_broken@ERROR: WINE_foo incorrectly 5 [6] WINE_bar correctly 6@or_broken@ERROR: WINE_bar incorrectly 5 [6] +--- Magic environment variables +@todo_wine@Has %cd% +CD value @pwd@@or_broken@CD value@space@ +@todo_wine@Has %date% +@todo_wine@Good %date% +@todo_wine@Match +@todo_wine@Has %errorlevel% +@todo_wine@Has %time% +@todo_wine@%time% has seconds +@todo_wine@%time% has 1/100s +End of %time% +@todo_wine@Match +@todo_wine@Has %random% +%random% looks random --- for /F ------ string argument a