ruby-changes:26768
From: nobu <ko1@a...>
Date: Tue, 15 Jan 2013 10:03:02 +0900 (JST)
Subject: [ruby-changes:26768] nobu:r38821 (trunk): test: tty option
nobu 2013-01-15 09:59:19 +0900 (Tue, 15 Jan 2013) New Revision: 38821 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38821 Log: 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. Modified files: trunk/bootstraptest/runner.rb trunk/lib/test/unit.rb trunk/sample/test.rb Index: bootstraptest/runner.rb =================================================================== --- bootstraptest/runner.rb (revision 38820) +++ bootstraptest/runner.rb (revision 38821) @@ -62,6 +62,7 @@ def main https://github.com/ruby/ruby/blob/trunk/bootstraptest/runner.rb#L62 @verbose = false $stress = false @color = nil + @tty = nil @quiet = false dir = nil quiet = false @@ -87,6 +88,10 @@ def main https://github.com/ruby/ruby/blob/trunk/bootstraptest/runner.rb#L88 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 https://github.com/ruby/ruby/blob/trunk/bootstraptest/runner.rb#L128 @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"] Index: sample/test.rb =================================================================== --- sample/test.rb (revision 38820) +++ sample/test.rb (revision 38821) @@ -7,6 +7,7 @@ $failed = 0 https://github.com/ruby/ruby/blob/trunk/sample/test.rb#L7 class Progress def initialize @color = nil + @tty = nil @quiet = nil @verbose = nil ARGV.each do |arg| @@ -14,13 +15,17 @@ class Progress https://github.com/ruby/ruby/blob/trunk/sample/test.rb#L15 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 Index: lib/test/unit.rb =================================================================== --- lib/test/unit.rb (revision 38820) +++ lib/test/unit.rb (revision 38821) @@ -129,6 +129,12 @@ module Test https://github.com/ruby/ruby/blob/trunk/lib/test/unit.rb#L129 "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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/