Last active
November 20, 2020 01:48
-
-
Save bitdivine/b785e6062d6fbf1becc69b78b8f6351f to your computer and use it in GitHub Desktop.
Fast failing cargo tests - runs new, recently broken and fast tests first
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -eu | |
touch ,logtimes | |
FLAGS="${FLAGS:-}" | |
all_tests_with_dummy_times() { | |
set -x | |
cargo test $FLAGS -- --list --format terse | awk '/: test/{print "0s", "new", substr($1, 1, length($1)-1)}' | |
} | |
test_times() { | |
< ,logtimes jq -R 'fromjson? | select( .type == "test" ) | select( .event == ("ok", "failed") ) | .exec_time + " " + .event + " " + .name' | tr -d '"' | |
} | |
tests_with_last_runtime() { | |
{ all_tests_with_dummy_times ; test_times ; } | tac | awk '!x[$3]++' | |
} | |
ordered_tests() { | |
if test -e ,logtimes ; | |
then tests_with_last_runtime | sort -n | sort -sd -k2,2 | awk '{print $3}' | |
else : We make use of the fact that xargs will run all tests if nothing is returned. We may change this though. | |
: We will however make sure that the code compiles: | |
set -x | |
cargo test $FLAGS --no-run | |
fi | |
} | |
run_tests() { | |
: It would be nice if cargo could emit both json, for the log, and human readable output. Unfortunately not, | |
: so we will have to prettify the JSON output and try to make it accessible to the human eye... | |
xargs -n1 -P $(cat /proc/cpuinfo | grep -c processor) cargo test $FLAGS -- --report-time -Z unstable-options --format json 2>/dev/null | |
} | |
format_output() { | |
jq --unbuffered -R 'fromjson? | select( .type == "test" ) | select( .event == ("ok", "failed") ) | .exec_time + " " + .event + " " + .name + ( if .event == "ok" then "" else " <=======================" end )' | tr -d '"' | |
} | |
ordered_tests | grep ${@:-.} | run_tests | tee -a ,logtimes | format_output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment