Class: FTest::Runner::ProcessSet::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/ftest/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Process

Returns a new instance of Process.



102
103
104
# File 'lib/ftest/runner.rb', line 102

def initialize file
  @file = file
end

Instance Attribute Details

#fdObject (readonly)

Returns the value of attribute fd.



98
99
100
# File 'lib/ftest/runner.rb', line 98

def fd
  @fd
end

#fileObject (readonly)

Returns the value of attribute file.



99
100
101
# File 'lib/ftest/runner.rb', line 99

def file
  @file
end

#pidObject (readonly)

Returns the value of attribute pid.



100
101
102
# File 'lib/ftest/runner.rb', line 100

def pid
  @pid
end

Instance Method Details

#finishObject



136
137
138
139
140
141
142
# File 'lib/ftest/runner.rb', line 136

def finish
  fd.read 1
  _, status = ::Process.wait2 pid
  status = status.exitstatus
  Config.internal_logger.debug "finished script #{@file}; status=#{status.inspect}"
  status == 0
end


124
125
126
127
128
129
130
131
132
133
134
# File 'lib/ftest/runner.rb', line 124

def print_stacktrace error
  locations = error.backtrace
  final_location = locations.shift
  locations = FTest::BacktraceFilter.(locations)

  lines = locations.map do |loc| "\tfrom #{loc}" end
  lines.unshift "#{final_location}: #{error.message} (#{error.class.name})"

  lines.reverse! if Config.reverse_backtraces
  Config.logger.error "Exception:\n#{lines * "\n"}"
end

#startObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ftest/runner.rb', line 106

def start
  @fd, wr = IO.pipe

  @pid = fork do
    @fd.close
    begin
      load file
    rescue => error
      print_stacktrace error
      exit 1
    ensure
      wr.write "\x00"
    end
  end

  freeze
end