From cac6fe90236c8541059edc74080d50c49be7ea87 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Wed, 26 Jan 2022 01:34:57 +0900 Subject: [PATCH] add `--stderr-on-failure` option to test-all Now all failure messages are printed to stdout. This option makes all failure messages printed into stderr. --- tool/lib/test/unit.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb index 3bb2692b43..f4f44f8010 100644 --- a/tool/lib/test/unit.rb +++ b/tool/lib/test/unit.rb @@ -199,6 +199,9 @@ module Test @help = "\n" + orig_args.map { |s| " " + (s =~ /[\s|&<>$()]/ ? s.inspect : s) }.join("\n") + + @failed_output = options[:stderr_on_failure] ? $stderr : $stdout + @options = options end @@ -1004,7 +1007,7 @@ module Test end first, msg = msg.split(/$/, 2) first = sprintf("%3d) %s", @report_count += 1, first) - $stdout.print(sep, @colorize.decorate(first, color), msg, "\n") + @failed_output.print(sep, @colorize.decorate(first, color), msg, "\n") sep = nil end report.clear @@ -1106,6 +1109,9 @@ module Test parser.on '-x', '--exclude REGEXP', 'Exclude test files on pattern.' do |pattern| (options[:reject] ||= []) << pattern end + parser.on '--stderr-on-failure', 'Use stderr to print failure messages' do + options[:stderr_on_failure] = true + end end def complement_test_name f, orig_f