Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TestSkip module to skip tests that fails in ruby CI #1167

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def with_cli
@stderr = nil
end

def bundler?
ENV.key?("BUNDLE_GEMFILE")
end

def test_ast
with_cli do |cli|
cli.run(%w(-r set ast))
Expand Down Expand Up @@ -542,8 +538,6 @@ def foo: () -> void
end

def test_collection_install
omit unless bundler?

Dir.mktmpdir do |dir|
Dir.chdir(dir) do
dir = Pathname(dir)
Expand Down Expand Up @@ -597,8 +591,6 @@ def test_collection_install
end

def test_collection_install_frozen
omit unless bundler?

Dir.mktmpdir do |dir|
Dir.chdir(dir) do
dir = Pathname(dir)
Expand Down Expand Up @@ -630,8 +622,6 @@ def test_collection_install_frozen
end

def test_collection_update
omit unless bundler?

Dir.mktmpdir do |dir|
Dir.chdir(dir) do
dir = Pathname(dir)
Expand Down
46 changes: 0 additions & 46 deletions test/stdlib/Net_HTTP_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class NetSingletonTest < Test::Unit::TestCase
testing "singleton(::Net::HTTP)"

def test_get
omit if ci?

$stdout = StringIO.new
assert_send_type "(URI::Generic) -> nil",
Net::HTTP, :get_print, URI("https://www.ruby-lang.org")
Expand All @@ -35,17 +33,13 @@ def test_get
end

def test_post
omit if ci?

assert_send_type "(URI, String, Hash[String, String]) -> Net::HTTPResponse",
Net::HTTP, :post, URI('http://www.example.com/api/search'), { "q" => "ruby", "max" => "50" }.to_json, "Content-Type" => "application/json"
assert_send_type "(URI, Hash[String, Symbol]) -> Net::HTTPResponse",
Net::HTTP, :post_form, URI('http://www.example.com/api/search'), { "q" => :ruby, "max" => :max }
end

def test_new
omit if ci?

assert_send_type "(String, Integer, nil, nil, nil, nil, nil) -> Net::HTTP",
Net::HTTP, :new, 'www.ruby-lang.org', 80, nil, nil, nil, nil, nil
end
Expand All @@ -64,114 +58,92 @@ def self.new
end

def test_inspect
omit if ci?

assert_send_type "() -> String",
TestNet.new, :inspect
end

def test_set_debug_output
omit if ci?
assert_send_type "(IO) -> void",
TestNet.new, :set_debug_output, $stderr
end

def test_address
omit if ci?
assert_send_type "() -> String",
TestNet.new, :address
end

def test_port
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :port
end

def test_ipaddr
omit if ci?
assert_send_type "() -> nil",
TestNet.new, :ipaddr
assert_send_type "(String) -> void",
TestNet.new, :ipaddr=, ('127.0.0.1')
end

def test_open_timeout
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :open_timeout
end

def test_read_timeout
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :read_timeout
assert_send_type "(Integer) -> void",
TestNet.new, :read_timeout=, 10
end

def test_write_timeout
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :write_timeout
assert_send_type "(Integer) -> void",
TestNet.new, :write_timeout=, 10
end

def test_continue_timeout
omit if ci?
assert_send_type "() -> nil",
TestNet.new, :continue_timeout
assert_send_type "(Integer) -> void",
TestNet.new, :continue_timeout=, 10
end

def test_max_retries
omit if ci?

assert_send_type "() -> Integer",
TestNet.new, :max_retries
assert_send_type "(Integer) -> void",
TestNet.new, :max_retries=, 10
end

def test_keep_alive_timeout
omit if ci?

assert_send_type "() -> Integer",
TestNet.new, :keep_alive_timeout
end

def test_started_?
omit if ci?

assert_send_type "() -> bool",
TestNet.new, :started?
assert_send_type "() -> bool",
TestNet.new, :active?
end

def test_use_ssl
omit if ci?

assert_send_type "() -> bool",
TestNet.new, :use_ssl?
assert_send_type "(bool) -> void",
TestNet.new, :use_ssl=, true
end

def test_start
omit if ci?

assert_send_type "() { (Net::HTTP) -> untyped } -> untyped",
TestNet.new, :start do |net_http| net_http.class end
assert_send_type "() -> Net::HTTP",
TestNet.new, :start
end

def test_proxy
omit if ci?

assert_send_type "() -> bool",
TestNet.new, :proxy?
assert_send_type "() -> bool",
Expand All @@ -193,8 +165,6 @@ def test_proxy
end

def test_http_verbs
omit if ci?

assert_send_type "(String) -> Net::HTTPResponse",
Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true), :get, '/en'
assert_send_type "(String, Hash[String, String]) -> Net::HTTPResponse",
Expand Down Expand Up @@ -326,8 +296,6 @@ def test_http_verbs
end

def test_request
omit if ci?

assert_send_type "(String, String) -> Net::HTTPResponse",
Net::HTTP.start('reqres.in', 443, use_ssl: true), :send_request, 'GET', 'api/users'
assert_send_type "(String, String, String, Hash[String, String]) -> Net::HTTPResponse",
Expand All @@ -346,15 +314,11 @@ class TestHTTPRequest < Test::Unit::TestCase
testing "::Net::HTTPRequest"

def test_inspect
omit if ci?

assert_send_type "() -> String",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :inspect
end

def test_attr_readers
omit if ci?

assert_send_type "() -> String",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :method
assert_send_type "() -> String",
Expand All @@ -366,8 +330,6 @@ def test_attr_readers
end

def test_body
omit if ci?

assert_send_type "() -> bool",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :request_body_permitted?
assert_send_type "() -> bool",
Expand All @@ -385,8 +347,6 @@ def test_body
end

def test_manipulation_of_headers
omit if ci?

assert_send_type "(String) -> nil",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :[], "Content-Type"
assert_send_type "(String, untyped) -> void",
Expand Down Expand Up @@ -460,8 +420,6 @@ def test_manipulation_of_headers
end

def test_iteration_on_headers
omit if ci?

assert_send_type "() { (String, String) -> untyped } -> Hash[String, Array[String]]",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :each_header do |str, array| "#{str} #{array}" end
assert_send_type "() -> Enumerator[[String, String], Hash[String, Array[String]]]",
Expand Down Expand Up @@ -520,8 +478,6 @@ def self.success
end

def test_attr_readers
omit if ci?

assert_send_type "() -> String",
Foo.success, :http_version
assert_send_type "() -> String",
Expand All @@ -537,8 +493,6 @@ def test_attr_readers
end

def test_manipulation_function
omit if ci?

assert_send_type "() -> String",
Foo.success, :inspect
assert_send_type "() -> untyped",
Expand Down
9 changes: 5 additions & 4 deletions test/stdlib/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
require "tmpdir"
require "stringio"
require "tempfile"
require_relative "../test_skip"

class Test::Unit::TestCase
prepend TestSkip
end

module Spy
def self.wrap(object, method_name)
Expand Down Expand Up @@ -375,10 +380,6 @@ def method_types(method)
end
end

def ci?
ENV["CI"] == "true"
end

def allows_error(*errors)
yield
rescue *errors => exn
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "tmpdir"
require "stringio"
require "open3"
require "test_skip"

unless ENV["XDG_CACHE_HOME"]
tmpdir = Dir.mktmpdir("rbs-test-")
Expand All @@ -22,6 +23,9 @@
rescue LoadError
end

class Test::Unit::TestCase
prepend TestSkip
end

module TestHelper
def has_gem?(*gems)
Expand Down
52 changes: 52 additions & 0 deletions test/test_skip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Including this module allows `omit` test cases based on an external file, not in the source code
#
# The file contains a list of the names of the test cases to skip:
#
# ```
# test_foo(RBS::UnitTest) # Test case name
# RBS::CLICtest # Test class name
# test_collection_install(CLITest) requires bundler setup # Can have comments
# ```
#
# And start tests with `$RBS_SKIP_TESTS` env var:
#
# ```
# $ RBS_SKIP_TESTS=../rbs_skip_tests rake test
# ```
#
module TestSkip
env = ENV["RBS_SKIP_TESTS"]
SKIP_TESTS_FILE =
if env
Pathname(env)
end

SKIP_TESTS =
if SKIP_TESTS_FILE
SKIP_TESTS_FILE.each_line.with_object({}) do |line, hash|
line.chomp!
line.gsub!(/#.*/, "")
line.strip!

next if line.empty?

name, message = line.split(/\s+/, 2)

hash[name] = message
end
end

if SKIP_TESTS
def setup
super

if SKIP_TESTS.key?(name) || SKIP_TESTS.key?(self.class.name)
if message = SKIP_TESTS[name] || SKIP_TESTS[self.class.name]
omit "Skip test by RBS_SKIP_TESTS(#{SKIP_TESTS_FILE}): #{message}"
else
omit "Skip test by RBS_SKIP_TESTS(#{SKIP_TESTS_FILE})"
end
end
end
end
end