Class: Micron::ProcRunner

Inherits:
Runner
  • Object
show all
Defined in:
lib/micron/proc_runner.rb

Constant Summary

Constants inherited from Runner

Runner::ERR, Runner::OUT, Runner::PASSTHROUGH_EXCEPTIONS

Instance Attribute Summary

Attributes inherited from Runner

#files, #reporters, #results

Instance Method Summary collapse

Methods inherited from Runner

#report, #synchronize

Constructor Details

#initialize(files = nil, method_patterns = nil, reporters = nil) ⇒ ProcRunner

Returns a new instance of ProcRunner.



10
11
12
# File 'lib/micron/proc_runner.rb', line 10

def initialize(files=nil, method_patterns=nil, reporters=nil)
  super(files, method_patterns, reporters)
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/micron/proc_runner.rb', line 14

def run
  $0 = "micron: proc_runner"
  # ERR.puts "#{$0} (#{$$})"

  state_path = ENV["MICRON_PATH"]
  FileUtils.mkdir_p(state_path)

  report(:start_tests, @files)
  @files.each do |file|

    ENV["MICRON_TEST_FILE"] = file
    pid = fork do
      exec("bundle exec micron --runclass")
    end
    Process.wait

    # puts "got stdout: #{cmd.stdout}"
    # puts "got stderr: #{cmd.stderr}"
    # puts "status: #{cmd.status}"
    # puts "exitstatus: #{cmd.exitstatus.inspect}"

    data_file = File.join(state_path, "#{pid}.data")
    File.open(data_file) do |f|
      while !f.eof
        clazz = Marshal.load(f) # read Clazz from child via file
        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
    File.delete(data_file)

  end

  report(:end_tests, @files, @results)

  return @results
end

#run_classObject

Child process which runs an entire test file/class



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/micron/proc_runner.rb', line 61

def run_class
  $0 = "micron:proc_run_class"
  # ERR.puts "micron: proc_run_class (#{$$})"

  test_file = TestFile.new(test_filename)
  report(:start_file, test_file)

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

  # pass data back to parent process
  data_file = File.join(ENV["MICRON_PATH"], "#{$$}.data")
  File.open(data_file, "w") do |f|
    results.each { |r| Marshal.dump(r, f) }
  end
end

#run_methodObject

Child process which runs a single method in a given file & class



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/micron/proc_runner.rb', line 83

def run_method
  $0 = "micron:proc_run_method"
  # ERR.puts "#{$0} (#{$$})"

  test_clazz = ENV["MICRON_TEST_CLASS"]
  test_method = ENV["MICRON_TEST_METHOD"]

  # ERR.puts "test_clazz: #{test_clazz}"
  # ERR.puts "test_method: #{test_method}"

  test_file = TestFile.new(test_filename)
  test_file.load(true)
  # load and run a specific method only
  result = test_file.run_method(test_clazz, test_method, Clazz)

  # pass data back to parent process
  data_file = File.join(ENV["MICRON_PATH"], "#{$$}.data")
  File.open(data_file, "w") do |f|
    Marshal.dump(result, f)
  end
end