Skip to content

Instantly share code, notes, and snippets.

@zerowidth
Created January 3, 2013 16:21
Show Gist options
  • Save zerowidth/4444649 to your computer and use it in GitHub Desktop.
Save zerowidth/4444649 to your computer and use it in GitHub Desktop.
custom test runners with bash / fuubar / test/unit. hacks heaped upon hacks for a particular dev environment.
# http://www.linuxjournal.com/content/use-date-command-measure-elapsed-time
function timer() {
if [[ $# -eq 0 ]]; then
echo $(date '+%s')
else
local stime=$1
etime=$(date '+%s')
if [[ -z "$stime" ]]; then stime=$etime; fi
dt=$((etime - stime))
ds=$((dt % 60))
dm=$(((dt / 60) % 60))
dh=$((dt / 3600))
printf '%d:%02d:%02d' $dh $dm $ds
fi
}
function t() {
start=$(timer)
if [ $# -gt 0 ]; then
sticky=""
clear
# time ruby -Itest $@ | grep -v PASS
time fuubar $@
status=${PIPESTATUS[0]}
else
sticky="-s"
clear
# bundle exec rake db:test:prepare && time bundle exec rake test | grep -v PASS
bundle exec rake db:test:prepare
status=0
time find test/unit -name '*_test.rb' | head -1 | xargs fuubar
status=$(($status + $?))
time find test/functional -name '*_test.rb' | head -1 | xargs fuubar
status=$(($status + $?))
time find test/integration -name '*_test.rb' | head -1 | xargs fuubar
status=$(($status + $?))
fi
elapsed=$(timer $start)
echo "-------------------"
echo "finished in $elapsed"
echo "-------------------"
if [ $status -eq 0 ]; then
growlnotify $sticky -m "succeeded in $elapsed" --image ~/bin/success.png
else
growlnotify $sticky -m "failed in $elapsed" --image ~/bin/failed.png
fi
}

how to use the test runner:

t test/unit/purchase_test.rb test/functional/purchases_controller_test.rb
#!/usr/local/bin/bash
# in ~/work/bin, do:
#
# gem unpack ruby-progressbar && mv ruby-progressbar* ruby-progressbar
# gem unpack fuubar-testunit && mv fuubar* fuubar-testunit
ruby \
-I ~/work/bin/fuubar-testunit/lib \
-I ~/work/bin/ruby-progressbar/lib \
-r fuubar-testunit \
-I test \
~/work/bin/test_runner.rb --runner=fuubar\
$*
#!/usr/bin/env ruby
class Object
def wtf?(msg=nil)
raise "WTF?#{" " if msg}#{msg} #{caller.first}"
end
end
ARGV.each { |f| require f unless f =~ /^-/ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment