Skip to content

Commit b66c79c

Browse files
committed
Clean up test excludes
Mostly not having to list version-specific excludes when testing against ripper/parse.y I also removed excludes that have since been implemented by parse.y
1 parent 86406f6 commit b66c79c

6 files changed

Lines changed: 37 additions & 66 deletions

File tree

test/prism/errors_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def assert_errors(filepath, version)
8888
expected = File.read(filepath, binmode: true, external_encoding: Encoding::UTF_8)
8989

9090
source = expected.lines.grep_v(/^\s*\^/).join.gsub(/\n*\z/, "")
91-
refute_valid_syntax(source) if current_major_minor == version
91+
refute_valid_syntax(source) if TestCase::CURRENT_MAJOR_MINOR == version
9292

9393
result = Prism.parse(source, version: version)
9494
errors = result.errors

test/prism/fixtures_test.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,9 @@ class FixturesTest < TestCase
2424
except << "whitequark/ruby_bug_19281.txt"
2525
end
2626

27-
if RUBY_VERSION < "3.4.0"
28-
except << "3.4/circular_parameters.txt"
29-
end
30-
31-
# Valid only on Ruby 3.3
32-
except << "3.3-3.3/block_args_in_array_assignment.txt"
33-
except << "3.3-3.3/it_with_ordinary_parameter.txt"
34-
except << "3.3-3.3/keyword_args_in_array_assignment.txt"
35-
except << "3.3-3.3/return_in_sclass.txt"
36-
37-
# Leaving these out until they are supported by parse.y.
38-
except << "4.0/leading_logical.txt"
39-
except << "4.0/endless_methods_command_call.txt"
40-
# https://bugs.ruby-lang.org/issues/21168#note-5
4127
except << "command_method_call_2.txt"
4228

43-
Fixture.each(except: except) do |fixture|
29+
Fixture.each_for_current_ruby(except: except) do |fixture|
4430
define_method(fixture.test_name) { assert_valid_syntax(fixture.read) }
4531
end
4632
end

test/prism/lex_test.rb

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
77
module Prism
88
class LexTest < TestCase
99
except = [
10-
# It seems like there are some oddities with nested heredocs and ripper.
11-
# Waiting for feedback on https://bugs.ruby-lang.org/issues/19838.
12-
"seattlerb/heredoc_nested.txt",
13-
"whitequark/dedenting_heredoc.txt",
14-
# Ripper seems to have a bug that the regex portions before and after
15-
# the heredoc are combined into a single token. See
16-
# https://bugs.ruby-lang.org/issues/19838.
10+
# https://bugs.ruby-lang.org/issues/21756
1711
"spanning_heredoc.txt",
18-
"spanning_heredoc_newlines.txt",
19-
# Prism emits a single :on_tstring_content in <<- style heredocs when there
20-
# is a line continuation preceded by escaped backslashes. It should emit two, same
21-
# as if the backslashes are not present.
12+
# Prism emits a single string in some cases when ripper splits them up
13+
"whitequark/dedenting_heredoc.txt",
2214
"heredocs_with_fake_newlines.txt",
15+
# Prism emits BEG for `on_regexp_end`
16+
"spanning_heredoc_newlines.txt",
2317
]
2418

2519
if RUBY_VERSION < "3.3.0"
@@ -42,17 +36,11 @@ class LexTest < TestCase
4236
except << "whitequark/ruby_bug_19281.txt"
4337
end
4438

45-
# https://bugs.ruby-lang.org/issues/20925
46-
except << "4.0/leading_logical.txt"
47-
48-
# https://bugs.ruby-lang.org/issues/17398#note-12
49-
except << "4.0/endless_methods_command_call.txt"
50-
5139
# https://bugs.ruby-lang.org/issues/21168#note-5
5240
except << "command_method_call_2.txt"
5341

54-
Fixture.each_with_version(except: except) do |fixture, version|
55-
define_method(fixture.test_name(version)) { assert_lex(fixture, version) }
42+
Fixture.each_for_current_ruby(except: except) do |fixture|
43+
define_method(fixture.test_name) { assert_lex(fixture) }
5644
end
5745

5846
def test_lex_file
@@ -97,12 +85,10 @@ def test_parse_lex_file
9785

9886
private
9987

100-
def assert_lex(fixture, version)
101-
return unless current_major_minor == version
102-
88+
def assert_lex(fixture)
10389
source = fixture.read
10490

105-
result = Prism.lex_compat(source, version: version)
91+
result = Prism.lex_compat(source, version: "current")
10692
assert_equal [], result.errors
10793

10894
Prism.lex_ripper(source).zip(result.value).each do |(ripper, prism)|

test/prism/ruby/parser_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_non_prism_builder_class_deprecated
171171

172172
if RUBY_VERSION >= "3.3"
173173
def test_current_parser_for_current_ruby
174-
major, minor = current_major_minor.split(".")
174+
major, minor = TestCase::CURRENT_MAJOR_MINOR.split(".")
175175
# Let's just hope there never is a Ruby 3.10 or similar
176176
expected = major.to_i * 10 + minor.to_i
177177
assert_equal(expected, Translation::ParserCurrent.new.version)

test/prism/ruby/ripper_test.rb

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,34 @@ module Prism
88
class RipperTest < TestCase
99
# Skip these tests that Ripper is reporting the wrong results for.
1010
incorrect = [
11-
# Not yet supported.
12-
"4.0/leading_logical.txt",
13-
1411
# Ripper incorrectly attributes the block to the keyword.
15-
"seattlerb/block_break.txt",
16-
"seattlerb/block_next.txt",
1712
"seattlerb/block_return.txt",
18-
"whitequark/break_block.txt",
19-
"whitequark/next_block.txt",
2013
"whitequark/return_block.txt",
2114

22-
# Ripper is not accounting for locals created by patterns using the **
23-
# operator within an `in` clause.
24-
"seattlerb/parse_pattern_058.txt",
25-
2615
# Ripper cannot handle named capture groups in regular expressions.
2716
"regex.txt",
28-
"regex_char_width.txt",
29-
"whitequark/lvar_injecting_match.txt",
3017

3118
# Ripper fails to understand some structures that span across heredocs.
3219
"spanning_heredoc.txt",
3320

34-
"3.3-3.3/block_args_in_array_assignment.txt",
35-
"3.3-3.3/it_with_ordinary_parameter.txt",
36-
"3.3-3.3/keyword_args_in_array_assignment.txt",
37-
"3.3-3.3/return_in_sclass.txt",
38-
39-
# https://bugs.ruby-lang.org/issues/20478
21+
# Ripper interprets circular keyword arguments as method calls.
4022
"3.4/circular_parameters.txt",
4123

42-
# https://bugs.ruby-lang.org/issues/17398#note-12
24+
# Ripper doesn't emit `args_add_block` when endless method is prefixed by modifier.
4325
"4.0/endless_methods_command_call.txt",
4426

4527
# https://bugs.ruby-lang.org/issues/21168#note-5
4628
"command_method_call_2.txt",
4729
]
4830

31+
if RUBY_VERSION.start_with?("3.3.")
32+
incorrect += [
33+
"whitequark/lvar_injecting_match.txt",
34+
"seattlerb/parse_pattern_058.txt",
35+
"regex_char_width.txt",
36+
]
37+
end
38+
4939
# Skip these tests that we haven't implemented yet.
5040
omitted = [
5141
"dos_endings.txt",
@@ -68,7 +58,7 @@ class RipperTest < TestCase
6858
"whitequark/slash_newline_in_heredocs.txt"
6959
]
7060

71-
Fixture.each(except: incorrect | omitted) do |fixture|
61+
Fixture.each_for_current_ruby(except: incorrect | omitted) do |fixture|
7262
define_method(fixture.test_name) { assert_ripper(fixture.read) }
7363
end
7464

test/prism/test_helper.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ def test_name(version = nil)
6666
end
6767
end
6868

69+
# Yields all fixtures.
6970
def self.each(except: [], &block)
7071
glob_pattern = ENV.fetch("FOCUS") { custom_base_path? ? File.join("**", "*.rb") : File.join("**", "*.txt") }
7172
paths = Dir[glob_pattern, base: BASE] - except
7273
paths.each { |path| yield Fixture.new(path) }
7374
end
7475

76+
# Yields all fixtures that are valid for the currently running ruby version.
77+
def self.each_for_current_ruby(except: [], &block)
78+
each(except: except) do |fixture|
79+
next unless TestCase.ruby_versions_for(fixture.path).include?(CURRENT_MAJOR_MINOR)
80+
yield fixture
81+
end
82+
end
83+
84+
# Yields all fixtures, once for each ruby version that they are valid in.
7585
def self.each_with_version(except: [], &block)
7686
each(except: except) do |fixture|
7787
TestCase.ruby_versions_for(fixture.path).each do |version|
@@ -232,6 +242,9 @@ def self.windows?
232242
# All versions that prism can parse
233243
SYNTAX_VERSIONS = %w[3.3 3.4 4.0]
234244

245+
# `RUBY_VERSION` with the patch version excluded
246+
CURRENT_MAJOR_MINOR = RUBY_VERSION.split(".")[0, 2].join(".")
247+
235248
# Returns an array of ruby versions that a given filepath should test against:
236249
# test.txt # => all available versions
237250
# 3.4/test.txt # => versions since 3.4 (inclusive)
@@ -250,13 +263,9 @@ def self.ruby_versions_for(filepath)
250263
end
251264
end
252265

253-
def current_major_minor
254-
RUBY_VERSION.split(".")[0, 2].join(".")
255-
end
256-
257266
if RUBY_VERSION >= "3.3.0"
258267
def test_all_syntax_versions_present
259-
assert_include(SYNTAX_VERSIONS, current_major_minor)
268+
assert_include(SYNTAX_VERSIONS, CURRENT_MAJOR_MINOR)
260269
end
261270
end
262271

0 commit comments

Comments
 (0)