https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0b400bbb98313197147eb…
commit 0b400bbb98313197147ebc4718b0618986816641
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Mon Jul 27 16:42:42 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Sep 23 00:22:45 2020 +0200
[CMD_ROSTEST] Add tests for particular ERRORLEVEL behaviour in some commands.
---
modules/rostests/win32/cmd/test_builtins.cmd | 102 +++++++++++++++++++++++
modules/rostests/win32/cmd/test_builtins.cmd.exp | 29 +++++++
2 files changed, 131 insertions(+)
diff --git a/modules/rostests/win32/cmd/test_builtins.cmd
b/modules/rostests/win32/cmd/test_builtins.cmd
index 7e232ca7ca6..4cec71c48aa 100644
--- a/modules/rostests/win32/cmd/test_builtins.cmd
+++ b/modules/rostests/win32/cmd/test_builtins.cmd
@@ -396,6 +396,108 @@ del tmp.cmd
cd .. & rmdir /s/q foobar
+::
+:: ERRORLEVEL tests for special commands.
+::
+:: For some commands, the errorlevel is set differently,
+:: whether or not they are run within a .BAT, a .CMD, or
+:: directly from the command-line.
+::
+:: These commands are:
+:: APPEND/DPATH, ASSOC, FTYPE, PATH, PROMPT, SET.
+::
+:: See
https://ss64.com/nt/errorlevel.html for more details.
+::
+
+echo ---------- Testing ERRORLEVEL in .BAT and .CMD ----------
+
+:: Use an auxiliary CMD file
+mkdir foobar && cd foobar
+
+echo --- In .BAT file
+call :outputErrLvlTestToBatch tmp.bat
+cmd /c tmp.bat
+del tmp.bat
+
+echo --- In .CMD file
+call :outputErrLvlTestToBatch tmp.cmd
+cmd /c tmp.cmd
+del tmp.cmd
+
+:: Cleanup
+cd .. & rmdir /s/q foobar
+
+:: Go to the next tests below.
+goto :continue
+
+:: ERRORLEVEL test helper function
+:outputErrLvlTestToBatch (filename)
+
+echo @echo off> %1
+echo setlocal enableextensions>> %1
+
+:: Reset the errorlevel
+echo call :zeroErrLvl>> %1
+
+:: dpath
+:: echo %errorlevel%
+:: dpath xxx
+:: echo %errorlevel%
+:: dpath
+:: echo %errorlevel%
+
+echo assoc^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo assoc .nonexisting^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo assoc .nonexisting^=^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+
+:: ftype
+:: echo %errorlevel%
+:: ftype xxx
+:: echo %errorlevel%
+:: ftype
+:: echo %errorlevel%
+
+echo path^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo path^;^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+
+echo prompt^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo prompt ^$p^$g^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo prompt foobar^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+
+echo set^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo set nonexisting^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo set nonexisting^=^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo set nonexisting^=trololol^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+echo set nonexisting^=^>NUL>> %1
+echo echo %%errorlevel%%>> %1
+
+echo goto :eof>> %1
+
+:: Zero ERRORLEVEL
+echo :zeroErrLvl>> %1
+echo exit /B 0 >> %1
+
+goto :eof
+
+
+::
+:: Next suite of tests.
+::
+:continue
+
+
::
:: Finished!
::
diff --git a/modules/rostests/win32/cmd/test_builtins.cmd.exp
b/modules/rostests/win32/cmd/test_builtins.cmd.exp
index 98f084e90a4..50cff1eae09 100644
--- a/modules/rostests/win32/cmd/test_builtins.cmd.exp
+++ b/modules/rostests/win32/cmd/test_builtins.cmd.exp
@@ -101,4 +101,33 @@ OK
OK
OK
OK
+---------- Testing ERRORLEVEL in .BAT and .CMD ----------
+--- In .BAT file
+0
+1
+2
+2
+2
+2
+2
+2
+2
+1
+1
+1
+1
+--- In .CMD file
+0
+1
+2
+0
+0
+0
+0
+0
+0
+1
+0
+0
+0
--------- Finished --------------