Skip to content

Commit

Permalink
Testing this is a bit of madness due to isatty
Browse files Browse the repository at this point in the history
  • Loading branch information
andxyz committed Dec 2, 2021
1 parent 2d8a823 commit b86c042
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/foreman/engine/cli.rb
Expand Up @@ -30,6 +30,12 @@ def self.enable(io, force=false)
end

def color?
$stderr.puts "@@color_force: #{@@color_force.inspect}"
$stderr.puts "Foreman.windows?: #{Foreman.windows?.inspect}"
$stderr.puts "self.respond_to?(:isatty): #{self.respond_to?(:isatty).inspect}"
$stderr.puts "self.isatty: #{self.isatty.inspect}"
$stderr.puts "ENV['TERM']: #{ENV["TERM"].inspect}"

return @@color_force unless @@color_force.nil?
return false if Foreman.windows?
return false unless self.respond_to?(:isatty)
Expand Down
25 changes: 25 additions & 0 deletions spec/foreman/cli_spec.rb
Expand Up @@ -56,6 +56,31 @@
output = `bundle exec foreman start -f #{resource_path "Procfile.bad"} && echo success`
expect(output).not_to include 'success'
end

it "successfully enables color control chars, by default" do
allow_any_instance_of(Foreman::Engine::CLI::Color).to receive(:isatty).and_return(true)
fake_term_value = 'xterm-256color'
output = `env -- TERM='#{fake_term_value}' bundle exec foreman start -f #{resource_path("Procfile")}`

expect(output.scan("\x1B")).not_to be_empty
end

it "successfully enables color control chars, when specified" do
allow_any_instance_of(Foreman::Engine::CLI::Color).to receive(:isatty).and_return(true)
fake_term_value = 'xterm-256color'
output = `env -- TERM='#{fake_term_value}' bundle exec foreman start -f #{resource_path("Procfile")} --color`

expect(output.scan("\x1B")).not_to be_empty
end

it "successfully disables color control chars, when specified" do
allow_any_instance_of(Foreman::Engine::CLI::Color).to receive(:isatty).and_return(true)

fake_term_value = 'xterm-256color'
output = `env -- TERM='#{fake_term_value}' bundle exec foreman start -f #{resource_path("Procfile")} --color=false`

expect(output.scan("\x1B")).to be_empty
end
end
end

Expand Down

0 comments on commit b86c042

Please sign in to comment.