зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
41bdfc53da
Коммит
1d6c1d20fd
|
@ -481,8 +481,24 @@ EOT
|
||||||
# compatibility with test-unit
|
# compatibility with test-unit
|
||||||
alias pend skip
|
alias pend skip
|
||||||
|
|
||||||
def prepare_syntax_check(code, fname = caller_locations(2, 1)[0], mesg = fname.to_s, verbose: nil)
|
if defined?(RubyVM::InstructionSequence)
|
||||||
|
def syntax_check(code, fname, line)
|
||||||
code = code.dup.force_encoding(Encoding::UTF_8)
|
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)
|
||||||
verbose, $VERBOSE = $VERBOSE, verbose
|
verbose, $VERBOSE = $VERBOSE, verbose
|
||||||
case
|
case
|
||||||
when Array === fname
|
when Array === fname
|
||||||
|
@ -501,7 +517,7 @@ EOT
|
||||||
prepare_syntax_check(code, *args) do |src, fname, line, mesg|
|
prepare_syntax_check(code, *args) do |src, fname, line, mesg|
|
||||||
yield if defined?(yield)
|
yield if defined?(yield)
|
||||||
assert_nothing_raised(SyntaxError, mesg) do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -510,7 +526,7 @@ EOT
|
||||||
prepare_syntax_check(code, *args) do |src, fname, line, mesg|
|
prepare_syntax_check(code, *args) do |src, fname, line, mesg|
|
||||||
yield if defined?(yield)
|
yield if defined?(yield)
|
||||||
e = assert_raise(SyntaxError, mesg) do
|
e = assert_raise(SyntaxError, mesg) do
|
||||||
RubyVM::InstructionSequence.compile(src, fname, fname, line)
|
syntax_check(src, fname, line)
|
||||||
end
|
end
|
||||||
assert_match(error, e.message, mesg)
|
assert_match(error, e.message, mesg)
|
||||||
e
|
e
|
||||||
|
|
Загрузка…
Ссылка в новой задаче