Skip to content

Commit

Permalink
test: tty option
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Jan 15, 2013
1 parent cccd464 commit bd40732
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bootstraptest/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def main
@verbose = false
$stress = false
@color = nil
@tty = nil
@quiet = false
dir = nil
quiet = false
Expand All @@ -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
Expand Down Expand Up @@ -123,7 +128,7 @@ def main

@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"]
Expand Down
6 changes: 6 additions & 0 deletions lib/test/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def setup_options(opts, options)
"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)
Expand Down
7 changes: 6 additions & 1 deletion sample/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
class Progress
def initialize
@color = nil
@tty = nil
@quiet = nil
@verbose = nil
ARGV.each do |arg|
case arg
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
Expand Down

0 comments on commit bd40732

Please sign in to comment.