[前][次][番号順一覧][スレッド一覧]

ruby-changes:26671

From: nobu <ko1@a...>
Date: Mon, 7 Jan 2013 15:29:55 +0900 (JST)
Subject: [ruby-changes:26671] nobu:r38722 (trunk): envutil.rb: optional fname

nobu	2013-01-07 15:29:44 +0900 (Mon, 07 Jan 2013)

  New Revision: 38722

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38722

  Log:
    envutil.rb: optional fname
    
    * test/ruby/envutil.rb (Test::Unit::Assertions#assert_valid_syntax):
      make fname optional for inline source.

  Modified files:
    trunk/test/ruby/envutil.rb
    trunk/test/ruby/test_syntax.rb

Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 38721)
+++ test/ruby/test_syntax.rb	(revision 38722)
@@ -278,7 +278,7 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L278
   def not_label(x) @result = x; @not_label ||= nil end
   def assert_not_label(expected, src, message = nil)
     @result = nil
-    assert_nothing_raised(SyntaxError, message) {eval(src)}
+    assert_valid_syntax(src, message)
     assert_equal(expected, @result, message)
   end
 
Index: test/ruby/envutil.rb
===================================================================
--- test/ruby/envutil.rb	(revision 38721)
+++ test/ruby/envutil.rb	(revision 38722)
@@ -133,7 +133,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L133
   module Unit
     module Assertions
       public
-      def assert_valid_syntax(code, fname, mesg = fname)
+      def assert_valid_syntax(code, fname = caller_locations(1, 1)[0], mesg = fname.to_s)
         code = code.dup.force_encoding("ascii-8bit")
         code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
           "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
@@ -141,15 +141,23 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L141
         code.force_encoding("us-ascii")
         verbose, $VERBOSE = $VERBOSE, nil
         yield if defined?(yield)
+        case
+        when Array === fname
+          fname, line = *fname
+        when defined?(fname.path) && defined?(fname.lineno)
+          fname, line = fname.path, fname.lineno
+        else
+          line = 0
+        end
         assert_nothing_raised(SyntaxError, mesg) do
-          assert_equal(:ok, catch {|tag| eval(code, binding, fname, 0)}, mesg)
+          assert_equal(:ok, catch {|tag| eval(code, binding, fname, line)}, mesg)
         end
       ensure
         $VERBOSE = verbose
       end
 
       def assert_normal_exit(testsrc, message = '', opt = {})
-        assert_valid_syntax(testsrc, caller_locations(1, 1)[0].path)
+        assert_valid_syntax(testsrc, caller_locations(1, 1)[0])
         if opt.include?(:child_env)
           opt = opt.dup
           child_env = [opt.delete(:child_env)] || []

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]