|
1 | 1 | 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 |
2 | 21 |
|
3 | 22 | # Tests that are known to fail or cause issues with ZJIT |
4 | 23 | excluded = [ |
|
61 | 80 | "test/ruby/test_yjit.rb", |
62 | 81 | ] |
63 | 82 |
|
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 | + |
66 | 98 | test_runner = "#{repo_root}/test/runner.rb" |
67 | 99 | miniruby_opts = "-I#{repo_root}/lib -I. -I.ext/common --zjit-call-threshold=1" |
68 | 100 | test_dir = "#{repo_root}/test/ruby" |
69 | 101 |
|
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 |
75 | 113 | end |
76 | 114 |
|
77 | 115 | command = "RUST_BACKTRACE=1 ruby --disable=gems #{test_runner} --ruby=\"#{miniruby} #{miniruby_opts}\"" |
78 | 116 |
|
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 |
80 | 122 | puts "Command: #{command}" |
81 | 123 |
|
82 | 124 | # Run each test |
83 | 125 | test_files.each_with_index do |test_file, idx| |
84 | 126 | 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 |
86 | 132 |
|
87 | 133 | # Build command using the test runner framework |
88 | 134 | cmd = %Q{#{command} #{test_file} 2>&1} |
|
0 commit comments