Skip to content

Commit

Permalink
dynamically run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanaraps committed Jun 15, 2018
1 parent 6119fc7 commit a20e36b
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ test_date() {
}

assert_equals() {
((tests+=1))

if [[ "$1" == "$2" ]]; then
((pass+=1))
status=$'\e[32m✔'
Expand All @@ -136,37 +134,20 @@ assert_equals() {
}

main() {
# Get the code blocks from README.md
source <(awk '/```sh$/{f=1;next}/```/{f=0}f' README.md) 2>/dev/null

head="-> Running tests on the Pure Bash Bible.."
printf '\n%s\n%s\n' "$head" "${head//?/-}"

test_trim_string
test_trim_all
test_regex
test_lower
test_upper
test_trim_quotes
test_strip_all
test_strip
test_lstrip
test_rstrip
test_reverse_array
test_remove_array_dups
test_cycle
test_head
test_tail
test_lines
test_count
test_dirname
test_basename
test_hex_to_rgb
test_rgb_to_hex
test_date

comp="Completed $tests tests. ${pass:-0} passed, ${err:-0} errored."
# Generate the list of tests to run.
IFS=$'\n' read -d "" -ra funcs < <(awk -F'(' '/^test_/ {print $1}' "$0")
for func in "${funcs[@]}"; do "$func"; done

comp="Completed ${#funcs[@]} tests. ${pass:-0} passed, ${err:-0} errored."
printf '%s\n%s\n\n' "${comp//?/-}" "$comp"

# If a test failed, exit with '1'.
[[ -f /tmp/err ]] || exit 0 && { rm /tmp/err; exit 1; }
}

Expand Down

0 comments on commit a20e36b

Please sign in to comment.