@@ -105,7 +105,7 @@ function bashunit::learn::mark_completed() {
105105# #
106106function bashunit::learn::is_completed() {
107107 local lesson=$1
108- [ -f " $LEARN_PROGRESS_FILE " ] && grep -q " ^$lesson $" " $LEARN_PROGRESS_FILE "
108+ [ -f " $LEARN_PROGRESS_FILE " ] && [ " $( " $GREP " -c " ^$lesson $" " $LEARN_PROGRESS_FILE " || true ) " -gt 0 ]
109109}
110110
111111# #
@@ -253,7 +253,7 @@ function test_bashunit_works() {
253253 fi
254254
255255 # Check if file contains assert_same
256- if ! grep -q " assert_same" " $test_file " ; then
256+ if [ " $( " $GREP " -c " assert_same" " $test_file " || true ) " -eq 0 ] ; then
257257 echo " ${_BASHUNIT_COLOR_FAILED} Your test should use assert_same${_BASHUNIT_COLOR_DEFAULT} "
258258 read -p " Press Enter to continue..." -r
259259 return 1
@@ -334,9 +334,9 @@ function test_multiple_assertions() {
334334 return 1
335335 fi
336336
337- if ! grep -q " assert_contains" " $test_file " ||
338- ! grep -q " assert_matches" " $test_file " ||
339- ! grep -q " assert_not_empty" " $test_file " ; then
337+ if [ " $( " $GREP " -c " assert_contains" " $test_file " || true ) " -eq 0 ] ||
338+ [ " $( " $GREP " -c " assert_matches" " $test_file " || true ) " -eq 0 ] ||
339+ [ " $( " $GREP " -c " assert_not_empty" " $test_file " || true ) " -eq 0 ] ; then
340340 echo " ${_BASHUNIT_COLOR_FAILED} Your test should use all three assertion types${_BASHUNIT_COLOR_DEFAULT} "
341341 read -p " Press Enter to continue..." -r
342342 return 1
@@ -427,8 +427,8 @@ function test_file_has_content() {
427427 return 1
428428 fi
429429
430- if ! grep -q " function set_up()" " $test_file " ||
431- ! grep -q " function tear_down()" " $test_file " ; then
430+ if [ " $( " $GREP " -c " function set_up()" " $test_file " || true ) " -eq 0 ] ||
431+ [ " $( " $GREP " -c " function tear_down()" " $test_file " || true ) " -eq 0 ] ; then
432432 echo " ${_BASHUNIT_COLOR_FAILED} Your test should define set_up and tear_down functions${_BASHUNIT_COLOR_DEFAULT} "
433433 read -p " Press Enter to continue..." -r
434434 return 1
@@ -521,7 +521,7 @@ function test_add_negative_numbers() {
521521 return 1
522522 fi
523523
524- if ! grep -q " source" " $test_file " ; then
524+ if [ " $( " $GREP " -c " source" " $test_file " || true ) " -eq 0 ] ; then
525525 echo " ${_BASHUNIT_COLOR_FAILED} Your test should source the calculator.sh file${_BASHUNIT_COLOR_DEFAULT} "
526526 read -p " Press Enter to continue..." -r
527527 return 1
@@ -710,7 +710,7 @@ function test_system_info_on_macos() {
710710 return 1
711711 fi
712712
713- if ! grep -q " mock" " $test_file " ; then
713+ if [ " $( " $GREP " -c " mock" " $test_file " || true ) " -eq 0 ] ; then
714714 echo " ${_BASHUNIT_COLOR_FAILED} Your test should use mock${_BASHUNIT_COLOR_DEFAULT} "
715715 read -p " Press Enter to continue..." -r
716716 return 1
@@ -827,7 +827,7 @@ function test_deploy_calls_docker_twice() {
827827 return 1
828828 fi
829829
830- if ! grep -q " spy" " $test_file " ; then
830+ if [ " $( " $GREP " -c " spy" " $test_file " || true ) " -eq 0 ] ; then
831831 echo " ${_BASHUNIT_COLOR_FAILED} Your test should use spy${_BASHUNIT_COLOR_DEFAULT} "
832832 read -p " Press Enter to continue..." -r
833833 return 1
@@ -860,7 +860,7 @@ File: validator.sh
860860
861861function is_valid_email() {
862862 local email_pattern='^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
863- echo "$1" | grep -qE "$email_pattern"
863+ [ "$( echo "$1" | "$GREP" -cE "$email_pattern" || true)" -gt 0 ]
864864}
865865───────────────────────────────────────────────────────────────
866866
@@ -941,7 +941,7 @@ function test_invalid_emails() {
941941 return 1
942942 fi
943943
944- if ! grep -q " function data_provider_" " $test_file " ; then
944+ if [ " $( " $GREP " -c " function data_provider_" " $test_file " || true ) " -eq 0 ] ; then
945945 echo " ${_BASHUNIT_COLOR_FAILED} Your test should define data provider functions${_BASHUNIT_COLOR_DEFAULT} "
946946 read -p " Press Enter to continue..." -r
947947 return 1
@@ -1057,7 +1057,8 @@ function test_missing_file_returns_127() {
10571057 return 1
10581058 fi
10591059
1060- if ! grep -q " assert_successful_code\|assert_exit_code\|assert_general_error" " $test_file " ; then
1060+ local _exit_assert_pattern=" assert_successful_code\|assert_exit_code\|assert_general_error"
1061+ if [ " $( " $GREP " -c " $_exit_assert_pattern " " $test_file " || true) " -eq 0 ]; then
10611062 echo " ${_BASHUNIT_COLOR_FAILED} Your test should use exit code assertions${_BASHUNIT_COLOR_DEFAULT} "
10621063 read -p " Press Enter to continue..." -r
10631064 return 1
@@ -1162,12 +1163,12 @@ function test_backup_failure_when_source_missing() {
11621163 local -a missing_components=()
11631164 local missing_components_count=0
11641165
1165- if ! grep -q " function set_up()" " $test_file " ; then
1166+ if [ " $( " $GREP " -c " function set_up()" " $test_file " || true ) " -eq 0 ] ; then
11661167 missing_components[missing_components_count]=" set_up function"
11671168 missing_components_count=$(( missing_components_count + 1 ))
11681169 fi
11691170
1170- if ! grep -q " function tear_down()" " $test_file " ; then
1171+ if [ " $( " $GREP " -c " function tear_down()" " $test_file " || true ) " -eq 0 ] ; then
11711172 missing_components[missing_components_count]=" tear_down function"
11721173 missing_components_count=$(( missing_components_count + 1 ))
11731174 fi
0 commit comments