Skip to content

Commit

Permalink
Use PTYs to launch the lisp for clucumber.
Browse files Browse the repository at this point in the history
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
antifuchs committed May 1, 2010
1 parent 5fadb2c commit f78b1ce
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 58 deletions.
63 changes: 63 additions & 0 deletions clucumber.rb
@@ -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
15 changes: 1 addition & 14 deletions features/load-order.feature
Expand Up @@ -4,20 +4,7 @@ Feature: Load order of files
specific order, so that I can rely on definitions in one file to be
present in the other.

Scenario: Support files are loaded before step definitions

Given a standard Cucumber project directory structure
Given a stub lisp file named "features/support/a.lisp"
Given a stub lisp file named "features/step_definitions/a.lisp"

When I start clucumber on port 42427
Then show me the clucumber output
Then files should be loaded in this order:
| support/a.lisp |
| step_definitions/a.lisp |


Scenario: Files are loaded in alphabetical order
Scenario: Files are loaded in alphabetical order, support before steps

Given a standard Cucumber project directory structure
Given a stub lisp file named "features/support/a.lisp"
Expand Down
3 changes: 1 addition & 2 deletions features/step_definitions/clucumber_steps.rb
Expand Up @@ -7,7 +7,7 @@

When /^I start clucumber on port (\d+)$/ do |port|
@clucumber = ClucumberSubprocess.new(File.join(working_dir, 'features'), :port => port)
@clucumber.wait_until_started
@clucumber.start
end

Then /^show me the clucumber output$/ do
Expand All @@ -20,6 +20,5 @@

Then /^files should be loaded in this order:$/ do |expected|
actual = File.readlines(File.join(working_dir, "files")).map {|line| [line.strip] }
puts actual.inspect
expected.diff!(actual)
end
21 changes: 21 additions & 0 deletions features/support/env.rb
Expand Up @@ -50,3 +50,24 @@ def run(command)
FileUtils.rm_rf ClucumberWorld.working_dir
FileUtils.mkdir ClucumberWorld.working_dir
end


# Start the main clucumber file

require File.expand_path("../../clucumber.rb", File.dirname(__FILE__))
begin
@main_clucumber = ClucumberSubprocess.new(File.expand_path("../", File.dirname(__FILE__)),
:port => 42428)
at_exit do
@main_clucumber.kill
FileUtils.rm_f File.expand_path("../step_definitions/clucumber.wire", File.dirname(__FILE__))
end

@main_clucumber.start <<-LISP
;; Load the current dir's system definition,
;; not what might be linked somewhere in the system:
(load #p"#{File.expand_path("../../clucumber.asd", File.dirname(__FILE__))}")
LISP
rescue PTY::ChildExited
puts(@main_clucumber && @main_clucumber.output)
end
42 changes: 0 additions & 42 deletions features/support/lisp.rb

This file was deleted.

0 comments on commit f78b1ce

Please sign in to comment.