From 3f0d3a962951adcabd21beb7724d67226ade4f92 Mon Sep 17 00:00:00 2001 From: Art Eschenlauer Date: Fri, 13 Aug 2021 21:46:18 -0500 Subject: [PATCH] fixed bug in icon.cmd when last argument to program matches name of program; refactored smoke tests; added run_smoke_test.cmd --- README.md | 31 +++-- examples/run_smoke_test.cmd | 16 +++ examples/smoke_test.cmd | 170 ++++++++++++++++++++++-- examples/smoke_test.output.expected.txt | 24 ++-- icon.cmd | 7 +- 5 files changed, 215 insertions(+), 33 deletions(-) create mode 100755 examples/run_smoke_test.cmd diff --git a/README.md b/README.md index a028f04..1f69224 100755 --- a/README.md +++ b/README.md @@ -58,6 +58,23 @@ Note that invoking `icont.cmd` or `icont.exe` produces `.bat' program that needs - This script facilitates construction of scripts that are valid Icon source code and may be just-in-time translated and executed. - See `example\example_shebang.cmd` and `example\#!icon.cmd` to see how to reference and use this script. +### Examples of how to use the top-level files + +- `examples\smoke_test.cmd` + - This demonstrates use of most of the files in the repository (at the top level and within `examples`). + - See [`examples\smoke_test.output.expected.txt`](./examples/smoke_test.output.expected.txt) for the expected output. + - Admittedly, it isn't highly readable. +- `examples\run_smoke_test.cmd` + - This runs `smoke_test.cmd` and compares the actual output to the expected output. + - This sets a zero exit code (accessible through the ERRORLEVEL pseudo-environment variable) when all tests pass and nonzero otherwise. +- `examples\example_shebang.cmd` and `examples\#!icon.cmd` leverage `icon.cmd` to execute a self-translating script that is still valid Icon source code. + - See smoke test 8 in `examples\smoke_test.cmd`. + - See also "Shebang - scripting with Icon" for details. +- `examples\example_stdin.cmd` is a simple example of how to translate and run Icon source code from a script file, passing arguments. + - The script is *not* valid Icon source code as a consequence. + - See smoke test 3 in `examples\smoke_test.cmd`. + - See also "Shebang - scripting with Icon" for details. + ### Files that you do not need to interact with directly The following files are used by the top level programs; you shouldn't need to interact with them directly. @@ -79,20 +96,6 @@ The following files are used by the top level programs; you shouldn't need to in 1. `bin\nticonx.exe` if it still exists (i.e., if it has not been moved since the `.bat` file was produced). 1. The first `iconx.exe`, `iconx.bat`, or `iconx.cmd` on the executable path, i.e., the `PATH` environmental variable. -### Examples of how to use the top-level files - -- `examples\smoke_test.cmd` - - This demonstrates use of most of the files in the repository (at the top level and within `examples`). - - See [`examples\smoke_test.output.expected.txt`](./examples/smoke_test.output.expected.txt) for the expected output. - - Admittedly, it isn't highly readable. -- `examples\example_shebang.cmd` and `examples\#!icon.cmd` leverage `icon.cmd` to execute a self-translating script that is still valid Icon source code. - - See smoke test 8 in `examples\smoke_test.cmd`. - - See also "Shebang - scripting with Icon" for details. -- `examples\example_stdin.cmd` is a simple example of how to translate and run Icon source code from a script file, passing arguments. - - The script is *not* valid Icon source code as a consequence. - - See smoke test 3 in `examples\smoke_test.cmd`. - - See also "Shebang - scripting with Icon" for details. - ## Shebang - scripting with Icon One option is to do just-in-time translation of your Icon source program. The `examples\example_shebang.cmd` and `examples\#!icon.cmd` scripts together: diff --git a/examples/run_smoke_test.cmd b/examples/run_smoke_test.cmd new file mode 100755 index 0000000..1c78eb1 --- /dev/null +++ b/examples/run_smoke_test.cmd @@ -0,0 +1,16 @@ +@set ERRORLEVEL=&setlocal&echo off +call %~dps0smoke_test.cmd > %~dps0smoke_test.output.actual.txt +if %ERRORLEVEL% neq 0 ( + (echo smoke_test.cmd FAILED with error %ERRORLEVEL%) + endlocal + exit/b %ERRORLEVEL% +) +if %ERRORLEVEL% neq 0 (echo smoke_test.cmd FAILED with error %ERRORLEVEL%)&endlocal&exit/b %ERRORLEVEL% +diff %~dps0smoke_test.output.expected.txt %~dps0smoke_test.output.actual.txt +if %ERRORLEVEL% neq 0 ( + (echo smoke_test.cmd FAILED because results differed from what was expected) + endlocal + exit/b %ERRORLEVEL% +) +echo.Smoke test was SUCCESSFUL. +endlocal&exit /b 0 diff --git a/examples/smoke_test.cmd b/examples/smoke_test.cmd index 5dcc092..89b1cc5 100755 --- a/examples/smoke_test.cmd +++ b/examples/smoke_test.cmd @@ -2,6 +2,10 @@ @ set SENTINEL=findstr& set PROMPT=running -$G &set ECHO_ON=off :: single-ampersand means execute second command regardless of EXITCODE from first command +set EXIT_CODE=0 +set EXIT_MSG=%~n0 SUCCEEDED +set TEST_NAME=initialization + pushd %~dps0 :: Extract world.icn from example_stdin.cmd @@ -14,31 +18,62 @@ if exist "%~dp0world.bat" del "%~dp0world.bat" @echo. @echo ------- Here is the Icon program used for these examples --------- type "%~dp0world.icn" +if %ERRORLEVEL% neq 0 ( + call :fail_msg fubar does not exist + goto :farewell +) @echo ------- Test one - Translate with default options [1] --------- +@echo ------- Test one - Translate with default options [1] 1>&2 @echo. set PROMPT=running one -$G @echo %ECHO_ON% (call "%~dp0..\icont.cmd" "%~dp0world.icn") >NUL 2>&1 +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=one translation + call :fail_msg icont.cmd world.icn failed + goto :farewell +) @echo %ECHO_ON% call "%~dp0world.bat" one @echo off +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=one execution + call :fail_msg call world.bat failed + goto :farewell +) del "%~dp0world.bat" @echo. @echo ------- Test two - Translate with custom options [2] --------- +@echo ------- Test two - Translate with custom options [2] 1>&2 @echo. set PROMPT=running two -$G @echo %ECHO_ON% call "%~dp0..\icont.cmd" -s -u -o "%~dp0mundo.exe" "%~dp0world.icn" 2>&1 +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=two translation + call :fail_msg icont.cmd -o mundo.exe world.icn failed + goto :farewell +) call "%~dp0..\bin\smudge.cmd" "%~dp0mundo.exe" --standalone +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=two smudge + call :fail_msg bin\smudge.cmd mundo.exe failed + goto :farewell +) if not exist "%~dp0cygwin1.dll" echo cygwin1.dll required for standalone execution was not found if not exist "%~dp0nticonx.exe" echo nticonx.exe required for standalone execution was not found @echo %ECHO_ON% call "%~dp0mundo.bat" one two @echo off +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=two execution + call :fail_msg call mundo.bat failed + goto :farewell +) :: prep for next test if exist "%~dp0cygwin1.dll" del "%~dp0cygwin1.dll" @@ -47,27 +82,44 @@ if exist "%~dp0mundo.bat" del "%~dp0mundo.bat" if exist "%~dp0world.icn" del "%~dp0world.icn" @echo. @echo ------- Test three - Translate from within a script and run [3] --------- +@echo ------- Test three - Translate from within a script and run [3] 1>&2 @echo. set PROMPT=running three -$G :: It is imperative that you use "call"; :: otherwise, the rest of the script is ignored. @echo %ECHO_ON% call example_stdin.cmd one two three +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=three translation and execution + call :fail_msg call example_stdin.cmd failed + goto :farewell +) @echo off :: Extract world.icn from example_stdin.cmd for next test findstr /v "%SENTINEL%" example_stdin.cmd > world.icn @echo. @echo ------- Test four - Explicity run the Icon Virtual Machine [4] --------- +@echo ------- Test four - Explicity run the Icon Virtual Machine [4] 1>&2 @echo. set PROMPT=running four -$G @echo. 4a. Invoke the Icon translator explicitly @echo %ECHO_ON% "%~dp0..\bin\nticont.exe" -s -u "%~dp0world.icn" +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=four a. translation + call :fail_msg call bin\nticont.exe world.icn failed + goto :farewell +) @echo. @echo. 4b. Invoke the Icon runtime explicitly @echo %ECHO_ON% "%~dp0..\bin\nticonx.exe" "%~dp0world.exe" one two three four +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=four b. execution + call :fail_msg call bin\nticonx.exe world.exe failed + goto :farewell +) del "%~dp0world.exe" @echo off @@ -75,28 +127,55 @@ del "%~dp0world.exe" @echo %ECHO_ON% @echo. 4c. Invoke the Icon translator by proxy - icont.exe to icont.cmd to nticont.exe "%~dp0..\icont.exe" -s -u "%~dp0world.icn" +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=four c. translation + call :fail_msg call icont.exe world.icn failed + goto :farewell +) @echo. @echo %ECHO_ON% @echo. 4d. Invoke the Icon runtime by proxy - iconx.exe to iconx.cmd to nticonx.exe "%~dp0..\iconx.exe" "%~dp0world.bat" won too three faure +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=four d. execution + call :fail_msg call iconx.exe world.exe failed + goto :farewell +) @echo off setlocal @echo. @echo ------- Test five - Implicity run the Icon Virtual Machine using CMD [5] --------- +@echo ------- Test five - Implicity run the Icon Virtual Machine using CMD [5] 1>&2 @echo. "%~dp0..\icont.exe" -s -u -o "%~dp0world.exe" "%~dp0world.icn" +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=five translation + call :fail_msg call icont.exe -o world.exe world.icn failed + goto :farewell +) call "%~dp0..\bin\smudge.cmd" "%~dp0world.exe" +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=five smudge + call :fail_msg call bin\smudge.cmd world.exe failed + goto :farewell +) set PROMPT=running five -$G set OLD_PATH=%PATH% set PATH=%~dp0..;%PATH% @echo %ECHO_ON% cmd /c ^""%~dp0world.bat" one two three four five^" +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=five execution + call :fail_msg call cmd /c world.bat failed + goto :farewell +) @echo off @echo. -@echo ------- Test six - Implicity run the Icon Virtual Machine in the background using START [6] --------- +@echo ------- Test six - Implicity run the Icon Virtual Machine in the background using START [6] --------- +@echo ------- Test six - Implicity run the Icon Virtual Machine in the background using START [6] 1>&2 @echo. set PROMPT=running six -$G @echo %ECHO_ON% @@ -110,7 +189,8 @@ if exist "%~dp0world.exe" del "%~dp0world.exe" endlocal @echo. -@echo ------- Test seven - Do not include the Icon Virtual Machine in the output file [7] --------- +@echo ------- Test seven - Do not include the Icon Virtual Machine in the output file [7] --------- +@echo ------- Test seven - Do not include the Icon Virtual Machine in the output file [7] 1>&2 @echo. set PROMPT=running seven -$G @@ -118,19 +198,51 @@ set PROMPT=running seven -$G set PATH=OLD_%PATH% @echo %ECHO_ON% call "%~dp0..\icont_nosmudge.cmd" -s -u "%~dp0world.icn" +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=seven translation + call :fail_msg call icont_nosmudge.cmd world.icn failed + goto :farewell +) + +if exist "%~dp0world.bat" echo Unexpectedly found "world.bat" +if exist "%~dp0world.bat" ( + @ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=seven wrot translation output not present + call :fail_msg call icont_nosmudge.cmd world.icn produced world.bat + goto :farewell + ) +) @echo %ECHO_ON% if not exist "%~dp0world.exe" echo Unexpectedly NOT having to smudge "world.exe" +if not exist "%~dp0world.exe" ( + @ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=seven nosmudge + call :fail_msg call icont_nosmudge.cmd world.icn unexpectedly smudged + goto :farewell + ) +) if exist "%~dp0world.exe" call "%~dp0..\bin\smudge.cmd" "%~dp0world.exe" >NUL +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=seven smudge + call :fail_msg call bin\smudge.cmd world.exe failed + goto :farewell +) @echo %ECHO_ON% if exist "%~dp0world.bat" call "%~dp0world.bat" uno deux drei tessera cinque seis seven +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=seven execution + call :fail_msg call world.bat failed + goto :farewell +) @echo off if exist "%~dp0world.bat" del "%~dp0world.bat" if exist "%~dp0world.bat" del "%~dp0world.bat" @echo. -@echo ------- Test eight - Shebang example [8] --------- +@echo ------- Test eight - Shebang example [8] --------- +@echo ------- Test eight - Shebang example [8] 1>&2 @echo. set PROMPT=running eight -$G @@ -138,34 +250,74 @@ set PROMPT=running eight -$G :: the shebang line in this case is NOT emitted because echo is OFF call "%~dp0example_shebang.cmd" ten nine eight seven six five four three two one zero "blast off" +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=eight translation and execution + call :fail_msg call example_shebang.cmd failed + goto :farewell +) @echo off @echo. -@echo ------- Test nine - icon.cmd invokes icont.cmd and iconx.cmd [9] --------- +@echo ------- Test nine - icon.cmd invokes icont.cmd and iconx.cmd [9] --------- +@echo ------- Test nine - icon.cmd invokes icont.cmd and iconx.cmd [9] 1>&2 @echo. set PROMPT=running nine -$G @echo %ECHO_ON% @echo. 9a. Invoke the icon.cmd script with quotes in the source file name -call %~dps0..\icon.cmd "%~dps0world.icn" nine "with quoted path to Icon source" +call %~dps0..\icon.cmd "%~dps0world.icn" nine "with quoted path to Icon source" hello world +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=nine a. translation and execution + call :fail_msg call icon quoted world.icn failed + goto :farewell +) @echo. @echo. 9b. Invoke the icon.cmd script without quotes in the source file name -call %~dps0..\icon.cmd %~dps0world.icn nine "without quoted path to Icon source" +call %~dps0..\icon.cmd %~dps0world.icn nine "without quoted path to Icon source" hello world +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=nine b. translation and execution + call :fail_msg call icon unquoted world.icn failed + goto :farewell +) @echo. @echo. 9c. Invoke the icon.cmd script on source from stdin -type "%~dp0world.icn" | %~dps0..\icon.cmd - nine "with Icon source from stdin" +type "%~dp0world.icn" | %~dps0..\icon.cmd - nine "with Icon source from stdin" hello world +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=nine c. translation and execution + call :fail_msg call icon piped script failed + goto :farewell +) @echo. @echo. 9d. Invoke the icont.cmd [not icono.cmd] script with spaces in file name copy "%~dp0world.icn" "%~dp0mio mundo.icn" >NUL :: double-ampersand means execute second command only if first command returns zero EXITCODE -call %~dps0..\icont.cmd -v0 "%~dps0mio mundo.icn"&& call "%~dps0mio mundo.bat" nine "via icont.cmd (rather than icon.cmd)" +call %~dps0..\icont.cmd -v0 "%~dps0mio mundo.icn"&& call "%~dps0mio mundo.bat" nine "via icont.cmd (rather than icon.cmd)" hello world +@ if %ERRORLEVEL% neq 0 ( + set TEST_NAME=nine d. translation and execution + call :fail_msg call icon quoted script with spaces in name failed + goto :farewell +) if exist "%~dp0mio mundo.icn" del "%~dp0mio mundo.icn" if exist "%~dp0mio mundo.bat" del "%~dp0mio mundo.bat" @echo off +goto farewell + + +:fail_msg + +set EXIT_CODE=%ERRORLEVEL% +echo %~n0 test %TEST_NAME% FAILED: %* 1>&2 +goto :eof + + +:farewell + @echo. @echo ------- "Where there's smoke, there's fire." -Anonymous --------- +@echo ------- "Where there's smoke, there's fire." -Anonymous --------- 1>&2 popd -endlocal +if %EXIT_CODE% neq 0 echo %EXIT_MSG% +endlocal&exit /b %EXIT_CODE% diff --git a/examples/smoke_test.output.expected.txt b/examples/smoke_test.output.expected.txt index 34e5abf..86cff16 100755 --- a/examples/smoke_test.output.expected.txt +++ b/examples/smoke_test.output.expected.txt @@ -129,7 +129,7 @@ pipes system function Icon Version 9.5.21b, July 21, 2021 -------- Test six - Implicity run the Icon Virtual Machine in the background using START [6] --------- +------- Test six - Implicity run the Icon Virtual Machine in the background using START [6] --------- There are 6 args one @@ -151,7 +151,7 @@ pipes system function Icon Version 9.5.21b, July 21, 2021 -------- Test seven - Do not include the Icon Virtual Machine in the output file [7] --------- +------- Test seven - Do not include the Icon Virtual Machine in the output file [7] --------- There are 7 args uno @@ -174,7 +174,7 @@ pipes system function Icon Version 9.5.21b, July 21, 2021 -------- Test eight - Shebang example [8] --------- +------- Test eight - Shebang example [8] --------- There are 12 args ten @@ -202,12 +202,14 @@ pipes system function Icon Version 9.5.21b, July 21, 2021 -------- Test nine - icon.cmd invokes icont.cmd and iconx.cmd [9] --------- +------- Test nine - icon.cmd invokes icont.cmd and iconx.cmd [9] --------- 9a. Invoke the icon.cmd script with quotes in the source file name -There are 2 args +There are 4 args nine with quoted path to Icon source +hello +world MS Windows Cygwin ASCII @@ -222,9 +224,11 @@ system function Icon Version 9.5.21b, July 21, 2021 9b. Invoke the icon.cmd script without quotes in the source file name -There are 2 args +There are 4 args nine without quoted path to Icon source +hello +world MS Windows Cygwin ASCII @@ -239,9 +243,11 @@ system function Icon Version 9.5.21b, July 21, 2021 9c. Invoke the icon.cmd script on source from stdin -There are 2 args +There are 4 args nine with Icon source from stdin +hello +world MS Windows Cygwin ASCII @@ -256,9 +262,11 @@ system function Icon Version 9.5.21b, July 21, 2021 9d. Invoke the icont.cmd [not icono.cmd] script with spaces in file name -There are 2 args +There are 4 args nine via icont.cmd (rather than icon.cmd) +hello +world MS Windows Cygwin ASCII diff --git a/icon.cmd b/icon.cmd index bcdc46d..b64e0f8 100755 --- a/icon.cmd +++ b/icon.cmd @@ -1,5 +1,6 @@ @echo off setlocal + set ARGS= set ICONT_ARGS= set ARG0=%~dps0 @@ -16,16 +17,18 @@ if ""%ARG%"" == ""/?"" goto usage if /I ""%ARG%"" == ""-H"" goto usage set ARG2=%2 + set JUST_DEFINED= if defined ICN_FILE goto next_arg + set JUST_DEFINED=true set ICONT_ARGS=%ARGS% if exist "%~dpns1.icn" set ICN_FILE=%~dpns1.icn& set ICNSRCdpnsx=%~dpnxs1& set ICNSRCdpns=%~dpns1& set ICNSRCdps=%~dps1& set ICNSRCns=%~ns1& set ARGS= if "%~ns1" == "-" set ICN_FILE=-& set ICNSRCns=%~ns1& set ARGS= :: single-ampersand means execute second command regardless of EXITCODE from first command :next_arg - if not "%~ns1" == "-" if not exist "%~dpns1.icn" set ARGS=%ARGS% %ARG% + if not defined ICN_FILE if not "%~ns1" == "-" if not exist "%~dpns1.icn" set ARGS=%ARGS% %ARG% + if defined ICN_FILE if not defined JUST_DEFINED set ARGS=%ARGS% %ARG% shift set ARG=%1 - :: if not "%~ns1" == "-" set ARGS=%ARGS% %ARG% if not defined ARG2 goto got_args goto more_args