Skip to content

Commit de69fb4

Browse files
committed
Merge pull request #1167 from ruby/test_skip
Add TestSkip module to skip tests that fails in ruby CI
1 parent ac42e4c commit de69fb4

File tree

5 files changed

+61
-60
lines changed

5 files changed

+61
-60
lines changed

test/rbs/cli_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ def with_cli
4545
@stderr = nil
4646
end
4747

48-
def bundler?
49-
ENV.key?("BUNDLE_GEMFILE")
50-
end
51-
5248
def test_ast
5349
with_cli do |cli|
5450
cli.run(%w(-r set ast))
@@ -542,8 +538,6 @@ def foo: () -> void
542538
end
543539

544540
def test_collection_install
545-
omit unless bundler?
546-
547541
Dir.mktmpdir do |dir|
548542
Dir.chdir(dir) do
549543
dir = Pathname(dir)
@@ -597,8 +591,6 @@ def test_collection_install
597591
end
598592

599593
def test_collection_install_frozen
600-
omit unless bundler?
601-
602594
Dir.mktmpdir do |dir|
603595
Dir.chdir(dir) do
604596
dir = Pathname(dir)
@@ -630,8 +622,6 @@ def test_collection_install_frozen
630622
end
631623

632624
def test_collection_update
633-
omit unless bundler?
634-
635625
Dir.mktmpdir do |dir|
636626
Dir.chdir(dir) do
637627
dir = Pathname(dir)

test/stdlib/Net_HTTP_test.rb

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class NetSingletonTest < Test::Unit::TestCase
99
testing "singleton(::Net::HTTP)"
1010

1111
def test_get
12-
omit if ci?
13-
1412
$stdout = StringIO.new
1513
assert_send_type "(URI::Generic) -> nil",
1614
Net::HTTP, :get_print, URI("https://www.ruby-lang.org")
@@ -35,17 +33,13 @@ def test_get
3533
end
3634

3735
def test_post
38-
omit if ci?
39-
4036
assert_send_type "(URI, String, Hash[String, String]) -> Net::HTTPResponse",
4137
Net::HTTP, :post, URI('http://www.example.com/api/search'), { "q" => "ruby", "max" => "50" }.to_json, "Content-Type" => "application/json"
4238
assert_send_type "(URI, Hash[String, Symbol]) -> Net::HTTPResponse",
4339
Net::HTTP, :post_form, URI('http://www.example.com/api/search'), { "q" => :ruby, "max" => :max }
4440
end
4541

4642
def test_new
47-
omit if ci?
48-
4943
assert_send_type "(String, Integer, nil, nil, nil, nil, nil) -> Net::HTTP",
5044
Net::HTTP, :new, 'www.ruby-lang.org', 80, nil, nil, nil, nil, nil
5145
end
@@ -64,114 +58,92 @@ def self.new
6458
end
6559

6660
def test_inspect
67-
omit if ci?
68-
6961
assert_send_type "() -> String",
7062
TestNet.new, :inspect
7163
end
7264

7365
def test_set_debug_output
74-
omit if ci?
7566
assert_send_type "(IO) -> void",
7667
TestNet.new, :set_debug_output, $stderr
7768
end
7869

7970
def test_address
80-
omit if ci?
8171
assert_send_type "() -> String",
8272
TestNet.new, :address
8373
end
8474

8575
def test_port
86-
omit if ci?
8776
assert_send_type "() -> Integer",
8877
TestNet.new, :port
8978
end
9079

9180
def test_ipaddr
92-
omit if ci?
9381
assert_send_type "() -> nil",
9482
TestNet.new, :ipaddr
9583
assert_send_type "(String) -> void",
9684
TestNet.new, :ipaddr=, ('127.0.0.1')
9785
end
9886

9987
def test_open_timeout
100-
omit if ci?
10188
assert_send_type "() -> Integer",
10289
TestNet.new, :open_timeout
10390
end
10491

10592
def test_read_timeout
106-
omit if ci?
10793
assert_send_type "() -> Integer",
10894
TestNet.new, :read_timeout
10995
assert_send_type "(Integer) -> void",
11096
TestNet.new, :read_timeout=, 10
11197
end
11298

11399
def test_write_timeout
114-
omit if ci?
115100
assert_send_type "() -> Integer",
116101
TestNet.new, :write_timeout
117102
assert_send_type "(Integer) -> void",
118103
TestNet.new, :write_timeout=, 10
119104
end
120105

121106
def test_continue_timeout
122-
omit if ci?
123107
assert_send_type "() -> nil",
124108
TestNet.new, :continue_timeout
125109
assert_send_type "(Integer) -> void",
126110
TestNet.new, :continue_timeout=, 10
127111
end
128112

129113
def test_max_retries
130-
omit if ci?
131-
132114
assert_send_type "() -> Integer",
133115
TestNet.new, :max_retries
134116
assert_send_type "(Integer) -> void",
135117
TestNet.new, :max_retries=, 10
136118
end
137119

138120
def test_keep_alive_timeout
139-
omit if ci?
140-
141121
assert_send_type "() -> Integer",
142122
TestNet.new, :keep_alive_timeout
143123
end
144124

145125
def test_started_?
146-
omit if ci?
147-
148126
assert_send_type "() -> bool",
149127
TestNet.new, :started?
150128
assert_send_type "() -> bool",
151129
TestNet.new, :active?
152130
end
153131

154132
def test_use_ssl
155-
omit if ci?
156-
157133
assert_send_type "() -> bool",
158134
TestNet.new, :use_ssl?
159135
assert_send_type "(bool) -> void",
160136
TestNet.new, :use_ssl=, true
161137
end
162138

163139
def test_start
164-
omit if ci?
165-
166140
assert_send_type "() { (Net::HTTP) -> untyped } -> untyped",
167141
TestNet.new, :start do |net_http| net_http.class end
168142
assert_send_type "() -> Net::HTTP",
169143
TestNet.new, :start
170144
end
171145

172146
def test_proxy
173-
omit if ci?
174-
175147
assert_send_type "() -> bool",
176148
TestNet.new, :proxy?
177149
assert_send_type "() -> bool",
@@ -193,8 +165,6 @@ def test_proxy
193165
end
194166

195167
def test_http_verbs
196-
omit if ci?
197-
198168
assert_send_type "(String) -> Net::HTTPResponse",
199169
Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true), :get, '/en'
200170
assert_send_type "(String, Hash[String, String]) -> Net::HTTPResponse",
@@ -326,8 +296,6 @@ def test_http_verbs
326296
end
327297

328298
def test_request
329-
omit if ci?
330-
331299
assert_send_type "(String, String) -> Net::HTTPResponse",
332300
Net::HTTP.start('reqres.in', 443, use_ssl: true), :send_request, 'GET', 'api/users'
333301
assert_send_type "(String, String, String, Hash[String, String]) -> Net::HTTPResponse",
@@ -346,15 +314,11 @@ class TestHTTPRequest < Test::Unit::TestCase
346314
testing "::Net::HTTPRequest"
347315

348316
def test_inspect
349-
omit if ci?
350-
351317
assert_send_type "() -> String",
352318
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :inspect
353319
end
354320

355321
def test_attr_readers
356-
omit if ci?
357-
358322
assert_send_type "() -> String",
359323
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :method
360324
assert_send_type "() -> String",
@@ -366,8 +330,6 @@ def test_attr_readers
366330
end
367331

368332
def test_body
369-
omit if ci?
370-
371333
assert_send_type "() -> bool",
372334
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :request_body_permitted?
373335
assert_send_type "() -> bool",
@@ -385,8 +347,6 @@ def test_body
385347
end
386348

387349
def test_manipulation_of_headers
388-
omit if ci?
389-
390350
assert_send_type "(String) -> nil",
391351
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :[], "Content-Type"
392352
assert_send_type "(String, untyped) -> void",
@@ -460,8 +420,6 @@ def test_manipulation_of_headers
460420
end
461421

462422
def test_iteration_on_headers
463-
omit if ci?
464-
465423
assert_send_type "() { (String, String) -> untyped } -> Hash[String, Array[String]]",
466424
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :each_header do |str, array| "#{str} #{array}" end
467425
assert_send_type "() -> Enumerator[[String, String], Hash[String, Array[String]]]",
@@ -520,8 +478,6 @@ def self.success
520478
end
521479

522480
def test_attr_readers
523-
omit if ci?
524-
525481
assert_send_type "() -> String",
526482
Foo.success, :http_version
527483
assert_send_type "() -> String",
@@ -537,8 +493,6 @@ def test_attr_readers
537493
end
538494

539495
def test_manipulation_function
540-
omit if ci?
541-
542496
assert_send_type "() -> String",
543497
Foo.success, :inspect
544498
assert_send_type "() -> untyped",

test/stdlib/test_helper.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
require "tmpdir"
55
require "stringio"
66
require "tempfile"
7+
require_relative "../test_skip"
8+
9+
class Test::Unit::TestCase
10+
prepend TestSkip
11+
end
712

813
module Spy
914
def self.wrap(object, method_name)
@@ -375,10 +380,6 @@ def method_types(method)
375380
end
376381
end
377382

378-
def ci?
379-
ENV["CI"] == "true"
380-
end
381-
382383
def allows_error(*errors)
383384
yield
384385
rescue *errors => exn

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require "tmpdir"
55
require "stringio"
66
require "open3"
7+
require "test_skip"
78

89
unless ENV["XDG_CACHE_HOME"]
910
tmpdir = Dir.mktmpdir("rbs-test-")
@@ -22,6 +23,9 @@
2223
rescue LoadError
2324
end
2425

26+
class Test::Unit::TestCase
27+
prepend TestSkip
28+
end
2529

2630
module TestHelper
2731
def has_gem?(*gems)

test/test_skip.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Including this module allows `omit` test cases based on an external file, not in the source code
2+
#
3+
# The file contains a list of the names of the test cases to skip:
4+
#
5+
# ```
6+
# test_foo(RBS::UnitTest) # Test case name
7+
# RBS::CLICtest # Test class name
8+
# test_collection_install(CLITest) requires bundler setup # Can have comments
9+
# ```
10+
#
11+
# And start tests with `$RBS_SKIP_TESTS` env var:
12+
#
13+
# ```
14+
# $ RBS_SKIP_TESTS=../rbs_skip_tests rake test
15+
# ```
16+
#
17+
module TestSkip
18+
env = ENV["RBS_SKIP_TESTS"]
19+
SKIP_TESTS_FILE =
20+
if env
21+
Pathname(env)
22+
end
23+
24+
SKIP_TESTS =
25+
if SKIP_TESTS_FILE
26+
SKIP_TESTS_FILE.each_line.with_object({}) do |line, hash|
27+
line.chomp!
28+
line.gsub!(/#.*/, "")
29+
line.strip!
30+
31+
next if line.empty?
32+
33+
name, message = line.split(/\s+/, 2)
34+
35+
hash[name] = message
36+
end
37+
end
38+
39+
if SKIP_TESTS
40+
def setup
41+
super
42+
43+
if SKIP_TESTS.key?(name) || SKIP_TESTS.key?(self.class.name)
44+
if message = SKIP_TESTS[name] || SKIP_TESTS[self.class.name]
45+
omit "Skip test by RBS_SKIP_TESTS(#{SKIP_TESTS_FILE}): #{message}"
46+
else
47+
omit "Skip test by RBS_SKIP_TESTS(#{SKIP_TESTS_FILE})"
48+
end
49+
end
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)