-
-
Save anonymous/877eede707f2889f4c59 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Working directory gets passed in as a command line argument | |
PROJ_TMP_DIR=$1 | |
cd $PROJ_TMP_DIR | |
# Store all of our build data here; massage it later. | |
BUILD_MSG=.build_msg | |
> $BUILD_MSG | |
# Get a pretty project name (the last two parts of the directory) | |
PROJECT_NAME=$(pwd | awk -F '/' '{print $(NF-1)"/"$(NF)}') | |
# Step 1: compile, and fail if we can't even do that. | |
make 1>build.log 2>build.error | |
if [ -s build.error ]; then | |
notify-send "FAIL: $PROJECT_NAME" "Build failed." | |
exit 1 | |
fi | |
# Step 2: Run all executables in the current directory | |
# with "test" in the filename | |
find . -maxdepth 1 -type f -executable | while read file; do | |
LOGFILE=$file".log" | |
ERRORFILE=$file".error" | |
# Run in a subshell to suppress 'aborted' messages | |
$($file 1>$LOGFILE 2>$ERRORFILE) &> /dev/null | |
# How'd we do? Log to our build file. | |
if [ $? -eq 0 ]; then | |
PASSED_COUNT=$((PASSED_COUNT+1)) | |
echo "P $file" >> $BUILD_MSG | |
else | |
FAILED_COUNT=$((FAILED_COUNT+1)) | |
echo "F $file" >> $BUILD_MSG | |
fi | |
done | |
# Step 3: Total up counts and from test cases into NOTIFY_MSG. | |
TOTAL_COUNT=$(cat $BUILD_MSG | wc -l) | |
PASS_COUNT=$(grep ^P $BUILD_MSG | wc -l) | |
FAIL_COUNT=$(grep ^F $BUILD_MSG | wc -l) | |
NOTIFY_MSG="$PASS_COUNT/$TOTAL_COUNT tests passed\n" | |
NOTIFY_MSG="$NOTIFY_MSG$(grep ^P $BUILD_MSG | sed 's/^P/-->/g')\n" | |
NOTIFY_MSG="$NOTIFY_MSG$FAIL_COUNT/$TOTAL_COUNT tests failed\n" | |
NOTIFY_MSG="$NOTIFY_MSG$(grep ^F $BUILD_MSG | sed 's/^F/-->/g')\n" | |
# Step 5: Run cppcheck and dump output to NOTIFY_MSG. | |
cppcheck --enable=all . 1>cppcheck.log 2>cppcheck.error | |
CPPCHECK_STYLE=$(cat cppcheck.log | grep '(style)' | wc -l) | |
CPPCHECK_WARNING=$(cat cppcheck.log | grep '(warning)' | wc -l) | |
NOTIFY_MSG="$NOTIFY_MSG\ncppcheck report:\n" | |
NOTIFY_MSG="$NOTIFY_MSG--> $CPPCHECK_STYLE style warnings\n" | |
NOTIFY_MSG="$NOTIFY_MSG--> $CPPCHECK_WARNING correctness warnings\n" | |
# cppcheck does not contribute to the failure count | |
if [ $FAIL_COUNT -eq 0 ]; then | |
notify-send "PASS: $PROJECT_NAME" "$NOTIFY_MSG" | |
else | |
notify-send "FAIL: $PROJECT_NAME" "$NOTIFY_MSG" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment