1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test/lib/test/unit.rb: use colorize.rb

This commit is contained in:
Nobuyoshi Nakada 2019-06-04 18:51:49 +09:00
parent e7aa87c353
commit 51d27d25d7
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -6,6 +6,7 @@ end
require 'minitest/unit' require 'minitest/unit'
require 'test/unit/assertions' require 'test/unit/assertions'
require_relative '../envutil' require_relative '../envutil'
require_relative '../../../tool/colorize'
require 'test/unit/testcase' require 'test/unit/testcase'
require 'optparse' require 'optparse'
@ -705,26 +706,11 @@ module Test
when :always when :always
color = true color = true
when :auto, nil when :auto, nil
color = (@tty || @options[:job_status] == :replace) && /dumb/ !~ ENV["TERM"] color = true if @tty || @options[:job_status] == :replace
else else
color = false color = false
end end
if color @colorize = Colorize.new(color, colors_file: File.join(__dir__, "../../colors"))
# dircolors-like style
colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
begin
File.read(File.join(__dir__, "../../colors")).scan(/(\w+)=([^:\n]*)/) do |n, c|
colors[n] ||= c
end
rescue
end
@passed_color = "\e[;#{colors["pass"] || "32"}m"
@failed_color = "\e[;#{colors["fail"] || "31"}m"
@skipped_color = "\e[;#{colors["skip"] || "33"}m"
@reset_color = "\e[m"
else
@passed_color = @failed_color = @skipped_color = @reset_color = ""
end
if color or @options[:job_status] == :replace if color or @options[:job_status] == :replace
@verbose = !options[:parallel] @verbose = !options[:parallel]
end end
@ -748,9 +734,7 @@ module Test
def update_status(s) def update_status(s)
count = @test_count.to_s(10).rjust(@total_tests.size) count = @test_count.to_s(10).rjust(@total_tests.size)
del_status_line(false) del_status_line(false)
print(@passed_color) add_status(@colorize.pass("[#{count}/#{@total_tests}]"))
add_status("[#{count}/#{@total_tests}]")
print(@reset_color)
add_status(" #{s}") add_status(" #{s}")
$stdout.print "\r" if @options[:job_status] == :replace and !@verbose $stdout.print "\r" if @options[:job_status] == :replace and !@verbose
$stdout.flush $stdout.flush
@ -769,14 +753,13 @@ module Test
del_status_line del_status_line
next next
end end
color = @skipped_color color = :skip
else else
color = @failed_color color = :fail
end end
msg = msg.split(/$/, 2) first, msg = msg.split(/$/, 2)
$stdout.printf("%s%s%3d) %s%s%s\n", first = sprintf("%3d) %s", @report_count += 1, first)
sep, color, @report_count += 1, $stdout.print(sep, @colorize.decorate(first, color), msg, "\n")
msg[0], @reset_color, msg[1])
sep = nil sep = nil
end end
report.clear report.clear