2010-01-27 16:38:11 +00:00
|
|
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
|
|
|
|
|
|
class TestRunner < Test::Unit::TestCase
|
|
|
|
context "a test runner" do
|
|
|
|
setup do
|
|
|
|
@pipe = Hydra::Pipe.new
|
2010-01-27 20:57:26 +00:00
|
|
|
@child = Process.fork do
|
2010-01-27 16:38:11 +00:00
|
|
|
@pipe.identify_as_child
|
|
|
|
Hydra::Runner.new(@pipe)
|
|
|
|
end
|
|
|
|
@pipe.identify_as_parent
|
|
|
|
end
|
2010-01-27 20:57:26 +00:00
|
|
|
teardown do
|
2010-01-27 22:19:32 +00:00
|
|
|
@pipe.close
|
2010-01-27 20:57:26 +00:00
|
|
|
Process.wait(@child)
|
|
|
|
end
|
2010-01-27 22:19:32 +00:00
|
|
|
should "boot and run a file and shut down" do
|
|
|
|
assert @pipe.gets.is_a?(Hydra::Messages::Runner::RequestFile)
|
|
|
|
|
2010-01-28 15:23:42 +00:00
|
|
|
file = File.join(File.dirname(__FILE__), 'fixtures', 'assert_true.rb')
|
2010-01-27 22:19:32 +00:00
|
|
|
@pipe.write(Hydra::Messages::Runner::RunFile.new(:file => file))
|
|
|
|
response = @pipe.gets
|
|
|
|
assert response.is_a?(Hydra::Messages::Runner::Results)
|
|
|
|
assert response.output =~ /Finished/
|
|
|
|
assert_equal file, response.file
|
|
|
|
@pipe.write(Hydra::Messages::Runner::Shutdown.new)
|
2010-01-27 16:38:11 +00:00
|
|
|
end
|
2010-01-27 22:19:32 +00:00
|
|
|
|
|
|
|
should "run a test" do
|
|
|
|
target = File.join(Dir.tmpdir, 'hydra_test.txt')
|
|
|
|
FileUtils.rm_f(target)
|
|
|
|
assert !File.exists?(target)
|
2010-01-28 15:23:42 +00:00
|
|
|
file = File.join(File.dirname(__FILE__), 'fixtures', 'write_file.rb')
|
2010-01-27 22:19:32 +00:00
|
|
|
assert @pipe.gets.is_a?(Hydra::Messages::Runner::RequestFile)
|
|
|
|
@pipe.write(Hydra::Messages::Runner::RunFile.new(:file => file))
|
|
|
|
response = @pipe.gets
|
|
|
|
@pipe.write(Hydra::Messages::Runner::Shutdown.new)
|
|
|
|
assert File.exists?(target)
|
|
|
|
assert_equal "HYDRA", File.read(target)
|
2010-01-27 20:19:48 +00:00
|
|
|
end
|
2010-01-27 16:38:11 +00:00
|
|
|
end
|
|
|
|
end
|