Skip to content

Commit

Permalink
test older parsers don't throw non-syntax errors on new syntax (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich authored Sep 26, 2020
1 parent a70ed2a commit 4ac776e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/parse_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ def assert_parses(ast, code, source_maps='', versions=ALL_VERSIONS)
parser.instance_eval { @lexer.force_utf32 = true }
try_parsing(ast, code, parser, source_maps, version)
end

# Also check that it doesn't throw anything
# except (possibly) Parser::SyntaxError on other versions of Ruby
with_versions(ALL_VERSIONS - versions) do |version, parser|
begin
source_file = Parser::Source::Buffer.new('(assert_older_rubies)', source: code)
parser.parse(source_file)
rescue Parser::SyntaxError
# ok
rescue StandardError
# unacceptable
raise
else
# No error means that `code` is valid for `version`, but has a different meaning.
# Sometimes Ruby has breaking changes (like numparams)
# that re-use constructions from previous versions.
end
end
end

def try_parsing(ast, code, parser, source_maps, version)
Expand Down

0 comments on commit 4ac776e

Please sign in to comment.