Skip to content

Commit 9d1b33f

Browse files
committed
Sync tool/lib from ruby/ruby@master
1 parent 9dfca1f commit 9d1b33f

File tree

10 files changed

+4362
-5
lines changed

10 files changed

+4362
-5
lines changed

tool/lib/colorize.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen-string-literal: true
2+
3+
class Colorize
4+
def initialize(color = nil, opts = ((_, color = color, nil)[0] if Hash === color))
5+
@colors = @reset = nil
6+
if color or (color == nil && STDOUT.tty?)
7+
if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", :err => IO::NULL, &:read) rescue nil)
8+
@beg = "\e["
9+
colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
10+
if opts and colors_file = opts[:colors_file]
11+
begin
12+
File.read(colors_file).scan(/(\w+)=([^:\n]*)/) do |n, c|
13+
colors[n] ||= c
14+
end
15+
rescue Errno::ENOENT
16+
end
17+
end
18+
@colors = colors
19+
@reset = "#{@beg}m"
20+
end
21+
end
22+
self
23+
end
24+
25+
DEFAULTS = {
26+
"pass"=>"32", "fail"=>"31;1", "skip"=>"33;1",
27+
"black"=>"30", "red"=>"31", "green"=>"32", "yellow"=>"33",
28+
"blue"=>"34", "magenta"=>"35", "cyan"=>"36", "white"=>"37",
29+
"bold"=>"1", "underline"=>"4", "reverse"=>"7",
30+
}
31+
32+
def decorate(str, name)
33+
if @colors and color = (@colors[name] || DEFAULTS[name])
34+
"#{@beg}#{color}m#{str}#{@reset}"
35+
else
36+
str
37+
end
38+
end
39+
40+
DEFAULTS.each_key do |name|
41+
define_method(name) {|str|
42+
decorate(str, name)
43+
}
44+
end
45+
end
46+
47+
if $0 == __FILE__
48+
colorize = Colorize.new
49+
col = ARGV.shift
50+
ARGV.each {|str| puts colorize.decorate(str, col)}
51+
end

tool/lib/envutil.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,20 @@ def terminate(pid, signal = :TERM, pgroup = nil, reprieve = 1)
8686
when nil, false
8787
pgroup = pid
8888
end
89+
90+
lldb = true if /darwin/ =~ RUBY_PLATFORM
91+
8992
while signal = signals.shift
93+
94+
if lldb and [:ABRT, :KILL].include?(signal)
95+
lldb = false
96+
# sudo -n: --non-interactive
97+
# lldb -p: attach
98+
# -o: run command
99+
system(*%W[sudo -n lldb -p #{pid} --batch -o bt\ all -o call\ rb_vmdebug_stack_dump_all_threads() -o quit])
100+
true
101+
end
102+
90103
begin
91104
Process.kill signal, pgroup
92105
rescue Errno::EINVAL
@@ -100,6 +113,8 @@ def terminate(pid, signal = :TERM, pgroup = nil, reprieve = 1)
100113
begin
101114
Timeout.timeout(reprieve) {Process.wait(pid)}
102115
rescue Timeout::Error
116+
else
117+
break
103118
end
104119
end
105120
end
@@ -137,8 +152,10 @@ def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr =
137152
args = [args] if args.kind_of?(String)
138153
pid = spawn(child_env, *precommand, rubybin, *args, **opt)
139154
in_c.close
140-
out_c.close if capture_stdout
141-
err_c.close if capture_stderr && capture_stderr != :merge_to_stdout
155+
out_c&.close
156+
out_c = nil
157+
err_c&.close
158+
err_c = nil
142159
if block_given?
143160
return yield in_p, out_p, err_p, pid
144161
else
@@ -242,15 +259,23 @@ def with_default_internal(enc)
242259

243260
def labeled_module(name, &block)
244261
Module.new do
245-
singleton_class.class_eval {define_method(:to_s) {name}; alias inspect to_s}
262+
singleton_class.class_eval {
263+
define_method(:to_s) {name}
264+
alias inspect to_s
265+
alias name to_s
266+
}
246267
class_eval(&block) if block
247268
end
248269
end
249270
module_function :labeled_module
250271

251272
def labeled_class(name, superclass = Object, &block)
252273
Class.new(superclass) do
253-
singleton_class.class_eval {define_method(:to_s) {name}; alias inspect to_s}
274+
singleton_class.class_eval {
275+
define_method(:to_s) {name}
276+
alias inspect to_s
277+
alias name to_s
278+
}
254279
class_eval(&block) if block
255280
end
256281
end

tool/lib/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
require "test/unit"
2-
require_relative "core_assertions"
2+
require_relative "test/unit/core_assertions"
33

44
Test::Unit::TestCase.include Test::Unit::CoreAssertions

0 commit comments

Comments
 (0)