Permalink
Browse files

Added support for writing test output to disk

  • Loading branch information...
1 parent b4f93d9 commit bf631f0ffbfe5647fefe76d4c730366f8cb83fe2 @lukebayes committed Mar 24, 2011
@@ -99,21 +99,22 @@ def add_action_alias alias_name, source_name
# already exists.
def create_action_method options
name = options[:name]
- accessor_can_be_defined_at name
-
- define_method(name) do |*params|
- action = name.to_s
- action = "y" if name == :confirm # Convert affirmation
- action << " #{params.join(' ')}" unless params.nil?
- action_stack << action
- execute_actions if process_launched?
+ if accessor_can_be_defined_at? name
+ define_method(name) do |*params|
+ action = name.to_s
+ action = "y" if name == :confirm # Convert confirmation
+ action << " #{params.join(' ')}" unless params.nil?
+ action_stack << action
+ execute_actions if process_launched?
+ end
end
end
##
- # TODO: Raise an exception if the name is
+ # TODO: Raise an exception and/or return false if the name is
# already taken?
- def accessor_can_be_defined_at name
+ def accessor_can_be_defined_at? name
+ true
end
end
@@ -280,6 +281,7 @@ def system_execute binary, params
# solution.
#params = "#{params} " + '2>&1'
@process_thread = Sprout.current_system.execute_thread binary, params, prompt do |message|
+ yield message if block_given?
Sprout.stdout.printf message
@prompted = true if prompt.match message
end
@@ -121,6 +121,10 @@ def execute_thread tool, options='', prompt=nil, &block
sleep(0.1)
end
+ if !t.alive?
+ raise Sprout::Errors::UsageError.new(t['runner'].read_err)
+ end
+
t
end
@@ -3,6 +3,43 @@ module Sprout
class FDB < Executable::Session
+ ##
+ # Path to the file where test results should be written.
+ #
+ # @default 'TestResults.xml'
+ # @see :test_result_prefix
+ # @see :test_result_suffix
+ attr_accessor :test_result_file
+
+ ##
+ # Regular expression that will match the preamble that is sent
+ # by your test framework to indicate the beginning of structured
+ # test output.
+ #
+ # @default /<TestResults>/
+ # @see :test_result_file
+ # @see :test_result_suffix
+ attr_accessor :test_result_prefix
+
+ ##
+ # Regular expression that will match the suffix that is sent
+ # by your test framework to indicate the end of structured
+ # test output.
+ #
+ # @default /<\/TestResults>/
+ # @see :test_result_file
+ # @see :test_result_prefix
+ attr_accessor :test_result_suffix
+
+ def initialize
+ super
+ @test_result = ''
+ @inside_test_result = false
+ @test_result_file = 'TestResults.xml'
+ @test_result_prefix = /<TestResults>/
+ @test_result_suffix = /<\/TestResults>/
+ end
+
set :default_prefix, '-'
##
@@ -737,6 +774,30 @@ class FDB < Executable::Session
add_action :what
add_action_alias :wh, :what
+ def system_execute binary, params
+ super do |message|
+ if message.match test_result_suffix
+ write_test_result
+ end
+ if @inside_test_result
+ @test_result << message
+ end
+ if message.match test_result_prefix
+ @inside_test_result = true
+ end
+ end
+ end
+
+ private
+
+ def write_test_result
+ File.open test_result_file, 'w+' do |f|
+ f.write @test_result
+ end
+ @test_result = ''
+ @inside_test_result = false
+ end
+
end
end
@@ -3,6 +3,7 @@
class FakeFDB
def initialize
+ validate_argv
str = "Adobe fdb (Flash Player Debugger) [build 16076]\n"
str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
str << "(fdb) "
@@ -39,6 +40,12 @@ class FakeFDB
gather_input
end
+ def validate_argv
+ if ARGV.size > 0
+ raise "FAKE FDB doesn't expect any params, but received, #{ARGV}"
+ end
+ end
+
def handle_run args
str = "Waiting for Player to connect\n"
str << "Player connected; session starting.\n"
@@ -57,6 +64,9 @@ class FakeFDB
def handle_continue args
str = "Continuing now\n"
+ str << "<TestResults>\n"
+ str << "Fake Content\n"
+ str << "</TestResults>\n"
str << "(fdb) "
printf str
end
@@ -88,3 +98,4 @@ end
fake_fdb = FakeFDB.new
+
@@ -10,12 +10,18 @@ class ExecutableSessionTest < Test::Unit::TestCase
# Uncomment the following to see interactive sessions:
#Sprout.stdout = $stdout
#Sprout.stderr = $stderr
+ @test_result_file = File.join fixtures, 'executable', 'Result.xml'
+ end
+
+ teardown do
+ remove_file @test_result_file
end
should "execute without shell params" do
@fdb = Sprout::FDB.new
# Comment to hit real FDB:
@fdb.binary_path = File.join fixtures, 'executable', 'flex3sdk_gem', 'fdb'
+ @fdb.test_result_file = @test_result_file
@fdb.execute false
@fdb.run
@@ -28,10 +34,14 @@ class ExecutableSessionTest < Test::Unit::TestCase
@fdb.break "AsUnitRunner:12"
@fdb.continue
- @fdb.continue
+ #@fdb.continue
#@fdb.handle_user_input
@fdb.quit
+
+ assert_file @test_result_file do |content|
+ assert_match content, /Fake Content/
+ end
end
end

0 comments on commit bf631f0

Please sign in to comment.