Skip to content

Commit c7fa655

Browse files
committed
Simplify Runner by using Config directly.
1 parent 4ed3ab8 commit c7fa655

1 file changed

Lines changed: 30 additions & 68 deletions

File tree

lib/rubytest/runner.rb

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,68 +27,35 @@ def self.run(config=nil, &config_proc)
2727
end
2828

2929
# Default report is in the old "dot-progress" format.
30-
DEFAULT_FORMAT = 'dotprogress'
30+
#DEFAULT_FORMAT = 'dotprogress'
3131

3232
# Exceptions that are not caught by test runner.
3333
OPEN_ERRORS = [NoMemoryError, SignalException, Interrupt, SystemExit]
3434

35-
# / / / A T T R I B U T E S / / /
35+
# Handle all configuration via the config instance.
36+
attr :config
3637

3738
# Test suite to run. This is a list of compliant test units and test cases.
38-
attr :suite
39-
40-
# Test files to load.
41-
attr :files
42-
43-
# Features to require prior to running tests.
44-
#attr :requires
45-
46-
# Reporter format name, or name fragment, used to look up reporter class.
47-
attr :format
48-
49-
#
50-
def format=(name)
51-
@format = name.to_s
52-
end
53-
54-
# Matching text used to filter which tests are run.
55-
attr :match
56-
57-
# Selected tags used to filter which tests are run.
58-
attr :tags
59-
60-
# List of units with which to filter tests. It is an array of strings
61-
# which are matched against module, class and method names.
62-
attr :units
63-
64-
# Show extra details in reports.
65-
def verbose?
66-
@verbose
39+
def suite
40+
config.suite
6741
end
6842

6943
#
70-
def verbose=(boolean)
71-
@verbose = !!boolean
72-
end
73-
74-
# Use "hard" test mode?
75-
def hard?
76-
@hard
77-
end
78-
44+
# TODO: Cache or not?
7945
#
80-
def hard=(boolean)
81-
@hard = !!boolean
46+
def test_files
47+
#@test_files ||= resolve_test_files
48+
resolve_test_files
8249
end
8350

84-
# Automatically assume local loadpaths?
85-
def autopath?
86-
@autopath
51+
# Reporter format name, or name fragment, used to look up reporter class.
52+
def format
53+
config.format
8754
end
8855

89-
#
90-
def autopath=(boolean)
91-
@autopath = !!boolean
56+
# Show extra details in reports.
57+
def verbose?
58+
config.verbose?
9259
end
9360

9461
# Instance of Advice is a special customizable observer.
@@ -124,15 +91,7 @@ def initialize(config=nil, &block)
12491

12592
block.call(@config) if block
12693

127-
@suite = @config.suite
128-
@files = @config.files
129-
@format = @config.format
130-
@tags = @config.tags
131-
@units = @config.units
132-
@match = @config.match
133-
@verbose = @config.verbose
134-
@hard = @config.hard
135-
@autopath = @config.autopath
94+
#@verbose = @config.verbose
13695

13796
@advice = Advice.new
13897
end
@@ -153,12 +112,15 @@ def initialize(config=nil, &block)
153112
# That the tests ran without error or failure.
154113
#
155114
def run
156-
Test::Config.load_path_setup if autopath?
115+
Test::Config.load_path_setup if config.autopath?
157116

158117
ignore_callers
159118

160-
files_resolved.each do |file|
161-
require file
119+
config.loadpath.each{ |path| $LOAD_PATH.unshift(path) }
120+
config.requires.each{ |file| require file }
121+
122+
test_files.each do |test_file|
123+
require test_file
162124
end
163125

164126
@reporter = reporter_load(format)
@@ -235,7 +197,7 @@ def run_test(test)
235197
observers.each{ |o| o.begin_test(test) }
236198
begin
237199
success = test.call
238-
if hard? && !success # TODO: separate run_test method to speed things up?
200+
if config.hard? && !success # TODO: separate run_test method to speed things up?
239201
raise Assertion, "failure of #{test}"
240202
else
241203
observers.each{ |o| o.pass(test) }
@@ -274,17 +236,17 @@ def select(cases)
274236
else
275237
cases.each do |tc|
276238
next if tc.respond_to?(:skip?) && tc.skip?
277-
next if !match.empty? && !match.any?{ |m| m =~ tc.to_s }
239+
next if !config.match.empty? && !config.match.any?{ |m| m =~ tc.to_s }
278240

279-
if !units.empty?
241+
if !config.units.empty?
280242
next unless tc.respond_to?(:unit)
281-
next unless units.find{ |u| tc.unit.start_with?(u) }
243+
next unless config.units.find{ |u| tc.unit.start_with?(u) }
282244
end
283245

284-
if !tags.empty?
246+
if !config.tags.empty?
285247
next unless tc.respond_to?(:tags)
286248
tc_tags = [tc.tags].flatten.map{ |t| t.to_s }
287-
next if (tags & tc_tags).empty?
249+
next if (config.tags & tc_tags).empty?
288250
end
289251

290252
selected << tc
@@ -330,8 +292,8 @@ def reporter_list
330292
# Files can be globs and directories which need to be
331293
# resolved to a list of files.
332294
#
333-
def files_resolved
334-
list = files.flatten
295+
def resolve_test_files
296+
list = config.files.flatten
335297
list = list.map{ |f| Dir[f] }.flatten
336298
list = list.map{ |f| File.directory?(f) ? Dir[File.join(f, '**/*.rb')] : f }
337299
list = list.flatten.uniq

0 commit comments

Comments
 (0)