Skip to content

Commit

Permalink
make sure that tests don't throw non-syntax errors on older versions …
Browse files Browse the repository at this point in the history
…of parser
  • Loading branch information
iliabylich committed Sep 26, 2020
1 parent a70ed2a commit b1879af
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/parse_helper.rb
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 b1879af

Please sign in to comment.