Class: Micron::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/micron/runner.rb,
lib/micron/runner/shim.rb,
lib/micron/runner/clazz.rb,
lib/micron/runner/debug.rb,
lib/micron/runner/method.rb,
lib/micron/runner/clazz19.rb,
lib/micron/runner/test_file.rb,
lib/micron/runner/proc_clazz.rb,
lib/micron/runner/fork_worker.rb,
lib/micron/runner/forking_clazz.rb,
lib/micron/runner/exception_info.rb,
lib/micron/runner/parallel_clazz.rb,
lib/micron/runner/process_reaper.rb,
lib/micron/runner/liveness_checker.rb,
lib/micron/runner/liveness_checker/ping.rb,
lib/micron/runner/liveness_checker/pong.rb

Overview

Default Runner - forks for each file

Direct Known Subclasses

ForkRunner, ProcRunner

Defined Under Namespace

Modules: Debug Classes: Clazz, ExceptionInfo, ForkWorker, ForkingClazz, LivenessChecker, Method, ParallelClazz, ProcClazz, ProcessReaper, Shim, TestFile

Constant Summary collapse

OUT =
$stdout
ERR =
$stderr
PASSTHROUGH_EXCEPTIONS =

these exceptions, if caught while running, will be re-raised

[
  NoMemoryError, SignalException, Interrupt, SystemExit
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files, method_patterns, reporters) ⇒ Runner

Returns a new instance of Runner.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/micron/runner.rb', line 29

def initialize(files, method_patterns, reporters)
  @files           = files
  @method_patterns = method_patterns || []
  @reporters       = reporters || []
  @results         = []

  @mutex = Mutex.new

  if self.class.to_s != "Micron::Runner" then
    # Only needed in fork/proc runners
    TestCase.class_eval do
      include TestCase::TeardownCoverage
    end
  end
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



27
28
29
# File 'lib/micron/runner.rb', line 27

def files
  @files
end

#reportersObject (readonly)

Returns the value of attribute reporters.



27
28
29
# File 'lib/micron/runner.rb', line 27

def reporters
  @reporters
end

#resultsObject (readonly)

Returns the value of attribute results.



27
28
29
# File 'lib/micron/runner.rb', line 27

def results
  @results
end

Instance Method Details

#report(method, *args) ⇒ Object

Fire the given report event on all reporters

Parameters:

  • method (Symbol)
  • (*args)


84
85
86
87
88
# File 'lib/micron/runner.rb', line 84

def report(method, *args)
  synchronize {
    @reporters.each { |r| r.send(method, *args) }
  }
end

#runObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/micron/runner.rb', line 45

def run
  report(:start_tests, @files)

  @files.each do |file|

    test_file = TestFile.new(file, @method_patterns)
    report(:start_file, test_file)

    begin
      test_file.load(true)
      results = test_file.run(Clazz)
    rescue Exception => ex
      results = [ex]
    end

    results.each do |clazz|
      if clazz.kind_of? Exception then
        STDERR.puts "Error loading test file: #{file}"
        STDERR.puts clazz
        STDERR.puts clazz.backtrace
        exit 1
      end

      # should be a Clazz
      @results << clazz
    end

  end

  EasyCov.dump
  report(:end_tests, @files, @results)

  return @results
end

#synchronize(&block) ⇒ Object

Output synchronization helper. Will NOT work across forks!



91
92
93
# File 'lib/micron/runner.rb', line 91

def synchronize(&block)
  @mutex.synchronize(&block)
end