Skip to content

Instantly share code, notes, and snippets.

@da3mon
Created October 16, 2009 05:06
Show Gist options
  • Save da3mon/211584 to your computer and use it in GitHub Desktop.
Save da3mon/211584 to your computer and use it in GitHub Desktop.
%w(rake/clean rubygems colored).each { |f| require f }
INCLUDE = "include"
ERLC_FLAGS = "-I#{INCLUDE} +warn_unused_vars +warn_unused_import"
SRC = FileList['src/*.erl']
TEST = FileList['test/*.erl']
OBJ = SRC.pathmap("%{^src$,ebin}X.beam")
TESTS = TEST.pathmap("%{^test$,ebin}X.beam")
CLEAN.include("ebin/*.beam", "tests/*.beam", "erl_crash.dump")
directory 'ebin'
directory 'tests'
rule ".beam" => ["%{ebin,src;ebin,test}X.erl"] do |t|
sh "erlc -D EUNIT -pa ebin -pz /Users/da3mon/hack/erlang/eunit/ebin -W #{ERLC_FLAGS} -o ebin #{t.source}"
end
def stack_trace(output="")
lines = output.split("\n")
index = erl_out(lines)
lines[index..erl_out(lines[(index + 1)...lines.length])] * "\n"
end
def erl_out(string_array)
string_array.index(string_array.detect { |line| line =~ /1>/ })
end
task :compile => ['ebin'] + OBJ + TESTS
task :default => [:clean, :test]
task :test => :compile do
puts "Modules under test:".cyan
TESTS.each do |test|
test[%r{.*/(test_.*).beam}]
next unless file_under_test = $1
command = "erl -pa ebin -run #{file_under_test} test -run init stop"
output = ENV['DEBUG'] ? [command.cyan] : []
file_under_test.gsub!(/test_/, '')
output << "#{file_under_test} tests: ".white + case test_output = `#{command}`
when /no tests/ then "no tests".yellow
when /\*failed\*/ then "failed\n#{stack_trace(test_output)}".red
when /tests passed/ then "passed".green
end
puts output
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment