diff options
author | Zachary Scott <e@zzak.io> | 2015-01-06 17:00:00 -0800 |
---|---|---|
committer | Zachary Scott <e@zzak.io> | 2015-01-06 17:00:00 -0800 |
commit | aa542dbcadae35d08acf31d066eeafc43ccc157c (patch) | |
tree | 512db556acd207d8aa387c6575d36df3d7806b08 /test/envutil.rb | |
parent | 424244baf2d0b8942fc9196d2072c9a848b0a18c (diff) | |
download | ruby-openssl-aa542dbcadae35d08acf31d066eeafc43ccc157c.tar.gz |
Sync EnvUtil from trunk
Diffstat (limited to 'test/envutil.rb')
-rw-r--r-- | test/envutil.rb | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/test/envutil.rb b/test/envutil.rb index f5fbb7c1..1193a1a5 100644 --- a/test/envutil.rb +++ b/test/envutil.rb @@ -1,7 +1,6 @@ # -*- coding: us-ascii -*- require "open3" require "timeout" -require "test/unit" require_relative "find_executable" module EnvUtil @@ -69,8 +68,14 @@ module EnvUtil stderr = th_stderr.value if capture_stderr && capture_stderr != :merge_to_stdout else signal = /mswin|mingw/ =~ RUBY_PLATFORM ? :KILL : :TERM + case pgroup = opt[:pgroup] + when 0, true + pgroup = -pid + when nil, false + pgroup = pid + end begin - Process.kill signal, pid + Process.kill signal, pgroup Timeout.timeout((reprieve unless signal == :KILL)) do Process.wait(pid) end @@ -357,7 +362,7 @@ module Test line -= 5 # lines until src src = <<eom # -*- coding: #{src.encoding}; -*- - require #{__dir__.dump}'/envutil';include Test::Unit::Assertions + require #{__dir__.dump}'/test/unit';include Test::Unit::Assertions END { puts [Marshal.dump($!)].pack('m'), "assertions=\#{self._assertions}" } @@ -467,6 +472,8 @@ eom next unless a > 0 and b > 0 assert_operator(a.fdiv(b), :<, limit, message(message) {"#{n}: #{b} => #{a}"}) end + rescue LoadError + skip end def assert_is_minus_zero(f) @@ -520,6 +527,38 @@ eom end end + # threads should respond to shift method. + # Array can be used. + def assert_join_threads(threads, message = nil) + errs = [] + values = [] + while th = threads.shift + begin + values << th.value + rescue Exception + errs << [th, $!] + end + end + if !errs.empty? + msg = "exceptions on #{errs.length} threads:\n" + + errs.map {|t, err| + "#{t.inspect}:\n" + + err.backtrace.map.with_index {|line, i| + if i == 0 + "#{line}: #{err.message} (#{err.class})" + else + "\tfrom #{line}" + end + }.join("\n") + }.join("\n---\n") + if message + msg = "#{message}\n#{msg}" + end + raise MiniTest::Assertion, msg + end + values + end + class << (AssertFile = Struct.new(:failure_message).new) include Assertions def assert_file_predicate(predicate, *args) |