From b002da89eb07c2c25cdb8b972b295d212f225cdc Mon Sep 17 00:00:00 2001 From: Toyam Cox Date: Thu, 5 Dec 2024 03:19:33 -0500 Subject: [PATCH 1/3] test(fixtures): Ease testing just one fixture --- fixtures/test-fixtures.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/fixtures/test-fixtures.sh b/fixtures/test-fixtures.sh index 2e58231..ec2eb4a 100755 --- a/fixtures/test-fixtures.sh +++ b/fixtures/test-fixtures.sh @@ -24,20 +24,29 @@ run_fixture() { return "$result" } +proc_fixture() { + # Since we are creating a subshell, all environment variables created by custom_env will be lost + # Return code is preserved + fixture="$1" + (run_fixture "$fixture") + exit_status=$? + if [ "$exit_status" -eq 0 ]; then + echo -e "[${GREEN}ok${NC}] $fixture" + else + echo -e "[${RED}fail${NC}] $fixture" + exit "$exit_status" + fi +} + main() { + [ $# -ne 0 ] && for fixture in "$@"; do + proc_fixture "$fixture" + done && exit 0 + find * -maxdepth 0 -type d -print0 | while IFS= read -r -d '' fixture; do - # Since we are creating a subshell, all environment variables created by custom_env will be lost - # Return code is preserved - (run_fixture "$fixture") - exit_status=$? - if [ "$exit_status" -eq 0 ]; then - echo -e "[${GREEN}ok${NC}] $fixture" - else - echo -e "[${RED}fail${NC}] $fixture" - exit "$exit_status" - fi + proc_fixture "$fixture" done } [ "$DEBUG" == 'true' ] && set -x && export RUST_LOG=debug -main +main "$@" From 33ce27e5e5deb471ad33b3d5c0a04253847f8bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 7 Dec 2024 18:08:52 +0300 Subject: [PATCH 2/3] refactor(fixture): rename proc_fixture to process_fixture --- fixtures/test-fixtures.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fixtures/test-fixtures.sh b/fixtures/test-fixtures.sh index ec2eb4a..705b3a7 100755 --- a/fixtures/test-fixtures.sh +++ b/fixtures/test-fixtures.sh @@ -24,7 +24,7 @@ run_fixture() { return "$result" } -proc_fixture() { +process_fixture() { # Since we are creating a subshell, all environment variables created by custom_env will be lost # Return code is preserved fixture="$1" @@ -40,11 +40,11 @@ proc_fixture() { main() { [ $# -ne 0 ] && for fixture in "$@"; do - proc_fixture "$fixture" + process_fixture "$fixture" done && exit 0 find * -maxdepth 0 -type d -print0 | while IFS= read -r -d '' fixture; do - proc_fixture "$fixture" + process_fixture "$fixture" done } From b1d7332e0c1110b95d2d4742a61149362adae2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 7 Dec 2024 18:09:38 +0300 Subject: [PATCH 3/3] docs(fixture): add comments to functions --- fixtures/test-fixtures.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fixtures/test-fixtures.sh b/fixtures/test-fixtures.sh index 705b3a7..e2d56ef 100755 --- a/fixtures/test-fixtures.sh +++ b/fixtures/test-fixtures.sh @@ -24,6 +24,7 @@ run_fixture() { return "$result" } +# Run the fixture and print the result process_fixture() { # Since we are creating a subshell, all environment variables created by custom_env will be lost # Return code is preserved @@ -39,10 +40,12 @@ process_fixture() { } main() { + # If arguments are passed, run only those fixtures [ $# -ne 0 ] && for fixture in "$@"; do process_fixture "$fixture" done && exit 0 + # Otherwise, run all fixtures find * -maxdepth 0 -type d -print0 | while IFS= read -r -d '' fixture; do process_fixture "$fixture" done