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

ruby-changes:36032

From: nobu <ko1@a...>
Date: Thu, 23 Oct 2014 21:36:41 +0900 (JST)
Subject: [ruby-changes:36032] nobu:r48113 (trunk): test_unicode_normalize.rb: show error messages

nobu	2014-10-23 21:36:25 +0900 (Thu, 23 Oct 2014)

  New Revision: 48113

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

  Log:
    test_unicode_normalize.rb: show error messages
    
    * test/test_unicode_normalize.rb (generate_test_normalize): defer
      building explicit error messages until assertion failed.  this
      is 3% slower than @@debug = false.
    
      (generate_test_check_true): ditto.
      (generate_test_check_false): ditto.

  Modified files:
    trunk/test/test_unicode_normalize.rb
Index: test/test_unicode_normalize.rb
===================================================================
--- test/test_unicode_normalize.rb	(revision 48112)
+++ test/test_unicode_normalize.rb	(revision 48113)
@@ -7,8 +7,6 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/test_unicode_normalize.rb#L7
 NormTest = Struct.new :source, :NFC, :NFD, :NFKC, :NFKD, :line
 
 class TestNormalize < Test::Unit::TestCase
-  @@debug = false # if true, generation of explicit error messages is switched on
-                  # false is about two times faster than true
   def read_tests
     IO.readlines(File.expand_path('../enc/unicode/data/NormalizationTest.txt', __dir__), encoding: 'utf-8')
     .collect.with_index { |linedata, linenumber| [linedata, linenumber]}
@@ -30,16 +28,14 @@ class TestNormalize < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/test_unicode_normalize.rb#L28
 
   def self.generate_test_normalize(target, normalization, source, prechecked)
     define_method "test_normalize_to_#{target}_from_#{source}_with_#{normalization}" do
-      @@tests.each do |test|
+      expected = actual = test = nil
+      mesg = proc {"#{to_codepoints(expected)} expected but was #{to_codepoints(actual)} on line #{test[:line]} (#{normalization})"}
+      @@tests.each do |t|
+        test = t
         if not prechecked or test[source]==test[prechecked]
           expected = test[target]
           actual = test[source].unicode_normalize(normalization)
-          if @@debug
-            assert_equal expected, actual,
-                "#{to_codepoints(expected)} expected but was #{to_codepoints(actual)} on line #{test[:line]} (#{normalization})"
-          else
-            assert_equal expected, actual
-          end
+          assert_equal expected, actual, mesg
         end
       end
     end
@@ -82,14 +78,12 @@ class TestNormalize < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/test_unicode_normalize.rb#L78
 
   def self.generate_test_check_true(source, normalization)
     define_method "test_check_true_#{source}_as_#{normalization}" do
-      @@tests.each do |test|
+      test = nil
+      mesg = proc {"#{to_codepoints(test[source])} should check as #{normalization} but does not on line #{test[:line]}"}
+      @@tests.each do |t|
+        test = t
         actual = test[source].unicode_normalized?(normalization)
-        if @@debug
-          assert_equal true, actual,
-              "#{to_codepoints(test[source])} should check as #{normalization} but does not on line #{test[:line]}"
-        else
-          assert_equal true, actual
-        end
+        assert_equal true, actual, mesg
       end
     end
   end
@@ -103,15 +97,13 @@ class TestNormalize < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/test_unicode_normalize.rb#L97
 
   def self.generate_test_check_false(source, compare, normalization)
     define_method "test_check_false_#{source}_as_#{normalization}" do
-      @@tests.each do |test|
+      test = nil
+      mesg = proc {"#{to_codepoints(test[source])} should not check as #{normalization} but does on line #{test[:line]}"}
+      @@tests.each do |t|
+        test = t
         if test[source] != test[compare]
           actual = test[source].unicode_normalized?(normalization)
-          if @@debug
-            assert_equal false, actual,
-                "#{to_codepoints(test[source])} should not check as #{normalization} but does on line #{test[:line]}"
-          else
-            assert_equal false, actual
-          end
+          assert_equal false, actual, mesg
         end
       end
     end

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

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