forked from antifuchs/clucumber
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PTYs to launch the lisp for clucumber.
Now we can launch multiple lisps, and keep track of them. Use this from the main test suite, and expose it to other programs who might want to use it, too.
- Loading branch information
Showing
5 changed files
with
86 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'pty' | ||
|
||
class ClucumberSubprocess | ||
attr_reader :output | ||
|
||
def initialize(dir, options={}) | ||
@dir = dir | ||
lisp = options[:lisp] || ENV['LISP'] || 'sbcl --disable-debugger' | ||
@port = options[:port] || raise("Need a port to run clucumber on.") | ||
@output = "" | ||
|
||
Dir.chdir(@dir) do | ||
@out, @in, @pid = PTY.spawn(lisp) | ||
end | ||
@reader = Thread.start { | ||
record_output | ||
} | ||
@in.puts(<<-LISP) | ||
(require :asdf) | ||
LISP | ||
end | ||
|
||
def start(additional_forms="") | ||
@in.puts <<-LISP | ||
#{additional_forms} | ||
(asdf:oos 'asdf:load-op :clucumber) | ||
(clucumber-external:start #p"./" "localhost" #{@port}) | ||
LISP | ||
until socket = TCPSocket.new("localhost", @port) rescue nil | ||
sleep 0.01 | ||
end | ||
File.open(File.join(@dir, "step_definitions", "clucumber.wire"), "w") do |out| | ||
YAML.dump({'host' => "localhost", 'port' => @port}, out) | ||
end | ||
socket.close | ||
end | ||
|
||
def record_output | ||
begin | ||
while line = @out.readline | ||
@output << line | ||
end | ||
rescue PTY::ChildExited | ||
STDOUT.puts "child exited, stopping." | ||
nil | ||
end | ||
end | ||
|
||
def kill | ||
if @pid | ||
@reader.terminate! | ||
Process.kill("TERM", @pid) | ||
Process.waitpid(@pid) | ||
@pid = nil | ||
end | ||
rescue PTY::ChildExited | ||
@pid = nil | ||
end | ||
|
||
def alive? | ||
!@pid.nil? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.