2019-09-29 13:16:10 +03:00
|
|
|
require 'rbconfig'
|
2020-01-18 14:46:55 +03:00
|
|
|
require 'timeout'
|
2021-09-30 21:13:00 +03:00
|
|
|
require 'fileutils'
|
2022-12-12 07:38:12 +03:00
|
|
|
require_relative 'lib/colorize'
|
2019-09-29 13:16:10 +03:00
|
|
|
|
2022-07-16 09:28:05 +03:00
|
|
|
ENV.delete("GNUMAKEFLAGS")
|
|
|
|
|
2021-08-07 12:32:24 +03:00
|
|
|
github_actions = ENV["GITHUB_ACTIONS"] == "true"
|
|
|
|
|
2019-09-29 13:16:10 +03:00
|
|
|
allowed_failures = ENV['TEST_BUNDLED_GEMS_ALLOW_FAILURES'] || ''
|
|
|
|
allowed_failures = allowed_failures.split(',').reject(&:empty?)
|
|
|
|
|
2022-07-15 20:08:06 +03:00
|
|
|
ENV["GEM_PATH"] = [File.realpath('.bundle'), File.realpath('../.bundle', __dir__)].join(File::PATH_SEPARATOR)
|
|
|
|
|
2022-12-12 07:38:12 +03:00
|
|
|
colorize = Colorize.new
|
2020-01-13 06:27:24 +03:00
|
|
|
rake = File.realpath("../../.bundle/bin/rake", __FILE__)
|
|
|
|
gem_dir = File.realpath('../../gems', __FILE__)
|
2023-06-13 19:21:27 +03:00
|
|
|
rubylib = [gem_dir+'/lib', ENV["RUBYLIB"]].compact.join(File::PATH_SEPARATOR)
|
2019-09-29 13:16:10 +03:00
|
|
|
exit_code = 0
|
2019-11-05 02:26:10 +03:00
|
|
|
ruby = ENV['RUBY'] || RbConfig.ruby
|
2020-12-03 15:31:44 +03:00
|
|
|
failed = []
|
2019-10-28 13:14:38 +03:00
|
|
|
File.foreach("#{gem_dir}/bundled_gems") do |line|
|
2020-07-05 12:59:06 +03:00
|
|
|
next if /^\s*(?:#|$)/ =~ line
|
2019-09-29 13:16:10 +03:00
|
|
|
gem = line.split.first
|
2020-12-02 11:06:09 +03:00
|
|
|
next if ARGV.any? {|pat| !File.fnmatch?(pat, gem)}
|
2023-08-14 16:28:19 +03:00
|
|
|
# 93(bright yellow) is copied from .github/workflows/mingw.yml
|
|
|
|
puts "#{github_actions ? "::group::\e\[93m" : "\n"}Testing the #{gem} gem#{github_actions ? "\e\[m" : ""}"
|
2019-09-29 13:16:10 +03:00
|
|
|
|
2022-07-27 11:36:45 +03:00
|
|
|
test_command = "#{ruby} -C #{gem_dir}/src/#{gem} #{rake} test"
|
2020-10-21 11:58:12 +03:00
|
|
|
first_timeout = 600 # 10min
|
2020-09-23 04:59:49 +03:00
|
|
|
|
2022-07-15 20:08:06 +03:00
|
|
|
toplib = gem
|
|
|
|
case gem
|
|
|
|
when "typeprof"
|
2021-08-24 20:49:49 +03:00
|
|
|
|
2022-07-15 20:08:06 +03:00
|
|
|
when "rbs"
|
2023-06-12 05:29:25 +03:00
|
|
|
# TODO: We should skip test file instead of test class/methods
|
|
|
|
skip_test_files = %w[
|
|
|
|
]
|
|
|
|
|
|
|
|
skip_test_files.each do |file|
|
|
|
|
path = "#{gem_dir}/src/#{gem}/#{file}"
|
|
|
|
File.unlink(path) if File.exist?(path)
|
|
|
|
end
|
|
|
|
|
2023-03-02 06:59:04 +03:00
|
|
|
test_command << " stdlib_test validate RBS_SKIP_TESTS=#{__dir__}/rbs_skip_tests SKIP_RBS_VALIDATION=true"
|
2020-10-21 11:58:12 +03:00
|
|
|
first_timeout *= 3
|
2021-10-28 09:49:55 +03:00
|
|
|
|
2022-07-15 20:08:06 +03:00
|
|
|
when "debug"
|
|
|
|
# Since debug gem requires debug.so in child processes without
|
2023-12-25 05:32:03 +03:00
|
|
|
# activating the gem, we preset necessary paths in RUBYLIB
|
2022-07-15 20:08:06 +03:00
|
|
|
# environment variable.
|
|
|
|
load_path = true
|
|
|
|
|
2023-06-12 04:02:42 +03:00
|
|
|
when "test-unit"
|
|
|
|
test_command = "#{ruby} -C #{gem_dir}/src/#{gem} test/run-test.rb"
|
|
|
|
|
2022-07-15 20:08:06 +03:00
|
|
|
when /\Anet-/
|
|
|
|
toplib = gem.tr("-", "/")
|
|
|
|
|
2021-06-28 07:55:49 +03:00
|
|
|
end
|
|
|
|
|
2022-07-15 20:08:06 +03:00
|
|
|
if load_path
|
|
|
|
libs = IO.popen([ruby, "-e", "old = $:.dup; require '#{toplib}'; puts $:-old"], &:read)
|
|
|
|
next unless $?.success?
|
|
|
|
puts libs
|
|
|
|
ENV["RUBYLIB"] = [libs.split("\n"), rubylib].join(File::PATH_SEPARATOR)
|
|
|
|
else
|
|
|
|
ENV["RUBYLIB"] = rubylib
|
2021-09-30 21:13:00 +03:00
|
|
|
end
|
|
|
|
|
2021-08-07 12:32:24 +03:00
|
|
|
print "[command]" if github_actions
|
2019-09-29 13:16:10 +03:00
|
|
|
puts test_command
|
2020-01-18 14:46:55 +03:00
|
|
|
pid = Process.spawn(test_command, "#{/mingw|mswin/ =~ RUBY_PLATFORM ? 'new_' : ''}pgroup": true)
|
2020-10-21 11:58:12 +03:00
|
|
|
{nil => first_timeout, INT: 30, TERM: 10, KILL: nil}.each do |sig, sec|
|
2020-01-18 14:46:55 +03:00
|
|
|
if sig
|
|
|
|
puts "Sending #{sig} signal"
|
|
|
|
Process.kill("-#{sig}", pid)
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
break Timeout.timeout(sec) {Process.wait(pid)}
|
|
|
|
rescue Timeout::Error
|
|
|
|
end
|
2022-07-24 10:35:38 +03:00
|
|
|
rescue Interrupt
|
|
|
|
exit_code = Signal.list["INT"]
|
|
|
|
Process.kill("-KILL", pid)
|
|
|
|
Process.wait(pid)
|
|
|
|
break
|
2020-01-18 14:46:55 +03:00
|
|
|
end
|
2019-09-29 13:16:10 +03:00
|
|
|
|
2023-08-14 16:28:19 +03:00
|
|
|
print "::endgroup::\n" if github_actions
|
2019-09-29 13:16:10 +03:00
|
|
|
unless $?.success?
|
2022-07-24 10:35:38 +03:00
|
|
|
|
2022-12-12 07:38:12 +03:00
|
|
|
mesg = "Tests failed " +
|
|
|
|
($?.signaled? ? "by SIG#{Signal.signame($?.termsig)}" :
|
|
|
|
"with exit code #{$?.exitstatus}")
|
|
|
|
puts colorize.decorate(mesg, "fail")
|
2019-09-29 13:16:10 +03:00
|
|
|
if allowed_failures.include?(gem)
|
2022-12-12 07:38:12 +03:00
|
|
|
mesg = "Ignoring test failures for #{gem} due to \$TEST_BUNDLED_GEMS_ALLOW_FAILURES"
|
|
|
|
puts colorize.decorate(mesg, "skip")
|
2019-09-29 13:16:10 +03:00
|
|
|
else
|
2020-12-03 15:31:44 +03:00
|
|
|
failed << gem
|
2022-07-24 10:35:38 +03:00
|
|
|
exit_code = $?.exitstatus if $?.exitstatus
|
2019-09-29 13:16:10 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-03 15:31:44 +03:00
|
|
|
puts "Failed gems: #{failed.join(', ')}" unless failed.empty?
|
2019-09-29 13:16:10 +03:00
|
|
|
exit exit_code
|