Skip to content

Commit

Permalink
refactor(*): revise to support custom test functions (#130)
Browse files Browse the repository at this point in the history
Update, for each exercise, its "runt*" and "test-*" scripts, to use optional custom test functions.
  • Loading branch information
ajborla authored Jul 27, 2024
1 parent 364ce48 commit c8d5041
Showing 260 changed files with 3,120 additions and 780 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/accumulate/test-accumulate
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
cd "testlib" 2>&1 >/dev/null
if [ $# -eq 0 ] ; then ./runt --regina ../accumulate-check ../accumulate ../accumulate-toplevel ; else ./runt "$@" ../accumulate-check ../accumulate ../accumulate-toplevel ; fi
if [ $# -eq 0 ] ; then ./runt --regina ../accumulate-check ../accumulate ../accumulate-toplevel accumulate-funcs ; else ./runt "$@" ../accumulate-check ../accumulate ../accumulate-toplevel accumulate-funcs ; fi
cd - 2>&1 >/dev/null
2 changes: 1 addition & 1 deletion exercises/practice/accumulate/test-accumulate.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@set options=%*
@if "%1"=="" @set options=--regina
@cd "testlib"
@call runt.bat %options% ..\accumulate-check ..\accumulate ..\accumulate-toplevel
@call runt.bat %options% ..\accumulate-check ..\accumulate ..\accumulate-toplevel accumulate-funcs
@cd ..
22 changes: 16 additions & 6 deletions exercises/practice/accumulate/testlib/runt
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@
#
# $1 -> the test script (rexx)
# $2 -> the application to test (rexx)
# %3 -> optional shared variable definitions file (rexx)
# $3 -> optional shared variable definitions file (rexx)
# $4 -> optional custom testing functions definitions file (rexx)
#
# This script concatenates the files:
#
@@ -15,6 +16,10 @@
#
# ${3}.rexx + t1.rexx + ${1}.rexx + t2.rexx + ${2}.rexx + t3.rexx
#
# or, if both optional files specified:
#
# ${3}.rexx + t1.rexx + ${1}.rexx + t2.rexx + ${2}.rexx + ${4}.rexx + t3.rexx
#
# and executes the resulting test runner file. The return code from the
# test runner is passed back to the command-line. Valid return code values:
#
@@ -40,6 +45,7 @@
# 2023-04-14 0.6.0 Anthony J. Borla Added JSON option.
# 2023-04-15 0.7.0 Anthony J. Borla Added toplevel support.
# 2023-04-15 0.7.1 Anthony J. Borla Revise header commentary.
# 2024-07-27 0.7.2 Anthony J. Borla Support test functions.
# -----------------------------------------------------------------------------

# ---- Constants
@@ -50,13 +56,14 @@ INTERPRETER="rexx"
# ---- Functions

usage() {
echo "Usage: ${0} [-h | --help] | [--keep] [--tap|--json] [--regina] test source [toplevel]"
echo "Usage: ${0} [-h | --help] | [--keep] [--tap|--json] [--regina] test source [toplevel] [checkfuncs]"
}

help() {
echo 'Executes t-rexx unit test runner using supplied Rexx test script on specified Rexx source file.'
echo ' * ${1} is the test script name, ${2} is the source file (code under test), both sans .rexx extension'
echo ' * ${3} is an optional Rexx file containing variables shared by the code under test (sans .rexx extension)'
echo ' * ${4} is another optional Rexx file containing custom functions used in testing'
echo ' * --tap option generates TAP-compliant output; default is verbose report style'
echo ' * --json option packages report style output as a JSON array (incompatible with --tap option)'
echo ' * --keep option ensures the generated test runner is not deleted'
@@ -93,17 +100,20 @@ done
[ -n "${TAP}" -a -n "${JSON}" ] && error 'Incorrect option combination: either --tap or --json, not both'

# Expecting two, or three, positional parameters; bail if not supplied
[ "$#" -ne "2" -a "$#" -ne "3" ] && error 'Incorrect arguments'
[ "$#" -ne "2" -a "$#" -ne "3" -a "$#" -ne "4" ] && error 'Incorrect arguments'

# Expecting each positional parameter to be a Rexx filename
[ -f "${1}.rexx" ] || error "Missing test script - ${1}.rexx"
[ -f "${2}.rexx" ] || error "Missing source file - ${2}.rexx"
[ "$#" -eq "4" ] && { [ -f "${4}.rexx" ] || error "Missing checkfuncs file - ${4}.rexx" ; }
[ "$#" -eq "3" ] && { [ -f "${3}.rexx" ] || error "Missing toplevel file - ${3}.rexx" ; }

# Assemble test runner from components and supplied files
[ "$#" -eq "3" ] \
&& cat "${3}.rexx" t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null \
|| cat t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null
case "$#" in
4) cat "${3}.rexx" t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" "${4}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null ;;
3) cat "${3}.rexx" t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null ;;
*) cat t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null ;;
esac

# Set output option
[ -n "${TAP}" ] && OUT="${TAP}"
34 changes: 30 additions & 4 deletions exercises/practice/accumulate/testlib/runt.bat
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
:: %1 -> the test script (rexx)
:: %2 -> the application to test (rexx)
:: %3 -> optional shared variable definitions file (rexx)
:: %4 -> optional custom testing functions definitions file (rexx)
::
:: This script concatenates the files:
::
@@ -15,6 +16,10 @@
::
:: %3.rexx + t1.rexx + %1.rexx + t2.rexx + %2.rexx + t3.rexx
::
:: or, if both optional files specified:
::
:: %3.rexx + t1.rexx + %1.rexx + t2.rexx + %2.rexx + %4.rexx + t3.rexx
::
:: and executes the resulting test runner file. The return code from the
:: test runner is passed back to the command-line. Valid return code values:
::
@@ -44,6 +49,7 @@
:: 2023-04-15 0.7.0 Anthony J. Borla Added toplevel support.
:: 2023-04-15 0.7.1 Anthony J. Borla Revise header commentary.
:: 2023-04-19 0.7.2 Anthony J. Borla Fix JSON option.
:: 2024-07-27 0.7.3 Anthony J. Borla Support test functions.
:: ----------------------------------------------------------------------------

:init
@@ -80,16 +86,31 @@
if "%1"=="" goto :argErr

:chkfile
:: Do source and test script files exist ?
:: Do optional files exist ?
if not "%4"=="" if not exist "%4.rexx" goto :noCheckFuncsFileErr
if not "%3"=="" if not exist "%3.rexx" goto :noToplevelFileErr

:: Do source and test script files exist ?
if not exist "%2.rexx" goto :noSourceFileErr
if not exist "%1.rexx" goto :noTestFileErr

:main
:: Assemble test runner from components and supplied files
if not "%3"=="" copy/v "%3.rexx"+t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:
if "%3"=="" copy/v t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:
if not "%4"=="" goto :copyFuncs
if not "%3"=="" goto :copyVarsOnly

:copyNoOptionals
copy/v t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:
goto :setOptions

:copyFuncs
copy/v "%3.rexx"+t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+"%4.rexx"+t3.rexx %RUNNER% > NUL:
goto :setOptions

:copyVarsOnly
copy/v "%3.rexx"+t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:

:setOptions
:: Set output option
if "%TAP%"=="TAP" set OUT=%TAP%
if "%JSON%"=="JSON" set OUT=%JSON%
@@ -113,6 +134,7 @@
echo Executes t-rexx unit test runner using supplied Rexx test script on specified Rexx source file.
echo * %%1 is the test script name, %%2 is the source file (code under test), both sans .rexx extension
echo * %%3 is an optional Rexx file containing variables shared by the code under test (sans .rexx extension)
echo * %%4 is another optional Rexx file containing custom functions used in testing
echo * --tap option generates TAP-compliant output; default is verbose report style
echo * --json option packages report style output as a JSON array (incompatible with --tap option)
echo * --keep option ensures the generated test runner is not deleted
@@ -130,6 +152,10 @@
echo Error: Incorrect option combination - either --tap or --json, not both
goto :usage

:noCheckFuncsFileErr
echo Error: Missing checkfuncs file - "%4.rexx"
goto :usage

:noToplevelFileErr
echo Error: Missing toplevel file - "%3.rexx"
goto :usage
@@ -143,7 +169,7 @@

:usage
echo.
echo Usage: %0 [-h ^| -? ^| --help ^| /h ^| /? ^| /help] ^| [--keep] [--tap^|--json] [--regina] test source [toplevel]
echo Usage: %0 [-h ^| -? ^| --help ^| /h ^| /? ^| /help] ^| [--keep] [--tap^|--json] [--regina] test source [toplevel] [checkfuncs]

:exit
exit/b %RC%
2 changes: 1 addition & 1 deletion exercises/practice/acronym/test-acronym
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
cd "testlib" 2>&1 >/dev/null
if [ $# -eq 0 ] ; then ./runt --regina ../acronym-check ../acronym ../acronym-toplevel ; else ./runt "$@" ../acronym-check ../acronym ../acronym-toplevel ; fi
if [ $# -eq 0 ] ; then ./runt --regina ../acronym-check ../acronym ../acronym-toplevel acronym-funcs ; else ./runt "$@" ../acronym-check ../acronym ../acronym-toplevel acronym-funcs ; fi
cd - 2>&1 >/dev/null
2 changes: 1 addition & 1 deletion exercises/practice/acronym/test-acronym.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@set options=%*
@if "%1"=="" @set options=--regina
@cd "testlib"
@call runt.bat %options% ..\acronym-check ..\acronym ..\acronym-toplevel
@call runt.bat %options% ..\acronym-check ..\acronym ..\acronym-toplevel acronym-funcs
@cd ..
22 changes: 16 additions & 6 deletions exercises/practice/acronym/testlib/runt
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@
#
# $1 -> the test script (rexx)
# $2 -> the application to test (rexx)
# %3 -> optional shared variable definitions file (rexx)
# $3 -> optional shared variable definitions file (rexx)
# $4 -> optional custom testing functions definitions file (rexx)
#
# This script concatenates the files:
#
@@ -15,6 +16,10 @@
#
# ${3}.rexx + t1.rexx + ${1}.rexx + t2.rexx + ${2}.rexx + t3.rexx
#
# or, if both optional files specified:
#
# ${3}.rexx + t1.rexx + ${1}.rexx + t2.rexx + ${2}.rexx + ${4}.rexx + t3.rexx
#
# and executes the resulting test runner file. The return code from the
# test runner is passed back to the command-line. Valid return code values:
#
@@ -40,6 +45,7 @@
# 2023-04-14 0.6.0 Anthony J. Borla Added JSON option.
# 2023-04-15 0.7.0 Anthony J. Borla Added toplevel support.
# 2023-04-15 0.7.1 Anthony J. Borla Revise header commentary.
# 2024-07-27 0.7.2 Anthony J. Borla Support test functions.
# -----------------------------------------------------------------------------

# ---- Constants
@@ -50,13 +56,14 @@ INTERPRETER="rexx"
# ---- Functions

usage() {
echo "Usage: ${0} [-h | --help] | [--keep] [--tap|--json] [--regina] test source [toplevel]"
echo "Usage: ${0} [-h | --help] | [--keep] [--tap|--json] [--regina] test source [toplevel] [checkfuncs]"
}

help() {
echo 'Executes t-rexx unit test runner using supplied Rexx test script on specified Rexx source file.'
echo ' * ${1} is the test script name, ${2} is the source file (code under test), both sans .rexx extension'
echo ' * ${3} is an optional Rexx file containing variables shared by the code under test (sans .rexx extension)'
echo ' * ${4} is another optional Rexx file containing custom functions used in testing'
echo ' * --tap option generates TAP-compliant output; default is verbose report style'
echo ' * --json option packages report style output as a JSON array (incompatible with --tap option)'
echo ' * --keep option ensures the generated test runner is not deleted'
@@ -93,17 +100,20 @@ done
[ -n "${TAP}" -a -n "${JSON}" ] && error 'Incorrect option combination: either --tap or --json, not both'

# Expecting two, or three, positional parameters; bail if not supplied
[ "$#" -ne "2" -a "$#" -ne "3" ] && error 'Incorrect arguments'
[ "$#" -ne "2" -a "$#" -ne "3" -a "$#" -ne "4" ] && error 'Incorrect arguments'

# Expecting each positional parameter to be a Rexx filename
[ -f "${1}.rexx" ] || error "Missing test script - ${1}.rexx"
[ -f "${2}.rexx" ] || error "Missing source file - ${2}.rexx"
[ "$#" -eq "4" ] && { [ -f "${4}.rexx" ] || error "Missing checkfuncs file - ${4}.rexx" ; }
[ "$#" -eq "3" ] && { [ -f "${3}.rexx" ] || error "Missing toplevel file - ${3}.rexx" ; }

# Assemble test runner from components and supplied files
[ "$#" -eq "3" ] \
&& cat "${3}.rexx" t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null \
|| cat t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null
case "$#" in
4) cat "${3}.rexx" t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" "${4}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null ;;
3) cat "${3}.rexx" t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null ;;
*) cat t1.rexx "${1}.rexx" t2.rexx "${2}.rexx" t3.rexx > "${RUNNER}" 2>/dev/null ;;
esac

# Set output option
[ -n "${TAP}" ] && OUT="${TAP}"
34 changes: 30 additions & 4 deletions exercises/practice/acronym/testlib/runt.bat
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
:: %1 -> the test script (rexx)
:: %2 -> the application to test (rexx)
:: %3 -> optional shared variable definitions file (rexx)
:: %4 -> optional custom testing functions definitions file (rexx)
::
:: This script concatenates the files:
::
@@ -15,6 +16,10 @@
::
:: %3.rexx + t1.rexx + %1.rexx + t2.rexx + %2.rexx + t3.rexx
::
:: or, if both optional files specified:
::
:: %3.rexx + t1.rexx + %1.rexx + t2.rexx + %2.rexx + %4.rexx + t3.rexx
::
:: and executes the resulting test runner file. The return code from the
:: test runner is passed back to the command-line. Valid return code values:
::
@@ -44,6 +49,7 @@
:: 2023-04-15 0.7.0 Anthony J. Borla Added toplevel support.
:: 2023-04-15 0.7.1 Anthony J. Borla Revise header commentary.
:: 2023-04-19 0.7.2 Anthony J. Borla Fix JSON option.
:: 2024-07-27 0.7.3 Anthony J. Borla Support test functions.
:: ----------------------------------------------------------------------------

:init
@@ -80,16 +86,31 @@
if "%1"=="" goto :argErr

:chkfile
:: Do source and test script files exist ?
:: Do optional files exist ?
if not "%4"=="" if not exist "%4.rexx" goto :noCheckFuncsFileErr
if not "%3"=="" if not exist "%3.rexx" goto :noToplevelFileErr

:: Do source and test script files exist ?
if not exist "%2.rexx" goto :noSourceFileErr
if not exist "%1.rexx" goto :noTestFileErr

:main
:: Assemble test runner from components and supplied files
if not "%3"=="" copy/v "%3.rexx"+t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:
if "%3"=="" copy/v t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:
if not "%4"=="" goto :copyFuncs
if not "%3"=="" goto :copyVarsOnly

:copyNoOptionals
copy/v t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:
goto :setOptions

:copyFuncs
copy/v "%3.rexx"+t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+"%4.rexx"+t3.rexx %RUNNER% > NUL:
goto :setOptions

:copyVarsOnly
copy/v "%3.rexx"+t1.rexx+"%1.rexx"+t2.rexx+"%2.rexx"+t3.rexx %RUNNER% > NUL:

:setOptions
:: Set output option
if "%TAP%"=="TAP" set OUT=%TAP%
if "%JSON%"=="JSON" set OUT=%JSON%
@@ -113,6 +134,7 @@
echo Executes t-rexx unit test runner using supplied Rexx test script on specified Rexx source file.
echo * %%1 is the test script name, %%2 is the source file (code under test), both sans .rexx extension
echo * %%3 is an optional Rexx file containing variables shared by the code under test (sans .rexx extension)
echo * %%4 is another optional Rexx file containing custom functions used in testing
echo * --tap option generates TAP-compliant output; default is verbose report style
echo * --json option packages report style output as a JSON array (incompatible with --tap option)
echo * --keep option ensures the generated test runner is not deleted
@@ -130,6 +152,10 @@
echo Error: Incorrect option combination - either --tap or --json, not both
goto :usage

:noCheckFuncsFileErr
echo Error: Missing checkfuncs file - "%4.rexx"
goto :usage

:noToplevelFileErr
echo Error: Missing toplevel file - "%3.rexx"
goto :usage
@@ -143,7 +169,7 @@

:usage
echo.
echo Usage: %0 [-h ^| -? ^| --help ^| /h ^| /? ^| /help] ^| [--keep] [--tap^|--json] [--regina] test source [toplevel]
echo Usage: %0 [-h ^| -? ^| --help ^| /h ^| /? ^| /help] ^| [--keep] [--tap^|--json] [--regina] test source [toplevel] [checkfuncs]

:exit
exit/b %RC%
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/test-all-your-base
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
cd "testlib" 2>&1 >/dev/null
if [ $# -eq 0 ] ; then ./runt --regina ../all-your-base-check ../all-your-base ../all-your-base-toplevel ; else ./runt "$@" ../all-your-base-check ../all-your-base ../all-your-base-toplevel ; fi
if [ $# -eq 0 ] ; then ./runt --regina ../all-your-base-check ../all-your-base ../all-your-base-toplevel all-your-base-funcs ; else ./runt "$@" ../all-your-base-check ../all-your-base ../all-your-base-toplevel all-your-base-funcs ; fi
cd - 2>&1 >/dev/null
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/test-all-your-base.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@set options=%*
@if "%1"=="" @set options=--regina
@cd "testlib"
@call runt.bat %options% ..\all-your-base-check ..\all-your-base ..\all-your-base-toplevel
@call runt.bat %options% ..\all-your-base-check ..\all-your-base ..\all-your-base-toplevel all-your-base-funcs
@cd ..
Loading

0 comments on commit c8d5041

Please sign in to comment.