Skip to content

Instantly share code, notes, and snippets.

@fsaravia
Created June 24, 2015 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsaravia/9a2c63c0063d99c80964 to your computer and use it in GitHub Desktop.
Save fsaravia/9a2c63c0063d99c80964 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
export PROTEST_REPORT=summary
export PROTEST_FAIL_EARLY=true
find_command() {
find ./test -name "*.rb" -mindepth 2
}
NUMBER_OF_FILES=$(echo `find_command | wc -l`)
RESULTS_FILE=last_results.txt
cleanup() {
if [[ -e $RESULTS_FILE ]]; then
rm $RESULTS_FILE
fi
}
cancel() {
cleanup
exit 0
}
trap cancel SIGINT
for file in `find_command`; do
((i++))
echo "Testing $file ($i/$NUMBER_OF_FILES)"
ruby $file > $RESULTS_FILE
if [[ $? != 0 ]]; then
echo "Test failed"
cat last_results.txt
break
fi
done
@inkel
Copy link

inkel commented Jun 24, 2015

Using Bash arrays FTW!

#! /usr/bin/env bash

export PROTEST_REPORT=summary
export PROTEST_FAIL_EARLY=true

FILES=($(find ./test/modules -name "*.rb" -mindepth 2))

RESULTS_FILE=last_results.txt

cleanup() {
  if [[ -e $RESULTS_FILE ]]; then
    rm $RESULTS_FILE
  fi
}

cancel() {
  cleanup
  exit 0
}

trap cancel SIGINT

for file in ${FILES[@]}; do
  ((i++))
  echo "Testing $file ($i/${#FILES[*]})"

  ruby $file > $RESULTS_FILE

  if [[ $? != 0 ]]; then
    echo "Test failed"
    cat last_results.txt
    break
  fi
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment