From 3c8674a721fd2f3437f021e1780056aa6f7a732c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Delanoy?= Date: Mon, 1 Aug 2011 11:46:53 +0200 Subject: [PATCH] cmd/tests: Add tests for variable delayed expansion. --- programs/cmd/tests/test_builtins.cmd | 40 ++++++++++++++++++++++++++++++++ programs/cmd/tests/test_builtins.cmd.exp | 15 ++++++++++++ 2 files changed, 55 insertions(+) diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 04d8fdda5a9..3f8c72e9ad0 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -168,6 +168,46 @@ echo P%ERRORLEVEL% echo %ERRORLEVEL%S echo P%ERRORLEVEL%S +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 FOO=foo +if %FOO% == foo ( + set FOO=bar + if !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 FOO=foo +if %FOO% == foo ( + set FOO=bar + if !FOO! == bar (echo bar) else echo foo +) +echo %ErrorLevel% +setlocal DisableDelayedExpansion +echo %ErrorLevel% +set FOO=foo +echo %FOO% +echo !FOO! +set FOO= + echo ------------ Testing conditional execution -------------- echo ...unconditional ^& call :setError 123 & echo foo1 diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index d7ac58a1245..b754faffb38 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -146,6 +146,21 @@ ERRORLEVEL P0 0S P0S +------------ Testing variable delayed expansion -------------- +...default mode (load-time expansion) +foo +!FOO! +foo +foo +...runtime (delayed) expansion mode +foo +@todo_wine@foo@or_broken@!FOO! +foo +@todo_wine@bar@or_broken@foo +0 +0@or_broken@1 +foo +!FOO! ------------ Testing conditional execution -------------- @todo_wine@...unconditional & foo1 -- 2.11.4.GIT