mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bootstraptest/runner.rb (show_progress): extracted from assert_check.
(assert_check): use show_progress. (assert_normal_exit): ditto. (assert_finish): ditto. (flunk): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
614ec73fc8
commit
92c0438049
2 changed files with 84 additions and 88 deletions
|
@ -1,3 +1,11 @@
|
|||
Tue Jun 14 23:02:36 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* bootstraptest/runner.rb (show_progress): extracted from assert_check.
|
||||
(assert_check): use show_progress.
|
||||
(assert_normal_exit): ditto.
|
||||
(assert_finish): ditto.
|
||||
(flunk): ditto.
|
||||
|
||||
Tue Jun 14 22:51:42 2011 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* test/date/test_*.rb: added tests.
|
||||
|
|
|
@ -155,11 +155,9 @@ def exec_test(pathes)
|
|||
end
|
||||
end
|
||||
|
||||
def assert_check(testsrc, message = '', opt = '')
|
||||
def show_progress(message = '')
|
||||
$stderr.puts "\##{@count} #{@location}" if @verbose
|
||||
result = get_result_string(testsrc, opt)
|
||||
check_coredump
|
||||
faildesc = yield(result)
|
||||
faildesc = yield
|
||||
if !faildesc
|
||||
$stderr.print '.'
|
||||
else
|
||||
|
@ -171,6 +169,14 @@ rescue Exception => err
|
|||
error err.message, message
|
||||
end
|
||||
|
||||
def assert_check(testsrc, message = '', opt = '')
|
||||
show_progress(message) {
|
||||
result = get_result_string(testsrc, opt)
|
||||
check_coredump
|
||||
yield(result)
|
||||
}
|
||||
end
|
||||
|
||||
def assert_equal(expected, testsrc, message = '')
|
||||
newtest
|
||||
assert_check(testsrc, message) {|result|
|
||||
|
@ -215,107 +221,89 @@ def assert_valid_syntax(testsrc, message = '')
|
|||
end
|
||||
|
||||
def assert_normal_exit(testsrc, *rest)
|
||||
newtest
|
||||
opt = {}
|
||||
opt = rest.pop if Hash === rest.last
|
||||
message, ignore_signals = rest
|
||||
message ||= ''
|
||||
timeout = opt[:timeout]
|
||||
newtest
|
||||
$stderr.puts "\##{@count} #{@location}" if @verbose
|
||||
faildesc = nil
|
||||
filename = make_srcfile(testsrc)
|
||||
old_stderr = $stderr.dup
|
||||
timeout_signaled = false
|
||||
begin
|
||||
$stderr.reopen("assert_normal_exit.log", "w")
|
||||
io = IO.popen("#{@ruby} -W0 #{filename}")
|
||||
pid = io.pid
|
||||
th = Thread.new {
|
||||
io.read
|
||||
io.close
|
||||
$?
|
||||
}
|
||||
if !th.join(timeout)
|
||||
Process.kill :KILL, pid
|
||||
timeout_signaled = true
|
||||
show_progress(message) {
|
||||
faildesc = nil
|
||||
filename = make_srcfile(testsrc)
|
||||
old_stderr = $stderr.dup
|
||||
timeout_signaled = false
|
||||
begin
|
||||
$stderr.reopen("assert_normal_exit.log", "w")
|
||||
io = IO.popen("#{@ruby} -W0 #{filename}")
|
||||
pid = io.pid
|
||||
th = Thread.new {
|
||||
io.read
|
||||
io.close
|
||||
$?
|
||||
}
|
||||
if !th.join(timeout)
|
||||
Process.kill :KILL, pid
|
||||
timeout_signaled = true
|
||||
end
|
||||
status = th.value
|
||||
ensure
|
||||
$stderr.reopen(old_stderr)
|
||||
old_stderr.close
|
||||
end
|
||||
status = th.value
|
||||
ensure
|
||||
$stderr.reopen(old_stderr)
|
||||
old_stderr.close
|
||||
end
|
||||
if status.signaled?
|
||||
signo = status.termsig
|
||||
signame = Signal.list.invert[signo]
|
||||
unless ignore_signals and ignore_signals.include?(signame)
|
||||
sigdesc = "signal #{signo}"
|
||||
if signame
|
||||
sigdesc = "SIG#{signame} (#{sigdesc})"
|
||||
end
|
||||
if timeout_signaled
|
||||
sigdesc << " (timeout)"
|
||||
end
|
||||
faildesc = pretty(testsrc, "killed by #{sigdesc}", nil)
|
||||
stderr_log = File.read("assert_normal_exit.log")
|
||||
if !stderr_log.empty?
|
||||
faildesc << "\n" if /\n\z/ !~ faildesc
|
||||
stderr_log << "\n" if /\n\z/ !~ stderr_log
|
||||
stderr_log.gsub!(/^.*\n/) { '| ' + $& }
|
||||
faildesc << stderr_log
|
||||
if status.signaled?
|
||||
signo = status.termsig
|
||||
signame = Signal.list.invert[signo]
|
||||
unless ignore_signals and ignore_signals.include?(signame)
|
||||
sigdesc = "signal #{signo}"
|
||||
if signame
|
||||
sigdesc = "SIG#{signame} (#{sigdesc})"
|
||||
end
|
||||
if timeout_signaled
|
||||
sigdesc << " (timeout)"
|
||||
end
|
||||
faildesc = pretty(testsrc, "killed by #{sigdesc}", nil)
|
||||
stderr_log = File.read("assert_normal_exit.log")
|
||||
if !stderr_log.empty?
|
||||
faildesc << "\n" if /\n\z/ !~ faildesc
|
||||
stderr_log << "\n" if /\n\z/ !~ stderr_log
|
||||
stderr_log.gsub!(/^.*\n/) { '| ' + $& }
|
||||
faildesc << stderr_log
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if !faildesc
|
||||
$stderr.print '.'
|
||||
true
|
||||
else
|
||||
$stderr.print 'F'
|
||||
error faildesc, message
|
||||
false
|
||||
end
|
||||
rescue Exception => err
|
||||
$stderr.print 'E'
|
||||
error err.message, message
|
||||
false
|
||||
faildesc
|
||||
}
|
||||
end
|
||||
|
||||
def assert_finish(timeout_seconds, testsrc, message = '')
|
||||
newtest
|
||||
$stderr.puts "\##{@count} #{@location}" if @verbose
|
||||
faildesc = nil
|
||||
filename = make_srcfile(testsrc)
|
||||
io = IO.popen("#{@ruby} -W0 #{filename}")
|
||||
pid = io.pid
|
||||
waited = false
|
||||
tlimit = Time.now + timeout_seconds
|
||||
while Time.now < tlimit
|
||||
if Process.waitpid pid, Process::WNOHANG
|
||||
waited = true
|
||||
break
|
||||
show_progress(message) {
|
||||
faildesc = nil
|
||||
filename = make_srcfile(testsrc)
|
||||
io = IO.popen("#{@ruby} -W0 #{filename}")
|
||||
pid = io.pid
|
||||
waited = false
|
||||
tlimit = Time.now + timeout_seconds
|
||||
while Time.now < tlimit
|
||||
if Process.waitpid pid, Process::WNOHANG
|
||||
waited = true
|
||||
break
|
||||
end
|
||||
sleep 0.1
|
||||
end
|
||||
sleep 0.1
|
||||
end
|
||||
if !waited
|
||||
Process.kill(:KILL, pid)
|
||||
Process.waitpid pid
|
||||
faildesc = pretty(testsrc, "not finished in #{timeout_seconds} seconds", nil)
|
||||
end
|
||||
io.close
|
||||
if !faildesc
|
||||
$stderr.print '.'
|
||||
else
|
||||
$stderr.print 'F'
|
||||
error faildesc, message
|
||||
end
|
||||
rescue Exception => err
|
||||
$stderr.print 'E'
|
||||
error err.message, message
|
||||
if !waited
|
||||
Process.kill(:KILL, pid)
|
||||
Process.waitpid pid
|
||||
faildesc = pretty(testsrc, "not finished in #{timeout_seconds} seconds", nil)
|
||||
end
|
||||
io.close
|
||||
faildesc
|
||||
}
|
||||
end
|
||||
|
||||
def flunk(message = '')
|
||||
newtest
|
||||
$stderr.print 'F'
|
||||
error message, ''
|
||||
show_progress('') { message }
|
||||
end
|
||||
|
||||
def pretty(src, desc, result)
|
||||
|
|
Loading…
Add table
Reference in a new issue