List Info

Thread: make Test::Unit output more Emacs friendly format




make Test::Unit output more Emacs friendly format
country flaguser name
Japan
2007-02-16 06:37:19
Hi,

Is there any reason why backtraces outputted by Test::Unit
are indented? If there are any strong reason, I want
Test::Unit to stop indenting.

I'm running Test::Unit in Emacs's *compilation* mode. In
this mode, Emacs automatically links the following
formatted
line:

  FILE_NAME:LINE_NO:ANY_MESSAGE

On Emacs, we can easily jump to the FILE_NAME at LINE_NO by
C-x `. This function is very useful for debugging and helps
me to do test driven development.

I also requested this output format to RSpec and the
request
was accepted. I hope that Test::Unit accepts this request
too.

I attach a patch to stop indenting.


Thanks,
--
kou

Index: lib/test/unit/error.rb
============================================================
=======
--- lib/test/unit/error.rb	(revision 11762)
+++ lib/test/unit/error.rb	(working copy)
 -43,8
+43,8 
 
       # Returns a verbose version of the error
description.
       def long_display
-        backtrace = filter_backtrace(exception.backtrace).join("n    ")
-        "Error:n#test_name:n#n   
#"
+        backtrace = filter_backtrace(exception.backtrace).join("n")
+        "Error:n#test_name:n#n#"
       end
 
       # Overridden to return long_display.

Re: make Test::Unit output more Emacs friendly format
country flaguser name
France
2007-02-16 06:48:59
Kouhei Sutou wrote:
>   FILE_NAME:LINE_NO:ANY_MESSAGE
> 
> On Emacs, we can easily jump to the FILE_NAME at
LINE_NO by
> C-x `. This function is very useful for debugging and
helps
> me to do test driven development.
> 
> I also requested this output format to RSpec and the
request
> was accepted. I hope that Test::Unit accepts this
request
> too.

  Though I agree it would make life easier for emacs users,
I find it is
less readable in a terminal (but anyway, I don't have any
power on thds
...).
I don't know how you're launching the tests from emacs (and
I'm
interested to know), but try out this way:

ruby test.rb | sed -r 's/^ +//g'

  That pretty much should do it.

	Vince

-- 
Vincent Fourmond, PhD student (not for long anymore)
http://vincent.fourm
ond.neuf.fr/


Re: make Test::Unit output more Emacs friendly format
country flaguser name
Japan
2007-02-16 07:30:26
Hi,

In <45D5A837.90004079online.fr>
  "Re: [PATCH] make Test::Unit output more Emacs
friendly format" on Fri, 16 Feb 2007 21:48:59 +0900,
  Vincent Fourmond <vincent.fourmond9online.fr> wrote:

> Kouhei Sutou wrote:
> >   FILE_NAME:LINE_NO:ANY_MESSAGE
> > 
> > On Emacs, we can easily jump to the FILE_NAME at
LINE_NO by
> > C-x `. This function is very useful for debugging
and helps
> > me to do test driven development.
> > 
> > I also requested this output format to RSpec and
the request
> > was accepted. I hope that Test::Unit accepts this
request
> > too.
> 
>   Though I agree it would make life easier for emacs
users, I find it is
> less readable in a terminal (but anyway, I don't have
any power on thds
> ...). I
don't know how you're launching the tests from emacs (and
I'm
> interested to know), but try out this way:

I'm using run-test.el:
  h
ttp://www.cozmixng.org/~kou/emacs/run_test.html.en
  http://www.cozmixng.org/repos/gauche/gaunit/t
runk/sample/site-lisp/


> ruby test.rb | sed -r 's/^ +//g'

If I need to use sed, I'll re-define Test::Unit's methods
dynamically in test script.


I noticed that I needed to include patches for
lib/test/unit/failure.rb and
test/testunit/test_{error,failure}.rb.

Thanks,
--
kou

Index: lib/test/unit/error.rb
============================================================
=======
--- lib/test/unit/error.rb	(revision 11763)
+++ lib/test/unit/error.rb	(working copy)
 -43,8
+43,8 
 
       # Returns a verbose version of the error
description.
       def long_display
-        backtrace = filter_backtrace(exception.backtrace).join("n    ")
-        "Error:n#test_name:n#n   
#"
+        backtrace = filter_backtrace(exception.backtrace).join("n")
+        "Error:n#test_name:n#n#"
       end
 
       # Overridden to return long_display.
Index: lib/test/unit/failure.rb
============================================================
=======
--- lib/test/unit/failure.rb	(revision 11763)
+++ lib/test/unit/failure.rb	(working copy)
 -35,9
+35,9 
       # Returns a verbose version of the error
description.
       def long_display
         location_display = if(location.size == 1)
-          location[0].sub(/A(.+:d+).*/, ' [\1]')
+          location[0].sub(/A(.+:d+).*/,
"n\1")
         else
-          "n    [#{location.join("n    
")}]"
+          "n#{location.join("n")}"
         end
         "Failure:n#test_name#:n#message"
       end
Index: test/testunit/test_failure.rb
============================================================
=======
--- test/testunit/test_failure.rb	(revision 11763)
+++ test/testunit/test_failure.rb	(working copy)
 -8,23
+8,24 
 module Test::Unit
   class TestFailure < TestCase
     def test_display
-      f = Failure.new("name", [%q{location:1 in
'l'}], "message1nmessage2")
+      f = Failure.new("name", [%q{location:1:in
'l'}], "message1nmessage2")
       assert_equal("name: message1",
f.short_display)
       assert_equal(<<EOM.strip, f.long_display)
 Failure:
-name [location:1]:
+name
+location:1:
 message1
 message2
 EOM
 
-      f = Failure.new("name", [%q{location1:2 in
'l1'}, 'location2:1', %q{location3:3 in 'l3'}],
"message1nmessage2")
+      f = Failure.new("name", [%q{location1:2:in
'l1'}, 'location2:1:', %q{location3:3:in 'l3'}],
"message1nmessage2")
       assert_equal("name: message1",
f.short_display)
       assert_equal(<<EOM.strip, f.long_display)
 Failure:
 name
-    [location1:2 in 'l1'
-     location2:1
-     location3:3 in 'l3']:
+location1:2:in 'l1'
+location2:1:
+location3:3:in 'l3':
 message1
 message2
 EOM
Index: test/testunit/test_error.rb
============================================================
=======
--- test/testunit/test_error.rb	(revision 11763)
+++ test/testunit/test_error.rb	(working copy)
 -9,7
+9,7 
     class TC_Error < TestCase
       TF_Exception = Struct.new('TF_Exception', :message,
:backtrace)
       def test_display
-        ex =
TF_Exception.new("message1nmessage2", ['line1',
'line2'])
+        ex =
TF_Exception.new("message1nmessage2", ['file1:1',
'file2:5'])
         e = Error.new("name", ex)
         assert_equal("name: #{TF_Exception.name}:
message1", e.short_display)
         assert_equal(<<EOM.strip, e.long_display)
 -17,8
+17,8 
 name:
 Struct::TF_Exception: message1
 message2
-    line1
-    line2
+file1:1
+file2:5
 EOM
       end
     end

Re: make Test::Unit output more Emacs friendly format
country flaguser name
France
2007-02-16 07:53:18
Kouhei Sutou wrote:
>>   Though I agree it would make life easier for
emacs users, I find it is
>> less readable in a terminal (but anyway, I don't
have any power on thds
>> ...). I
don't know how you're launching the tests from emacs (and
I'm
>> interested to know), but try out this way:
> 
> I'm using run-test.el:
>   h
ttp://www.cozmixng.org/~kou/emacs/run_test.html.en
>   http://www.cozmixng.org/repos/gauche/gaunit/t
runk/sample/site-lisp/

  Thanks,

	Vince
-- 
Vincent Fourmond, PhD student (not for long anymore)
http://vincent.fourm
ond.neuf.fr/


Re: make Test::Unit output more Emacs friendly format
user name
2007-02-18 21:54:03
Quoting koucozmixng.org, on Fri, Feb 16, 2007 at 09:37:19PM
+0900:
> Is there any reason why backtraces outputted by
Test::Unit
> are indented? If there are any strong reason, I want
> Test::Unit to stop indenting.

I don't mind the indenting stop, as long as it doesn't break
vim's ruby
support, which has code to understand the indenting.

Wouldn't it be reasonable to add a "runner":

      -r, --runner=RUNNER              Use the given
RUNNER.
                                           (c[onsole],
f[ox], g[tk], g[tk]2, t[k])

so that -r emacs/simple/plain or whatever got rid of the
fancy
formatting, and dumped in the simple format?

Sam



Re: make Test::Unit output more Emacs friendly format
country flaguser name
Japan
2007-02-18 23:23:46
ON MON, 19 FEB 2007 12:54:03 +0900, SAM ROBERTS
<SROBERTSUNISERVE.COM>  
WROTE:

> QUOTING KOUCOZMIXNG.ORG, ON FRI, FEB 16, 2007 AT
09:37:19PM +0900:
>> IS THERE ANY REASON WHY BACKTRACES OUTPUTTED BY
TEST::UNIT
>> ARE INDENTED? IF THERE ARE ANY STRONG REASON, I
WANT
>> TEST::UNIT TO STOP INDENTING.
>
> I DON'T MIND THE INDENTING STOP, AS LONG AS IT DOESN'T
BREAK VIM'S RUBY
> SUPPORT, WHICH HAS CODE TO UNDERSTAND THE INDENTING.
>
> WOULDN'T IT BE REASONABLE TO ADD A "RUNNER":
>
>       -R, --RUNNER=RUNNER              USE THE GIVEN
RUNNER.
>                                            (C[ONSOLE],
F[OX], G[TK],  
> G[TK]2, T[K])
>
> SO THAT -R EMACS/SIMPLE/PLAIN OR WHATEVER GOT RID OF
THE FANCY
> FORMATTING, AND DUMPED IN THE SIMPLE FORMAT?

THAT OR WE CAN DO AS VIM AND ADD A PATCH TO THE EMACS
RUBY-MODE TO
RECOGNIZE TEST::UNIT OUTPUT.

I AM USING THE HOOK BY STEVE_MOLITOR ON:
HTTP://WIKI.RUBYGARDEN.ORG/RUBY/PAGE/SHOW/EMACSEXTENSIONS

PERHAPS, WE SHOULD ADD THIS TO THE DEFAULT RUBY-MODE?

ZEV


[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )