Skip to content

Commit

Permalink
git test hook improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Kieran Elmes committed Feb 28, 2021
1 parent 5f03b7a commit 699f9cb
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions script/run-tests.bash

This file was deleted.

File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions scripts/run-tests.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

ninja -C build test > test_output && cat test_output
ninja -C build coverage

ok=$(grep Ok test_output | grep [0-9] -o)
fail=$(grep "^Fail" test_output | grep [0-9] -o)
total_tests=$(echo $ok + $fail | bc -l)

total_coverage=$(grep "TOTAL" build/meson-logs/coverage.txt | grep -o "[0-9]*\%" | tr -d '%')

echo "coverage: $total%"

if (( $(echo "$total <= 50" | bc -l) )) ; then
COLOR=red
elif (( $(echo "$total > 80" | bc -l) )); then
COLOR=green
else
COLOR=orange
fi

# coverage badge
badgename="coverage-$total_coverage-$COLOR.svg"

if [ ! -f badgename ]; then
curl "https://img.shields.io/badge/coverage-$total_coverage%25-$COLOR" > badges/$badgename
fi

cp badges/$badgename coverage-badge.svg
git add coverage-badge.svg -f

# test results badge

if (( $(echo "$fail > $ok" | bc -l) )) ; then
COLOR=red
elif (( $(echo "$fail > 0" | bc -l) )); then
COLOR=orange
else
COLOR=green
fi

badgename="results-$ok-$fail.svg"

if [ ! -f badgename ]; then
curl "https://img.shields.io/badge/Tests-$ok%20out%20of%20$total_tests-$COLOR.svg" > badges/$badgename
fi

cp badges/$badgename test-badge.svg
git add test-badge.svg -f
1 change: 1 addition & 0 deletions test-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 699f9cb

Please sign in to comment.