4 require_relative 'lib/colorize'
6 ENV.delete("GNUMAKEFLAGS")
8 github_actions = ENV["GITHUB_ACTIONS"] == "true"
10 allowed_failures = ENV['TEST_BUNDLED_GEMS_ALLOW_FAILURES'] || ''
11 allowed_failures = allowed_failures.split(',').reject(&:empty?)
13 ENV["GEM_PATH"] = [File.realpath('.bundle'), File.realpath('../.bundle', __dir__)].join(File::PATH_SEPARATOR)
15 colorize = Colorize.new
16 rake = File.realpath("../../.bundle/bin/rake", __FILE__)
17 gem_dir = File.realpath('../../gems', __FILE__)
18 rubylib = [gem_dir+'/lib', ENV["RUBYLIB"]].compact.join(File::PATH_SEPARATOR)
20 ruby = ENV['RUBY'] || RbConfig.ruby
22 File.foreach("#{gem_dir}/bundled_gems") do |line|
23 next if /^\s*(?:#|$)/ =~ line
24 gem = line.split.first
25 next if ARGV.any? {|pat| !File.fnmatch?(pat, gem)}
26 # 93(bright yellow) is copied from .github/workflows/mingw.yml
27 puts "#{github_actions ? "::group::\e\[93m" : "\n"}Testing the #{gem} gem#{github_actions ? "\e\[m" : ""}"
29 test_command = "#{ruby} -C #{gem_dir}/src/#{gem} #{rake} test"
30 first_timeout = 600 # 10min
40 # TODO: We should skip test file instead of test class/methods
44 skip_test_files.each do |file|
45 path = "#{gem_dir}/src/#{gem}/#{file}"
46 File.unlink(path) if File.exist?(path)
49 test_command << " stdlib_test validate RBS_SKIP_TESTS=#{__dir__}/rbs_skip_tests SKIP_RBS_VALIDATION=true"
53 # Since debug gem requires debug.so in child processes without
54 # activating the gem, we preset necessary paths in RUBYLIB
55 # environment variable.
59 test_command = "#{ruby} -C #{gem_dir}/src/#{gem} test/run-test.rb"
62 toplib = gem.tr("-", "/")
67 libs = IO.popen([ruby, "-e", "old = $:.dup; require '#{toplib}'; puts $:-old"], &:read)
68 next unless $?.success?
70 ENV["RUBYLIB"] = [libs.split("\n"), rubylib].join(File::PATH_SEPARATOR)
72 ENV["RUBYLIB"] = rubylib
75 print "[command]" if github_actions
77 pid = Process.spawn(test_command, "#{/mingw|mswin/ =~ RUBY_PLATFORM ? 'new_' : ''}pgroup": true)
78 {nil => first_timeout, INT: 30, TERM: 10, KILL: nil}.each do |sig, sec|
80 puts "Sending #{sig} signal"
81 Process.kill("-#{sig}", pid)
84 break Timeout.timeout(sec) {Process.wait(pid)}
88 exit_code = Signal.list["INT"]
89 Process.kill("-KILL", pid)
94 print "::endgroup::\n" if github_actions
97 mesg = "Tests failed " +
98 ($?.signaled? ? "by SIG#{Signal.signame($?.termsig)}" :
99 "with exit code #{$?.exitstatus}")
100 puts colorize.decorate(mesg, "fail")
101 if allowed_failures.include?(gem)
102 mesg = "Ignoring test failures for #{gem} due to \$TEST_BUNDLED_GEMS_ALLOW_FAILURES"
103 puts colorize.decorate(mesg, "skip")
106 exit_code = $?.exitstatus if $?.exitstatus
111 puts "Failed gems: #{failed.join(', ')}" unless failed.empty?