turn 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +10 -0
- data/Gemfile +9 -0
- data/History.txt +26 -1
- data/NOTICE.txt +35 -0
- data/{README.txt → README.md} +36 -33
- data/Version.txt +1 -1
- data/demo/test_autorun_minitest.rb +4 -2
- data/lib/turn.rb +2 -2
- data/lib/turn/autoload.rb +6 -0
- data/lib/turn/autorun/minitest.rb +11 -167
- data/lib/turn/autorun/minitest0.rb +163 -0
- data/lib/turn/autorun/testunit.rb +6 -113
- data/lib/turn/autorun/testunit0.rb +116 -0
- data/lib/turn/colorize.rb +19 -11
- data/lib/turn/command.rb +15 -2
- data/lib/turn/components/method.rb +13 -2
- data/lib/turn/controller.rb +79 -33
- data/lib/turn/reporter.rb +4 -2
- data/lib/turn/reporters/cue_reporter.rb +1 -1
- data/lib/turn/reporters/dot_reporter.rb +5 -1
- data/lib/turn/reporters/outline_reporter.rb +17 -5
- data/lib/turn/reporters/pretty_reporter.rb +24 -17
- data/lib/turn/runners/crossrunner.rb +2 -2
- data/lib/turn/runners/isorunner.rb +11 -10
- data/lib/turn/runners/minirunner.rb +34 -52
- data/lib/turn/runners/solorunner.rb +0 -1
- data/lib/turn/runners/testrunner.rb +12 -15
- data/lib/turn/version.rb +1 -1
- data/license/GPLv2.txt +340 -0
- data/license/MIT-LICENSE.txt +21 -0
- data/license/RUBY-LICENSE.txt +56 -0
- data/test/helper.rb +26 -1
- data/test/test_framework.rb +22 -1
- data/test/test_reporters.rb +1 -1
- data/test/test_runners.rb +13 -4
- data/turn.gemspec +21 -30
- metadata +63 -92
data/lib/turn/command.rb
CHANGED
@@ -16,6 +16,7 @@ module Turn
|
|
16
16
|
# -I --loadpath=PATHS add given PATHS to the $LOAD_PATH
|
17
17
|
# -r --requires=LIBS require given LIBS before running tests
|
18
18
|
# -m --minitest Force use of MiniTest framework.
|
19
|
+
# -t --trace Turn on invoke/execute tracing, enable full backtrace.
|
19
20
|
#
|
20
21
|
# RUN MODES
|
21
22
|
# --normal run all tests in a single process [default]
|
@@ -64,6 +65,9 @@ module Turn
|
|
64
65
|
# Output mode.
|
65
66
|
attr :outmode
|
66
67
|
|
68
|
+
# Enable full backtrace
|
69
|
+
attr :trace
|
70
|
+
|
67
71
|
#
|
68
72
|
def initialize
|
69
73
|
@live = nil
|
@@ -75,6 +79,7 @@ module Turn
|
|
75
79
|
@runmode = nil
|
76
80
|
@outmode = nil
|
77
81
|
@framework = RUBY_VERSION >= "1.9" ? :minitest : :testunit
|
82
|
+
@trace = nil
|
78
83
|
end
|
79
84
|
|
80
85
|
#
|
@@ -118,6 +123,10 @@ module Turn
|
|
118
123
|
@framework = :minitest
|
119
124
|
end
|
120
125
|
|
126
|
+
opts.on("-T", '--trace', "Turn on invoke/execute tracing, enable full backtrace") do
|
127
|
+
@trace = true
|
128
|
+
end
|
129
|
+
|
121
130
|
# Turn does not support Test::Unit 2.0+
|
122
131
|
#opts.on('-u', '--testunit', "Force use of TestUnit framework") do
|
123
132
|
# @framework = :testunit
|
@@ -203,9 +212,10 @@ module Turn
|
|
203
212
|
|
204
213
|
@loadpath = ['lib'] if loadpath.empty?
|
205
214
|
|
206
|
-
tests = ARGV.empty? ? nil :
|
215
|
+
tests = ARGV.empty? ? nil : argv.dup
|
207
216
|
|
208
|
-
|
217
|
+
#config = Turn::Configuration.new do |c|
|
218
|
+
config = Turn.config do |c|
|
209
219
|
c.live = live
|
210
220
|
c.log = log
|
211
221
|
c.loadpath = loadpath
|
@@ -216,8 +226,11 @@ module Turn
|
|
216
226
|
c.pattern = pattern
|
217
227
|
c.matchcase = matchcase
|
218
228
|
c.framework = framework
|
229
|
+
c.trace = trace
|
219
230
|
end
|
220
231
|
|
232
|
+
controller = Turn::Controller.new(config)
|
233
|
+
|
221
234
|
result = controller.start
|
222
235
|
|
223
236
|
if result
|
@@ -12,27 +12,38 @@ module Turn
|
|
12
12
|
@name = name
|
13
13
|
@fail = false
|
14
14
|
@error = false
|
15
|
+
@skip = false
|
15
16
|
@raised = nil
|
16
17
|
@message = nil
|
17
18
|
@backtrace = []
|
18
19
|
end
|
19
20
|
|
20
21
|
def fail!(assertion)
|
21
|
-
@fail, @error = true, false
|
22
|
+
@fail, @error, @skip = true, false, false
|
22
23
|
@raised = assertion
|
23
24
|
@message = assertion.message
|
24
25
|
@backtrace = assertion.backtrace
|
25
26
|
end
|
26
27
|
|
27
28
|
def error!(exception)
|
28
|
-
@fail, @error = false, true
|
29
|
+
@fail, @error, @skip = false, true, false
|
29
30
|
@raised = exception
|
30
31
|
@message = exception.message
|
31
32
|
@backtrace = exception.backtrace
|
32
33
|
end
|
33
34
|
|
35
|
+
def skip!(assertion)
|
36
|
+
@fail, @error, @skip = false, false, true
|
37
|
+
@raised = assertion
|
38
|
+
@message = assertion.message
|
39
|
+
@backtrace = assertion.backtrace
|
40
|
+
end
|
41
|
+
|
34
42
|
def fail? ; @fail ; end
|
35
43
|
def error? ; @error ; end
|
44
|
+
def skip? ; @skip ; end
|
45
|
+
|
46
|
+
# TODO: should this include `or @skip`?
|
36
47
|
def pass? ; !(@fail or @error) ; end
|
37
48
|
|
38
49
|
def to_s ; name ; end
|
data/lib/turn/controller.rb
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
module Turn
|
4
|
+
|
4
5
|
require 'turn/version'
|
6
|
+
require 'turn/autoload'
|
5
7
|
require 'turn/components/suite.rb'
|
6
8
|
require 'turn/components/case.rb'
|
7
9
|
require 'turn/components/method.rb'
|
8
10
|
|
9
|
-
#
|
11
|
+
# Configure Turn
|
12
|
+
def self.config(&block)
|
13
|
+
@config ||= Configuration.new
|
14
|
+
block.call(@config) if block
|
15
|
+
@config
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
10
19
|
#
|
11
20
|
#--
|
12
21
|
# TODO: Add support to test run loggging.
|
13
22
|
#++
|
14
|
-
class
|
23
|
+
class Configuration
|
15
24
|
|
16
25
|
# List of if file names or glob pattern of tests to run.
|
17
26
|
attr_accessor :tests
|
@@ -51,8 +60,15 @@ module Turn
|
|
51
60
|
# Test framework, either :minitest or :testunit
|
52
61
|
attr_accessor :framework
|
53
62
|
|
63
|
+
# Enable full backtrace
|
64
|
+
attr_accessor :trace
|
65
|
+
|
66
|
+
# Use natural language case names.
|
67
|
+
attr_accessor :natural
|
68
|
+
|
54
69
|
def verbose? ; @verbose ; end
|
55
70
|
def live? ; @live ; end
|
71
|
+
def natural? ; @natural ; end
|
56
72
|
|
57
73
|
private
|
58
74
|
|
@@ -63,15 +79,19 @@ module Turn
|
|
63
79
|
|
64
80
|
#
|
65
81
|
def initialize_defaults
|
66
|
-
@loadpath
|
67
|
-
@tests
|
68
|
-
@exclude
|
69
|
-
@requires
|
70
|
-
@live
|
71
|
-
@log
|
72
|
-
#@format
|
82
|
+
@loadpath ||= ['lib']
|
83
|
+
@tests ||= ["test/**/{test,}*{,test}.rb"]
|
84
|
+
@exclude ||= []
|
85
|
+
@requires ||= []
|
86
|
+
@live ||= false
|
87
|
+
@log ||= true
|
88
|
+
#@format ||= nil
|
73
89
|
#@runner ||= RUBY_VERSION >= "1.9" ? MiniRunner : TestRunner
|
74
|
-
@
|
90
|
+
@matchcase ||= nil
|
91
|
+
@pattern ||= /.*/
|
92
|
+
@natural ||= false
|
93
|
+
|
94
|
+
@files = nil # reset files just in case
|
75
95
|
end
|
76
96
|
|
77
97
|
# Collect test configuation.
|
@@ -134,61 +154,88 @@ module Turn
|
|
134
154
|
ex = ex.flatten.reject{ |f| File.directory?(f) }
|
135
155
|
|
136
156
|
(fs - ex).uniq.map{ |f| File.expand_path(f) }
|
137
|
-
)
|
157
|
+
).flatten
|
138
158
|
end
|
139
159
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
if files.empty?
|
144
|
-
$stderr.puts "No tests."
|
145
|
-
return
|
146
|
-
end
|
147
|
-
|
148
|
-
testrun = runner.new(self)
|
149
|
-
|
150
|
-
testrun.start
|
160
|
+
# TODO: Better name ?
|
161
|
+
def suite_name
|
162
|
+
files.map{ |path| File.dirname(path).sub(Dir.pwd+'/','') }.uniq.join(',')
|
151
163
|
end
|
152
164
|
|
153
165
|
# Select reporter based on output mode.
|
154
166
|
def reporter
|
155
167
|
@reporter ||= (
|
168
|
+
opts = { :trace=>trace, :natural=>natural? }
|
156
169
|
case format
|
157
170
|
when :marshal
|
158
171
|
require 'turn/reporters/marshal_reporter'
|
159
|
-
Turn::MarshalReporter.new($stdout)
|
172
|
+
Turn::MarshalReporter.new($stdout, opts)
|
160
173
|
when :progress
|
161
174
|
require 'turn/reporters/progress_reporter'
|
162
|
-
Turn::ProgressReporter.new($stdout)
|
175
|
+
Turn::ProgressReporter.new($stdout, opts)
|
163
176
|
when :dotted
|
164
177
|
require 'turn/reporters/dot_reporter'
|
165
|
-
Turn::DotReporter.new($stdout)
|
178
|
+
Turn::DotReporter.new($stdout, opts)
|
166
179
|
when :pretty
|
167
180
|
require 'turn/reporters/pretty_reporter'
|
168
|
-
Turn::PrettyReporter.new($stdout)
|
181
|
+
Turn::PrettyReporter.new($stdout, opts)
|
169
182
|
when :cue
|
170
183
|
require 'turn/reporters/cue_reporter'
|
171
|
-
Turn::CueReporter.new($stdout)
|
184
|
+
Turn::CueReporter.new($stdout, opts)
|
172
185
|
else
|
173
186
|
require 'turn/reporters/outline_reporter'
|
174
|
-
Turn::OutlineReporter.new($stdout)
|
187
|
+
Turn::OutlineReporter.new($stdout, opts)
|
175
188
|
end
|
176
189
|
)
|
177
190
|
end
|
178
191
|
|
192
|
+
end
|
193
|
+
|
194
|
+
# = Controller
|
195
|
+
#
|
196
|
+
class Controller
|
197
|
+
|
198
|
+
#
|
199
|
+
def initialize(config=Turn.config)
|
200
|
+
@config = config
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
attr :config
|
205
|
+
|
206
|
+
#
|
207
|
+
def start
|
208
|
+
if config.files.empty?
|
209
|
+
$stderr.puts "No tests."
|
210
|
+
return
|
211
|
+
end
|
212
|
+
|
213
|
+
setup
|
214
|
+
|
215
|
+
testrun = runner.new
|
216
|
+
testrun.start
|
217
|
+
end
|
218
|
+
|
219
|
+
#
|
220
|
+
def setup
|
221
|
+
config.loadpath.each{ |path| $: << path } unless config.live?
|
222
|
+
config.requires.each{ |path| require(path) }
|
223
|
+
config.files.each{ |path| require(path) }
|
224
|
+
end
|
225
|
+
|
179
226
|
# # Insatance of Runner, selected based on format and runmode.
|
180
227
|
def runner
|
181
228
|
@runner ||= (
|
182
|
-
case framework
|
229
|
+
case config.framework
|
183
230
|
when :minitest
|
184
231
|
require 'turn/runners/minirunner'
|
185
232
|
else
|
186
233
|
require 'turn/runners/testrunner'
|
187
234
|
end
|
188
235
|
|
189
|
-
case runmode
|
236
|
+
case config.runmode
|
190
237
|
when :marshal
|
191
|
-
if framework == :minitest
|
238
|
+
if config.framework == :minitest
|
192
239
|
Turn::MiniRunner
|
193
240
|
else
|
194
241
|
Turn::TestRunner
|
@@ -200,7 +247,7 @@ module Turn
|
|
200
247
|
require 'turn/runners/crossrunner'
|
201
248
|
Turn::CrossRunner
|
202
249
|
else
|
203
|
-
if framework == :minitest
|
250
|
+
if config.framework == :minitest
|
204
251
|
Turn::MiniRunner
|
205
252
|
else
|
206
253
|
Turn::TestRunner
|
@@ -212,4 +259,3 @@ module Turn
|
|
212
259
|
end
|
213
260
|
|
214
261
|
end
|
215
|
-
|
data/lib/turn/reporter.rb
CHANGED
@@ -18,8 +18,10 @@ module Turn
|
|
18
18
|
|
19
19
|
attr :io
|
20
20
|
|
21
|
-
def initialize(io)
|
22
|
-
@io
|
21
|
+
def initialize(io, opts={})
|
22
|
+
@io = io || $stdout
|
23
|
+
@trace = opts[:trace]
|
24
|
+
@natural = opts[:natural]
|
23
25
|
end
|
24
26
|
|
25
27
|
# These methods are called in the process of running the tests.
|
@@ -55,7 +55,11 @@ module Turn
|
|
55
55
|
list.uniq.each do |testunit|
|
56
56
|
message = testunit.fail? ? ' ' + FAIL : ERROR
|
57
57
|
message = message + ' ' + testunit.message.tabto(0)
|
58
|
-
|
58
|
+
backtrace = filter_backtrace(testunit.backtrace)
|
59
|
+
message << "\n" + (backtrace.shift || '')
|
60
|
+
if @trace
|
61
|
+
message << "\n" + backtrace.join("\n")
|
62
|
+
end
|
59
63
|
report << "\n" << message << "\n"
|
60
64
|
end
|
61
65
|
report << "\n"
|
@@ -33,7 +33,14 @@ module Turn
|
|
33
33
|
# @file = test.file
|
34
34
|
# io.puts(test.file)
|
35
35
|
#end
|
36
|
-
|
36
|
+
|
37
|
+
name = if @natural
|
38
|
+
" #{test.name.gsub("test_", "").gsub(/_/, " ")}"
|
39
|
+
else
|
40
|
+
" #{test.name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
io.print " %-69s" % name
|
37
44
|
|
38
45
|
@stdout.rewind
|
39
46
|
@stderr.rewind
|
@@ -59,10 +66,15 @@ module Turn
|
|
59
66
|
|
60
67
|
io.puts(" #{FAIL}")
|
61
68
|
io.puts Colorize.bold(message).tabto(8)
|
69
|
+
|
62
70
|
unless backtrace.empty?
|
63
|
-
|
64
|
-
|
65
|
-
|
71
|
+
label = "Assertion at "
|
72
|
+
tabsize = 8
|
73
|
+
backtrace1 = label + backtrace.shift
|
74
|
+
io.puts(backtrace1.tabto(tabsize))
|
75
|
+
if @trace
|
76
|
+
io.puts backtrace.map{|l| l.tabto(label.length + tabsize) }.join("\n")
|
77
|
+
end
|
66
78
|
end
|
67
79
|
show_captured_output
|
68
80
|
end
|
@@ -125,7 +137,7 @@ module Turn
|
|
125
137
|
pass = total - failure - error
|
126
138
|
|
127
139
|
bar = '=' * 78
|
128
|
-
if
|
140
|
+
if colorize?
|
129
141
|
bar = if pass == total then Colorize.green(bar)
|
130
142
|
else Colorize.red(bar) end
|
131
143
|
end
|
@@ -66,16 +66,19 @@ module Turn
|
|
66
66
|
|
67
67
|
message = assertion.message
|
68
68
|
|
69
|
-
if assertion.respond_to?(:backtrace)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
_trace = if assertion.respond_to?(:backtrace)
|
70
|
+
filter_backtrace(assertion.backtrace)
|
71
|
+
else
|
72
|
+
filter_backtrace(assertion.location).first
|
73
|
+
end
|
75
74
|
io.puts
|
76
|
-
|
77
|
-
io.puts message
|
78
|
-
io.puts
|
75
|
+
tabsize = 10
|
76
|
+
#io.puts pad(message, tabsize)
|
77
|
+
io.puts message.tabto(tabsize)
|
78
|
+
io.puts _trace.shift.tabto(tabsize)
|
79
|
+
if @trace
|
80
|
+
io.puts _trace.map{|l| l.tabto(tabsize) }.join("\n")
|
81
|
+
end
|
79
82
|
#show_captured_output
|
80
83
|
end
|
81
84
|
|
@@ -89,15 +92,19 @@ module Turn
|
|
89
92
|
|
90
93
|
message = exception.message
|
91
94
|
|
92
|
-
if exception.respond_to?(:backtrace)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
_trace = if exception.respond_to?(:backtrace)
|
96
|
+
filter_backtrace(exception.backtrace)
|
97
|
+
else
|
98
|
+
filter_backtrace(exception.location)
|
99
|
+
end
|
100
|
+
trace = _trace.shift
|
98
101
|
io.puts
|
99
|
-
|
100
|
-
io.puts
|
102
|
+
tabsize = 10
|
103
|
+
io.puts message.tabto(tabsize)
|
104
|
+
io.puts trace.tabto(tabsize)
|
105
|
+
if @trace
|
106
|
+
io.puts _trace.map{|l| l.tabto(tabsize) }.join("\n")
|
107
|
+
end
|
101
108
|
end
|
102
109
|
|
103
110
|
# TODO: skip support
|
@@ -15,8 +15,8 @@ module Turn
|
|
15
15
|
def start
|
16
16
|
suite = TestSuite.new
|
17
17
|
|
18
|
-
files = @
|
19
|
-
viles = @
|
18
|
+
files = @config.files
|
19
|
+
viles = @config.files # TODO: make selectable ?
|
20
20
|
|
21
21
|
#files = files.select{ |f| File.extname(f) == '.rb' and File.file?(f) }
|
22
22
|
#viles = viles.select{ |f| File.extname(f) == '.rb' and File.file?(f) }
|
@@ -19,14 +19,15 @@ module Turn
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def initialize
|
23
|
-
@
|
24
|
-
|
22
|
+
def initialize
|
23
|
+
@config = Turn.config
|
24
|
+
|
25
|
+
@reporter = @config.reporter
|
25
26
|
#yield(self) if block_given?
|
26
|
-
@loadpath =
|
27
|
-
@requires =
|
28
|
-
@live =
|
29
|
-
@minitest =
|
27
|
+
@loadpath = @config.loadpath
|
28
|
+
@requires = @config.requires
|
29
|
+
@live = @config.live?
|
30
|
+
@minitest = @config.framework == :minitest
|
30
31
|
end
|
31
32
|
|
32
33
|
public
|
@@ -36,7 +37,7 @@ module Turn
|
|
36
37
|
#
|
37
38
|
def start
|
38
39
|
suite = TestSuite.new
|
39
|
-
testruns = @
|
40
|
+
testruns = @config.files.collect do |file|
|
40
41
|
name = file.sub(Dir.pwd+'/','')
|
41
42
|
suite.new_case(name, file)
|
42
43
|
end
|
@@ -95,7 +96,8 @@ module Turn
|
|
95
96
|
files = kase.files
|
96
97
|
|
97
98
|
# remove any unexpected output injected at the beginning
|
98
|
-
|
99
|
+
b = out.index(/^---/)
|
100
|
+
yaml = out[b..-1]
|
99
101
|
sub_suite = YAML.load(yaml)
|
100
102
|
|
101
103
|
# TODO: How to handle pairs?
|
@@ -164,4 +166,3 @@ module Turn
|
|
164
166
|
end#class IsoRunner
|
165
167
|
|
166
168
|
end#module Turn
|
167
|
-
|