cleaner emacs frontend; added clear backend
[augment.git] / lib / backends / test_unit_backend.rb
blobf160a10b973a48fa47931b0b8857b303e825c0d3
1 Object.flet(:at_exit => lambda {}) do
2   # keep miniunit's at_exit block from running
3   gem 'miniunit', ">= 1.0.1"
4   require 'test/unit'
5 end
7 module Test
8   def Unit.puke(*args) # puke in a bucket
9     TestUnitBackend.failure_bucket(*args)
10   end
11 end
13 class TestUnitBackend < Backend
14   class << self
15     def run(file)
16       @file = file
17       @layers = {}
19       load(find_test_for(file))
20       # this will call record_failure as needed
21       with_no_output { Test::Unit.autotest }
22       write_layers
23     end
25     def failure_bucket(klass, method, exception)
26       # FIXME: errors here could actually occur in impl rather than test file
27       (@layers[@file] ||= []) << Layer.from_failure(@file, klass, method, exception)
28     end
30     def find_test_for(file)
31       # TODO: return test for implementation if possible
32       file
33     end
34   end
35   
36   Augment::BACKENDS['test'] = self
37 end
39 # TODO: let Layer.new handle this by using a Fixnum instead of range
40 def Layer.from_failure(file, klass, method, exception)
41   color = Test::Assertion === exception ? 'red' : 'yellow'
43   trace = exception.backtrace.detect { |e| e =~ Regexp.new(file) }
44   line = trace.match(/:(\d*):/)[1]
46   range = Layer.line_to_char_range(file, line.to_i)
47   Layer.new(range, color, exception.message, TestUnitBackend)
48 end