Skip to content

Commit

Permalink
Merge pull request #2410 from natalie-lang/better-test-groups
Browse files Browse the repository at this point in the history
Split test/natalie/**/*_test.rb files into groups too
  • Loading branch information
seven1m authored Dec 23, 2024
2 parents 2224cec + 6f4472a commit 5041642
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
12 changes: 9 additions & 3 deletions spec/support/split_specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
raise 'expected "groupN"' unless num =~ /group(\d+)/
num = $1.to_i - 1

list = Dir['spec/**/*_spec.rb']
slice_size = (list.size / groups.to_f).ceil
raise "expected 1-#{groups}" unless (0...groups.to_i).include?(num)

list = Dir['spec/**/*_spec.rb', 'test/natalie/**/*_test.rb']

rand = Random.new(42)
sorted_list = list.sort_by { |item| rand.rand }

slice_size = (sorted_list.size / groups.to_f).ceil
groups = []
list.each_slice(slice_size).each do |group|
sorted_list.each_slice(slice_size).each do |group|
groups << group
end

Expand Down
11 changes: 10 additions & 1 deletion test/ruby/natalie_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
parallelize_me!

Dir.chdir File.expand_path('../..', __dir__)
Dir['test/natalie/**/*_test.rb'].each do |path|
files = Dir['test/natalie/**/*_test.rb']

if !(glob = ENV['GLOB']).to_s.empty?
glob_files = files & Dir[*glob.split(',')]
puts "Matched #{glob_files.size} out of #{files.size} total test files:"
puts glob_files.to_a
files = glob_files
end

files.each do |path|
code = File.read(path, encoding: 'utf-8')
describe path do
if code =~ /# skip-ruby/
Expand Down
31 changes: 17 additions & 14 deletions test/ruby/ruby_specs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ def spec_timeout(path)
end

Dir.chdir File.expand_path('../..', __dir__)
glob = if ENV['DEBUG_COMPILER']
# I use this when I'm working on the compiler,
# as it catches 99% of bugs and finishes a lot quicker.
Dir['spec/language/*_spec.rb']
elsif !(glob = ENV['GLOB']).to_s.empty?
# GLOB="spec/core/io/*_spec.rb,spec/core/thread/*_spec.rb" rake test
Dir[*glob.split(',')].tap do |files|
puts 'Matched files:'
puts files.to_a
end
else
Dir['spec/**/*_spec.rb']
end
glob.each do |path|
files = if ENV['DEBUG_COMPILER']
# I use this when I'm working on the compiler,
# as it catches 99% of bugs and finishes a lot quicker.
Dir['spec/language/*_spec.rb']
else
Dir['spec/**/*_spec.rb']
end

if !(glob = ENV['GLOB']).to_s.empty?
# GLOB="spec/core/io/*_spec.rb,spec/core/thread/*_spec.rb" rake test
glob_files = files & Dir[*glob.split(',')]
puts "Matched #{glob_files.size} out of #{files.size} total spec files:"
puts glob_files.to_a
files = glob_files
end

files.each do |path|
describe path do
it 'passes all specs' do
out_nat = Timeout.timeout(spec_timeout(path), nil, "execution expired running: #{path}") do
Expand Down

0 comments on commit 5041642

Please sign in to comment.