Skip to content

Commit

Permalink
test(fixtures): ease testing with just one fixture (#374)
Browse files Browse the repository at this point in the history
* test(fixtures): Ease testing just one fixture

* refactor(fixture): rename proc_fixture to process_fixture

* docs(fixture): add comments to functions

---------

Co-authored-by: Orhun Parmaksız <[email protected]>
  • Loading branch information
Vaelatern and orhun authored Dec 7, 2024
1 parent 03dc194 commit 1bbc764
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions fixtures/test-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,32 @@ 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
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() {
# 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
# 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
process_fixture "$fixture"
done
}

[ "$DEBUG" == 'true' ] && set -x && export RUST_LOG=debug
main
main "$@"

0 comments on commit 1bbc764

Please sign in to comment.