Skip to content

Instantly share code, notes, and snippets.

@lumeet
Created January 24, 2015 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lumeet/75e56f01ff996187dbc0 to your computer and use it in GitHub Desktop.
Save lumeet/75e56f01ff996187dbc0 to your computer and use it in GitHub Desktop.
Scan JRuby test excludes
#!/usr/bin/env bin/jruby
require 'fileutils'
def replace_file(path)
FileUtils.mv path, "#{path}.tmp"
File.open("#{path}.tmp", 'r') do |src|
File.open(path, 'w') do |dest|
src.each_line do |l|
line = yield l
dest.print line if line
end
dest.close
end
src.close
end
FileUtils.rm "#{path}.tmp"
end
def include_all(filepaths, exceptions)
filepaths.map do |path|
basename = File.basename(path, '.rb')
replace_file(path) do |line|
if (method_name = line.match(/^\s*exclude\s+:([^\s,]+)/).to_a.last)
identifier = "#{basename}##{method_name}"
if exceptions.include?(identifier) || !(line =~ /needs\ investigation/)
puts "Skip #{identifier}"
else
line = "# #{line}"
end
end
line
end
end
end
def exclude_selected(excludes)
excludes.each do |class_name, methods|
path = "test/mri/excludes/#{class_name.gsub('::', '/')}.rb"
next unless File.file?(path)
basename = File.basename(path, '.rb')
replace_file(path) do |line|
if (method_name = line.match(/^#\s*exclude\s+:'?([^\s,']+)/).to_a.last)
if methods.include? method_name
puts "Excluding #{class_name}##{method_name}"
line = line.sub(/^#\ /, '')
else
line = nil
end
end
line
end
end
end
def scan
`bin/jruby -S rake test:mri | awk '/\)\ (Error|Failure):/{getline;print}'`
end
def parse_failing(data)
lines = data.split("\n")
excludes = {}
unless lines.empty?
lines.each do |line|
class_name, rest = line.split('#', 2)
method_name, _ = rest.split(/(:|\ )/, 2)
excludes[class_name] ||= []
excludes[class_name] << method_name
end
end
excludes
end
def remove_temp_files
FileUtils.rm Dir.glob('test/mri/excludes/**/*.rb.tmp')
end
def restore_untouched_tests(filepaths)
filepaths.map do |path|
next unless File.file?(path)
next unless File.read(path) =~ /^#/
puts "Restoring #{path}"
class_name = File.basename(path, '.rb')
replace_file(path) do |line|
if (method_name = line.match(/^#\s*exclude\s+:'?([^\s,']+)/).to_a.last)
puts "Excluding #{class_name}##{method_name}"
line = line.sub(/^#\ /, '')
end
line
end
end
end
hanging_tests = ['TestBigDecimal#test_exception_overflow',
'TestBignum#test_pow',
'TestIterator#test_ljump',
'TestPTY#test_pty_check_default',
'TestPTY#test_pty_check_raise',
'TestPTY#test_spawn_with_block',
'TestPTY#test_spawn_without_block',
'TestIO#test_readlines_limit_0',
'TestThread#test_mutex_interrupt',
'TestThread#test_thread_join_main_thread',
'TestThread#test_thread_timer_and_interrupt',
'TestThread#test_thread_variable?',
'TestTimeout#test_enumerator_next',
'TestCSV::Encodings#test_can_write_csv_in_any_encoding',
'TestCSV::Encodings#test_read_with_default_encoding',
'TestCSV::Encodings#test_reading_with_most_encodings',
'TestCSV::Encodings#test_regular_expression_escaping',
'TestCSV::Features#test_gzip_reader_bug_fix',
'TestPipe#test_eof_0',
'TestPipe#test_eof_1']
#filepaths = Dir['test/mri/excludes/**/*.rb']
filepaths = Dir['test/mri/excludes/*.rb']
begin
puts 'Including all except hanging tests...'
include_all(filepaths, hanging_tests)
puts 'Scanning, this will take several minutes...'
output = scan
File.write('output.txt', output)
failing_by_class = parse_failing(output)
exclude_selected(failing_by_class)
ensure
remove_temp_files
restore_untouched_tests(filepaths)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment