diff options
| author | Mike Dalessio <mike.dalessio@gmail.com> | 2023-08-25 16:04:55 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-08-28 12:37:28 +0000 |
| commit | 06f5d8f3a04e147fd757f2ed15882592bb66e3a9 (patch) | |
| tree | e4bc7fb35b90f06078b15210e2dcd89cb500e9d9 | |
| parent | 00439dbdb4909f0c78b37f6ed1e3f88c4cb05d46 (diff) | |
[ruby/yarp] Improve how we declare ripper exceptions in parse_test.rb
Specific files are named earlier in the block, and we now have the
ability to skip just the lex matching, or skip ripper entirely (for
files that don't parse).
https://github.com/ruby/yarp/commit/dcd3806dca
| -rw-r--r-- | test/yarp/parse_test.rb | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/test/yarp/parse_test.rb b/test/yarp/parse_test.rb index b9f852abf9..70f061242b 100644 --- a/test/yarp/parse_test.rb +++ b/test/yarp/parse_test.rb @@ -46,7 +46,7 @@ class ParseTest < Test::Unit::TestCase # To accurately compare against Ripper, we need to make sure that we're # running on Ruby 3.2+. - check_ripper = RUBY_VERSION >= "3.2.0" + ripper_enabled = RUBY_VERSION >= "3.2.0" # The FOCUS environment variable allows you to specify one particular fixture # to test, instead of all of them. @@ -63,6 +63,22 @@ class ParseTest < Test::Unit::TestCase directory = File.dirname(snapshot) FileUtils.mkdir_p(directory) unless File.directory?(directory) + ripper_should_parse = ripper_should_match = ripper_enabled + + # This file has changed behavior in Ripper in Ruby 3.3, so we skip it if + # we're on an earlier version. + ripper_should_match = false if relative == "seattlerb/pct_w_heredoc_interp_nested.txt" && RUBY_VERSION < "3.3.0" + + # It seems like there are some oddities with nested heredocs and ripper. + # Waiting for feedback on https://bugs.ruby-lang.org/issues/19838. + ripper_should_match = false if relative == "seattlerb/heredoc_nested.txt" + + # Ripper seems to have a bug that the regex portions before and after the heredoc are combined + # into a single token. See https://bugs.ruby-lang.org/issues/19838. + # + # Additionally, Ripper cannot parse the %w[] fixture in this file, so set ripper_should_parse to false. + ripper_should_match = false if relative == "wrapping_heredoc.txt" + define_method "test_filepath_#{relative}" do # First, read the source from the filepath. Use binmode to avoid converting CRLF on Windows, # and explicitly set the external encoding to UTF-8 to override the binmode default. @@ -70,7 +86,7 @@ class ParseTest < Test::Unit::TestCase # Make sure that it can be correctly parsed by Ripper. If it can't, then we have a fixture # that is invalid Ruby. - refute_nil Ripper.sexp_raw(source) if check_ripper + refute_nil(Ripper.sexp_raw(source), "Ripper failed to parse") if ripper_should_parse # Next, assert that there were no errors during parsing. result = YARP.parse(source, relative) @@ -118,25 +134,13 @@ class ParseTest < Test::Unit::TestCase assert_equal expected_newlines, YARP.const_get(:Debug).newlines(source) - # This file has changed behavior in Ripper in Ruby 3.3, so we skip it if - # we're on an earlier version. - return if relative == "seattlerb/pct_w_heredoc_interp_nested.txt" && RUBY_VERSION < "3.3.0" - - # It seems like there are some oddities with nested heredocs and ripper. - # Waiting for feedback on https://bugs.ruby-lang.org/issues/19838. - return if relative == "seattlerb/heredoc_nested.txt" - - # Ripper seems to have a bug that the regex portions before and after the heredoc are combined - # into a single token. - return if relative == "wrapping_heredoc.txt" - - # Finally, assert that we can lex the source and get the same tokens as - # Ripper. - lex_result = YARP.lex_compat(source) - assert_equal [], lex_result.errors - tokens = lex_result.value + if ripper_should_parse && ripper_should_match + # Finally, assert that we can lex the source and get the same tokens as + # Ripper. + lex_result = YARP.lex_compat(source) + assert_equal [], lex_result.errors + tokens = lex_result.value - if check_ripper begin YARP.lex_ripper(source).zip(tokens).each do |(ripper, yarp)| assert_equal ripper, yarp |
