Class: OCRunner::TestRunner
- Inherits:
-
Object
- Object
- OCRunner::TestRunner
- Includes:
- Console
- Defined in:
- lib/ocrunner/test_runner.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#current_directory ⇒ Object
readonly
Returns the value of attribute current_directory.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#suites ⇒ Object
readonly
Returns the value of attribute suites.
Instance Method Summary collapse
- #build_command ⇒ Object
- #clean_path(path) ⇒ Object
- #display_log ⇒ Object
- #display_summary ⇒ Object
-
#initialize(options) ⇒ TestRunner
constructor
A new instance of TestRunner.
- #process_console_output(line) ⇒ Object
- #run_tests ⇒ Object
Methods included from Console
Constructor Details
#initialize(options) ⇒ TestRunner
Returns a new instance of TestRunner.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ocrunner/test_runner.rb', line 7 def initialize() @suites = [] @log = '' @current_directory = Dir.pwd @options = build_command run_tests display_summary display_log end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/ocrunner/test_runner.rb', line 5 def command @command end |
#current_directory ⇒ Object (readonly)
Returns the value of attribute current_directory.
5 6 7 |
# File 'lib/ocrunner/test_runner.rb', line 5 def current_directory @current_directory end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
5 6 7 |
# File 'lib/ocrunner/test_runner.rb', line 5 def log @log end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/ocrunner/test_runner.rb', line 5 def @options end |
#suites ⇒ Object (readonly)
Returns the value of attribute suites.
5 6 7 |
# File 'lib/ocrunner/test_runner.rb', line 5 def suites @suites end |
Instance Method Details
#build_command ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ocrunner/test_runner.rb', line 19 def build_command @command = "xcodebuild -target #{@options[:target]} -configuration #{@options[:config]} " + "-sdk #{@options[:sdk]} #{@options[:parallel] ? '-parallelizeTargets' : ''} build" if @options[:debug_command] puts @command exit end end |
#clean_path(path) ⇒ Object
114 115 116 |
# File 'lib/ocrunner/test_runner.rb', line 114 def clean_path(path) path.gsub(@current_directory + '/', '') end |
#display_log ⇒ Object
63 64 65 |
# File 'lib/ocrunner/test_runner.rb', line 63 def display_log puts @log if @options[:verbose] end |
#display_summary ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ocrunner/test_runner.rb', line 38 def display_summary passed = true @suites.each do |suite| failed = suite.cases.reject {|c| c.passed} failed.each do |c| passed = false puts puts ' ' + red("[#{suite.name} #{c.name}] FAIL") + " on line #{c.line} of #{clean_path(c.path)}" puts ' ' + c. unless c..nil? end puts end @suites.each do |suite| failed = suite.cases.reject {|c| c.passed} puts "Suite '#{suite.name}': #{suite.cases.size - failed.size} passes and #{failed.size} failures in #{suite.time} seconds." end puts if passed puts green('*** BUILD SUCCEEDED ***') else puts red('*** BUILD FAILED ***') end end |
#process_console_output(line) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ocrunner/test_runner.rb', line 67 def process_console_output(line) # test case started if line =~ /Test Case '-\[\w+ (.+)\]' started/ @current_case = TestCase.new($1) end # test case passed if line =~ /Test Case .+ passed/ @current_case.passed = true @current_suite.cases << @current_case @current_case = nil print(green('.')) end # test failure if line =~ /(.+\.m):(\d+): error: -\[(.+) (.+)\] :(?: (.+):)? / @current_case.passed = false @current_case.path = $1 @current_case.line = $2 @current_case. = $5 @current_suite.cases << @current_case @current_case = nil print red('.') end # start test suite if line =~ /Test Suite '([^\/]+)' started/ @current_suite = TestSuite.new($1) print "#{$1} " end # finish test suite if @current_suite && line =~ /^Executed/ && line =~ /\(([\d\.]+)\) seconds/ @current_suite.time = $1 @suites << @current_suite @current_suite = nil print "\n" # clear console line end # no Xcode project found if line =~ /does not contain an Xcode project/ puts red('No Xcode project was found.') exit end end |
#run_tests ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ocrunner/test_runner.rb', line 28 def run_tests IO.popen("#{@command} 2>&1") do |f| while line = f.gets do @log << line process_console_output(line) $stdout.flush end end end |