Skip to content

Commit

Permalink
Tied up executable session so that it works well with real and fake fdb
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebayes committed Jan 13, 2011
1 parent 5779bab commit a9810fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 99 deletions.
8 changes: 8 additions & 0 deletions lib/sprout/executable/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def initialize
initialize_parameters
end

def stdout=(io)
@stdout = io
end

def stdout
@stdout ||= Sprout.stdout
end

def parse! commandline_options
begin
option_parser.parse! commandline_options
Expand Down
14 changes: 11 additions & 3 deletions lib/sprout/executable/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ def read_from pipe
break if line.match prompt

if char == "\n"
$stdout.printf line
stdout.printf line
line = ''
end
end

$stdout.printf line
stdout.printf line

should_continue_reading? line, pipe
end
Expand Down Expand Up @@ -280,6 +280,14 @@ def update_rake_task_name_from_args *args
#
# @return [Thread]
def system_execute binary, params
# Combine the stderr and stdout for long-lived
# processes so that they are both written to
# stdout, this allows us to collect these streams
# without threads or blocking eternally.
#
# Thanks to https://github.com/apinstein for this
# solution.
params = "#{params} " + '2>&1'
Sprout.current_system.execute_thread binary, params
end

Expand All @@ -297,7 +305,7 @@ def execute_actions
##
# Execute a single action.
def execute_action action, silence=false
$stdout.puts(action) unless silence
stdout.puts(action) unless silence
process_runner.puts action
wait_for_prompt
end
Expand Down
104 changes: 8 additions & 96 deletions test/unit/executable_session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,115 +10,27 @@ class ExecutableSessionTest < Test::Unit::TestCase
# Uncomment the following to see interactive sessions:
#Sprout.stdout = $stdout
#Sprout.stderr = $stderr

@fdb = Sprout::FDB.new
@fdb.binary_path = File.join fixtures, 'executable', 'flex3sdk_gem', 'fdb'
end

should "execute without shell params" do
@fdb = Sprout::FDB.new
@fdb.execute false
@fdb.run

Kernel.system 'open ~/Projects/Sprouts/flashsdk/test/fixtures/flashplayer/AsUnit\ Runner.swf'

@fdb.wait_for_prompt
# Uncomment if you are on OSX and want to
# test the real FDB while running a real SWF:
#Kernel.system 'open ~/Projects/Sprouts/flashsdk/test/fixtures/flashplayer/AsUnit\ Runner.swf'
#@fdb.wait_for_prompt

@fdb.break "AsUnitRunner:12"

@fdb.continue
@fdb.continue
@fdb.quit

#@fdb.handle_user_input
end
end

end


=begin
context "a new daemon delegate" do
setup do
# Uncomment the following to see interactive sessions:
#Sprout.stdout = $stdout
#Sprout.stderr = $stderr
# Comment the following and install the flashsdk
# to run test against actual fdb:
insert_fake_executable File.join(fixtures, 'executable', 'flex3sdk_gem', 'fdb')
end
should "execute without shell params" do
@fdb = Sprout::FDB.new
# For some reason, using mocha expectations are
# actually stubbing the methods and breaking this
# test. Not sure what I'm doing wrong here...
#@fdb.expects(:execute_action).at_least(6)
@fdb.run
@fdb.break "AsUnitRunner:12"
@fdb.continue
@fdb.kill
@fdb.confirm
@fdb.quit
@fdb.execute
end
should "open and wait for real-time interactions" do
@fdb = Sprout::FDB.new
# For some reason, using mocha expectations are
# actually stubbing the methods and breaking this
# test. Not sure what I'm doing wrong here...
#@fdb.expects(:execute_action).at_least(6)
@fdb.execute false
@fdb.run
@fdb.break "AsUnitRunner:12"
@fdb.continue
@fdb.kill
@fdb.confirm
@fdb.quit
@fdb.wait # wait for actions to finish.
end
should "print errors" do
##
# Collect the messages sent to stderr:
@fdb = Sprout::FDB.new
# For some reason, using mocha expectations are
# actually stubbing the methods and breaking this
# test. Not sure what I'm doing wrong here...
#@fdb.expects(:execute_action).at_least(6)
@fdb.execute false
@fdb.run_with_error
@fdb.quit
@fdb.wait # wait for actions to finish.
assert_matches /This is an error!/, Sprout.stderr.read
end
should "execute from rake task" do
f = fdb :fdb_debug do |t|
t.run
t.break "AsUnitRunner:12"
t.continue
t.kill
t.confirm
t.quit
end
f.execute
# NOTE: If this call raises, then the
# Executable.update_rake_task_name method
# must have changed, and the Daemon override
# is no longer preventing non-File tasks
# from being added to the CLEAN collection.
#
# Adding this as a message to the error would
# not display for some reason...
assert_equal 0, CLEAN.size
end
end

end
=end

0 comments on commit a9810fa

Please sign in to comment.