Skip to content

Commit f201a36

Browse files
committed
Allow zjit/test_runner.rb to take argument and options
1 parent c31ac49 commit f201a36

1 file changed

Lines changed: 55 additions & 9 deletions

File tree

zjit/test_runner.rb

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
require "pathname"
2+
require "optparse"
3+
4+
# Parse command-line arguments
5+
options = {}
6+
parser = OptionParser.new do |opts|
7+
opts.banner = "Usage: ruby zjit/test_runner.rb [options] [test_file]"
8+
9+
opts.on("--miniruby PATH", "Path to miniruby executable") do |path|
10+
options[:miniruby] = path
11+
end
12+
13+
opts.on("-h", "--help", "Show this message") do
14+
puts opts
15+
exit
16+
end
17+
end
18+
19+
args = parser.parse!(ARGV)
20+
specific_test = args.first
221

322
# Tests that are known to fail or cause issues with ZJIT
423
excluded = [
@@ -61,28 +80,55 @@
6180
"test/ruby/test_yjit.rb",
6281
]
6382

64-
repo_root = ENV["CI"] ? "../src" : "."
65-
miniruby = Dir.exist?("#{repo_root}/build") ? "#{repo_root}/build/miniruby" : "#{repo_root}/miniruby"
83+
# Determine repo root based on the context
84+
if specific_test && specific_test.start_with?("test/")
85+
# When a specific test file is provided, use current directory as repo root
86+
repo_root = "."
87+
else
88+
repo_root = ENV["CI"] ? "../src" : "."
89+
end
90+
91+
# Use provided miniruby path or default
92+
if options[:miniruby]
93+
miniruby = options[:miniruby]
94+
else
95+
miniruby = Dir.exist?("#{repo_root}/build") ? "#{repo_root}/build/miniruby" : "#{repo_root}/miniruby"
96+
end
97+
6698
test_runner = "#{repo_root}/test/runner.rb"
6799
miniruby_opts = "-I#{repo_root}/lib -I. -I.ext/common --zjit-call-threshold=1"
68100
test_dir = "#{repo_root}/test/ruby"
69101

70-
total_test_files = Dir.glob("#{test_dir}/**/*.rb")
71-
72-
# Filter out excluded tests
73-
test_files = total_test_files.reject do |file|
74-
excluded.any? { |excluded_file| file.end_with?(excluded_file) }
102+
# Determine which tests to run
103+
if specific_test
104+
# Run specific test file
105+
test_files = [specific_test]
106+
total_test_files = test_files
107+
else
108+
# Run all tests except excluded ones
109+
total_test_files = Dir.glob("#{test_dir}/**/*.rb")
110+
test_files = total_test_files.reject do |file|
111+
excluded.any? { |excluded_file| file.end_with?(excluded_file) }
112+
end
75113
end
76114

77115
command = "RUST_BACKTRACE=1 ruby --disable=gems #{test_runner} --ruby=\"#{miniruby} #{miniruby_opts}\""
78116

79-
puts "Running #{test_files.length} (#{total_test_files.length} total) test files with ZJIT..."
117+
if specific_test
118+
puts "Running specific test file: #{specific_test}"
119+
else
120+
puts "Running #{test_files.length} (#{total_test_files.length} total) test files with ZJIT..."
121+
end
80122
puts "Command: #{command}"
81123

82124
# Run each test
83125
test_files.each_with_index do |test_file, idx|
84126
relative_path = Pathname.new(test_file).relative_path_from(Pathname.new("."))
85-
print "[#{idx + 1}/#{test_files.length}] #{relative_path}... "
127+
if test_files.length == 1
128+
print "Running #{relative_path}... "
129+
else
130+
print "[#{idx + 1}/#{test_files.length}] #{relative_path}... "
131+
end
86132

87133
# Build command using the test runner framework
88134
cmd = %Q{#{command} #{test_file} 2>&1}

0 commit comments

Comments
 (0)