summaryrefslogtreecommitdiff
path: root/test/prism/ruby
diff options
context:
space:
mode:
authorEarlopain <14981592+Earlopain@users.noreply.github.com>2025-10-17 16:19:56 +0200
committergit <svn-admin@ruby-lang.org>2025-10-22 14:50:11 +0000
commit6047eada20d39bbe80976c31277ec7916118f78a (patch)
tree0c2d25b98d2cc9180ac89d5b2065796860deea14 /test/prism/ruby
parent66c12bd5194396fab66338a87ca8f2d89f1d66d0 (diff)
[ruby/prism] Make error and snapshot tests multi-version aware
This one has been on my mind for a while now. Currently, there are only tests against the latest syntax version. This changes the snapshot structure as follows: * Snapshots at their current location are tested against all syntax versions * Snapshots inside a version folder like "3.3" are tested against all versions starting from that version * Snapshots inside a version folder like "3.3-4.2" are tested against all versions in the given range. This makes sure that as new syntax is added, older versions still work as expected. I also added a few tests for now valid syntax that should be invalid in older versions (and the other way around as well) These tests run really fast. So even though it does 3x the work for these, I am still able to run the whole test suite in just 11 seconds. https://github.com/ruby/prism/commit/5191b1aa68
Diffstat (limited to 'test/prism/ruby')
-rw-r--r--test/prism/ruby/parser_test.rb13
-rw-r--r--test/prism/ruby/ripper_test.rb12
-rw-r--r--test/prism/ruby/ruby_parser_test.rb12
3 files changed, 27 insertions, 10 deletions
diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb
index 10b5fca5ea..016fda91f0 100644
--- a/test/prism/ruby/parser_test.rb
+++ b/test/prism/ruby/parser_test.rb
@@ -65,11 +65,14 @@ module Prism
# 1.. && 2
"ranges.txt",
+ # https://bugs.ruby-lang.org/issues/20478
+ "3.4/circular_parameters.txt",
+
# Cannot yet handling leading logical operators.
- "leading_logical.txt",
+ "3.5/leading_logical.txt",
# Ruby >= 3.5 specific syntax
- "endless_methods_command_call.txt",
+ "3.5/endless_methods_command_call.txt",
# https://bugs.ruby-lang.org/issues/21168#note-5
"command_method_call_2.txt",
@@ -165,9 +168,9 @@ module Prism
if RUBY_VERSION >= "3.3"
def test_current_parser_for_current_ruby
- major, minor, _patch = Gem::Version.new(RUBY_VERSION).segments
+ major, minor = current_major_minor.split(".")
# Let's just hope there never is a Ruby 3.10 or similar
- expected = major * 10 + minor
+ expected = major.to_i * 10 + minor.to_i
assert_equal(expected, Translation::ParserCurrent.new.version)
end
end
@@ -189,7 +192,7 @@ module Prism
end
def test_it_block_parameter_syntax
- it_fixture_path = Pathname(__dir__).join("../../../test/prism/fixtures/it.txt")
+ it_fixture_path = Pathname(__dir__).join("../../../test/prism/fixtures/3.4/it.txt")
buffer = Parser::Source::Buffer.new(it_fixture_path)
buffer.source = it_fixture_path.read
diff --git a/test/prism/ruby/ripper_test.rb b/test/prism/ruby/ripper_test.rb
index 4916ec8d9d..12c854aea6 100644
--- a/test/prism/ruby/ripper_test.rb
+++ b/test/prism/ruby/ripper_test.rb
@@ -9,7 +9,7 @@ module Prism
# Skip these tests that Ripper is reporting the wrong results for.
incorrect = [
# Not yet supported.
- "leading_logical.txt",
+ "3.5/leading_logical.txt",
# Ripper incorrectly attributes the block to the keyword.
"seattlerb/block_break.txt",
@@ -31,8 +31,16 @@ module Prism
# Ripper fails to understand some structures that span across heredocs.
"spanning_heredoc.txt",
+ "3.3-3.3/block_args_in_array_assignment.txt",
+ "3.3-3.3/it_with_ordinary_parameter.txt",
+ "3.3-3.3/keyword_args_in_array_assignment.txt",
+ "3.3-3.3/return_in_sclass.txt",
+
+ # https://bugs.ruby-lang.org/issues/20478
+ "3.4/circular_parameters.txt",
+
# https://bugs.ruby-lang.org/issues/17398#note-12
- "endless_methods_command_call.txt",
+ "3.5/endless_methods_command_call.txt",
# https://bugs.ruby-lang.org/issues/21168#note-5
"command_method_call_2.txt",
diff --git a/test/prism/ruby/ruby_parser_test.rb b/test/prism/ruby/ruby_parser_test.rb
index ec55e41967..7640ddaf1c 100644
--- a/test/prism/ruby/ruby_parser_test.rb
+++ b/test/prism/ruby/ruby_parser_test.rb
@@ -39,7 +39,6 @@ module Prism
"dos_endings.txt",
"heredocs_with_fake_newlines.txt",
"heredocs_with_ignored_newlines.txt",
- "leading_logical.txt",
"method_calls.txt",
"methods.txt",
"multi_write.txt",
@@ -77,8 +76,15 @@ module Prism
"whitequark/ruby_bug_19281.txt",
"whitequark/slash_newline_in_heredocs.txt",
- # Ruby >= 3.5 specific syntax
- "endless_methods_command_call.txt",
+ "3.3-3.3/block_args_in_array_assignment.txt",
+ "3.3-3.3/it_with_ordinary_parameter.txt",
+ "3.3-3.3/keyword_args_in_array_assignment.txt",
+ "3.3-3.3/return_in_sclass.txt",
+
+ "3.4/circular_parameters.txt",
+
+ "3.5/endless_methods_command_call.txt",
+ "3.5/leading_logical.txt",
# https://bugs.ruby-lang.org/issues/21168#note-5
"command_method_call_2.txt",