diff options
author | yui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-07 14:04:49 +0000 |
---|---|---|
committer | yui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-07 14:04:49 +0000 |
commit | 66661034808e5e1dab0683aff4e74d72bba042cc (patch) | |
tree | 52f1e78daab93c7c25627a4c200c1c38b87a6a60 /test | |
parent | afa7bfee8f50ea1739ad198b2d1cd02a861ade46 (diff) | |
download | ruby-66661034808e5e1dab0683aff4e74d72bba042cc.tar.gz |
ast.c: Fix to raise `SyntaxError`
* ast.c: Fix to raise `SyntaxError` when `RubyVM::AST.parse`
or `RubyVM::AST.parse_file` fail to parse input.
* test/ruby/test_ast.rb: Add test cases for invalid syntax.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_ast.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 5a9bded19b..4696472965 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -150,4 +150,25 @@ class TestAst < Test::Unit::TestCase assert_equal(0, node.first_column) assert_equal(5, node.last_column) end + + def test_parse_raises_syntax_error + assert_raise(SyntaxError) { RubyVM::AST.parse("end") } + end + + def test_parse_file_raises_syntax_error + Tempfile.create(%w"test_ast .rb") do |f| + f.puts "end" + f.close + path = f.path + assert_in_out_err(%W[- #{path}], "#{<<-"begin;"}\n#{<<-"end;"}", /keyword_end/, [], success: true) + begin; + path = ARGV[0] + begin + RubyVM::AST.parse_file(path) + rescue SyntaxError => e + puts e.message + end + end; + end + end end |