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.
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
2007-07-06 13:23:53 +04:00
|
|
|
dir = File.join(Dir.tmpdir, 'bootstraptest.tmpwd')
|
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=(.*)/
|
|
|
|
@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
|
2007-06-24 10:52:59 +04:00
|
|
|
when /\A--dir=(.*)/
|
|
|
|
dir = $1
|
|
|
|
true
|
2007-07-06 09:50:42 +04:00
|
|
|
when /\A(-q|--q(uiet))\z/
|
|
|
|
quiet = true
|
|
|
|
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.
|
|
|
|
default: /tmp/bootstraptest.tmpwd
|
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
|
|
|
|
exit 0
|
2007-02-24 10:47:53 +03:00
|
|
|
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) }
|
2007-06-24 10:52:59 +04:00
|
|
|
|
2007-07-06 09:50:42 +04:00
|
|
|
unless quiet
|
|
|
|
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
|
|
|
|
$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
|
|
|
|
|
|
|
|
def exec_test(pathes)
|
|
|
|
@count = 0
|
|
|
|
@error = 0
|
|
|
|
@errbuf = []
|
|
|
|
@location = nil
|
|
|
|
pathes.each do |path|
|
2007-07-06 13:23:53 +04:00
|
|
|
$stderr.print "\n#{File.basename(path)} "
|
2007-02-24 10:47:53 +03:00
|
|
|
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
|
|
|
|
|
2007-02-25 05:10:38 +03:00
|
|
|
def assert_equal(expected, testsrc)
|
2007-02-24 10:47:53 +03:00
|
|
|
newtest
|
2007-02-24 13:28:36 +03:00
|
|
|
$stderr.puts "\##{@count} #{@location}" if @verbose
|
2007-02-25 05:10:38 +03:00
|
|
|
result = get_result_string(testsrc)
|
2007-02-24 10:47:53 +03:00
|
|
|
check_coredump
|
2007-02-25 05:10:38 +03:00
|
|
|
if expected == result
|
2007-02-24 10:47:53 +03:00
|
|
|
$stderr.print '.'
|
|
|
|
else
|
|
|
|
$stderr.print 'F'
|
2007-02-25 05:10:38 +03:00
|
|
|
error pretty(testsrc, expected, result)
|
2007-02-24 10:47:53 +03:00
|
|
|
end
|
|
|
|
rescue Exception => err
|
|
|
|
$stderr.print 'E'
|
|
|
|
error err.message
|
|
|
|
end
|
|
|
|
|
2007-02-25 05:10:38 +03:00
|
|
|
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
|
|
|
|
|
2007-02-24 10:47:53 +03:00
|
|
|
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'
|
2007-02-25 04:28:14 +03:00
|
|
|
FileUtils.rm_f Dir.glob('core.*')
|
2007-02-24 10:47:53 +03:00
|
|
|
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
|