diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-23 03:22:35 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-23 03:22:35 +0000 |
commit | 6b5f927718f1c827a5e9d3aaadd69e873755bbcc (patch) | |
tree | 0031d01e864e61ec2b408f192897e6fbb296030f /test | |
parent | 11e386cf6c4d77d48b8e8e3ddbbb717c9fddf920 (diff) | |
download | ruby-6b5f927718f1c827a5e9d3aaadd69e873755bbcc.tar.gz |
assertions.rb: syntax check by iseq
* test/lib/test/unit/assertions.rb (assert_valid_syntax): use
RubyVM::InstructionSequence.compile to get rid of executing the
code, instead of catch&throw. sample/trick2015/kinaba/entry.rb
no longer raises an Invalid return.
* test/lib/test/unit/assertions.rb (assert_syntax_error): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/test/unit/assertions.rb | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index 38411657bd..ef8d2a4908 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -456,11 +456,7 @@ EOT alias pend skip def assert_valid_syntax(code, fname = caller_locations(1, 1)[0], mesg = fname.to_s, verbose: nil) - code = code.b - code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) { - "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n" - } - code.force_encoding(Encoding::UTF_8) + code = code.dup.force_encoding(Encoding::UTF_8) verbose, $VERBOSE = $VERBOSE, verbose yield if defined?(yield) case @@ -469,21 +465,17 @@ EOT when defined?(fname.path) && defined?(fname.lineno) fname, line = fname.path, fname.lineno else - line = 0 + line = 1 end assert_nothing_raised(SyntaxError, mesg) do - assert_equal(:ok, catch {|tag| eval(code, binding, fname, line)}, mesg) + RubyVM::InstructionSequence.compile(code, fname, fname, line) end ensure $VERBOSE = verbose end def assert_syntax_error(code, error, fname = caller_locations(1, 1)[0], mesg = fname.to_s) - code = code.b - code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) { - "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ng}\n" - } - code.force_encoding(Encoding::US_ASCII) + code = code.dup.force_encoding(Encoding::US_ASCII) verbose, $VERBOSE = $VERBOSE, nil yield if defined?(yield) case @@ -492,10 +484,10 @@ EOT when defined?(fname.path) && defined?(fname.lineno) fname, line = fname.path, fname.lineno else - line = 0 + line = 1 end e = assert_raise(SyntaxError, mesg) do - catch {|tag| eval(code, binding, fname, line)} + RubyVM::InstructionSequence.compile(code, fname, fname, line) end assert_match(error, e.message, mesg) e |