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