From 6047eada20d39bbe80976c31277ec7916118f78a Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:19:56 +0200 Subject: [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 --- test/prism/errors/3.3-3.3/circular_parameters.txt | 12 ++++++++ test/prism/errors/3.3-3.4/leading_logical.txt | 34 ++++++++++++++++++++++ .../errors/3.3-3.4/private_endless_method.txt | 3 ++ .../errors/3.4/block_args_in_array_assignment.txt | 3 ++ .../3.4/dont_allow_return_inside_sclass_body.txt | 3 ++ .../errors/3.4/it_with_ordinary_parameter.txt | 3 ++ .../3.4/keyword_args_in_array_assignment.txt | 3 ++ .../errors/block_args_in_array_assignment.txt | 3 -- .../dont_allow_return_inside_sclass_body.txt | 3 -- test/prism/errors/it_with_ordinary_parameter.txt | 3 -- .../errors/keyword_args_in_array_assignment.txt | 3 -- 11 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 test/prism/errors/3.3-3.3/circular_parameters.txt create mode 100644 test/prism/errors/3.3-3.4/leading_logical.txt create mode 100644 test/prism/errors/3.3-3.4/private_endless_method.txt create mode 100644 test/prism/errors/3.4/block_args_in_array_assignment.txt create mode 100644 test/prism/errors/3.4/dont_allow_return_inside_sclass_body.txt create mode 100644 test/prism/errors/3.4/it_with_ordinary_parameter.txt create mode 100644 test/prism/errors/3.4/keyword_args_in_array_assignment.txt delete mode 100644 test/prism/errors/block_args_in_array_assignment.txt delete mode 100644 test/prism/errors/dont_allow_return_inside_sclass_body.txt delete mode 100644 test/prism/errors/it_with_ordinary_parameter.txt delete mode 100644 test/prism/errors/keyword_args_in_array_assignment.txt (limited to 'test/prism/errors') diff --git a/test/prism/errors/3.3-3.3/circular_parameters.txt b/test/prism/errors/3.3-3.3/circular_parameters.txt new file mode 100644 index 0000000000..ef9642b075 --- /dev/null +++ b/test/prism/errors/3.3-3.3/circular_parameters.txt @@ -0,0 +1,12 @@ +def foo(bar = bar) = 42 + ^~~ circular argument reference - bar + +def foo(bar: bar) = 42 + ^~~ circular argument reference - bar + +proc { |foo = foo| } + ^~~ circular argument reference - foo + +proc { |foo: foo| } + ^~~ circular argument reference - foo + diff --git a/test/prism/errors/3.3-3.4/leading_logical.txt b/test/prism/errors/3.3-3.4/leading_logical.txt new file mode 100644 index 0000000000..2a702e281d --- /dev/null +++ b/test/prism/errors/3.3-3.4/leading_logical.txt @@ -0,0 +1,34 @@ +1 +&& 2 +^~ unexpected '&&', ignoring it +&& 3 +^~ unexpected '&&', ignoring it + +1 +|| 2 +^ unexpected '|', ignoring it + ^ unexpected '|', ignoring it +|| 3 +^ unexpected '|', ignoring it + ^ unexpected '|', ignoring it + +1 +and 2 +^~~ unexpected 'and', ignoring it +and 3 +^~~ unexpected 'and', ignoring it + +1 +or 2 +^~ unexpected 'or', ignoring it +or 3 +^~ unexpected 'or', ignoring it + +1 +and foo +^~~ unexpected 'and', ignoring it + +2 +or foo +^~ unexpected 'or', ignoring it + diff --git a/test/prism/errors/3.3-3.4/private_endless_method.txt b/test/prism/errors/3.3-3.4/private_endless_method.txt new file mode 100644 index 0000000000..8aae5e0cd3 --- /dev/null +++ b/test/prism/errors/3.3-3.4/private_endless_method.txt @@ -0,0 +1,3 @@ +private def foo = puts "Hello" + ^ unexpected string literal, expecting end-of-input + diff --git a/test/prism/errors/3.4/block_args_in_array_assignment.txt b/test/prism/errors/3.4/block_args_in_array_assignment.txt new file mode 100644 index 0000000000..71dca8452b --- /dev/null +++ b/test/prism/errors/3.4/block_args_in_array_assignment.txt @@ -0,0 +1,3 @@ +matrix[5, &block] = 8 + ^~~~~~ unexpected block arg given in index assignment; blocks are not allowed in index assignment expressions + diff --git a/test/prism/errors/3.4/dont_allow_return_inside_sclass_body.txt b/test/prism/errors/3.4/dont_allow_return_inside_sclass_body.txt new file mode 100644 index 0000000000..c29fe01728 --- /dev/null +++ b/test/prism/errors/3.4/dont_allow_return_inside_sclass_body.txt @@ -0,0 +1,3 @@ +class << A; return; end + ^~~~~~ Invalid return in class/module body + diff --git a/test/prism/errors/3.4/it_with_ordinary_parameter.txt b/test/prism/errors/3.4/it_with_ordinary_parameter.txt new file mode 100644 index 0000000000..ff9c4276ca --- /dev/null +++ b/test/prism/errors/3.4/it_with_ordinary_parameter.txt @@ -0,0 +1,3 @@ +proc { || it } + ^~ 'it' is not allowed when an ordinary parameter is defined + diff --git a/test/prism/errors/3.4/keyword_args_in_array_assignment.txt b/test/prism/errors/3.4/keyword_args_in_array_assignment.txt new file mode 100644 index 0000000000..e379ec0ef4 --- /dev/null +++ b/test/prism/errors/3.4/keyword_args_in_array_assignment.txt @@ -0,0 +1,3 @@ +matrix[5, axis: :y] = 8 + ^~~~~~~~ unexpected keyword arg given in index assignment; keywords are not allowed in index assignment expressions + diff --git a/test/prism/errors/block_args_in_array_assignment.txt b/test/prism/errors/block_args_in_array_assignment.txt deleted file mode 100644 index 71dca8452b..0000000000 --- a/test/prism/errors/block_args_in_array_assignment.txt +++ /dev/null @@ -1,3 +0,0 @@ -matrix[5, &block] = 8 - ^~~~~~ unexpected block arg given in index assignment; blocks are not allowed in index assignment expressions - diff --git a/test/prism/errors/dont_allow_return_inside_sclass_body.txt b/test/prism/errors/dont_allow_return_inside_sclass_body.txt deleted file mode 100644 index c29fe01728..0000000000 --- a/test/prism/errors/dont_allow_return_inside_sclass_body.txt +++ /dev/null @@ -1,3 +0,0 @@ -class << A; return; end - ^~~~~~ Invalid return in class/module body - diff --git a/test/prism/errors/it_with_ordinary_parameter.txt b/test/prism/errors/it_with_ordinary_parameter.txt deleted file mode 100644 index ff9c4276ca..0000000000 --- a/test/prism/errors/it_with_ordinary_parameter.txt +++ /dev/null @@ -1,3 +0,0 @@ -proc { || it } - ^~ 'it' is not allowed when an ordinary parameter is defined - diff --git a/test/prism/errors/keyword_args_in_array_assignment.txt b/test/prism/errors/keyword_args_in_array_assignment.txt deleted file mode 100644 index e379ec0ef4..0000000000 --- a/test/prism/errors/keyword_args_in_array_assignment.txt +++ /dev/null @@ -1,3 +0,0 @@ -matrix[5, axis: :y] = 8 - ^~~~~~~~ unexpected keyword arg given in index assignment; keywords are not allowed in index assignment expressions - -- cgit v1.2.3