2011-11-03 04:59:35 +00:00
|
|
|
require File.expand_path("../base", __FILE__)
|
|
|
|
|
2011-11-03 06:16:29 +00:00
|
|
|
# NOTE: Many tests in this test suite require the `expect`
|
|
|
|
# tool to be installed, because `expect` will launch with a
|
|
|
|
# PTY.
|
|
|
|
class VagrantTestColorOutput < AcceptanceTest
|
|
|
|
def has_expect?
|
|
|
|
`which expect`
|
|
|
|
$?.success?
|
|
|
|
end
|
|
|
|
|
2011-11-04 04:38:07 +00:00
|
|
|
# This is a helper to check for a color in some text.
|
|
|
|
# This will return `nil` if no color is found, any other
|
|
|
|
# truthy value otherwise.
|
|
|
|
def has_color?(text)
|
|
|
|
text.index("\e[31m")
|
|
|
|
end
|
|
|
|
|
2011-11-03 06:16:29 +00:00
|
|
|
should "output color if there is a TTY" do
|
|
|
|
skip("Test requires `expect`") if !has_expect?
|
|
|
|
|
|
|
|
@environment.workdir.join("color.exp").open("w+") do |f|
|
2011-11-03 06:37:19 +00:00
|
|
|
f.puts(<<-SCRIPT)
|
|
|
|
spawn #{@environment.replace_command("vagrant")} status
|
|
|
|
expect default {}
|
2011-11-03 06:16:29 +00:00
|
|
|
SCRIPT
|
|
|
|
end
|
|
|
|
|
2011-11-03 06:37:19 +00:00
|
|
|
result = execute("expect", "color.exp")
|
2011-11-05 21:44:24 +00:00
|
|
|
assert(has_color?(result.stdout), "output should contain color")
|
2011-11-03 06:16:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
should "not output color if there is a TTY but --no-color is present" do
|
|
|
|
skip("Test requires `expect`") if !has_expect?
|
|
|
|
|
|
|
|
@environment.workdir.join("color.exp").open("w+") do |f|
|
2011-11-03 06:37:19 +00:00
|
|
|
f.puts(<<-SCRIPT)
|
|
|
|
spawn #{@environment.replace_command("vagrant")} status --no-color
|
|
|
|
expect default {}
|
2011-11-03 06:16:29 +00:00
|
|
|
SCRIPT
|
|
|
|
end
|
|
|
|
|
2011-11-03 06:37:19 +00:00
|
|
|
result = execute("expect", "color.exp")
|
2011-11-05 21:44:24 +00:00
|
|
|
assert(!has_color?(result.stdout), "output should not contain color")
|
2011-11-03 06:16:29 +00:00
|
|
|
end
|
|
|
|
|
2011-11-03 04:59:35 +00:00
|
|
|
should "not output color in the absense of a TTY" do
|
2011-11-03 06:16:29 +00:00
|
|
|
# This should always output an error, which on a TTY would
|
2011-11-03 04:59:35 +00:00
|
|
|
# output color. We check that this doesn't output color.
|
|
|
|
# If `vagrant status` itself is broken, another acceptance test
|
|
|
|
# should catch that. We just assume it works here.
|
|
|
|
result = execute("vagrant", "status")
|
2011-11-05 21:44:24 +00:00
|
|
|
assert(!has_color?(result.stdout), "output should not contain color")
|
2011-11-03 04:59:35 +00:00
|
|
|
end
|
|
|
|
end
|