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