2012-10-25 18:06:31 +04:00
|
|
|
"exec" "${RUBY-ruby}" "-x" "$0" "$@" || true # -*- mode: ruby; coding: utf-8 -*-
|
2009-08-03 11:20:14 +04:00
|
|
|
#!./ruby
|
2007-02-25 04:28:14 +03:00
|
|
|
# $Id$
|
2007-02-24 10:47:53 +03:00
|
|
|
|
|
|
|
# NOTE:
|
|
|
|
# Never use optparse in this file.
|
|
|
|
# Never use test/unit in this file.
|
|
|
|
# Never use Ruby extensions in this file.
|
2018-07-30 11:05:22 +03:00
|
|
|
# Maintain Ruby 1.8 compatibility for now
|
2007-02-24 10:47:53 +03:00
|
|
|
|
2007-07-06 13:23:53 +04:00
|
|
|
begin
|
|
|
|
require 'fileutils'
|
|
|
|
require 'tmpdir'
|
|
|
|
rescue LoadError
|
|
|
|
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
|
|
|
retry
|
|
|
|
end
|
2007-02-24 10:47:53 +03:00
|
|
|
|
2007-08-17 09:41:10 +04:00
|
|
|
if !Dir.respond_to?(:mktmpdir)
|
|
|
|
# copied from lib/tmpdir.rb
|
2009-08-23 10:15:00 +04:00
|
|
|
def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil)
|
|
|
|
case prefix_suffix
|
|
|
|
when nil
|
|
|
|
prefix = "d"
|
|
|
|
suffix = ""
|
|
|
|
when String
|
|
|
|
prefix = prefix_suffix
|
|
|
|
suffix = ""
|
|
|
|
when Array
|
|
|
|
prefix = prefix_suffix[0]
|
|
|
|
suffix = prefix_suffix[1]
|
|
|
|
else
|
|
|
|
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
|
|
|
end
|
2007-08-17 09:41:10 +04:00
|
|
|
tmpdir ||= Dir.tmpdir
|
|
|
|
t = Time.now.strftime("%Y%m%d")
|
|
|
|
n = nil
|
|
|
|
begin
|
|
|
|
path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
|
|
|
path << "-#{n}" if n
|
2009-08-23 10:15:00 +04:00
|
|
|
path << suffix
|
2007-08-17 09:41:10 +04:00
|
|
|
Dir.mkdir(path, 0700)
|
|
|
|
rescue Errno::EEXIST
|
|
|
|
n ||= 0
|
|
|
|
n += 1
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
if block_given?
|
|
|
|
begin
|
|
|
|
yield path
|
|
|
|
ensure
|
|
|
|
FileUtils.remove_entry_secure path
|
|
|
|
end
|
|
|
|
else
|
|
|
|
path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-02-24 10:47:53 +03:00
|
|
|
def main
|
2007-02-25 05:10:38 +03:00
|
|
|
@ruby = File.expand_path('miniruby')
|
2007-02-24 13:28:36 +03:00
|
|
|
@verbose = false
|
2016-08-07 13:34:11 +03:00
|
|
|
$VERBOSE = false
|
2011-06-11 13:07:26 +04:00
|
|
|
$stress = false
|
2012-05-30 05:24:08 +04:00
|
|
|
@color = nil
|
2013-01-15 04:59:19 +04:00
|
|
|
@tty = nil
|
2012-06-26 11:46:26 +04:00
|
|
|
@quiet = false
|
2007-08-17 09:41:10 +04:00
|
|
|
dir = nil
|
2007-07-06 09:50:42 +04:00
|
|
|
quiet = false
|
2007-02-24 10:47:53 +03:00
|
|
|
tests = nil
|
|
|
|
ARGV.delete_if {|arg|
|
|
|
|
case arg
|
|
|
|
when /\A--ruby=(.*)/
|
2008-01-30 05:59:59 +03:00
|
|
|
@ruby = $1
|
|
|
|
@ruby.gsub!(/^([^ ]*)/){File.expand_path($1)}
|
2008-05-11 17:54:04 +04:00
|
|
|
@ruby.gsub!(/(\s+-I\s*)((?!(?:\.\/)*-(?:\s|\z))\S+)/){$1+File.expand_path($2)}
|
2008-05-11 17:39:35 +04:00
|
|
|
@ruby.gsub!(/(\s+-r\s*)(\.\.?\/\S+)/){$1+File.expand_path($2)}
|
2007-02-24 10:47:53 +03:00
|
|
|
true
|
|
|
|
when /\A--sets=(.*)/
|
2010-02-07 17:09:43 +03:00
|
|
|
tests = Dir.glob("#{File.dirname($0)}/test_{#{$1}}*.rb").sort
|
2007-02-24 10:47:53 +03:00
|
|
|
puts tests.map {|path| File.basename(path) }.inspect
|
|
|
|
true
|
2007-06-24 10:52:59 +04:00
|
|
|
when /\A--dir=(.*)/
|
|
|
|
dir = $1
|
|
|
|
true
|
2007-09-14 11:18:23 +04:00
|
|
|
when /\A(--stress|-s)/
|
|
|
|
$stress = true
|
2012-06-15 04:56:36 +04:00
|
|
|
when /\A--color(?:=(?:always|(auto)|(never)|(.*)))?\z/
|
|
|
|
warn "unknown --color argument: #$3" if $3
|
|
|
|
@color = $1 ? nil : !$2
|
2012-05-30 05:24:08 +04:00
|
|
|
true
|
2013-01-15 04:59:19 +04:00
|
|
|
when /\A--tty(=(?:yes|(no)|(.*)))?\z/
|
|
|
|
warn "unknown --tty argument: #$3" if $3
|
|
|
|
@tty = !$1 || !$2
|
|
|
|
true
|
2007-07-06 09:50:42 +04:00
|
|
|
when /\A(-q|--q(uiet))\z/
|
|
|
|
quiet = true
|
2012-06-26 11:46:26 +04:00
|
|
|
@quiet = true
|
2007-07-06 09:50:42 +04:00
|
|
|
true
|
2007-02-24 13:28:36 +03:00
|
|
|
when /\A(-v|--v(erbose))\z/
|
|
|
|
@verbose = true
|
2007-02-24 10:53:14 +03:00
|
|
|
when /\A(-h|--h(elp)?)\z/
|
2007-02-24 10:51:52 +03:00
|
|
|
puts(<<-End)
|
|
|
|
Usage: #{File.basename($0, '.*')} --ruby=PATH [--sets=NAME,NAME,...]
|
2007-02-24 13:28:36 +03:00
|
|
|
--sets=NAME,NAME,... Name of test sets.
|
2007-06-24 10:52:59 +04:00
|
|
|
--dir=DIRECTORY Working directory.
|
2009-08-23 10:24:33 +04:00
|
|
|
default: /tmp/bootstraptestXXXXX.tmpwd
|
2012-06-15 04:56:33 +04:00
|
|
|
--color[=WHEN] Colorize the output. WHEN defaults to 'always'
|
|
|
|
or can be 'never' or 'auto'.
|
2007-09-14 11:18:23 +04:00
|
|
|
-s, --stress stress test.
|
2007-02-24 13:28:36 +03:00
|
|
|
-v, --verbose Output test name before exec.
|
2007-07-06 09:50:42 +04:00
|
|
|
-q, --quiet Don\'t print header message.
|
2007-02-24 13:28:36 +03:00
|
|
|
-h, --help Print this message and quit.
|
2007-02-24 10:51:52 +03:00
|
|
|
End
|
2008-05-11 17:54:04 +04:00
|
|
|
exit true
|
2012-06-16 02:12:30 +04:00
|
|
|
when /\A-j/
|
|
|
|
true
|
2007-02-24 10:47:53 +03:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
}
|
|
|
|
if tests and not ARGV.empty?
|
|
|
|
$stderr.puts "--tests and arguments are exclusive"
|
2008-05-11 17:54:04 +04:00
|
|
|
exit false
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
|
|
|
tests ||= ARGV
|
2010-02-07 17:09:43 +03:00
|
|
|
tests = Dir.glob("#{File.dirname($0)}/test_*.rb").sort if tests.empty?
|
2007-02-24 10:47:53 +03:00
|
|
|
pathes = tests.map {|path| File.expand_path(path) }
|
2007-06-24 10:52:59 +04:00
|
|
|
|
2012-05-07 22:53:42 +04:00
|
|
|
@progress = %w[- \\ | /]
|
|
|
|
@progress_bs = "\b" * @progress[0].size
|
2013-01-15 04:59:19 +04:00
|
|
|
@tty = $stderr.tty? if @tty.nil?
|
2012-05-30 05:24:08 +04:00
|
|
|
case @color
|
|
|
|
when nil
|
|
|
|
@color = @tty && /dumb/ !~ ENV["TERM"]
|
|
|
|
end
|
2012-07-05 10:15:00 +04:00
|
|
|
@tty &&= !@verbose
|
2012-05-30 05:24:08 +04:00
|
|
|
if @color
|
2012-06-15 04:56:39 +04:00
|
|
|
# dircolors-like style
|
2015-05-17 03:50:11 +03:00
|
|
|
colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
|
|
|
|
begin
|
|
|
|
File.read(File.join(__dir__, "../test/colors")).scan(/(\w+)=([^:\n]*)/) do |n, c|
|
|
|
|
colors[n] ||= c
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
2015-05-17 03:50:02 +03:00
|
|
|
@passed = "\e[;#{colors["pass"] || "32"}m"
|
|
|
|
@failed = "\e[;#{colors["fail"] || "31"}m"
|
2012-05-07 22:53:42 +04:00
|
|
|
@reset = "\e[m"
|
|
|
|
else
|
2014-06-10 18:11:57 +04:00
|
|
|
@passed = @failed = @reset = ""
|
2012-05-07 22:53:42 +04:00
|
|
|
end
|
2007-07-06 09:50:42 +04:00
|
|
|
unless quiet
|
|
|
|
puts Time.now
|
2009-02-18 09:27:47 +03:00
|
|
|
if defined?(RUBY_DESCRIPTION)
|
|
|
|
puts "Driver is #{RUBY_DESCRIPTION}"
|
|
|
|
elsif defined?(RUBY_PATCHLEVEL)
|
|
|
|
puts "Driver is ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}#{RUBY_PLATFORM}) [#{RUBY_PLATFORM}]"
|
|
|
|
else
|
|
|
|
puts "Driver is ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
|
|
|
end
|
2008-05-11 17:54:04 +04:00
|
|
|
puts "Target is #{`#{@ruby} -v`.chomp}"
|
2007-07-06 09:50:42 +04:00
|
|
|
puts
|
|
|
|
$stdout.flush
|
|
|
|
end
|
2007-06-24 10:52:59 +04:00
|
|
|
|
2007-02-24 10:47:53 +03:00
|
|
|
in_temporary_working_directory(dir) {
|
|
|
|
exec_test pathes
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-06-10 18:11:57 +04:00
|
|
|
def erase(e = true)
|
2014-06-20 07:12:44 +04:00
|
|
|
if e and @columns > 0 and !@verbose
|
2014-06-10 18:11:57 +04:00
|
|
|
"\r#{" "*@columns}\r"
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-02-24 10:47:53 +03:00
|
|
|
def exec_test(pathes)
|
|
|
|
@count = 0
|
|
|
|
@error = 0
|
|
|
|
@errbuf = []
|
|
|
|
@location = nil
|
2014-06-10 18:11:57 +04:00
|
|
|
@columns = 0
|
|
|
|
@width = pathes.map {|path| File.basename(path).size}.max + 2
|
2007-02-24 10:47:53 +03:00
|
|
|
pathes.each do |path|
|
2012-07-05 10:15:00 +04:00
|
|
|
@basename = File.basename(path)
|
2014-06-10 18:11:57 +04:00
|
|
|
$stderr.printf("%s%-*s ", erase(@quiet), @width, @basename)
|
|
|
|
$stderr.flush
|
|
|
|
@columns = @width + 1
|
2011-06-14 18:17:42 +04:00
|
|
|
$stderr.puts if @verbose
|
2012-05-07 22:53:42 +04:00
|
|
|
count = @count
|
|
|
|
error = @error
|
2007-02-24 10:47:53 +03:00
|
|
|
load File.expand_path(path)
|
2012-05-07 22:53:42 +04:00
|
|
|
if @tty
|
|
|
|
if @error == error
|
2014-06-10 18:11:57 +04:00
|
|
|
msg = "PASS #{@count-count}"
|
|
|
|
@columns += msg.size - 1
|
|
|
|
$stderr.print "#{@progress_bs}#{@passed}#{msg}#{@reset}"
|
2012-05-07 22:53:42 +04:00
|
|
|
else
|
2014-06-10 18:11:57 +04:00
|
|
|
msg = "FAIL #{@error-error}/#{@count-count}"
|
|
|
|
$stderr.print "#{@progress_bs}#{@failed}#{msg}#{@reset}"
|
|
|
|
@columns = 0
|
2012-05-07 22:53:42 +04:00
|
|
|
end
|
|
|
|
end
|
2014-06-10 18:11:57 +04:00
|
|
|
$stderr.puts unless @quiet and @tty and @error == error
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
2014-06-10 18:11:57 +04:00
|
|
|
$stderr.print(erase) if @quiet
|
2007-02-24 10:47:53 +03:00
|
|
|
if @error == 0
|
2009-02-04 15:57:17 +03:00
|
|
|
if @count == 0
|
|
|
|
$stderr.puts "No tests, no problem"
|
|
|
|
else
|
2013-01-15 04:59:16 +04:00
|
|
|
$stderr.puts "#{@passed}PASS#{@reset} all #{@count} tests"
|
2009-02-04 15:57:17 +03:00
|
|
|
end
|
2008-05-11 17:54:04 +04:00
|
|
|
exit true
|
2007-02-24 10:47:53 +03:00
|
|
|
else
|
|
|
|
@errbuf.each do |msg|
|
|
|
|
$stderr.puts msg
|
|
|
|
end
|
2013-01-15 04:59:16 +04:00
|
|
|
$stderr.puts "#{@failed}FAIL#{@reset} #{@error}/#{@count} tests failed"
|
2008-05-11 17:54:04 +04:00
|
|
|
exit false
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-14 18:07:02 +04:00
|
|
|
def show_progress(message = '')
|
2011-06-14 18:17:42 +04:00
|
|
|
if @verbose
|
|
|
|
$stderr.print "\##{@count} #{@location} "
|
2012-07-05 10:15:00 +04:00
|
|
|
elsif @tty
|
2012-07-05 12:18:23 +04:00
|
|
|
$stderr.print "#{@progress_bs}#{@progress[@count % @progress.size]}"
|
2011-06-14 18:17:42 +04:00
|
|
|
end
|
2014-06-07 23:57:43 +04:00
|
|
|
t = Time.now if @verbose
|
2012-07-05 10:15:00 +04:00
|
|
|
faildesc, errout = with_stderr {yield}
|
2014-06-07 23:57:43 +04:00
|
|
|
t = Time.now - t if @verbose
|
2007-08-14 16:48:12 +04:00
|
|
|
if !faildesc
|
2012-05-07 22:53:42 +04:00
|
|
|
if @tty
|
|
|
|
$stderr.print "#{@progress_bs}#{@progress[@count % @progress.size]}"
|
2014-06-07 23:57:43 +04:00
|
|
|
elsif @verbose
|
2014-06-08 05:22:11 +04:00
|
|
|
$stderr.printf(". %.3f\n", t)
|
2012-05-07 22:53:42 +04:00
|
|
|
else
|
|
|
|
$stderr.print '.'
|
|
|
|
end
|
2007-02-24 10:47:53 +03:00
|
|
|
else
|
2014-06-08 05:22:11 +04:00
|
|
|
$stderr.print "#{@failed}F"
|
|
|
|
$stderr.printf(" %.3f", t) if @verbose
|
|
|
|
$stderr.print "#{@reset}"
|
2011-06-14 18:17:42 +04:00
|
|
|
$stderr.puts if @verbose
|
2007-08-14 16:48:12 +04:00
|
|
|
error faildesc, message
|
2012-07-05 10:15:00 +04:00
|
|
|
unless errout.empty?
|
|
|
|
$stderr.print "#{@failed}stderr output is not empty#{@reset}\n", adjust_indent(errout)
|
|
|
|
end
|
|
|
|
if @tty and !@verbose
|
2014-06-10 18:11:57 +04:00
|
|
|
$stderr.printf("%-*s%s", @width, @basename, @progress[@count % @progress.size])
|
2012-07-05 10:15:00 +04:00
|
|
|
end
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
2011-11-12 08:37:54 +04:00
|
|
|
rescue Interrupt
|
2017-11-06 10:35:37 +03:00
|
|
|
$stderr.puts "\##{@count} #{@location}"
|
2018-06-29 06:28:26 +03:00
|
|
|
raise
|
2007-02-24 10:47:53 +03:00
|
|
|
rescue Exception => err
|
|
|
|
$stderr.print 'E'
|
2011-06-14 18:17:42 +04:00
|
|
|
$stderr.puts if @verbose
|
2007-08-06 09:36:14 +04:00
|
|
|
error err.message, message
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
|
|
|
|
2017-01-23 05:47:16 +03:00
|
|
|
def assert_check(testsrc, message = '', opt = '', **argh)
|
2011-06-14 18:07:02 +04:00
|
|
|
show_progress(message) {
|
2017-01-23 05:47:16 +03:00
|
|
|
result = get_result_string(testsrc, opt, **argh)
|
2011-06-14 18:07:02 +04:00
|
|
|
check_coredump
|
|
|
|
yield(result)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-01-23 05:47:16 +03:00
|
|
|
def assert_equal(expected, testsrc, message = '', opt = '', **argh)
|
2007-08-14 20:06:44 +04:00
|
|
|
newtest
|
2017-01-23 05:47:16 +03:00
|
|
|
assert_check(testsrc, message, opt, **argh) {|result|
|
2007-08-14 16:48:12 +04:00
|
|
|
if expected == result
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
desc = "#{result.inspect} (expected #{expected.inspect})"
|
|
|
|
pretty(testsrc, desc, result)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_match(expected_pattern, testsrc, message = '')
|
2007-08-14 20:06:44 +04:00
|
|
|
newtest
|
2007-08-14 16:48:12 +04:00
|
|
|
assert_check(testsrc, message) {|result|
|
|
|
|
if expected_pattern =~ result
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
desc = "#{expected_pattern.inspect} expected to be =~\n#{result.inspect}"
|
|
|
|
pretty(testsrc, desc, result)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2007-10-05 11:43:34 +04:00
|
|
|
def assert_not_match(unexpected_pattern, testsrc, message = '')
|
|
|
|
newtest
|
|
|
|
assert_check(testsrc, message) {|result|
|
|
|
|
if unexpected_pattern !~ result
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
desc = "#{unexpected_pattern.inspect} expected to be !~\n#{result.inspect}"
|
|
|
|
pretty(testsrc, desc, result)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2008-01-17 20:02:30 +03:00
|
|
|
def assert_valid_syntax(testsrc, message = '')
|
|
|
|
newtest
|
|
|
|
assert_check(testsrc, message, '-c') {|result|
|
|
|
|
result if /Syntax OK/ !~ result
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-06-21 04:34:33 +03:00
|
|
|
def assert_normal_exit(testsrc, *rest, timeout: nil, **opt)
|
2011-06-14 18:07:02 +04:00
|
|
|
newtest
|
2010-02-17 15:27:34 +03:00
|
|
|
message, ignore_signals = rest
|
|
|
|
message ||= ''
|
2011-06-14 18:07:02 +04:00
|
|
|
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
|
2010-02-17 15:27:34 +03:00
|
|
|
end
|
2011-06-14 18:07:02 +04:00
|
|
|
status = th.value
|
|
|
|
ensure
|
|
|
|
$stderr.reopen(old_stderr)
|
|
|
|
old_stderr.close
|
|
|
|
end
|
2016-06-28 16:29:38 +03:00
|
|
|
if status && status.signaled?
|
2011-06-14 18:07:02 +04:00
|
|
|
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
|
2008-07-11 15:51:39 +04:00
|
|
|
end
|
2008-06-11 07:16:28 +04:00
|
|
|
end
|
2011-06-14 18:07:02 +04:00
|
|
|
faildesc
|
|
|
|
}
|
2007-09-29 07:32:57 +04:00
|
|
|
end
|
|
|
|
|
2007-09-27 02:40:44 +04:00
|
|
|
def assert_finish(timeout_seconds, testsrc, message = '')
|
|
|
|
newtest
|
2011-06-14 18:07:02 +04:00
|
|
|
show_progress(message) {
|
|
|
|
faildesc = nil
|
|
|
|
filename = make_srcfile(testsrc)
|
|
|
|
io = IO.popen("#{@ruby} -W0 #{filename}")
|
|
|
|
pid = io.pid
|
|
|
|
waited = false
|
2018-06-27 05:37:26 +03:00
|
|
|
tlimit = Time.now + timeout_seconds
|
2018-07-30 11:05:22 +03:00
|
|
|
diff = timeout_seconds
|
|
|
|
while diff > 0
|
2011-06-14 18:07:02 +04:00
|
|
|
if Process.waitpid pid, Process::WNOHANG
|
|
|
|
waited = true
|
|
|
|
break
|
|
|
|
end
|
2018-07-30 11:05:22 +03:00
|
|
|
if io.respond_to?(:read_nonblock)
|
|
|
|
if IO.select([io], nil, nil, diff)
|
2018-11-20 05:16:30 +03:00
|
|
|
tries = 0
|
2018-07-30 11:05:22 +03:00
|
|
|
begin
|
|
|
|
io.read_nonblock(1024)
|
2018-11-20 05:16:30 +03:00
|
|
|
rescue IO::WaitReadable
|
|
|
|
IO.select([io])
|
|
|
|
tries += 1
|
|
|
|
break if tries > 3
|
|
|
|
retry
|
2018-07-30 11:05:22 +03:00
|
|
|
rescue Errno::EAGAIN, EOFError
|
|
|
|
break
|
|
|
|
end while true
|
|
|
|
end
|
|
|
|
else
|
|
|
|
sleep 0.1
|
|
|
|
end
|
|
|
|
diff = tlimit - Time.now
|
2007-09-27 02:40:44 +04:00
|
|
|
end
|
2011-06-14 18:07:02 +04:00
|
|
|
if !waited
|
|
|
|
Process.kill(:KILL, pid)
|
|
|
|
Process.waitpid pid
|
|
|
|
faildesc = pretty(testsrc, "not finished in #{timeout_seconds} seconds", nil)
|
|
|
|
end
|
|
|
|
io.close
|
|
|
|
faildesc
|
|
|
|
}
|
2007-09-27 02:40:44 +04:00
|
|
|
end
|
|
|
|
|
2008-01-14 12:45:46 +03:00
|
|
|
def flunk(message = '')
|
|
|
|
newtest
|
2011-06-14 18:07:02 +04:00
|
|
|
show_progress('') { message }
|
2008-01-14 12:45:46 +03:00
|
|
|
end
|
|
|
|
|
2007-08-14 16:48:12 +04:00
|
|
|
def pretty(src, desc, result)
|
2016-10-11 19:36:14 +03:00
|
|
|
src = src.sub(/\A\s*\n/, '')
|
2007-08-14 16:48:12 +04:00
|
|
|
(/\n/ =~ src ? "\n#{adjust_indent(src)}" : src) + " #=> #{desc}"
|
2007-02-25 05:10:38 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
INDENT = 27
|
|
|
|
|
|
|
|
def adjust_indent(src)
|
2014-06-22 03:43:50 +04:00
|
|
|
untabify(src).gsub(/^ {#{INDENT}}/o, '').gsub(/^/, ' ').sub(/\s*\z/, "\n")
|
2007-02-25 05:10:38 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def untabify(str)
|
2008-02-12 09:28:23 +03:00
|
|
|
str.gsub(/^\t+/) {' ' * (8 * $&.size) }
|
2007-02-25 05:10:38 +03:00
|
|
|
end
|
|
|
|
|
2017-01-23 05:47:16 +03:00
|
|
|
def make_srcfile(src, frozen_string_literal: nil)
|
2007-09-27 02:40:44 +04:00
|
|
|
filename = 'bootstraptest.tmp.rb'
|
|
|
|
File.open(filename, 'w') {|f|
|
2017-01-23 05:47:16 +03:00
|
|
|
f.puts "#frozen_string_literal:true" if frozen_string_literal
|
2007-09-27 02:40:44 +04:00
|
|
|
f.puts "GC.stress = true" if $stress
|
|
|
|
f.puts "print(begin; #{src}; end)"
|
|
|
|
}
|
|
|
|
filename
|
|
|
|
end
|
|
|
|
|
2017-01-23 05:47:16 +03:00
|
|
|
def get_result_string(src, opt = '', **argh)
|
2007-02-24 10:47:53 +03:00
|
|
|
if @ruby
|
2017-01-23 05:47:16 +03:00
|
|
|
filename = make_srcfile(src, **argh)
|
2007-07-20 04:50:42 +04:00
|
|
|
begin
|
2008-01-17 20:02:30 +03:00
|
|
|
`#{@ruby} -W0 #{opt} #{filename}`
|
2007-07-20 04:50:42 +04:00
|
|
|
ensure
|
2013-10-16 12:46:00 +04:00
|
|
|
raise Interrupt if $? and $?.signaled? && $?.termsig == Signal.list["INT"]
|
2007-07-20 04:50:42 +04:00
|
|
|
raise CoreDumpError, "core dumped" if $? and $?.coredump?
|
|
|
|
end
|
2007-02-24 10:47:53 +03:00
|
|
|
else
|
|
|
|
eval(src).to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-04 01:19:52 +04:00
|
|
|
def with_stderr
|
|
|
|
out = err = nil
|
2012-07-04 15:23:13 +04:00
|
|
|
begin
|
|
|
|
r, w = IO.pipe
|
2012-07-04 01:19:52 +04:00
|
|
|
stderr = $stderr.dup
|
|
|
|
$stderr.reopen(w)
|
|
|
|
w.close
|
|
|
|
reader = Thread.start {r.read}
|
|
|
|
begin
|
|
|
|
out = yield
|
|
|
|
ensure
|
|
|
|
$stderr.reopen(stderr)
|
|
|
|
err = reader.value
|
|
|
|
end
|
2012-07-04 15:23:13 +04:00
|
|
|
ensure
|
|
|
|
w.close rescue nil
|
|
|
|
r.close rescue nil
|
2012-07-04 01:19:52 +04:00
|
|
|
end
|
|
|
|
return out, err
|
|
|
|
end
|
|
|
|
|
2007-02-24 10:47:53 +03:00
|
|
|
def newtest
|
|
|
|
@location = File.basename(caller(2).first)
|
|
|
|
@count += 1
|
|
|
|
cleanup_coredump
|
|
|
|
end
|
|
|
|
|
2007-08-06 09:36:14 +04:00
|
|
|
def error(msg, additional_message)
|
2012-07-05 10:15:00 +04:00
|
|
|
msg = "#{@failed}\##{@count} #{@location}#{@reset}: #{msg} #{additional_message}"
|
|
|
|
if @tty
|
2014-06-10 18:11:57 +04:00
|
|
|
$stderr.puts "#{erase}#{msg}"
|
2012-07-05 10:15:00 +04:00
|
|
|
else
|
|
|
|
@errbuf.push msg
|
|
|
|
end
|
2007-02-24 10:47:53 +03:00
|
|
|
@error += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_temporary_working_directory(dir)
|
2007-08-17 09:41:10 +04:00
|
|
|
if dir
|
|
|
|
Dir.mkdir dir
|
|
|
|
Dir.chdir(dir) {
|
|
|
|
yield
|
|
|
|
}
|
|
|
|
else
|
2009-08-23 10:15:00 +04:00
|
|
|
Dir.mktmpdir(["bootstraptest", ".tmpwd"]) {|d|
|
2007-08-17 09:41:10 +04:00
|
|
|
Dir.chdir(d) {
|
|
|
|
yield
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup_coredump
|
|
|
|
FileUtils.rm_f 'core'
|
2007-02-25 04:28:14 +03:00
|
|
|
FileUtils.rm_f Dir.glob('core.*')
|
2007-07-20 04:50:42 +04:00
|
|
|
FileUtils.rm_f @ruby+'.stackdump' if @ruby
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
class CoreDumpError < StandardError; end
|
|
|
|
|
|
|
|
def check_coredump
|
2007-07-20 04:50:42 +04:00
|
|
|
if File.file?('core') or not Dir.glob('core.*').empty? or
|
|
|
|
(@ruby and File.exist?(@ruby+'.stackdump'))
|
2007-02-24 10:47:53 +03:00
|
|
|
raise CoreDumpError, "core dumped"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
main
|