From 1df6486b88f85a77387f25fb2d97db8fbf98f967 Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Mon, 11 Nov 2024 08:59:00 +0100 Subject: [PATCH] ci: Allow for single exercise test exection (#849) --- README.md | 16 ++++++++++++++++ bin/test.sh | 9 +++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bea83633..25972da3 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,22 @@ composer test:run This is included in `composer ci` to run the CI checks locally. +### Run a specific test + +If you want to run tests for one specific exercise, you can do it with following cli command. + +```shell +composer test:run -- exercise-name +# e.g +composer test:run -- book-store +``` + +If you want to run all starting with let's say 'b' you can run + +```shell +composer test:run -- "b*" +``` + ## Running Style Checker This project uses a slightly [modified][local-file-phpcs-config] version of [PSR-12]. diff --git a/bin/test.sh b/bin/test.sh index 8213cdb6..182accb1 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -13,7 +13,12 @@ file_ext="php" function main { has_failures=0 - all_practice_exercise_dirs=$(find ./exercises/practice -maxdepth 1 -mindepth 1 -type d | sort) + name_filter=() + if [ $# -ge 1 ] && [ -n "$1" ]; then + name_filter=("-name" "$1") + fi + + all_practice_exercise_dirs=$(find ./exercises/practice -maxdepth 1 -mindepth 1 -type d "${name_filter[@]}" | sort) for exercise_dir in $all_practice_exercise_dirs; do test "${exercise_dir}" "example" if [[ $? -ne 0 ]]; then @@ -21,7 +26,7 @@ function main { fi done - all_concept_exercise_dirs=$(find ./exercises/concept -maxdepth 1 -mindepth 1 -type d | sort) + all_concept_exercise_dirs=$(find ./exercises/concept -maxdepth 1 -mindepth 1 -type d "${name_filter[@]}" | sort) for exercise_dir in $all_concept_exercise_dirs; do test "${exercise_dir}" "exemplar" if [[ $? -ne 0 ]]; then