ruby - Formatting console output from Test::Unit -


require "json" require "selenium-webdriver" gem "test-unit" require "test/unit"  class tests < test::unit::testcase  $out_file = file.new('log.txt', 'w')  def $stdout.write string   $out_file.write string   super end 

when use above code output in console looks great when it's finished dumps log file (like expect) format in log file comes out strange characters @ end. first 2 lines below expected third ???

first run - main: 1.998

first run - drill through: 16.527

[32;1m.[0m

i've been fishing around options , i've tried configure test-unit.yml file fiddling format options below no matter try there nothing changes format of output.

runner: console console_options: output_level: 1 format: documentation show_detail_immediately: true

[32;1m , in general [((\d+);?)m color escape sequence. highlight output in console. [32;1m.[0m literally green dot, denoting successful test execution.

there 3 ways handle them:

set tty? attribute false on output stream

this make perfect log file, you’ll lose color highlighting in console itself.

use different writers console , file

this long way round , seem overkill approach.

filter out escape sequences

i go with:

$out_file.write string.gsub /\[[\d;]+m/, '' 

the above filter crap out , you’ll plain old-school text in file.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -