diff options
author | Kevin Newton <[email protected]> | 2024-09-13 11:21:28 -0400 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-09-13 12:51:53 -0400 |
commit | 9afc6a981deae6e23d938cf5c2c4baadfeaafdb1 (patch) | |
tree | 5142d19e6b502057f96ccf2937e91a6808fd7f90 /test/prism/result/warnings_test.rb | |
parent | d42d19059d75bf1c05c1bc916775b47629b59eb7 (diff) |
[PRISM] Only parse shebang on main script
Fixes [Bug #20730]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11617
Diffstat (limited to 'test/prism/result/warnings_test.rb')
-rw-r--r-- | test/prism/result/warnings_test.rb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/test/prism/result/warnings_test.rb b/test/prism/result/warnings_test.rb index 504458e178..fa87295898 100644 --- a/test/prism/result/warnings_test.rb +++ b/test/prism/result/warnings_test.rb @@ -336,23 +336,24 @@ module Prism def test_shebang_ending_with_carriage_return msg = "shebang line ending with \\r may cause problems" - assert_warning(<<~RUBY, msg, compare: false) + assert_warning(<<~RUBY, msg, compare: false, main_script: true) #!ruby\r p(123) RUBY - assert_warning(<<~RUBY, msg, compare: false) + assert_warning(<<~RUBY, msg, compare: false, main_script: true) #!ruby \r p(123) RUBY - assert_warning(<<~RUBY, msg, compare: false) + assert_warning(<<~RUBY, msg, compare: false, main_script: true) #!ruby -Eutf-8\r p(123) RUBY - # Used with the `-x` object, to ignore the script up until the first shebang that mentioned "ruby". - assert_warning(<<~SCRIPT, msg, compare: false) + # Used with the `-x` object, to ignore the script up until the first + # shebang that mentioned "ruby". + assert_warning(<<~SCRIPT, msg, compare: false, main_script: true) #!/usr/bin/env bash # Some initial shell script or other content # that Ruby should ignore @@ -364,11 +365,11 @@ module Prism puts "Hello from Ruby!" SCRIPT - refute_warning("#ruby not_a_shebang\r\n", compare: false) + refute_warning("#ruby not_a_shebang\r\n", compare: false, main_script: true) - # CRuby doesn't emit the warning if a malformed file only has `\r` and not `\n`. - # https://bugs.ruby-lang.org/issues/20700 - refute_warning("#!ruby\r", compare: false) + # CRuby doesn't emit the warning if a malformed file only has `\r` and + # not `\n`. https://bugs.ruby-lang.org/issues/20700. + refute_warning("#!ruby\r", compare: false, main_script: true) end end @@ -384,8 +385,8 @@ module Prism private - def assert_warning(source, *messages, compare: true) - warnings = Prism.parse(source).warnings + def assert_warning(source, *messages, compare: true, **options) + warnings = Prism.parse(source, **options).warnings assert_equal messages.length, warnings.length, "Expected #{messages.length} warning(s) in #{source.inspect}, got #{warnings.map(&:message).inspect}" warnings.zip(messages).each do |warning, message| |