https://git.reactos.org/?p=reactos.git;a=commitdiff;h=aee1dd297272b35dff3ac…
commit aee1dd297272b35dff3ac5061bc6e6421999e0d8
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Mon Jul 27 00:49:18 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Aug 19 20:36:00 2020 +0200
[CMD_ROSTEST] Add tests for GOTO :EOF
---
modules/rostests/win32/cmd/test_goto_call.cmd | 58 +++++++++++++++++++++++
modules/rostests/win32/cmd/test_goto_call.cmd.exp | 6 +++
2 files changed, 64 insertions(+)
diff --git a/modules/rostests/win32/cmd/test_goto_call.cmd
b/modules/rostests/win32/cmd/test_goto_call.cmd
index 14c374770f6..6a8d3579bc5 100644
--- a/modules/rostests/win32/cmd/test_goto_call.cmd
+++ b/modules/rostests/win32/cmd/test_goto_call.cmd
@@ -50,6 +50,64 @@ goto :EOF
:continue
+::
+:: Testing :EOF support
+::
+echo --------- Testing :EOF support ---------
+
+:: Use an auxiliary CMD file to test GOTO :EOF
+mkdir foobar && cd foobar
+
+:: GOTO :EOF is available only if commands extensions are enabled
+echo @echo off> tmp.cmd
+echo setlocal disableextensions>> tmp.cmd
+echo goto :eof>> tmp.cmd
+call :setError 0
+cmd /c tmp.cmd
+if %errorlevel% equ 0 (echo Unexpected: GOTO :EOF did not fail^^!) else echo OK
+
+:: GOTO :EOF is done only if the ":EOF" part is followed by whitespace or
ends.
+:: The following two GOTO's fail because the labels cannot be found.
+echo @echo off> tmp.cmd
+echo setlocal enableextensions>> tmp.cmd
+echo goto :eof,lol>> tmp.cmd
+echo echo Batch continues^^!>> tmp.cmd
+call :setError 0
+cmd /c tmp.cmd
+if %errorlevel% equ 0 (echo Unexpected: GOTO :eof,lol did not fail^^!) else echo OK
+
+echo @echo off> tmp.cmd
+echo setlocal enableextensions>> tmp.cmd
+echo goto :eof:lol>> tmp.cmd
+echo echo Batch continues^^!>> tmp.cmd
+call :setError 0
+cmd /c tmp.cmd
+if %errorlevel% equ 0 (echo Unexpected: GOTO :eof:lol did not fail^^!) else echo OK
+
+:: GOTO :EOF expects at least one whitespace character before anything else.
+:: Not even '+',':' or other separators are allowed.
+echo @echo off> tmp.cmd
+echo setlocal enableextensions>> tmp.cmd
+echo goto :eof+lol>> tmp.cmd
+echo echo Batch continues^^!>> tmp.cmd
+call :setError 0
+cmd /c tmp.cmd
+if %errorlevel% equ 0 (echo Unexpected: GOTO :eof+lol did not fail^^!) else echo OK
+
+:: This GOTO :EOF works.
+echo @echo off> tmp.cmd
+echo setlocal enableextensions>> tmp.cmd
+echo goto :eof@tab@+lol>> tmp.cmd
+echo echo You should not see this^^!>> tmp.cmd
+call :setError 0
+cmd /c tmp.cmd
+if %errorlevel% neq 0 (echo Unexpected: GOTO :EOF did fail^^!) else echo OK
+
+
+:: Cleanup
+cd .. & rd /s/q foobar
+
+
::
:: Testing GOTO/CALL from and to within parenthesized blocks.
::
diff --git a/modules/rostests/win32/cmd/test_goto_call.cmd.exp
b/modules/rostests/win32/cmd/test_goto_call.cmd.exp
index e3566367b04..f375908a87b 100644
--- a/modules/rostests/win32/cmd/test_goto_call.cmd.exp
+++ b/modules/rostests/win32/cmd/test_goto_call.cmd.exp
@@ -2,6 +2,12 @@
Test GOTO ok
--------- Testing CALL within batch ---------
Test CALL ok from :test_call
+--------- Testing :EOF support ---------
+OK
+OK
+OK
+OK
+OK
--------- Testing GOTO within block ---------
Block-test 1: Single-line
Block-test 2: Multi-line