-
-
Save PtaxLaine/8107f50dbe6902c9c0890df6d2f38d26 to your computer and use it in GitHub Desktop.
A git pre-commit hook to make sure your Rust code is properly formatted and the tests pass, so you never commit bad code
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
#!/bin/bash | |
check_char='\xE2\x9C\x93' | |
cross_char='\xE2\x9D\x8C' | |
green='\033[0;32m' | |
red='\033[0;31m' | |
nc='\033[0m' | |
check="$green$check_char$nc" | |
cross="$red$cross_char$nc" | |
errors=0 | |
echo -n "Checking formatting... " | |
if diff=$(cargo fmt -- --check --color always 2>&1); then | |
echo -e "$check" | |
else | |
echo -e "$cross" | |
echo "Rust formatting checking failed. Show checking report? (y/n)" | |
read printrep | |
if [ "$printrep" == "y" ]; then | |
echo -e "$diff" | |
fi | |
errors=1 | |
fi | |
echo -n "Running tests... " | |
if result=$(cargo test --color always 2>&1); then | |
echo -e "$check" | |
else | |
echo -e "$cross" | |
echo "$result" | |
errors=1 | |
fi | |
if [ "$errors" != "0" ]; then | |
echo "Failed" | |
exit -1 | |
else | |
echo "OK" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment