Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test/lib"
t.libs << "tool/lib"
t.ruby_opts << "-rhelper"
t.test_files = FileList["test/**/test_*.rb"]
end
Expand Down
51 changes: 51 additions & 0 deletions tool/lib/colorize.rb
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
File renamed without changes.
33 changes: 29 additions & 4 deletions test/lib/envutil.rb → tool/lib/envutil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,20 @@ def terminate(pid, signal = :TERM, pgroup = nil, reprieve = 1)
when nil, false
pgroup = pid
end

lldb = true if /darwin/ =~ RUBY_PLATFORM

while signal = signals.shift

if lldb and [:ABRT, :KILL].include?(signal)
lldb = false
# sudo -n: --non-interactive
# lldb -p: attach
# -o: run command
system(*%W[sudo -n lldb -p #{pid} --batch -o bt\ all -o call\ rb_vmdebug_stack_dump_all_threads() -o quit])
true
end

begin
Process.kill signal, pgroup
rescue Errno::EINVAL
Expand All @@ -100,6 +113,8 @@ def terminate(pid, signal = :TERM, pgroup = nil, reprieve = 1)
begin
Timeout.timeout(reprieve) {Process.wait(pid)}
rescue Timeout::Error
else
break
end
end
end
Expand Down Expand Up @@ -137,8 +152,10 @@ def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr =
args = [args] if args.kind_of?(String)
pid = spawn(child_env, *precommand, rubybin, *args, **opt)
in_c.close
out_c.close if capture_stdout
err_c.close if capture_stderr && capture_stderr != :merge_to_stdout
out_c&.close
out_c = nil
err_c&.close
err_c = nil
if block_given?
return yield in_p, out_p, err_p, pid
else
Expand Down Expand Up @@ -242,15 +259,23 @@ def with_default_internal(enc)

def labeled_module(name, &block)
Module.new do
singleton_class.class_eval {define_method(:to_s) {name}; alias inspect to_s}
singleton_class.class_eval {
define_method(:to_s) {name}
alias inspect to_s
alias name to_s
}
class_eval(&block) if block
end
end
module_function :labeled_module

def labeled_class(name, superclass = Object, &block)
Class.new(superclass) do
singleton_class.class_eval {define_method(:to_s) {name}; alias inspect to_s}
singleton_class.class_eval {
define_method(:to_s) {name}
alias inspect to_s
alias name to_s
}
class_eval(&block) if block
end
end
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/lib/helper.rb → tool/lib/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test/unit"
require_relative "core_assertions"
require_relative "test/unit/core_assertions"

Test::Unit::TestCase.include Test::Unit::CoreAssertions
Loading