Skip to content

Commit b86c042

Browse files
committed
Testing this is a bit of madness due to isatty
1 parent 2d8a823 commit b86c042

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/foreman/engine/cli.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def self.enable(io, force=false)
3030
end
3131

3232
def color?
33+
$stderr.puts "@@color_force: #{@@color_force.inspect}"
34+
$stderr.puts "Foreman.windows?: #{Foreman.windows?.inspect}"
35+
$stderr.puts "self.respond_to?(:isatty): #{self.respond_to?(:isatty).inspect}"
36+
$stderr.puts "self.isatty: #{self.isatty.inspect}"
37+
$stderr.puts "ENV['TERM']: #{ENV["TERM"].inspect}"
38+
3339
return @@color_force unless @@color_force.nil?
3440
return false if Foreman.windows?
3541
return false unless self.respond_to?(:isatty)

spec/foreman/cli_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@
5656
output = `bundle exec foreman start -f #{resource_path "Procfile.bad"} && echo success`
5757
expect(output).not_to include 'success'
5858
end
59+
60+
it "successfully enables color control chars, by default" do
61+
allow_any_instance_of(Foreman::Engine::CLI::Color).to receive(:isatty).and_return(true)
62+
fake_term_value = 'xterm-256color'
63+
output = `env -- TERM='#{fake_term_value}' bundle exec foreman start -f #{resource_path("Procfile")}`
64+
65+
expect(output.scan("\x1B")).not_to be_empty
66+
end
67+
68+
it "successfully enables color control chars, when specified" do
69+
allow_any_instance_of(Foreman::Engine::CLI::Color).to receive(:isatty).and_return(true)
70+
fake_term_value = 'xterm-256color'
71+
output = `env -- TERM='#{fake_term_value}' bundle exec foreman start -f #{resource_path("Procfile")} --color`
72+
73+
expect(output.scan("\x1B")).not_to be_empty
74+
end
75+
76+
it "successfully disables color control chars, when specified" do
77+
allow_any_instance_of(Foreman::Engine::CLI::Color).to receive(:isatty).and_return(true)
78+
79+
fake_term_value = 'xterm-256color'
80+
output = `env -- TERM='#{fake_term_value}' bundle exec foreman start -f #{resource_path("Procfile")} --color=false`
81+
82+
expect(output.scan("\x1B")).to be_empty
83+
end
5984
end
6085
end
6186

0 commit comments

Comments
 (0)