Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for writing test output to disk

  • Loading branch information...
commit bf631f0ffbfe5647fefe76d4c730366f8cb83fe2 1 parent b4f93d9
Luke Bayes authored
22 lib/sprout/executable/session.rb
@@ -99,21 +99,22 @@ def add_action_alias alias_name, source_name
99 99 # already exists.
100 100 def create_action_method options
101 101 name = options[:name]
102   - accessor_can_be_defined_at name
103   -
104   - define_method(name) do |*params|
105   - action = name.to_s
106   - action = "y" if name == :confirm # Convert affirmation
107   - action << " #{params.join(' ')}" unless params.nil?
108   - action_stack << action
109   - execute_actions if process_launched?
  102 + if accessor_can_be_defined_at? name
  103 + define_method(name) do |*params|
  104 + action = name.to_s
  105 + action = "y" if name == :confirm # Convert confirmation
  106 + action << " #{params.join(' ')}" unless params.nil?
  107 + action_stack << action
  108 + execute_actions if process_launched?
  109 + end
110 110 end
111 111 end
112 112
113 113 ##
114   - # TODO: Raise an exception if the name is
  114 + # TODO: Raise an exception and/or return false if the name is
115 115 # already taken?
116   - def accessor_can_be_defined_at name
  116 + def accessor_can_be_defined_at? name
  117 + true
117 118 end
118 119
119 120 end
@@ -280,6 +281,7 @@ def system_execute binary, params
280 281 # solution.
281 282 #params = "#{params} " + '2>&1'
282 283 @process_thread = Sprout.current_system.execute_thread binary, params, prompt do |message|
  284 + yield message if block_given?
283 285 Sprout.stdout.printf message
284 286 @prompted = true if prompt.match message
285 287 end
4 lib/sprout/system/base_system.rb
@@ -121,6 +121,10 @@ def execute_thread tool, options='', prompt=nil, &block
121 121 sleep(0.1)
122 122 end
123 123
  124 + if !t.alive?
  125 + raise Sprout::Errors::UsageError.new(t['runner'].read_err)
  126 + end
  127 +
124 128 t
125 129 end
126 130
61 test/fixtures/executable/fdb.rb
@@ -3,6 +3,43 @@ module Sprout
3 3
4 4 class FDB < Executable::Session
5 5
  6 + ##
  7 + # Path to the file where test results should be written.
  8 + #
  9 + # @default 'TestResults.xml'
  10 + # @see :test_result_prefix
  11 + # @see :test_result_suffix
  12 + attr_accessor :test_result_file
  13 +
  14 + ##
  15 + # Regular expression that will match the preamble that is sent
  16 + # by your test framework to indicate the beginning of structured
  17 + # test output.
  18 + #
  19 + # @default /<TestResults>/
  20 + # @see :test_result_file
  21 + # @see :test_result_suffix
  22 + attr_accessor :test_result_prefix
  23 +
  24 + ##
  25 + # Regular expression that will match the suffix that is sent
  26 + # by your test framework to indicate the end of structured
  27 + # test output.
  28 + #
  29 + # @default /<\/TestResults>/
  30 + # @see :test_result_file
  31 + # @see :test_result_prefix
  32 + attr_accessor :test_result_suffix
  33 +
  34 + def initialize
  35 + super
  36 + @test_result = ''
  37 + @inside_test_result = false
  38 + @test_result_file = 'TestResults.xml'
  39 + @test_result_prefix = /<TestResults>/
  40 + @test_result_suffix = /<\/TestResults>/
  41 + end
  42 +
6 43 set :default_prefix, '-'
7 44
8 45 ##
@@ -737,6 +774,30 @@ class FDB < Executable::Session
737 774 add_action :what
738 775 add_action_alias :wh, :what
739 776
  777 + def system_execute binary, params
  778 + super do |message|
  779 + if message.match test_result_suffix
  780 + write_test_result
  781 + end
  782 + if @inside_test_result
  783 + @test_result << message
  784 + end
  785 + if message.match test_result_prefix
  786 + @inside_test_result = true
  787 + end
  788 + end
  789 + end
  790 +
  791 + private
  792 +
  793 + def write_test_result
  794 + File.open test_result_file, 'w+' do |f|
  795 + f.write @test_result
  796 + end
  797 + @test_result = ''
  798 + @inside_test_result = false
  799 + end
  800 +
740 801 end
741 802 end
742 803
11 test/fixtures/executable/flex3sdk_gem/fdb
@@ -3,6 +3,7 @@
3 3 class FakeFDB
4 4
5 5 def initialize
  6 + validate_argv
6 7 str = "Adobe fdb (Flash Player Debugger) [build 16076]\n"
7 8 str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
8 9 str << "(fdb) "
@@ -39,6 +40,12 @@ class FakeFDB
39 40 gather_input
40 41 end
41 42
  43 + def validate_argv
  44 + if ARGV.size > 0
  45 + raise "FAKE FDB doesn't expect any params, but received, #{ARGV}"
  46 + end
  47 + end
  48 +
42 49 def handle_run args
43 50 str = "Waiting for Player to connect\n"
44 51 str << "Player connected; session starting.\n"
@@ -57,6 +64,9 @@ class FakeFDB
57 64
58 65 def handle_continue args
59 66 str = "Continuing now\n"
  67 + str << "<TestResults>\n"
  68 + str << "Fake Content\n"
  69 + str << "</TestResults>\n"
60 70 str << "(fdb) "
61 71 printf str
62 72 end
@@ -88,3 +98,4 @@ end
88 98
89 99 fake_fdb = FakeFDB.new
90 100
  101 +
12 test/unit/executable_session_test.rb
@@ -10,12 +10,18 @@ class ExecutableSessionTest < Test::Unit::TestCase
10 10 # Uncomment the following to see interactive sessions:
11 11 #Sprout.stdout = $stdout
12 12 #Sprout.stderr = $stderr
  13 + @test_result_file = File.join fixtures, 'executable', 'Result.xml'
  14 + end
  15 +
  16 + teardown do
  17 + remove_file @test_result_file
13 18 end
14 19
15 20 should "execute without shell params" do
16 21 @fdb = Sprout::FDB.new
17 22 # Comment to hit real FDB:
18 23 @fdb.binary_path = File.join fixtures, 'executable', 'flex3sdk_gem', 'fdb'
  24 + @fdb.test_result_file = @test_result_file
19 25
20 26 @fdb.execute false
21 27 @fdb.run
@@ -28,10 +34,14 @@ class ExecutableSessionTest < Test::Unit::TestCase
28 34 @fdb.break "AsUnitRunner:12"
29 35
30 36 @fdb.continue
31   - @fdb.continue
  37 + #@fdb.continue
32 38
33 39 #@fdb.handle_user_input
34 40 @fdb.quit
  41 +
  42 + assert_file @test_result_file do |content|
  43 + assert_match content, /Fake Content/
  44 + end
35 45 end
36 46
37 47 end

0 comments on commit bf631f0

Please sign in to comment.
Something went wrong with that request. Please try again.