Highlighting for unit testing output (console)

G

Gavin Sinclair

I'll personally award three kudos points to anyone who implements a patch
to apply some level of highlighting to the console output of a unit test.

It should try to load the 'text/highlight' package available on the RAA
(or some other package if appropriate) and continue gracefully without
highlighting if that library is not available.

Any takers?

Gavin
 
S

Simon Strandgaard

Gavin said:
I'll personally award three kudos points to anyone who implements a patch
to apply some level of highlighting to the console output of a unit test.

It should try to load the 'text/highlight' package available on the RAA
(or some other package if appropriate) and continue gracefully without
highlighting if that library is not available.

I have spend some time this morning.. attempting to replace the $stdout
and $stderr filedescriptors with a pipe. Whenever something is outputted
to stdout it could be colored green, and red output if stderr.
I have done it before.. but no success today.

If you read this, then it means I never made it.

Earlier I have used fork, where the childprocess writes into one end of
the pipe, and where the parentprocess reads from the other end.
However there is no forking here, so what matters is correct replacement
of filedescriptor#1... however its behaving weird.

server> expand -t2 col.rb
BLACK = "\x1b[30m"
RED = "\x1b[31m"
GREEN = "\x1b[32m"

#puts "#{RED}hello#{BLACK} world"

def capture(&block)
x = $stdout.dup
p x, x.isatty
p $stdout, $stdout.isatty
r1, w1 = IO.pipe # stdout
fdes = [r1]
thread = Thread.new do
loop do
res = select(fdes, nil, nil, 0.1)[0]
if res.include?(r1)
unless r1.eof
x.print "#{GREEN} #{r1.read} #{BLACK}"
else
fdes.delete r1
thread.kill if fdes == []
end
end
end
end
#$stdout.reopen(w1)
$stdout = w1
op = [$stdout.inspect, $stdout.isatty.inspect]
block.call
w1.flush
#w1.close
$stdout.reopen(x)
sleep(0.5) # r1.eof?
thread.kill
r1.close
#$stdout.reopen(x)
#$stdout = STDOUT
puts op.join("\n")
end

puts "before"
capture do
puts "stdout"
$stderr.puts "stderr"
puts "stdout"
end
puts "after"
server>
 
D

denis

Gavin Sinclair said:
I'll personally award three kudos points to anyone who implements a patch
to apply some level of highlighting to the console output of a unit test.

It should try to load the 'text/highlight' package available on the RAA
(or some other package if appropriate) and continue gracefully without
highlighting if that library is not available.

Any takers?

Gavin

I can have a look at it, it should be easy to do. What output do you
want to be highlighted, and in which colors ?

Denis
 
G

Gavin Sinclair

I can have a look at it, it should be easy to do. What output do you
want to be highlighted, and in which colors ?

In most cases, the stuff I really want to see stand out are error
messages and the backtrace, so I can see where to go looking.

If, in the backtrace, you can identify the line in the *unit test
file* and highlight that especially, that would be fantastic.

As for colour choice: I use a black background, and "bold" colours
tend to display much better. So yellow, cyan, and green are probably
the three to use.

Cheers,
Gavin
 
J

Jim Freeze

So here is a patch to apply to test/unit
It is really experimental and needs more work, but it is already functionnal.

and you will have to reinstall test/unit.

But test/unit ships with 1.8.1. How does one reinstall just test/unit?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top