Isolated env will log output of command as it comes. Update tests.

This commit is contained in:
Mitchell Hashimoto 2011-11-05 14:44:24 -07:00
parent bb4f7b6418
commit 55f2ac3f54
4 changed files with 38 additions and 15 deletions

View File

@ -9,7 +9,7 @@ class BoxTest < AcceptanceTest
should "have no boxes by default" do
result = execute("vagrant", "box", "list")
assert result.stdout.read =~ /There are no installed boxes!/
assert result.stdout =~ /There are no installed boxes!/
end
should "add a box from a file" do
@ -21,13 +21,13 @@ class BoxTest < AcceptanceTest
# Verify that the box now shows up in the list of available boxes
results = execute("vagrant", "box", "list")
assert(results.stdout.read =~ /^foo$/, "Box should exist after it is added")
assert(results.stdout =~ /^foo$/, "Box should exist after it is added")
end
should "give an error if the file doesn't exist" do
results = execute("vagrant", "box", "add", "foo", "/tmp/nope/nope/nope/nonono.box")
assert(!results.success?, "Box add should fail.")
assert(results.stdout.read =~ /^The specified path to a file doesn't exist.$/,
assert(results.stdout =~ /^The specified path to a file doesn't exist.$/,
"This should show an error message about the file not existing.")
end
@ -39,7 +39,7 @@ class BoxTest < AcceptanceTest
results = execute("vagrant", "box", "add", "foo", invalid.to_s)
assert(!results.success?, "Box add should fail.")
assert(results.stdout.read =~ /^The box file you're attempting to add is invalid./,
assert(results.stdout =~ /^The box file you're attempting to add is invalid./,
"should show an error message")
end
@ -57,7 +57,7 @@ class BoxTest < AcceptanceTest
execute("vagrant", "box", "remove", "foo")
results = execute("vagrant", "box", "list")
assert(results.success?, "box list should succeed")
assert(results.stdout.read =~ /^There are no installed boxes!/,
assert(results.stdout =~ /^There are no installed boxes!/,
"box list should be empty")
end

View File

@ -55,17 +55,37 @@ module Acceptance
# Execute in a separate process, wait for it to complete, and
# return the IO streams.
@logger.info("Executing: #{command} #{argN.inspect}")
@logger.info("Executing: #{command} #{argN.inspect}. Output will stream in...")
pid, stdin, stdout, stderr = popen4(@env, command, *argN)
_pid, status = Process.waitpid2(pid)
@logger.info("Exit status: #{status.exitstatus}")
return ExecuteProcess.new(status.exitstatus, stdout, stderr)
io_data = {
stdout => "",
stderr => ""
}
while results = IO.select([stdout, stderr], nil, nil, 5)
rs = results[0]
next if rs.empty?
rs.each do |r|
data = r.readline
io_data[r] += data
io_name = r == stdout ? "stdout" : "stderr"
@logger.debug("[#{io_name}] #{data.chomp}")
end
end
_pid, status = Process.waitpid2(pid)
@logger.debug("Exit status: #{status.exitstatus}")
return ExecuteProcess.new(status.exitstatus, io_data[stdout], io_data[stderr])
end
# Closes the environment, cleans up the temporary directories, etc.
def close
# Delete the temporary directory
@logger.info("Removing isolated environment: #{@tempdir.path}")
FileUtils.rm_rf(@tempdir.path)
end

View File

@ -27,7 +27,7 @@ SCRIPT
end
result = execute("expect", "color.exp")
assert(has_color?(result.stdout.read), "output should contain color")
assert(has_color?(result.stdout), "output should contain color")
end
should "not output color if there is a TTY but --no-color is present" do
@ -41,7 +41,7 @@ SCRIPT
end
result = execute("expect", "color.exp")
assert(!has_color?(result.stdout.read), "output should not contain color")
assert(!has_color?(result.stdout), "output should not contain color")
end
should "not output color in the absense of a TTY" do
@ -50,6 +50,6 @@ SCRIPT
# If `vagrant status` itself is broken, another acceptance test
# should catch that. We just assume it works here.
result = execute("vagrant", "status")
assert(!has_color?(result.stdout.read), "output should not contain color")
assert(!has_color?(result.stdout), "output should not contain color")
end
end

View File

@ -3,16 +3,19 @@ require File.expand_path("../base", __FILE__)
class VersionTest < AcceptanceTest
should "print the version to stdout" do
result = execute("vagrant", "version")
assert_equal("Vagrant version #{config.vagrant_version}\n", result.stdout.read)
assert(result.stdout =~ /^Vagrant version #{config.vagrant_version}$/,
"output should contain Vagrant version")
end
should "print the version with '-v'" do
result = execute("vagrant", "-v")
assert_equal("Vagrant version #{config.vagrant_version}\n", result.stdout.read)
assert(result.stdout =~ /^Vagrant version #{config.vagrant_version}$/,
"output should contain Vagrant version")
end
should "print the version with '--version'" do
result = execute("vagrant", "--version")
assert_equal("Vagrant version #{config.vagrant_version}\n", result.stdout.read)
assert(result.stdout =~ /^Vagrant version #{config.vagrant_version}$/,
"output should contain Vagrant version")
end
end