1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/bootstraptest/runner.rb
ko1 3aa45744ab * bootstraptest/runner.rb: set default directory to
'/tmp/bootstraptest.tmpwd' and add --dir option.
  fix to output driver and target information.
* common.mk: fix to run btest on BASERUBY and
  add OPTS to pass option ("make btest OPTS=...").



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-24 06:52:59 +00:00

158 lines
3.4 KiB
Ruby

# $Id$
# NOTE:
# Never use optparse in this file.
# Never use test/unit in this file.
# Never use Ruby extensions in this file.
$LOAD_PATH.unshift "#{File.dirname($0)}/lib"
require 'fileutils'
def main
@ruby = File.expand_path('miniruby')
@verbose = false
dir = '/tmp/bootstraptest.tmpwd'
tests = nil
ARGV.delete_if {|arg|
case arg
when /\A--ruby=(.*)/
@ruby = File.expand_path($1)
true
when /\A--sets=(.*)/
tests = Dir.glob("#{File.dirname($0)}/test_{#{$1}}*.rb")
puts tests.map {|path| File.basename(path) }.inspect
true
when /\A--dir=(.*)/
dir = $1
true
when /\A(-v|--v(erbose))\z/
@verbose = true
when /\A(-h|--h(elp)?)\z/
puts(<<-End)
Usage: #{File.basename($0, '.*')} --ruby=PATH [--sets=NAME,NAME,...]
--sets=NAME,NAME,... Name of test sets.
--dir=DIRECTORY Working directory.
default: /tmp/bootstraptest.tmpwd
-v, --verbose Output test name before exec.
-h, --help Print this message and quit.
End
exit 0
else
false
end
}
if tests and not ARGV.empty?
$stderr.puts "--tests and arguments are exclusive"
exit 1
end
tests ||= ARGV
tests = Dir.glob("#{File.dirname($0)}/test_*.rb") if tests.empty?
pathes = tests.map {|path| File.expand_path(path) }
puts Time.now
patchlevel = defined?(RUBY_PATCHLEVEL) ? " pachlevel #{RUBY_PATCHLEVEL}" : ''
puts "Driver is ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}#{patchlevel}) [#{RUBY_PLATFORM}]"
puts "Target is #{`#{@ruby} -v`}"
puts
in_temporary_working_directory(dir) {
exec_test pathes
}
end
def exec_test(pathes)
@count = 0
@error = 0
@errbuf = []
@location = nil
pathes.each do |path|
load File.expand_path(path)
end
$stderr.puts
if @error == 0
$stderr.puts "PASS #{@count} tests"
exit 0
else
@errbuf.each do |msg|
$stderr.puts msg
end
$stderr.puts "FAIL #{@error}/#{@count} tests failed"
exit 1
end
end
def assert_equal(expected, testsrc)
newtest
$stderr.puts "\##{@count} #{@location}" if @verbose
result = get_result_string(testsrc)
check_coredump
if expected == result
$stderr.print '.'
else
$stderr.print 'F'
error pretty(testsrc, expected, result)
end
rescue Exception => err
$stderr.print 'E'
error err.message
end
def pretty(src, ex, result)
(/\n/ =~ src ? "\n#{adjust_indent(src)}" : src) +
" #=> #{result.inspect} (expected #{ex.inspect})"
end
INDENT = 27
def adjust_indent(src)
untabify(src).gsub(/^ {#{INDENT}}/o, '').gsub(/^/, ' ')
end
def untabify(str)
str.gsub(/^\t+/) {|tabs| ' ' * (8 * tabs.size) }
end
def get_result_string(src)
if @ruby
File.open('bootstraptest.tmp.rb', 'w') {|f|
f.puts "print(begin; #{src}; end)"
}
`#{@ruby} bootstraptest.tmp.rb`
else
eval(src).to_s
end
end
def newtest
@location = File.basename(caller(2).first)
@count += 1
cleanup_coredump
end
def error(msg)
@errbuf.push "\##{@count} #{@location}: #{msg}"
@error += 1
end
def in_temporary_working_directory(dir)
FileUtils.rm_rf dir
Dir.mkdir dir
Dir.chdir(dir) {
yield
}
end
def cleanup_coredump
FileUtils.rm_f 'core'
FileUtils.rm_f Dir.glob('core.*')
end
class CoreDumpError < StandardError; end
def check_coredump
if File.file?('core') or not Dir.glob('core.*').empty?
raise CoreDumpError, "core dumped"
end
end
main