Skip to content

Instantly share code, notes, and snippets.

@astery
Created September 15, 2017 12:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astery/8fc05b8cc120449b42c52ea16d66917b to your computer and use it in GitHub Desktop.
Save astery/8fc05b8cc120449b42c52ea16d66917b to your computer and use it in GitHub Desktop.
Bash script which add summary after running `mix tests` in umbrella root
#!/usr/bin/env bash
set +m
shopt -s lastpipe
app_name="unknown"
declare -A app_tests
declare -A app_fails
declare -A app_warnings
declare -A app_errors
mix test |
while IFS= read -r line
do
echo "$line"
if [[ "$line" =~ ^(==> ([^[:blank:]]*).*)$ ]]; then
app_name="${BASH_REMATCH[2]}"
apps+=($app_name)
app_tests[$app_name]=0
app_fails[$app_name]=0
app_warnings[$app_name]=0
app_errors[$app_name]=0
fi
if [[ "$line" =~ ^(([[:digit:]]+) tests, ([[:digit:]]+) failures.*)$ ]]; then
app_tests[$app_name]="${BASH_REMATCH[2]}"
app_fails[$app_name]="${BASH_REMATCH[3]}"
fi
if [[ "$line" =~ (\[error\]) ]]; then
((app_errors[$app_name]+=$(echo "$line" | grep -o "\[error\]" | wc -l)))
fi
if [[ "$line" =~ (\[warn\]) ]]; then
((app_warnings[$app_name]+=$(echo "$line" | grep -o "\[warn\]" | wc -l)))
fi
done
result=${PIPESTATUS[0]}
echo
for app in "${apps[@]}"
do
printf "%-20s %3s tests, %3s failures, %3s warnings, %3s errors\n" "$app:" "${app_tests[$app]}" "${app_fails[$app]}" "${app_warnings[$app]}" "${app_errors[$app]}"
((total_tests+=${app_tests[$app]}))
((total_fails+=${app_fails[$app]}))
((total_warnings+=${app_warnings[$app]}))
((total_errors+=${app_errors[$app]}))
done
echo
echo "total: $total_tests tests, $total_fails failures, $total_warnings warnings, $total_errors errors"
exit $result

Run in umbrella root ./mix_test_summary.sh

==> gql
........

Finished in 0.4 seconds
8 tests, 0 failures

Randomized with seed 451224
==> web
...........10:00:40.739 [error] Postgrex.Protocol (#PID<0.19544.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.19506.0> exited: no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
.......10:00:42.042 [error] Postgrex.Protocol (#PID<0.20809.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.20782.0> exited: no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
...

Finished in 4.2 seconds
21 tests, 0 failures

Randomized with seed 451224
==> main
..

Finished in 0.02 seconds
2 tests, 0 failures

Randomized with seed 451224

..all input and..

gql: 8 tests, 0 failures, 0 warnings, 0 errors
web: 21 tests, 0 failures, 0 warnings, 2 errors
main: 2 tests, 0 failures, 0 warnings, 0 errors

total: 31 tests, 0 failures, 0 warnings, 2 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment