ocrunner 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -13,20 +13,40 @@ To run tests as files are changed (autotest-style), use:
13
13
 
14
14
  ocrunner --auto
15
15
 
16
+
17
+ == Signals
18
+
19
+ Control-c: kill ocrunner
20
+ Control-\: toggle verbosity and rerun tests. This is nice for when the pretty filtered output doesn't show quite enough information to you.
21
+
22
+
23
+ == Pretty debug logging with PRPLog()
24
+
25
+ This is a little crazy, but ocrunner has support for displaying debug log messaged from your Objective-C code through the use of a custom logging macro. The messages are colored purple in order to make them easier to see in the verbose output. To use this feature, add the following macro to a header or prefix file in your Xcode project:
26
+
27
+ #define PRPLog(format, ...) NSLog([NSString stringWithFormat: @"%s:%d:%s:\033[35m%@\033[0m", __PRETTY_FUNCTION__, __LINE__, __FILE__, format] ## __VA_ARGS__)
28
+
29
+ ocrunner will display the latest version of this macro when run with --prplog-help.
30
+
31
+
16
32
  == I don't like your defaults
17
33
 
18
34
  Don't worry, you can specify the target/configuration/sdk options passed to xcodebuild. You can see all the available options by running ocrunner -h:
35
+
36
+ --sdk, -s <s>: SDK to build against (default: iphonesimulator3.1.3)
37
+ --target, -t <s>: Target to build (default: Test)
38
+ --config, -c <s>: Configuration to use (default: Debug)
39
+ --parallel, -p: Use multiple processors to build multiple targets (parallelizeTargets) (default: true)
40
+ --auto, -a: Watch filesystem for changes and run tests when they occur
41
+ --growl, -g: Report results using Growl
42
+ --debug-command, -d: Print xcodebuild command and exit
43
+ --verbose, -v: Display all xcodebuild output after summary
44
+ --loud-compilation, -l: Always show verbose output when a compilation or linking error occurs (default: true)
45
+ --prplog, -r: Display PRPLog log messages (default: true)
46
+ --prplog-help, -o: Print PRPLog code example and exit
47
+ --version, -e: Print version and exit
48
+ --help, -h: Show this message
19
49
 
20
- --sdk, -s <s>: SDK to build against (default: iphonesimulator3.1.3)
21
- --target, -t <s>: Target to build (default: Test)
22
- --config, -c <s>: Configuration to use (default: Debug)
23
- --parallel, -p: Use multiple processors to build multiple targets (parallelizeTargets) (default: true)
24
- --auto, -a: Watch filesystem for changes and run tests when they occur
25
- --growl, -g: Report results using Growl
26
- --debug-command, -d: Print xcodebuild command and exit
27
- --verbose, -v: Display all xcodebuild output after summary
28
- --version, -e: Print version and exit
29
- --help, -h: Show this message
30
50
 
31
51
  == Note on Patches/Pull Requests
32
52
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.3.0
data/lib/ocrunner.rb CHANGED
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/ocrunner/cli'
2
1
  require File.dirname(__FILE__) + '/ocrunner/console'
2
+ require File.dirname(__FILE__) + '/ocrunner/cli'
3
3
  require File.dirname(__FILE__) + '/ocrunner/test_case'
4
4
  require File.dirname(__FILE__) + '/ocrunner/test_error'
5
5
  require File.dirname(__FILE__) + '/ocrunner/test_suite'
data/lib/ocrunner/cli.rb CHANGED
@@ -3,6 +3,11 @@ require 'fssm'
3
3
 
4
4
  module OCRunner
5
5
  module CLI
6
+
7
+ class << self
8
+ include OCRunner::Console
9
+ end
10
+
6
11
  def self.run
7
12
 
8
13
  Kernel.trap('INT') { puts; exit }
@@ -26,9 +31,22 @@ module OCRunner
26
31
  opt :debug_command, "Print xcodebuild command and exit", :type => :boolean, :default => false
27
32
  opt :verbose, "Display all xcodebuild output after summary", :type => :boolean, :default => false
28
33
  opt :loud_compilation, "Always show verbose output when a compilation or linking error occurs", :type => :boolean, :default => true
34
+ opt :prplog, "Display PRPLog log messages", :type => :boolean, :default => true
35
+ opt :prplog_help, "Print PRPLog code example and exit", :type => :boolean, :default => false
36
+ end
37
+
38
+ if opts[:prplog_help]
39
+ present do
40
+ puts indent blue "Add this to a header or prefix file in your Xcode project:"
41
+ puts indent '#define PRPLog(format, ...) NSLog([NSString stringWithFormat: @"%s:%d:%s:\033[35m%@\033[0m", __PRETTY_FUNCTION__, __LINE__, __FILE__, format] ## __VA_ARGS__)'
42
+ end
43
+ exit
29
44
  end
30
45
 
31
46
  execute = Proc.new{ OCRunner::TestRunner.new(opts) }
47
+
48
+ Kernel.trap('QUIT') { opts[:verbose] = !opts[:verbose]; execute.call}
49
+
32
50
  execute.call
33
51
 
34
52
  if opts[:auto]
@@ -1,12 +1,22 @@
1
- # color helpers courtesy of RSpec http://github.com/dchelimsky/rspec
1
+ # color helpers originally courtesy of RSpec http://github.com/dchelimsky/rspec
2
2
 
3
3
  module OCRunner
4
4
  module Console
5
5
  def colorize(text, color_code)
6
- "#{color_code}#{text}\033[0m"
6
+ "#{color_code}#{text.to_s}\033[0m"
7
7
  end
8
8
 
9
9
  def red(text); colorize(text, "\033[31m"); end
10
10
  def green(text); colorize(text, "\033[32m"); end
11
+ def blue(text); colorize(text, "\033[34m"); end
12
+
13
+ def indent(text='')
14
+ " " + text.to_s
15
+ end
16
+ def present(&block)
17
+ puts
18
+ yield
19
+ puts
20
+ end
11
21
  end
12
22
  end
@@ -15,8 +15,8 @@ module OCRunner
15
15
  @compilation_error_occurred = false
16
16
  @output = []
17
17
 
18
- setup
19
18
  build_command
19
+ setup
20
20
  run_tests
21
21
  summarize
22
22
  display_results
@@ -31,37 +31,39 @@ module OCRunner
31
31
  @command = "xcodebuild -target #{@options[:target]} -configuration #{@options[:config]} " +
32
32
  "-sdk #{@options[:sdk]} #{@options[:parallel] ? '-parallelizeTargets' : ''} build"
33
33
  if @options[:debug_command]
34
- puts @command
34
+ present do
35
+ puts indent @command
36
+ end
35
37
  exit
36
38
  end
37
39
  end
38
40
 
39
41
  def run_tests
40
- IO.popen("#{@command} 2>&1") do |f|
41
- while line = f.gets do
42
- @log << line
43
- process_console_output(line)
44
- $stdout.flush
45
- end
42
+
43
+ puts "ocrunner started. control-c to exit, control-\\ to toggle verbosity\n\n"
44
+
45
+ execute @command do |line|
46
+ @log << line
47
+ process_console_output(line)
48
+ $stdout.flush
46
49
  end
47
50
  end
48
51
 
49
52
  def summarize
50
53
 
51
54
  @suites.each do |suite|
52
- suite.cases.reject {|kase| kase.passed?}.each do |kase|
53
- out
55
+ suite.failed_cases.each do |kase|
54
56
  out ' ' + red("[#{suite.name} #{kase.name}] FAIL")
55
57
  kase.errors.each do |error|
56
58
  out ' ' + red(error.message) + " line #{error.line} of #{clean_path(error.path)}"
57
59
  end
58
60
  end
59
- out
61
+ out if suite.failures?
60
62
  end
61
63
 
62
64
  @suites.each do |suite|
63
- failed = suite.cases.reject {|kase| kase.passed?}
64
- out "Suite '#{suite.name}': #{suite.cases.size - failed.size} passes and #{failed.size} failures in #{suite.time} seconds."
65
+ number = suite.failed_cases.size
66
+ out "Suite '#{suite.name}': #{suite.cases.size - number} passes and #{number} failures in #{suite.time} seconds."
65
67
  end
66
68
 
67
69
  out
@@ -74,7 +76,6 @@ module OCRunner
74
76
  end
75
77
 
76
78
  def display_results
77
- puts
78
79
  puts @log if @options[:verbose] || (compilation_error_occurred && @options[:loud_compilation])
79
80
  puts @output.join("\n")
80
81
  puts
@@ -96,6 +97,28 @@ module OCRunner
96
97
  end
97
98
 
98
99
  def process_console_output(line)
100
+
101
+ if @options[:prplog]
102
+ if line.include?("\033\[35m")
103
+ line =~ /-(\[.+\]):(\d+):(.+):/
104
+ out blue("#{$1} on line #{$2} of #{clean_path($3)}:")
105
+ out line.slice(line.index("\033\[35m")..-1)
106
+ @debug_output = true
107
+ return
108
+ end
109
+
110
+ if line.include?("\033[0m")
111
+ @debug_output = false
112
+ out line
113
+ out
114
+ return
115
+ end
116
+
117
+ if @debug_output
118
+ out line
119
+ return
120
+ end
121
+ end
99
122
 
100
123
  # test case started
101
124
  if line =~ /Test Case '-\[.+ (.+)\]' started/
@@ -134,9 +157,9 @@ module OCRunner
134
157
  if line =~ /The executable for the test bundle at (.+\.octest) could not be found/
135
158
  build_error("Test executable #{clean_path($1)} could not be found")
136
159
  end
137
-
160
+
138
161
  # compilation errors
139
- if line =~ /(.+\.m):(\d+): error: (.*)/
162
+ if !@current_case && line =~ /(.+\.m):(\d+): error: (.*)/
140
163
  compilation_error_occurred!
141
164
  build_error($&)
142
165
  end
@@ -153,6 +176,11 @@ module OCRunner
153
176
  build_error($&)
154
177
  end
155
178
 
179
+ # bus error
180
+ if line =~ /Bus error/
181
+ build_error('Bus error while running tests.')
182
+ end
183
+
156
184
  # segfault
157
185
  if line =~ /Segmentation fault/
158
186
  build_error('Segmentation fault while running tests.')
@@ -170,7 +198,7 @@ module OCRunner
170
198
  end
171
199
 
172
200
  def out(line = '')
173
- @output << line
201
+ @output << line.rstrip
174
202
  end
175
203
 
176
204
  def clean_path(path)
@@ -179,7 +207,19 @@ module OCRunner
179
207
 
180
208
  def growl(message)
181
209
  if @options[:growl]
182
- `growlnotify -i "xcodeproj" -m "#{message}" `
210
+ execute "growlnotify -i \"xcodeproj\" -m \"#{message}\"" do |error|
211
+ if error =~ /command not found/
212
+ out red('You must have growl and growl notify installed to enable growl support. See http://growl.info.')
213
+ end
214
+ end
215
+ end
216
+ end
217
+
218
+ def execute(cmd, &block)
219
+ IO.popen("#{cmd} 2>&1") do |f|
220
+ while line = f.gets do
221
+ yield line
222
+ end
183
223
  end
184
224
  end
185
225
 
@@ -10,5 +10,13 @@ module OCRunner
10
10
  @name = name
11
11
  @cases = []
12
12
  end
13
+
14
+ def failures?
15
+ @cases.any? {|kase| !kase.passed?}
16
+ end
17
+
18
+ def failed_cases
19
+ @cases.reject {|kase| kase.passed?}
20
+ end
13
21
  end
14
22
  end
data/ocrunner.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ocrunner}
8
- s.version = "0.2.5"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jim Benton"]
12
- s.date = %q{2010-04-08}
12
+ s.date = %q{2010-04-09}
13
13
  s.default_executable = %q{ocrunner}
14
14
  s.description = %q{Provides pretty console output for running OCUnit tests with xcodebuilder from the command line}
15
15
  s.email = %q{jim@autonomousmachine.com}
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 5
9
- version: 0.2.5
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jim Benton
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-08 00:00:00 -05:00
17
+ date: 2010-04-09 00:00:00 -05:00
18
18
  default_executable: ocrunner
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency