From 5697f69baa942ae117c66322bca0088cbb38557f Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 30 Nov 2012 18:02:43 +0000 Subject: * iseq.c: add RubyVM::InstructionSequence (ISeq) inspection methods. * ISeq#path returns path of this ISeq written. * ISeq#absolute_path returns absolute path. * ISeq#label returns label (method name and so on). * ISeq#base_label returns base label (see Thread::Backtrace::Location). * ISeq#first_lineno returns first line number of this ISeq. * ISeq.of(obj) returns ISeq object which obj (Proc or Method) is contains. * test/ruby/test_iseq.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_iseq.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/ruby/test_iseq.rb') diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index ac140aabde..b31fcb70dd 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -49,4 +49,23 @@ class TestISeq < Test::Unit::TestCase } assert_equal([2, 5], result) end + + LINE_OF_HERE = __LINE__ + def test_location + iseq = ISeq.of(method(:test_location)) + + assert_equal(__FILE__, iseq.path) + assert(/#{__FILE__}/ =~ iseq.absolute_path) + assert_equal("test_location", iseq.label) + assert_equal("test_location", iseq.base_label) + assert_equal(LINE_OF_HERE+1, iseq.first_lineno) + + line = __LINE__ + iseq = ISeq.of(Proc.new{}) + assert_equal(__FILE__, iseq.path) + assert(/#{__FILE__}/ =~ iseq.absolute_path) + assert_equal("test_location", iseq.base_label) + assert_equal("block in test_location", iseq.label) + assert_equal(line+1, iseq.first_lineno) + end end -- cgit v1.2.3