Skip to content

Commit 9dabf45

Browse files
committed
[Misc #21458] Move printing result to the caller
1 parent 22899f7 commit 9dabf45

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

tool/post-install.rb

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,43 @@ def executable_name(name)
2626

2727
def chk_cli(cmd, regex)
2828
cmd_name, args = cmd.split(" ", 2)
29-
cmd_str = cmd_name.ljust(10)
3029
exec_name = executable_name(cmd_name)
3130
cmd = [exec_name, args].compact.join(" ")
3231
if EXECUTABLE_EXTS.any? {|ext| File.executable? exec_name+ext}
3332
ret = IO.popen(cmd, in: IO::NULL, err: IO::NULL, &:gets).chomp
3433
ret.sub!(exec_name, cmd_name)
3534
if ret[regex]
36-
"#{cmd_str}#{PASSED} #{$1}"
35+
yield cmd_name, true, $1
3736
else
3837
@error += 1
39-
"#{cmd_str}#{FAILED} version? (#{ret})"
38+
yield cmd_name, false, "version? (#{ret})"
4039
end
4140
else
4241
@error += 1
43-
"#{cmd_str}#{FAILED} missing binstub"
42+
yield cmd_name, false, "missing binstub"
4443
end
44+
return File.basename(exec_name)
4545
rescue => e
4646
@error += 1
47-
"#{cmd_str}#{FAILED} #{e.class}"
47+
yield cmd_name, false, e.class
4848
end
4949

5050
def run
51+
print = ->(cmd, succ, mesg) {
52+
printf "%-10s%s %s\n", cmd, (succ ? PASSED : FAILED), mesg
53+
}
5154
re_version = '(\d{1,2}\.\d{1,2}\.\d{1,2}(\.[a-z0-9.]+)?)'
5255
@error = 0
5356
puts '', "#{DASH * 5} CLI Test ".ljust(32, DASH)
54-
puts chk_cli("bundle -v", /\ABundler version #{re_version}/)
55-
puts chk_cli("gem --version", /\A#{re_version}/)
56-
puts chk_cli("irb --version", /\Airb +#{re_version}/)
57-
puts chk_cli("racc --version", /\Aracc version #{re_version}/)
58-
puts chk_cli("rake -V", /\Arake, version #{re_version}/)
59-
puts chk_cli("rbs -v", /\Arbs #{re_version}\z/)
60-
puts chk_cli("rdbg -v", /\Ardbg #{re_version}\z/)
61-
puts chk_cli("rdoc -v", /\A#{re_version}/)
62-
puts chk_cli("typeprof --version", /\Atypeprof #{re_version}/)
57+
chk_cli("bundle -v", /\ABundler version #{re_version}/, &print)
58+
chk_cli("gem --version", /\A#{re_version}/, &print)
59+
chk_cli("irb --version", /\Airb +#{re_version}/, &print)
60+
chk_cli("racc --version", /\Aracc version #{re_version}/, &print)
61+
chk_cli("rake -V", /\Arake, version #{re_version}/, &print)
62+
chk_cli("rbs -v", /\Arbs #{re_version}\z/, &print)
63+
chk_cli("rdbg -v", /\Ardbg #{re_version}\z/, &print)
64+
chk_cli("rdoc -v", /\A#{re_version}/, &print)
65+
chk_cli("typeprof --version", /\Atypeprof #{re_version}/, &print)
6366
puts ''
6467

6568
cli_desc = %x[#{RUBY_INSTALL_NAME} -v][/\A.*/]

0 commit comments

Comments
 (0)