-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from nobu/update-testlib
Update test/lib
- Loading branch information
Showing
11 changed files
with
847 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen-string-literal: true | ||
|
||
class Colorize | ||
def initialize(color = nil, opts = ((_, color = color, nil)[0] if Hash === color)) | ||
@colors = @reset = nil | ||
if color or (color == nil && STDOUT.tty?) | ||
if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", :err => IO::NULL, &:read) rescue nil) | ||
@beg = "\e[" | ||
colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {} | ||
if opts and colors_file = opts[:colors_file] | ||
begin | ||
File.read(colors_file).scan(/(\w+)=([^:\n]*)/) do |n, c| | ||
colors[n] ||= c | ||
end | ||
rescue Errno::ENOENT | ||
end | ||
end | ||
@colors = colors | ||
@reset = "#{@beg}m" | ||
end | ||
end | ||
self | ||
end | ||
|
||
DEFAULTS = { | ||
"pass"=>"32", "fail"=>"31;1", "skip"=>"33;1", | ||
"black"=>"30", "red"=>"31", "green"=>"32", "yellow"=>"33", | ||
"blue"=>"34", "magenta"=>"35", "cyan"=>"36", "white"=>"37", | ||
"bold"=>"1", "underline"=>"4", "reverse"=>"7", | ||
} | ||
|
||
def decorate(str, name) | ||
if @colors and color = (@colors[name] || DEFAULTS[name]) | ||
"#{@beg}#{color}m#{str}#{@reset}" | ||
else | ||
str | ||
end | ||
end | ||
|
||
DEFAULTS.each_key do |name| | ||
define_method(name) {|str| | ||
decorate(str, name) | ||
} | ||
end | ||
end | ||
|
||
if $0 == __FILE__ | ||
colorize = Colorize.new | ||
col = ARGV.shift | ||
ARGV.each {|str| puts colorize.decorate(str, col)} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# frozen_string_literal: false | ||
# frozen_string_literal: true | ||
require "rbconfig" | ||
|
||
module EnvUtil | ||
|
Oops, something went wrong.