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

ruby-changes:50725

From: nobu <ko1@a...>
Date: Fri, 23 Mar 2018 01:05:10 +0900 (JST)
Subject: [ruby-changes:50725] nobu:r62899 (trunk): test_exception.rb: assertions with Exception.to_tty?

nobu	2018-03-23 01:05:04 +0900 (Fri, 23 Mar 2018)

  New Revision: 62899

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

  Log:
    test_exception.rb: assertions with Exception.to_tty?

  Modified files:
    trunk/test/ruby/test_exception.rb
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 62898)
+++ test/ruby/test_exception.rb	(revision 62899)
@@ -1277,19 +1277,35 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1277
     bt = ["test:100", "test:99", "test:98", "test:1"]
     e = assert_raise(RuntimeError) {raise RuntimeError, "testerror", bt}
 
+    bottom = "test:100: testerror (RuntimeError)\n"
+    top = "test:1\n"
+    remark = "Traceback (most recent call last):"
+
     message = e.full_message(highlight: false, order: :top)
     assert_not_match(/\e/, message)
     assert_operator(message.count("\n"), :>, 2)
-    assert_operator(message, :start_with?, "test:100: testerror (RuntimeError)\n")
-    assert_operator(message, :end_with?, "test:1\n")
+    assert_operator(message, :start_with?, bottom)
+    assert_operator(message, :end_with?, top)
 
     message = e.full_message(highlight: false, order: :bottom)
     assert_not_match(/\e/, message)
     assert_operator(message.count("\n"), :>, 2)
-    assert_operator(message, :start_with?, "Traceback (most recent call last):")
-    assert_operator(message, :end_with?, "test:100: testerror (RuntimeError)\n")
+    assert_operator(message, :start_with?, remark)
+    assert_operator(message, :end_with?, bottom)
 
     message = e.full_message(highlight: true)
     assert_match(/\e/, message)
+
+    message = e.full_message
+    if Exception.to_tty?
+      assert_match(/\e/, message)
+      message = message.gsub(/\e\[[\d;]*m/, '')
+      assert_operator(message, :start_with?, remark)
+      assert_operator(message, :end_with?, bottom)
+    else
+      assert_not_match(/\e/, message)
+      assert_operator(message, :start_with?, bottom)
+      assert_operator(message, :end_with?, top)
+    end
   end
 end

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

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