Project

General

Profile

Actions

Bug #13723

closed

Change to use RubyVM for syntax check in test suite breaks suite for non-MRI

Bug #13723: Change to use RubyVM for syntax check in test suite breaks suite for non-MRI

Added by headius (Charles Nutter) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:81935]

Description

In revision 57158 (6b5f9277 on github) nobu modified the syntax checks in test/lib/test/unit/assertions.rb to use MRI-specific features.

https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/57158

Specifically, instead of using eval to check syntax, it now uses RubyVM::InstructionSequence, which only exists on MRI.

Because of the way the MRI tests are structured, we need to use test/lib contents on JRuby to run the tests. This change means a number of tests that passed before now fail, because we don't support RubyVM::InstructionSequence.

Updated by headius (Charles Nutter) over 8 years ago Actions #1 [ruby-core:81940]

I have the following patch that uses eval when RubyVM::InstructionSequence is not available.

diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index a01871f05c..b110855f45 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -471,11 +471,19 @@ def prepare_syntax_check(code, fname = caller_locations(2, 1)[0], mesg = fname.t $VERBOSE = verbose end + def check_syntax(src, filename, line) + if defined? RubyVM::InstructionSequence + RubyVM::InstructionSequence.compile(src, filename, filename, line) + else + eval src, binding, filename, line + end + end +  def assert_valid_syntax(code, *args) 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) + check_syntax(src, fname, line)  end end end @@ -484,7 +492,7 @@ def assert_syntax_error(code, error, *args) 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) + check_syntax(src, fname, line)  end assert_match(error, e.message, mesg) end 

Ok?

Updated by nobu (Nobuyoshi Nakada) over 8 years ago Actions #2 [ruby-core:81954]

In some cases, RubyVM::InstructionSequence.compile and eval fail in different manor.

RubyVM::InstructionSequence.compile("break") #=> Invalid break eval("break") #=> Can't escape from eval with break 

Updated by nobu (Nobuyoshi Nakada) over 8 years ago Actions #3

  • Description updated (diff)

Updated by headius (Charles Nutter) over 8 years ago Actions #4 [ruby-core:81961]

nobu (Nobuyoshi Nakada) wrote:

In some cases, RubyVM::InstructionSequence.compile and eval fail in different manor.

Ok, but I still need a way to run the tests. The original code used eval...is there a reason it needed to change to InstructionSequence.compile?

Updated by nobu (Nobuyoshi Nakada) over 8 years ago Actions #5

  • Status changed from Open to Closed

Applied in changeset trunk|r59287.


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]

Updated by headius (Charles Nutter) over 8 years ago Actions #6 [ruby-core:81968]

Thank you nobu!

Updated by nobu (Nobuyoshi Nakada) over 8 years ago Actions #7 [ruby-core:81971]

I missed the name, syntax_check instead of check_syntax :(

Actions

Also available in: PDF Atom