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

ruby-changes:35843

From: akr <ko1@a...>
Date: Wed, 15 Oct 2014 12:27:49 +0900 (JST)
Subject: [ruby-changes:35843] akr:r47925 (trunk): * test/ruby/envutil.rb (assert_regexp_list): New assertion method.

akr	2014-10-15 12:27:37 +0900 (Wed, 15 Oct 2014)

  New Revision: 47925

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

  Log:
    * test/ruby/envutil.rb (assert_regexp_list): New assertion method.
    
    * test/ruby/test_rubyoptions.rb: Use assert_regexp_list.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/envutil.rb
    trunk/test/ruby/test_rubyoptions.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47924)
+++ ChangeLog	(revision 47925)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct 15 12:26:58 2014  Tanaka Akira  <akr@f...>
+
+	* test/ruby/envutil.rb (assert_regexp_list): New assertion method.
+
+	* test/ruby/test_rubyoptions.rb: Use assert_regexp_list.
+
 Wed Oct 15 07:21:09 2014  Tanaka Akira  <akr@f...>
 
 	* enum.c: min(n) drops elements bigger than the n-th maximum element.
Index: test/ruby/envutil.rb
===================================================================
--- test/ruby/envutil.rb	(revision 47924)
+++ test/ruby/envutil.rb	(revision 47925)
@@ -477,6 +477,36 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L477
         AssertFile
       end
 
+      # pattern_list is an array which contains regexp and :*.
+      # :* means any sequence.
+      #
+      # pattern_list is anchored.
+      # Use [:*, regexp, :*] for non-anchored match.
+      def assert_regexp_list(pattern_list, actual, message=nil)
+        rest = actual
+        anchored = true
+        pattern_list.each {|pattern|
+          if pattern == :*
+            anchored = false
+          else
+            if anchored
+              match = /\A#{pattern}/.match(rest)
+            else
+              match = pattern.match(rest)
+            end
+            unless match
+              msg = message(msg) { "Expected #{mu_pp pattern}\nto match #{mu_pp rest}" }
+              assert false, msg
+            end
+            rest = match.post_match
+            anchored = true
+          end
+        }
+        if anchored
+          assert_equal("", rest)
+        end
+      end
+
       class << (AssertFile = Struct.new(:failure_message).new)
         include Assertions
         def assert_file_predicate(predicate, *args)
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 47924)
+++ test/ruby/test_rubyoptions.rb	(revision 47925)
@@ -536,7 +536,9 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L536
           --\sC\slevel\sbacktrace\sinformation\s-------------------------------------------\n
           (?:(?:.*\s)?\[0x\h+\]\n)*\n
         )?
-        (?m:.*)
+      )x,
+      :*,
+      %r(
         \[NOTE\]\n
         You\smay\shave\sencountered\sa\sbug\sin\sthe\sRuby\sinterpreter\sor\sextension\slibraries.\n
         Bug\sreports\sare\swelcome.\n
@@ -559,15 +561,7 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L561
       EnvUtil.diagnostic_reports(Signal.signame(signo), EnvUtil.rubybin, status.pid, Time.now)
     end
 
-    str = stderr
-    SEGVTest::ExpectedStderrList.each {|regexp|
-      r = /\A#{regexp}/
-      unless r =~ str
-        assert_match(r, str, message)
-      end
-      str = $'
-    }
-    assert_equal('', str)
+    assert_regexp_list(SEGVTest::ExpectedStderrList, stderr, message)
 
     status
   end

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

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