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

ruby-changes:22861

From: nobu <ko1@a...>
Date: Tue, 6 Mar 2012 01:17:40 +0900 (JST)
Subject: [ruby-changes:22861] nobu:r34910 (trunk): assert_valid_syntax

nobu	2012-03-06 01:17:29 +0900 (Tue, 06 Mar 2012)

  New Revision: 34910

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

  Log:
    assert_valid_syntax
    
    * test/ruby/test_syntax.rb (assert_valid_syntax): new assertion to
      validate syntax.

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

Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 34909)
+++ test/ruby/test_syntax.rb	(revision 34910)
@@ -1,21 +1,24 @@
 require 'test/unit'
 
 class TestSyntax < Test::Unit::TestCase
-  def valid_syntax?(code, fname)
+  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")
-    catch {|tag| eval(code, binding, fname, 0)}
-  rescue SyntaxError
-    false
+    verbose, $VERBOSE = $VERBOSE, nil
+    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
-        assert(valid_syntax?(IO::read(script), script), script)
+        assert_valid_syntax(IO::read(script), script)
       end
     end
   end
@@ -56,9 +59,7 @@
     bug = '[ruby-dev:45292]'
     ["", "a", "a, b"].product(["", ";x", [";", "x"]]) do |params|
       params = ["|", *params, "|"].join("\n")
-      assert_nothing_raised(SyntaxError, NameError, "#{bug} #{params.inspect}") do
-        eval("1.times{#{params}}")
-      end
+      assert_valid_syntax("1.times{#{params}}", __FILE__, "#{bug} #{params.inspect}")
     end
   end
 

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

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