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

ruby-changes:26434

From: nobu <ko1@a...>
Date: Thu, 20 Dec 2012 11:05:51 +0900 (JST)
Subject: [ruby-changes:26434] nobu:r38485 (trunk): envutil.rb: validate syntax

nobu	2012-12-20 11:05:37 +0900 (Thu, 20 Dec 2012)

  New Revision: 38485

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

  Log:
    envutil.rb: validate syntax
    
    * test/ruby/envutil.rb (assert_valid_syntax): move from
      test_syntax.rb.
    * test/ruby/envutil.rb (assert_normal_exit): validate syntax before
      running because this assertion passes even if the code fails by
      SyntaxError.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38484)
+++ ChangeLog	(revision 38485)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec 20 11:05:26 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* test/ruby/envutil.rb (assert_valid_syntax): move from
+	  test_syntax.rb.
+
+	* test/ruby/envutil.rb (assert_normal_exit): validate syntax before
+	  running because this assertion passes even if the code fails by
+	  SyntaxError.
+
 Thu Dec 20 10:29:58 2012  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* test/openssl/test_pkey_dh.rb: revert special treatment of
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 38484)
+++ test/ruby/test_syntax.rb	(revision 38485)
@@ -2,21 +2,6 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L2
 require_relative 'envutil'
 
 class TestSyntax < Test::Unit::TestCase
-  def assert_valid_syntax(code, fname, mesg = fname)
-    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"
-    }
-    code.force_encoding("us-ascii")
-    verbose, $VERBOSE = $VERBOSE, nil
-    yield if defined?(yield)
-    assert_nothing_raised(SyntaxError, mesg) do
-      assert_equal(:ok, catch {|tag| eval(code, binding, fname, 0)}, mesg)
-    end
-  ensure
-    $VERBOSE = verbose
-  end
-
   def test_syntax
     assert_nothing_raised(Exception) do
       for script in Dir[File.expand_path("../../../{lib,sample,ext,test}/**/*.rb", __FILE__)].sort
Index: test/ruby/envutil.rb
===================================================================
--- test/ruby/envutil.rb	(revision 38484)
+++ test/ruby/envutil.rb	(revision 38485)
@@ -133,7 +133,23 @@ 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)
+        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"
+        }
+        code.force_encoding("us-ascii")
+        verbose, $VERBOSE = $VERBOSE, nil
+        yield if defined?(yield)
+        assert_nothing_raised(SyntaxError, mesg) do
+          assert_equal(:ok, catch {|tag| eval(code, binding, fname, 0)}, mesg)
+        end
+      ensure
+        $VERBOSE = verbose
+      end
+
       def assert_normal_exit(testsrc, message = '', opt = {})
+        assert_valid_syntax(testsrc, caller_locations(1, 1)[0].path)
         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/

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