lib/pork.rb in pork-1.0.4 vs lib/pork.rb in pork-1.1.0
- old
+ new
@@ -15,16 +15,59 @@
# default to :execute while eliminating warnings for uninitialized ivar
def self.execute_mode execute=nil
@execute = execute || @execute ||= :execute
end
+ def self.stat
+ @stat ||= Pork::Stat.new
+ end
+
+ def self.seed
+ @seed ||= if Random.const_defined?(:DEFAULT)
+ Random::DEFAULT.seed
+ else
+ Thread.current.randomizer.seed # Rubinius (rbx)
+ end
+ end
+
+ def self.trap sig='SIGINT'
+ Signal.trap(sig) do
+ stat.report
+ puts "\nterminated by signal SIGINT"
+ exit! 255
+ end
+ end
+
+ def self.run
+ if ENV['PORK_TEST']
+ require 'pork/isolate'
+ if paths = Executor.all_tests[ENV['PORK_TEST']]
+ case execute_mode
+ when :execute
+ paths.each{ |p| Executor.isolate(p, stat) }
+ else
+ @stat = Executor.public_send(execute_mode, stat, paths)
+ end
+ else
+ puts "Cannot find test: #{ENV['PORK_TEST']}"
+ exit! 254
+ end
+ else
+ @stat = Executor.public_send(execute_mode, stat)
+ end
+ end
+
def self.autorun auto=true
@auto = auto
@autorun ||= at_exit do
next unless @auto
+ Random.srand(ENV['PORK_SEED'].to_i) if ENV['PORK_SEED']
+ execute_mode(ENV['PORK_MODE']) if ENV['PORK_MODE']
require "pork/mode/#{execute_mode}" unless execute_mode == :execute
- stat = Executor.public_send(execute_mode)
+ seed
+ trap
+ run
stat.report
- exit stat.failures.size + stat.errors.size + ($! && 1).to_i
+ exit! stat.failures.size + stat.errors.size + ($! && 1).to_i
end
end
end