Class: TestUnitHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/zombie-chaser/test_unit_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_pattern) ⇒ TestUnitHandler

Returns a new instance of TestUnitHandler.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zombie-chaser/test_unit_handler.rb', line 9

def initialize(test_pattern)
  raise "Error: can't detect any files in test pattern #{test_pattern.inspect} (Don't forget to use forward slashes even in Windows)" if Dir.glob(test_pattern).empty?
  Dir.glob(test_pattern).each {|test| require test} #In heckle, this is separated out
  obj_sp = Test::Unit::Collector::ObjectSpace.new
  test_suite = Test::Unit::TestSuite.new("Mutation slayer test suite")
  test_suite << obj_sp.collect
  @test_suite_size = test_suite.size
  @test_runner_mediator =  Test::Unit::UI::TestRunnerMediator.new(test_suite)
  @test_runner_mediator.add_listener(Test::Unit::TestResult::FAULT) {test_failed}
  @test_runner_mediator.add_listener(Test::Unit::TestCase::FINISHED) {test_finished}
  @result_queue = Queue.new
  @failure_encountered = false
end

Instance Attribute Details

#result_queueObject (readonly)

Returns the value of attribute result_queue.



7
8
9
# File 'lib/zombie-chaser/test_unit_handler.rb', line 7

def result_queue
  @result_queue
end

#test_suite_sizeObject (readonly)

Returns the value of attribute test_suite_size.



7
8
9
# File 'lib/zombie-chaser/test_unit_handler.rb', line 7

def test_suite_size
  @test_suite_size
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/zombie-chaser/test_unit_handler.rb', line 23

def run
  begin
    catch(:stop_test_runner) do
      @test_runner_mediator.run_suite
    end
  rescue Chaser::Timeout
    @result_queue.enq(:failure)
    raise
  ensure
    @result_queue.enq(:end_of_work)
  end
  not @failure_encountered
end

#test_failedObject



37
38
39
40
41
# File 'lib/zombie-chaser/test_unit_handler.rb', line 37

def test_failed
  @result_queue.enq(:failure)
  @failure_encountered = true
  throw :stop_test_runner
end

#test_finishedObject



43
44
45
# File 'lib/zombie-chaser/test_unit_handler.rb', line 43

def test_finished
  @result_queue.enq(:pass)
end