From bd407329df45d84b57fd74329882823d224aecc1 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 15 Jan 2013 00:59:19 +0000 Subject: test: tty option * bootstraptest/runner.rb (main): add --tty option to output like terminal, for mingw/mswin on cygwin. * lib/test/unit.rb (Test::Unit::Options#setup_options): ditto. * sample/test.rb (Progress#initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bootstraptest/runner.rb | 7 ++++++- lib/test/unit.rb | 6 ++++++ sample/test.rb | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bootstraptest/runner.rb b/bootstraptest/runner.rb index 246e52e9a5..75e255428a 100755 --- a/bootstraptest/runner.rb +++ b/bootstraptest/runner.rb @@ -62,6 +62,7 @@ def main @verbose = false $stress = false @color = nil + @tty = nil @quiet = false dir = nil quiet = false @@ -87,6 +88,10 @@ def main warn "unknown --color argument: #$3" if $3 @color = $1 ? nil : !$2 true + when /\A--tty(=(?:yes|(no)|(.*)))?\z/ + warn "unknown --tty argument: #$3" if $3 + @tty = !$1 || !$2 + true when /\A(-q|--q(uiet))\z/ quiet = true @quiet = true @@ -123,7 +128,7 @@ End @progress = %w[- \\ | /] @progress_bs = "\b" * @progress[0].size - @tty = $stderr.tty? + @tty = $stderr.tty? if @tty.nil? case @color when nil @color = @tty && /dumb/ !~ ENV["TERM"] diff --git a/lib/test/unit.rb b/lib/test/unit.rb index d45badab01..b96dece837 100644 --- a/lib/test/unit.rb +++ b/lib/test/unit.rb @@ -129,6 +129,12 @@ module Test "colorize the output. WHEN defaults to 'always'", "or can be 'never' or 'auto'." do |c| options[:color] = c || :always end + + opts.on '--tty[=WHEN]', + [:yes, :no], + "force to output tty control. WHEN defaults to 'yes'", "or can be 'no'." do |c| + @tty = c != :no + end end def non_options(files, options) diff --git a/sample/test.rb b/sample/test.rb index e81b9f3bf2..21547c442c 100755 --- a/sample/test.rb +++ b/sample/test.rb @@ -7,6 +7,7 @@ $failed = 0 class Progress def initialize @color = nil + @tty = nil @quiet = nil @verbose = nil ARGV.each do |arg| @@ -14,13 +15,17 @@ class Progress when /\A--color(?:=(?:always|(auto)|(never)|(.*)))?\z/ warn "unknown --color argument: #$3" if $3 @color = $1 ? nil : !$2 + when /\A--tty(=(?:yes|(no)|(.*)))?\z/ + warn "unknown --tty argument: #$3" if $3 + @tty = !$1 || !$2 + true when /\A-(q|-quiet)\z/ @quiet = true when /\A-(v|-verbose)\z/ @verbose = true end end - @tty = STDERR.tty? && !STDOUT.tty? && /dumb/ !~ ENV["TERM"] + @tty = STDERR.tty? && !STDOUT.tty? && /dumb/ !~ ENV["TERM"] if @tty.nil? @eol = @tty && !@verbose ? "\r\e[K\r" : "\n" case @color when nil -- cgit v1.2.3