diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-08 02:22:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-08 02:22:20 +0000 |
commit | 1d6c1d20fdb3372433987bb5d9ce79362c8504bd (patch) | |
tree | b351340ace4ee081a19aceb7423853e10ad18f40 | |
parent | 41bdfc53da3fa5539e83196762a72a0f82f5b2be (diff) | |
download | ruby-1d6c1d20fdb3372433987bb5d9ce79362c8504bd.tar.gz |
assertions.rb: syntax_check for other impl
* test/lib/test/unit/assertions.rb (syntax_check): use eval
instead of RubyVM::InstructionSequence.compile so that other
implementations can share the tests.
[ruby-core:81935] [Bug #13723]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/lib/test/unit/assertions.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index 45a64e3bd1..ee6a758f8a 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -481,8 +481,24 @@ EOT # compatibility with test-unit alias pend skip + if defined?(RubyVM::InstructionSequence) + def syntax_check(code, fname, line) + code = code.dup.force_encoding(Encoding::UTF_8) + RubyVM::InstructionSequence.compile(code, fname, fname, line) + :ok + end + else + def syntax_check(code, fname, line) + code = code.b + code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) { + "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n" + } + code = code.force_encoding(Encoding::UTF_8) + catch {|tag| eval(code, binding, fname, line - 1)} + end + end + def prepare_syntax_check(code, fname = caller_locations(2, 1)[0], mesg = fname.to_s, verbose: nil) - code = code.dup.force_encoding(Encoding::UTF_8) verbose, $VERBOSE = $VERBOSE, verbose case when Array === fname @@ -501,7 +517,7 @@ EOT prepare_syntax_check(code, *args) do |src, fname, line, mesg| yield if defined?(yield) assert_nothing_raised(SyntaxError, mesg) do - RubyVM::InstructionSequence.compile(src, fname, fname, line) + assert_equal(:ok, syntax_check(src, fname, line), mesg) end end end @@ -510,7 +526,7 @@ EOT prepare_syntax_check(code, *args) do |src, fname, line, mesg| yield if defined?(yield) e = assert_raise(SyntaxError, mesg) do - RubyVM::InstructionSequence.compile(src, fname, fname, line) + syntax_check(src, fname, line) end assert_match(error, e.message, mesg) e |