[CMD_ROSTEST] Add more tests for the command echoer and new tests for the parser.

This commit is contained in:
Hermès Bélusca-Maïto 2020-07-27 19:29:59 +02:00
parent b217d8bd14
commit 7988a2ac54
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 746 additions and 0 deletions

View file

@ -251,6 +251,457 @@ if 1==1 (
)
:: Parsing FOR, IF and REM commands.
::
:: Note: wrong syntaxes for FOR, IF, REM or parsing operators
:: are considered syntactic errors and batch running stops.
:: For all other commands, execution continues.
::
@echo on
echo --------- Parsing FOR, IF and REM commands ---------
fOr@space@@space@@space@@tab@@tab@ /d@space@@space@@tab@ %%d iN (*)@space@@space@@tab@ do eCHo %%d
:for /asdf
:: for /d %%d in (*) do echo %%d
:: for /d %%d in (*) do echo %%~fd
for /d %%d in (*) do echo %%~ed
for /d %%d in (*) do echo %~d0:
fOr@tab@@space@@space@@space@@space@@space@@space@@space@@space@@tab@/l@space@@tab@ %%c@space@@space@@tab@ iN@tab@ (1,1,5)@space@@space@@tab@ Do@space@@space@@tab@@space@@tab@ echo@tab@@space@@space@@space@@space@@tab@@tab@%%c
iF@space@@space@@tab@ 457@space@@tab@@space@@tab@neQ@space@@space@@tab@ 458@space@@tab@ (@space@@tab@ echo@space@@tab@ %~d0 ) eLSe (@space@@space@@tab@ echo $~d0@space@@tab@ )
::: if 457 nea 458 (echo %~d0) eLSe (echo $~dp)
:if 457 nea 458 (echo yo) else (echo ya)
:if 457 leq 458 (rem/? /d)
:: if 457 leq 458 ( if 457 nea 458 (echo hi) else (echo yo) )
iF@space@@space@@tab@ "2147483647"@space@@space@@tab@ gEq@space@@tab@@space@@tab@ "2147483648"@space@@tab@ (Echo Larger)@space@@space@@tab@ Else@space@@tab@ (:Echo Smaller)
ecHO sMaLlEr)
iF@space@@space@@tab@eRrOrlevel 0 echo hi!
:: rem@tab@@space@@tab@ /df@space@@space@@tab@ /d
rEM /v@space@@tab@/d
REm@space@@space@@space@@tab@@tab@ /d
rEm REM2 /d
reM@space@@tab@ /d@space@@tab@ >@space@@tab@ NUL
:reM /?/d
:: These commands, even commented out via the parser comment colon,
:: cause parsing errors even when being commented out.
:: Replace the two '%' by a single one to see the effects.
::
:echo %~f0 %%~dp %~p1
:echo %%~d0 $~dp
:echo %%~dp:
:echo %%~b0
::
:: Parsing random commands
::
echo --------- Parsing random commands ---------
:: Parsing these commands should fail (when being un-commmented).
:@a ( b & |
: a ( b & |
:: If goto fails, batch stops. (Done OK in ROS' cmd)
:goto /asdf whatever
dir > NUL &(b)
setlocal enabledelayedexpansion
echo %~dp0
set SOMEVAR=C:\ReAcToS
rem %SOMEVAR% |
Set "_var=first"
Set "_var=second" & Rem %_var% !_var!
Set "_var=third" & Echo %_var% !_var!
endlocal
::
:: Parsing line continuations, either from parenthesized blocks
:: or via the escape caret.
:: It may be informative to manually run this test under CMD
:: with cmd!fDumpTokens and cmd!fDumpParse flags enabled.
::
echo --------- Parsing line continuations ---------
(
a & b
c
d
)
::
:: Parsed as:
:: '('[ '&'[a, CRLF[b, CRLF[c,d] ] ] ]
::
(
a && b
c
d
)
::
:: Parsed as:
:: '('[ CRLF['&&'[a,b], CRLF[c,d]] ]
::
(a & b)
(
a & b
)
(
a & b
c & d
)
(a & ^
b
c & d
)
::
:: Parsed as:
:: '('[ '&'[a, CRLF[b, '&'[c,d] ] ]
::
(
a & b
c
d
)
::
:: Parsed as:
:: '('[ '&'[a, CRLF[b, CRLF[c,d] ] ] ]
::
(
a && b
c
d
)
::
:: Parsed as:
:: '('[ CRLF['&&'[a,b], CRLF[c,d]] ]
::
(
a || b
c
d
)
::
:: Parsed as:
:: '('[ CRLF['||'[a,b], CRLF[c,d]] ]
::
(
a
b & c
d
)
::
:: Parsed as:
:: '('[ CRLF[a, '&'[b, CRLF[c,d]]] ]
::
(
a
b && c
d
)
::
:: Parsed as:
:: '('[ CRLF[a, CRLF['&&'[b,c], d]] ]
::
(
a
b
c && d
)
::
:: Parsed as:
:: '('[ CRLF[a, CRLF[b, '&&'[c,d]]] ]
::
(
a
b
c & d
)
::
:: Parsed as:
:: '('[ CRLF[a, CRLF[b, '&'[c,d]]] ]
::
(
a
b
c
d
)
::
:: Parsed as:
:: '('[ CRLF[a, CRLF[b, CRLF[c,d] ] ] ]
::
REM foo^
bar^
baz trol^
if 1==1 (echo a) else (echo b)
if 1==1 (echo a
) else (echo b)
if 1==1 (echo a) else (
echo b)
if 1==1 (
echo a
) else (
echo b
)
REM if 1==1 (^
REM echo a
REM ) ^
REM else
REM (^
REM echo b
REM )
REM if 1==1 (^
REM echo a
REM ) ^
REM else^
REM (^
REM echo b
REM )
REM if 1==1 (^
REM echo a
REM ) ^
REM else^
REM (
REM echo b
REM )
if 1==1 (^
echo a
)
if 1==1 (^
@echo a
)
(foo ^
bar
)
(foo ^
&& bar
baz
)
(foo ^
&& bar
baz
)
REM (foo^
REM && bar
REM baz
REM )
(foo^
bar
baz
)
(foo &^
& bar
baz
)
(^
foo
bar
)
(
foo ^
bar
)
(
foo ^
&& bar
baz
)
(
foo ^
&& bar
baz
)
REM (
REM
REM
REM foo^
REM && bar
REM baz
REM )
(
foo^
bar
baz
)
(
foo &^
& bar
baz
)
(
^
foo
bar
)
::
:: Tests for Character Escape and Line Continuation
::
(^"!pc::^=^!^")
(^
"!pc::^=^!^")
(
^"!pc::^=^!^")
(^"!pc::^=^
% New line %
!^")
REM @ 2>&1 ( ( dir) ) && lol
echo & ^
&&lol
REM echo & ^
REM ^
REM &&lol
trol ^
&&lol
trol^
&&lol
REM (echo hi)^
REM &&lol
rem trol(^
line
@rem trol2""^
line2
:trol3^
line3
echo trol^
line
:echo trol^
line
@echo off
::

View file

@ -322,4 +322,299 @@ updated TN == TN
updated TN == TN
updated TN == TN
updated TN == TN
@pwd@>echo --------- Parsing FOR, IF and REM commands ---------@space@
--------- Parsing FOR, IF and REM commands ---------
@pwd@>fOr / %d iN (*) do eCHo %d@space@
@pwd@>eCHo script_testsuite@space@
script_testsuite
@pwd@>for / %d in (*) do echo %~ed@space@
@pwd@>echo %~ed@space@
%~ed
@pwd@>for / %d in (*) do echo D::@space@
@pwd@>echo D::@space@
D::
@pwd@>fOr /L %c iN (1 1 5) Do echo@tab@@space@@space@@space@@space@@tab@@tab@%c@space@
@pwd@>echo@tab@@space@@space@@space@@space@@tab@@tab@1@space@
@space@@space@@space@@space@@tab@@tab@1
@pwd@>echo@tab@@space@@space@@space@@space@@tab@@tab@2@space@
@space@@space@@space@@space@@tab@@tab@2
@pwd@>echo@tab@@space@@space@@space@@space@@tab@@tab@3@space@
@space@@space@@space@@space@@tab@@tab@3
@pwd@>echo@tab@@space@@space@@space@@space@@tab@@tab@4@space@
@space@@space@@space@@space@@tab@@tab@4
@pwd@>echo@tab@@space@@space@@space@@space@@tab@@tab@5@space@
@space@@space@@space@@space@@tab@@tab@5
@pwd@>iF 457 NEQ 458 (echo@space@@tab@ D: ) eLSe (echo $~d0@space@@tab@ )@space@
@tab@ D:@space@
@pwd@>iF "2147483647" GEQ "2147483648" (Echo Larger ) Else (ecHO sMaLlEr )@space@
sMaLlEr
@pwd@>iF eRrOrlevel 0 echo hi!@space@
hi
@pwd@>rEM /v@space@@tab@/d@space@
@pwd@>REm@space@@space@@space@@tab@@tab@ /d@space@
@pwd@>rEm REM2 /d@space@
@pwd@>reM@space@@tab@ /d@space@@tab@ >@space@@tab@ NUL@space@
@pwd@>echo --------- Parsing random commands ---------@space@
--------- Parsing random commands ---------
@pwd@>dir 1>NUL & (b)@space@
@pwd@>setlocal enabledelayedexpansion@space@
@pwd@>echo @pwd@\@space@
@pwd@\
@pwd@>set SOMEVAR=C:\ReAcToS@space@
@pwd@>rem C:\ReAcToS |@space@
@pwd@>Set "_var=first"@space@
@pwd@>Set "_var=second" & Rem first !_var!@space@
@pwd@>Set "_var=third" & Echo second !_var!@space@
second third
@pwd@>endlocal
@pwd@>echo --------- Parsing line continuations ---------@space@
--------- Parsing line continuations ---------
@pwd@>(a & b@space@
c@space@
d)@space@
@pwd@>(
a && b@space@
c@space@
d
)@space@
@pwd@>(a & b)@space@
@pwd@>(a & b)@space@
@pwd@>(a & b@space@
c & d)@space@
@pwd@>(a & b@space@
c & d)@space@
@pwd@>(a & b@space@
c@space@
d)@space@
@pwd@>(
a && b@space@
c@space@
d
)@space@
@pwd@>(
a || b@space@
c@space@
d
)@space@
@pwd@>(
a@space@
b & c@space@
d
)@space@
@pwd@>(
a@space@
b && c@space@
d
)@space@
@pwd@>(
a@space@
b@space@
c && d
)@space@
@pwd@>(
a@space@
b@space@
c & d
)@space@
@pwd@>(
a@space@
b@space@
c@space@
d
)@space@
@pwd@>REMbaz trol^@space@
@pwd@>if 1 == 1 (echo a ) else (echo b )@space@
a
@pwd@>if 1 == 1 (echo a ) else (echo b )@space@
a
@pwd@>if 1 == 1 (echo a ) else (echo b )@space@
a
@pwd@>if 1 == 1 (echo a ) else (echo b )@space@
a
@pwd@>REM if 1==1 (^@space@
@pwd@>REM echo a@space@
@pwd@>REM ) ^@space@
@pwd@>REM else@space@
@pwd@>REMREM echo b@space@
@pwd@>REM )@space@
@pwd@>REM if 1==1 (^@space@
@pwd@>REM echo a@space@
@pwd@>REM ) ^@space@
@pwd@>REMREM (^@space@
@pwd@>REM echo b@space@
@pwd@>REM )@space@
@pwd@>REM if 1==1 (^@space@
@pwd@>REM echo a@space@
@pwd@>REM ) ^@space@
@pwd@>REMREM (@space@
@pwd@>REM echo b@space@
@pwd@>REM )@space@
@pwd@>if 1 == 1 (echo a )@space@
a
@pwd@>if 1 == 1 ()@space@
a
@pwd@>(foo bar )@space@
@pwd@>(foo & & bar@space@
baz)@space@
@pwd@>(
foo && bar@space@
baz
)@space@
@pwd@>REMREM && bar@space@
@pwd@>REM baz@space@
@pwd@>REM )@space@
@pwd@>(
bar@space@
baz
)@space@
@pwd@>(foo & & bar@space@@space@
baz)@space@
@pwd@>(
foo@space@
bar
)@space@
@pwd@>(foo bar )@space@
@pwd@>(foo & & bar@space@
baz)@space@
@pwd@>(
foo && bar@space@
baz
)@space@
@pwd@>REM (@space@
@pwd@>REM
@pwd@>REM
@pwd@>REMREM && bar@space@
@pwd@>REM baz@space@
@pwd@>REM )@space@
@pwd@>(
bar@space@
baz
)@space@
@pwd@>(foo & & bar@space@@space@
baz)@space@
@pwd@>(
foo@space@
bar
)@space@
@pwd@>("!pc::=!")@space@
@pwd@>("!pc::^=^!^")@space@
@pwd@>("!pc::=!")@space@
@pwd@>(!")@space@
@pwd@>REM @ 2>&1 ( ( dir) ) && lol@space@
@pwd@>echo & & & lol
ECHO is on.
@pwd@>REM echo & ^@space@
@pwd@>REMREM &&lol@space@
@pwd@>trol & & lol
@pwd@>trol& & lol
@pwd@>REM (echo hi)^@space@
@pwd@>REM &&lol@space@
@pwd@>remline@space@
@pwd@>echo trolline@space@
trolline
--------- Finished --------------