Skip to content

Commit 1f198ea

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 1f198ea

File tree

7 files changed

+37
-82
lines changed

7 files changed

+37
-82
lines changed

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 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/locals_test.rb

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
# in comparing the locals because they will be the same.
1414
return if RubyVM::InstructionSequence.compile("").to_a[4][:parser] == :prism
1515

16-
# In Ruby 3.4.0, the local table for method forwarding changed. But 3.4.0 can
17-
# refer to the dev version, so while 3.4.0 still isn't released, we need to
18-
# check if we have a high enough revision.
19-
return if RubyVM::InstructionSequence.compile("def foo(...); end").to_a[13][2][2][10].length != 1
20-
2116
# Omit tests if running on a 32-bit machine because there is a bug with how
2217
# Ruby is handling large ISeqs on 32-bit machines
2318
return if RUBY_PLATFORM =~ /i686/
@@ -31,19 +26,11 @@ class LocalsTest < TestCase
3126
# CRuby is eliminating dead code.
3227
"whitequark/ruby_bug_10653.txt",
3328

34-
# Valid only on Ruby 3.3
35-
"3.3-3.3/block_args_in_array_assignment.txt",
36-
"3.3-3.3/it_with_ordinary_parameter.txt",
37-
"3.3-3.3/keyword_args_in_array_assignment.txt",
38-
"3.3-3.3/return_in_sclass.txt",
39-
40-
# Leaving these out until they are supported by parse.y.
41-
"4.0/leading_logical.txt",
42-
"4.0/endless_methods_command_call.txt",
43-
"command_method_call_2.txt"
29+
# https://bugs.ruby-lang.org/issues/21168#note-5
30+
"command_method_call_2.txt",
4431
]
4532

46-
Fixture.each(except: except) do |fixture|
33+
Fixture.each_for_current_ruby(except: except) do |fixture|
4734
define_method(fixture.test_name) { assert_locals(fixture) }
4835
end
4936

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 = 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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ def self.each(except: [], &block)
7272
paths.each { |path| yield Fixture.new(path) }
7373
end
7474

75+
def self.each_for_current_ruby(except: [], &block)
76+
each(except: except) do |fixture|
77+
next unless TestCase.ruby_versions_for(fixture.path).include?(CURRENT_MAJOR_MINOR)
78+
yield fixture
79+
end
80+
end
81+
7582
def self.each_with_version(except: [], &block)
7683
each(except: except) do |fixture|
7784
TestCase.ruby_versions_for(fixture.path).each do |version|
@@ -232,6 +239,9 @@ def self.windows?
232239
# All versions that prism can parse
233240
SYNTAX_VERSIONS = %w[3.3 3.4 4.0]
234241

242+
# `RUBY_VERSION` with the patch version excluded
243+
CURRENT_MAJOR_MINOR = RUBY_VERSION.split(".")[0, 2].join(".")
244+
235245
# Returns an array of ruby versions that a given filepath should test against:
236246
# test.txt # => all available versions
237247
# 3.4/test.txt # => versions since 3.4 (inclusive)
@@ -250,13 +260,9 @@ def self.ruby_versions_for(filepath)
250260
end
251261
end
252262

253-
def current_major_minor
254-
RUBY_VERSION.split(".")[0, 2].join(".")
255-
end
256-
257263
if RUBY_VERSION >= "3.3.0"
258264
def test_all_syntax_versions_present
259-
assert_include(SYNTAX_VERSIONS, current_major_minor)
265+
assert_include(SYNTAX_VERSIONS, CURRENT_MAJOR_MINOR)
260266
end
261267
end
262268

0 commit comments

Comments
 (0)