rubytest 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.index CHANGED
@@ -17,10 +17,6 @@ requirements:
17
17
  - build
18
18
  development: true
19
19
  name: detroit
20
- - groups:
21
- - build
22
- development: true
23
- name: dotopts
24
20
  - groups:
25
21
  - test
26
22
  development: true
@@ -57,9 +53,9 @@ paths:
57
53
  created: '2011-07-23'
58
54
  summary: Ruby Universal Test Harness
59
55
  title: Ruby Test
60
- version: 0.6.0
56
+ version: 0.7.0
61
57
  name: rubytest
62
58
  description: ! "Ruby Test is a universal test harness for Ruby. It can handle any
63
59
  compliant \ntest framework, even running tests from multiple frameworks in a single
64
60
  pass."
65
- date: '2013-02-09'
61
+ date: '2013-02-17'
data/HISTORY.md CHANGED
@@ -1,6 +1,39 @@
1
1
  # RELEASE HISTORY
2
2
 
3
- ## 0.6.0 / 2013-02-10
3
+ ## 0.7.0 / 2013-02-18
4
+
5
+ Version 0.7 is a significant release. The library has been simplified
6
+ by spinning-off both the command-line tool and the Rake task as
7
+ `rubytest-cli` and `rubytest-rake` respectively. This was done for a
8
+ couple of good reasons: a) It focuses the the library on it's core
9
+ functionality and b) and it makes the library suitable for becoming
10
+ a Ruby standard library, should that ever become a possibility.
11
+
12
+ Changes:
13
+
14
+ * Spun off command-line tool as `rubytest-cli`.
15
+ * Spun off Rake task as `rubytest-rake`.
16
+
17
+
18
+ ## 0.6.1 / 2013-02-16
19
+
20
+ Configurations can now supply a before and after procedure to be
21
+ run right before or right after tests are run. This can be useful
22
+ for setting up coverage tools Simplecov, which has to be setup
23
+ before the applicable code is required but after all supporting
24
+ test infrustructure is required. This release also fixes
25
+ the `-c/--config` option, to prevent name clashes between gems and
26
+ local config files.
27
+
28
+ Changes:
29
+
30
+ * Add before and after config procs.
31
+ * Fix -c/--config loading.
32
+ * Remove use of DotOpts, it is not good enough yet.
33
+ * Move Rake plugin to separate plugin project.
34
+
35
+
36
+ ## 0.6.0 / 2013-02-11
4
37
 
5
38
  This release of Ruby Test takes a hard step back and reconsiders how
6
39
  to handle configuration from the ground up. Current users of Ruby Test
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [Homepage](http://rubyworks.github.com/rubytest) /
4
4
  [User Guide](http://wiki.github.com/rubyworks/rubytest) /
5
- [Development](http://github.com/rubyworks/rubytest) /
6
- [Issues](http://github.com/rubyworks/rubytest/issues)
5
+ [Support](http://github.com/rubyworks/rubytest/issues) /
6
+ [Development](http://github.com/rubyworks/rubytest)
7
7
 
8
8
  [![Build Status](https://secure.travis-ci.org/rubyworks/rubytest.png)](http://travis-ci.org/rubyworks/rubytest)
9
9
  [![Gem Version](https://badge.fury.io/rb/rubytest.png)](http://badge.fury.io/rb/rubytest)
@@ -57,50 +57,64 @@ also be installed in an FHS compliant fashion if necessary.
57
57
 
58
58
  ## Running Tests
59
59
 
60
- There are a few ways to run tests. First, there is the command line tool
61
- e.g.
60
+ There are a few ways to run tests.
62
61
 
63
- $ rubytest test/test_*.rb
62
+ ### Via Runner Scripts
64
63
 
65
- The command line tool takes various options, use `-h/--help` to see them.
64
+ Out of the box Ruby Test doesn't provide any special means for doing so,
65
+ you simply write you own runner script using the Ruby Test API.
66
+ Here is the basic example:
66
67
 
67
- When running tests, you need to be sure to load in your test framework
68
- or your framework's Ruby Test adapter. This is usually done via a helper
69
- script in the test files, but might also be done via command line options,
70
- e.g.
68
+ require 'rubytest'
71
69
 
72
- $ rubytest -r lemon -r ae test/test_*.rb
70
+ Test.run! do |r|
71
+ r.loadpath 'lib'
72
+ r.test_files 'test/test_*.rb'
73
+ end
74
+
75
+ Put that in a `test/runner.rb` script and run it with `ruby` or
76
+ add `#!/usr/bin/env ruby` at the top and put it in `bin/test`
77
+ setting `chmod u+x bin/test`. Either way, you now have your test
78
+ runner.
79
+
80
+ ### Via Command-line Tool
73
81
 
74
- Ruby Test supports [dotopts](http://rubyworks.github.com/dotopts) out of the
75
- box, so it easy to setup reusable options. For example, a `.option` file
76
- entry might be:
82
+ Probably the easiest way to run tests is via the command line tool available
83
+ via the `rubytest-cli` plug-in. You can read more about it on its
84
+ [webpage](http://rubyworks.github.com/rubytest-cli), but we will quickly go
85
+ over it here.
77
86
 
78
- rubytest
79
- -f progress
80
- -r spectroscope
81
- -r rspecial
82
- spec/spec_*.rb
87
+ The basic usage example is:
83
88
 
84
- If you are using a build tool to run your tests, such as Rake or Fire, it is
85
- best to shell out to `rubytest`. This keeps your test environent as prestine
86
- as possible.
89
+ $ rubytest -Ilib test/test_*.rb
90
+
91
+ The command line tool takes various options, most of which correspond directly
92
+ to the configuration options of the `Test.run/Test.configure` API. Use
93
+ `-h/--help` to see them all.
94
+
95
+ If you are using a build tool to run your tests, such as Rake or Ergo, shelling
96
+ out to `rubytest` is a good way to go as it keeps your test environment as
97
+ pristine as possible, e.g.
87
98
 
88
99
  desc "run tests"
89
100
  task :test
90
101
  sh "rubytest"
91
102
  end
92
103
 
93
- RubyTest comes with a Rake task plugin, but its use is all but deprecated
94
- because it's basically just a glorified rendition of the above.
104
+ ### Via Rake Task
105
+
106
+ There is also a Rake plug-in that can be installed called `rubytest-rake`.
107
+ Surf over to its [webpage](http://rubyworks.github.com/rubytest-rake) for details.
108
+ A basic example in its case, add to ones Rakefile:
95
109
 
96
110
  require 'rubytest/rake'
97
111
 
98
112
  Test::Rake::TestTask.new :test do |run|
99
113
  run.requires << 'lemon'
100
- run.files = 'test/test_*.rb'
114
+ run.test_files = 'test/test_*.rb'
101
115
  end
102
116
 
103
- See the Wiki for more information on the different ways to run tests.
117
+ See the Wiki for more detailed information on the different ways to run tests.
104
118
 
105
119
 
106
120
  ## Requirements
@@ -15,7 +15,8 @@ a test. For instance, given an abtriray object defined as follows.
15
15
 
16
16
  If we pass this to a test runner as part of a test suite,
17
17
 
18
- runner = Test::Runner.new(:suite=>[test], :format=>'test')
18
+ config = Test::Config.new(:suite=>[test], :format=>'test')
19
+ runner = Test::Runner.new(config)
19
20
 
20
21
  success = runner.run
21
22
 
@@ -17,10 +17,6 @@ requirements:
17
17
  - build
18
18
  development: true
19
19
  name: detroit
20
- - groups:
21
- - build
22
- development: true
23
- name: dotopts
24
20
  - groups:
25
21
  - test
26
22
  development: true
@@ -57,9 +53,9 @@ paths:
57
53
  created: '2011-07-23'
58
54
  summary: Ruby Universal Test Harness
59
55
  title: Ruby Test
60
- version: 0.6.0
56
+ version: 0.7.0
61
57
  name: rubytest
62
58
  description: ! "Ruby Test is a universal test harness for Ruby. It can handle any
63
59
  compliant \ntest framework, even running tests from multiple frameworks in a single
64
60
  pass."
65
- date: '2013-02-09'
61
+ date: '2013-02-17'
@@ -33,11 +33,6 @@ module Test
33
33
  #
34
34
  # @return nothing
35
35
  def run(argv=nil)
36
- begin
37
- require 'dotopts'
38
- rescue LoadError
39
- end
40
-
41
36
  argv = (argv || ARGV.dup)
42
37
 
43
38
  options.parse!(argv)
@@ -86,6 +81,7 @@ module Test
86
81
  config.format = 'tapj'
87
82
  end
88
83
 
84
+ # tempted to change -T
89
85
  opt.on '-t', '--tag TAG', 'select tests by tag' do |tag|
90
86
  config.tags.concat makelist(tag)
91
87
  end
@@ -118,6 +114,9 @@ module Test
118
114
  opt.on '-c', '--config FILE', "require local config file (immediately)" do |file|
119
115
  config.load_config(file)
120
116
  end
117
+ #opt.on '-T', '--tests GLOB', "tests to run (if none given as arguments)" do |glob|
118
+ # config.files << glob
119
+ #end
121
120
  opt.on '-V' , '--verbose', 'provide extra detail in reports' do
122
121
  config.verbose = true
123
122
  end
@@ -1,13 +1,18 @@
1
1
  module Test
2
2
 
3
+ # Stores test configurations.
4
+ def self.config
5
+ @config ||= {}
6
+ end
7
+
3
8
  # Configure test run via a block then will be passed a `Config` instance.
4
9
  #
5
10
  # @return [Config]
6
- def self.configure(&block)
11
+ def self.configure(profile=nil, &block)
7
12
  if reconfigure?
8
- configuration.apply(&block)
13
+ configuration(profile).apply(profile, &block)
9
14
  else
10
- @config = Config.new(&block)
15
+ config[profile.to_s] = Config.new(&block)
11
16
  end
12
17
  end
13
18
 
@@ -23,9 +28,9 @@ module Test
23
28
  # Get the current configuration.
24
29
  #
25
30
  # @return [Config]
26
- def self.configuration(reconfigurable=false)
31
+ def self.configuration(profile=nil, reconfigurable=false)
27
32
  @reconfigure = true if reconfigurable
28
- @config ||= Config.new
33
+ config[profile.to_s] ||= Config.new
29
34
  end
30
35
 
31
36
  ##
@@ -39,12 +44,6 @@ module Test
39
44
  # Glob used to find project root directory.
40
45
  GLOB_ROOT = '{.index,.gemspec,.git,.hg,_darcs,lib/}'
41
46
 
42
- # RubyTest configuration file can be in '.test.rb`, `etc/test.rb`
43
- # or `config/test.rb`, `.test`, in that order of precedence.
44
- #
45
- # @deprecated Use manual -c/--config option instead.
46
- GLOB_CONFIG = '{.test.rb,etc/test.rb,config/test.rb,.test}'
47
-
48
47
  #
49
48
  def self.assertionless
50
49
  @assertionless
@@ -55,28 +54,6 @@ module Test
55
54
  @assertionaless = !!boolean
56
55
  end
57
56
 
58
- # Load configuration file. An example file might look like:
59
- #
60
- # Test.configure do |run|
61
- # run.files << 'test/case_*.rb'
62
- # end
63
- #
64
- # @deprecated Planned for deprecation in April 2013.
65
- def self.load_config
66
- if config_file
67
- file = config_file.sub(Dir.pwd+'/','')
68
- $stderr.puts "Automatic #{file} loading has been deprecated.\nUse -c option for future version."
69
- load config_file
70
- end
71
- end
72
-
73
- # Find traditional configuration file.
74
- #
75
- # @deprecated
76
- def self.config_file
77
- @config_file ||= Dir.glob(File.join(root, GLOB_CONFIG)).first
78
- end
79
-
80
57
  # Find and cache project root directory.
81
58
  #
82
59
  # @return [String] Project's root path.
@@ -139,19 +116,16 @@ module Test
139
116
 
140
117
  #apply_environment
141
118
 
142
- settings.each do |k,v|
143
- send("#{k}=", v)
144
- end
145
-
146
- self.class.load_config # deprecated!!!
147
-
148
- apply(&block)
119
+ apply(settings, &block)
149
120
  end
150
121
 
151
122
  # Evaluate configuration block.
152
123
  #
153
124
  # @return nothing
154
- def apply(&block)
125
+ def apply(hash={}, &block)
126
+ hash.each do |k,v|
127
+ send("#{k}=", v)
128
+ end
155
129
  block.call(self) if block
156
130
  end
157
131
 
@@ -171,7 +145,8 @@ module Test
171
145
  # List of test files to run.
172
146
  #
173
147
  # @return [Array<String>]
174
- def files
148
+ def files(*list)
149
+ @files.concat(makelist(list)) unless list.empty?
175
150
  @files
176
151
  end
177
152
  alias test_files files
@@ -201,7 +176,11 @@ module Test
201
176
  # Paths to add to $LOAD_PATH.
202
177
  #
203
178
  # @return [Array<String>]
204
- attr :loadpath
179
+ def loadpath(*list)
180
+ @loadpath.concat(makelist(list)) unless list.empty?
181
+ @loadpath
182
+ end
183
+ alias :load_path :loadpath
205
184
 
206
185
  # Set paths to add to $LOAD_PATH.
207
186
  #
@@ -209,11 +188,15 @@ module Test
209
188
  def loadpath=(list)
210
189
  @loadpath = makelist(list)
211
190
  end
191
+ alias :load_path= :loadpath=
212
192
 
213
193
  # Scripts to require prior to tests.
214
194
  #
215
195
  # @return [Array<String>]
216
- attr :requires
196
+ def requires(*list)
197
+ @requires.concat(makelist(list)) unless list.empty?
198
+ @requires
199
+ end
217
200
 
218
201
  # Set the features that need to be required before the
219
202
  # test files.
@@ -226,15 +209,19 @@ module Test
226
209
  # Name of test report format, by default it is `dotprogress`.
227
210
  #
228
211
  # @return [String] format
229
- def format
212
+ def format(name=nil)
213
+ @format = name.to_s if name
230
214
  @format || DEFAULT_FORMAT
231
215
  end
232
216
 
233
217
  # Set test report format.
234
218
  #
219
+ # @param [String] name
220
+ # Name of the report format.
221
+ #
235
222
  # @return [String] format
236
- def format=(format)
237
- @format = format.to_s
223
+ def format=(name)
224
+ @format = name.to_s
238
225
  end
239
226
 
240
227
  # Provide extra details in reports?
@@ -254,7 +241,8 @@ module Test
254
241
  # Selection of tags for filtering tests.
255
242
  #
256
243
  # @return [Array<String>]
257
- def tags
244
+ def tags(*list)
245
+ @tags.concat(makelist(list)) unless list.empty?
258
246
  @tags
259
247
  end
260
248
 
@@ -268,7 +256,8 @@ module Test
268
256
  # Description match for filtering tests.
269
257
  #
270
258
  # @return [Array<String>]
271
- def match
259
+ def match(*list)
260
+ @match.concat(makelist(list)) unless list.empty?
272
261
  @match
273
262
  end
274
263
 
@@ -283,7 +272,8 @@ module Test
283
272
  # which are matched against module, class and method names.
284
273
  #
285
274
  # @return [Array<String>]
286
- def units
275
+ def units(*list)
276
+ @units.concat(makelist(list)) unless list.empty?
287
277
  @units
288
278
  end
289
279
 
@@ -312,7 +302,8 @@ module Test
312
302
  # Change to this directory before running tests.
313
303
  #
314
304
  # @return [String]
315
- def chdir
305
+ def chdir(dir=nil)
306
+ @chdir = dir.to_s if dir
316
307
  @chdir
317
308
  end
318
309
 
@@ -323,6 +314,22 @@ module Test
323
314
  @chdir = dir.to_s
324
315
  end
325
316
 
317
+ # Procedure to call, just before running tests.
318
+ #
319
+ # @return [Proc,nil]
320
+ def before(&proc)
321
+ @before = proc if proc
322
+ @before
323
+ end
324
+
325
+ # Procedure to call, just after running tests.
326
+ #
327
+ # @return [Proc,nil]
328
+ def after(&proc)
329
+ @after = proc if proc
330
+ @after
331
+ end
332
+
326
333
  # The mode is only useful for specialied purposes, such as how
327
334
  # to run tests via the Rake task. It has no general purpose
328
335
  # and can be ignored in most cases.
@@ -390,27 +397,26 @@ module Test
390
397
  @loadpath = env(:loadpath, @loadpath) if @loadpath.empty?
391
398
  end
392
399
 
393
- # Load configuration file.
400
+ # Load configuration file for project.
401
+ #
402
+ # File names are prefixed with `./` to ensure they are from a local
403
+ # source. An extension of `.rb` is assumed if the file lacks an one.
394
404
  #
395
405
  # @return [Boolean] true if file was required
396
406
  def load_config(file)
397
- try_paths = ['etc', 'config']
398
- try_paths.concat loadpath
399
- try_paths << '.'
400
- try_paths = try_paths.uniq
407
+ file = file + '.rb' if File.extname(file) == ''
401
408
 
402
409
  if chdir
403
- try_paths = try_paths.map{ |path| File.join(chdir, path) }
410
+ file = File.join(chdir, file)
411
+ else
412
+ file = File.join('.', file)
404
413
  end
405
414
 
406
- hold_path = $LOAD_PATH.dup
407
- $LOAD_PATH.replace(try_paths)
408
- begin
409
- success = require file
410
- ensure
411
- $LOAD_PATH.replace(hold_path)
415
+ if File.exist?(file)
416
+ return require(file)
417
+ else
418
+ raise "config file not found -- `#{file}'"
412
419
  end
413
- success
414
420
  end
415
421
 
416
422
  private
@@ -1,34 +1,65 @@
1
1
  module Test
2
2
 
3
- # Currently this is an alias for configure, however it is likely
4
- # to become an alias for `Runner.run` in the future.
3
+ # Alias for `Test.configure`.
4
+ # Use #run! to run tests immediately.
5
5
  #
6
- # @deprecated Will probably change behavior in future.
7
- def self.run(config=nil, &config_proc)
8
- $stderr.puts "configuration profiles no longer supported." if config
9
- configure(&config_proc)
6
+ def self.run(profile=nil, &config_proc)
7
+ configure(profile, &config_proc)
8
+ end
9
+
10
+ # Configure and run immediately.
11
+ #
12
+ # @todo Should this method return the success instead of exiting?
13
+ # @todo Wrap run in at_exit ?
14
+ #
15
+ # @return [void]
16
+ def self.run!(config=nil, &config_proc)
17
+ begin
18
+ success = Runner.run(config, &config_proc)
19
+ exit -1 unless success
20
+ rescue => error
21
+ raise error if $DEBUG
22
+ $stderr.puts('ERROR: ' + error.to_s)
23
+ exit -1
24
+ end
10
25
  end
11
26
 
12
27
  # The Test::Runner class handles the execution of tests.
13
28
  #
14
29
  class Runner
15
30
 
16
- # TODO: Wrap run in at_exit ?
17
- def self.run(config=nil, &config_proc)
31
+ # Run tests.
32
+ #
33
+ # @param [Config,Hash,String,Symbol] config
34
+ # Either a Config instance, a hash to construct a Config
35
+ # instance with, or a name of a configuration profile.
36
+ #
37
+ # @return [Boolean] Success of test run.
38
+ def self.run(config=nil, &config_proc) #:yield:
18
39
  runner = Runner.new(config, &config_proc)
19
- begin
20
- success = runner.run
21
- exit -1 unless success
22
- rescue => error
23
- raise error if $DEBUG
24
- $stderr.puts('ERROR: ' + error.to_s)
25
- exit -1
26
- end
40
+ runner.run
27
41
  end
28
42
 
29
43
  # Exceptions that are not caught by test runner.
30
44
  OPEN_ERRORS = [NoMemoryError, SignalException, Interrupt, SystemExit]
31
45
 
46
+ # New Runner.
47
+ #
48
+ # @param [Config] config
49
+ # Config instance.
50
+ #
51
+ def initialize(config) #:yield:
52
+ @config = case config
53
+ when Config then config
54
+ when Hash then Config.new(config)
55
+ else Test.configuration(config)
56
+ end
57
+
58
+ yeild(@config) if block_given?
59
+
60
+ @advice = Advice.new
61
+ end
62
+
32
63
  # Handle all configuration via the config instance.
33
64
  attr :config
34
65
 
@@ -78,23 +109,6 @@ module Test
78
109
  advice.join(type, &block)
79
110
  end
80
111
 
81
- # New Runner.
82
- #
83
- # @param [Config] config
84
- # Config instance.
85
- #
86
- def initialize(config=nil, &block)
87
- if config
88
- @config = Hash === config ? Config.new(config) : config
89
- else
90
- @config = Test.configuration
91
- end
92
-
93
- block.call(@config) if block
94
-
95
- @advice = Advice.new
96
- end
97
-
98
112
  # The reporter to use for ouput.
99
113
  attr :reporter
100
114
 
@@ -116,8 +130,12 @@ module Test
116
130
 
117
131
  ignore_callers
118
132
 
119
- config.loadpath.each{ |path| $LOAD_PATH.unshift(path) }
120
- config.requires.each{ |file| require file }
133
+ config.loadpath.flatten.each{ |path| $LOAD_PATH.unshift(path) }
134
+ config.requires.flatten.each{ |file| require file }
135
+
136
+ # Config before advice occurs after loadpath and require are
137
+ # applied and before test files are required.
138
+ config.before.call if config.before
121
139
 
122
140
  test_files.each do |test_file|
123
141
  require test_file
@@ -131,6 +149,8 @@ module Test
131
149
  observers.each{ |o| o.begin_suite(suite) }
132
150
  run_thru(suite)
133
151
  observers.each{ |o| o.end_suite(suite) }
152
+
153
+ config.after.call if config.after
134
154
  end
135
155
 
136
156
  recorder.success?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-11 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ansi
@@ -59,22 +59,6 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: dotopts
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
62
  - !ruby/object:Gem::Dependency
79
63
  name: qed
80
64
  requirement: !ruby/object:Gem::Requirement
@@ -112,9 +96,7 @@ description: ! "Ruby Test is a universal test harness for Ruby. It can handle an
112
96
  pass."
113
97
  email:
114
98
  - transfire@gmail.com
115
- executables:
116
- - ruby-test
117
- - rubytest
99
+ executables: []
118
100
  extensions: []
119
101
  extra_rdoc_files:
120
102
  - LICENSE.txt
@@ -122,8 +104,6 @@ extra_rdoc_files:
122
104
  - README.md
123
105
  files:
124
106
  - .index
125
- - bin/ruby-test
126
- - bin/rubytest
127
107
  - demo/01_test.md
128
108
  - demo/02_case.md
129
109
  - demo/applique/ae.rb
@@ -138,7 +118,6 @@ files:
138
118
  - lib/rubytest/core_ext/file.rb
139
119
  - lib/rubytest/core_ext/string.rb
140
120
  - lib/rubytest/core_ext.rb
141
- - lib/rubytest/rake.rb
142
121
  - lib/rubytest/recorder.rb
143
122
  - lib/rubytest/reporters/abstract.rb
144
123
  - lib/rubytest/reporters/abstract_hash.rb
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require 'rubytest'
4
- Test::CLI.run
5
- rescue RuntimeError => error
6
- raise error if $DEBUG
7
- $stderr.puts error
8
- end
9
-
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require 'rubytest'
4
- Test::CLI.run
5
- rescue RuntimeError => error
6
- raise error if $DEBUG
7
- $stderr.puts error
8
- end
9
-
@@ -1,137 +0,0 @@
1
- require 'rubytest'
2
- require 'rake/tasklib'
3
-
4
- module Test
5
-
6
- ##
7
- # Rake subspace.
8
- #
9
- module Rake
10
-
11
- ##
12
- # Define a test rake task.
13
- #
14
- # The `TEST` environment variable can be used to select tests
15
- # when using this task. Note, this is just a more convenient
16
- # way than using `RUBYTEST_FILES`.
17
- #
18
- class TestTask < ::Rake::TaskLib
19
-
20
- # Glob patterns are used by default to select test scripts.
21
- DEFAULT_TESTS = [
22
- 'test/**/case_*.rb',
23
- 'test/**/*_case.rb',
24
- 'test/**/test_*.rb',
25
- 'test/**/*_test.rb'
26
- ]
27
-
28
- # Test run configuration.
29
- #
30
- # @return [Config]
31
- attr :config
32
-
33
- # Initialize new Rake::TestTask instance.
34
- #
35
- def initialize(name='test', desc='run tests', &block)
36
- @name = name || 'test'
37
- @desc = desc
38
-
39
- @config = Test::Config.new
40
-
41
- @config.files << default_tests if @config.files.empty?
42
- @config.loadpath << 'lib' if @config.loadpath.empty?
43
-
44
- block.call(@config)
45
-
46
- define_task
47
- end
48
-
49
- # Define rake task for testing.
50
- #
51
- # @return nothing
52
- def define_task
53
- desc @desc
54
- task @name do
55
- config.mode == 'shell' ? run_shell : run
56
- end
57
- end
58
-
59
- # Run tests, via fork is possible, otherwise straight out.
60
- #
61
- # @return nothing
62
- def run
63
- if Process.respond_to?(:fork)
64
- fork {
65
- runner = Test::Runner.new(config)
66
- success = runner.run
67
- exit -1 unless success
68
- }
69
- Process.wait
70
- else
71
- runner = Test::Runner.new(config)
72
- success = runner.run
73
- exit -1 unless success
74
- end
75
- end
76
-
77
- # Run test via command line shell.
78
- #
79
- # @return nothing
80
- def shell_run
81
- success = ruby(*config.to_shellwords)
82
- exit -1 unless success
83
- end
84
-
85
- # Resolve test globs.
86
- #
87
- # @todo Implementation probably cna be simplified.
88
- # @return [Array<String>] List of test files.
89
- def test_files
90
- files = tests
91
- files = files.map{ |f| Dir[f] }.flatten
92
- files = files.map{ |f| File.directory?(f) ? Dir[File.join(f, '**/*.rb')] : f }
93
- files = files.flatten.uniq
94
- files = files.map{ |f| File.expand_path(f) }
95
- files
96
- end
97
-
98
- # Default test globs. For extra convenience will look for list in
99
- # `ENV['TEST']` first.
100
- #
101
- # @return [Array<String>]
102
- def default_tests
103
- if ENV['TEST']
104
- ENV['TEST'].split(/[:;]/)
105
- else
106
- DEFAULT_TESTS
107
- end
108
- end
109
-
110
- =begin
111
- # Shell out to current ruby command.
112
- #
113
- # @return [Boolean] Success of shell call.
114
- def ruby(*argv)
115
- system(ruby_command, *argv)
116
- end
117
-
118
- # Get current ruby shell command.
119
- #
120
- # @return [String] Ruby shell command.
121
- def ruby_command
122
- @ruby_command ||= (
123
- require 'rbconfig'
124
- ENV['RUBY'] ||
125
- File.join(
126
- RbConfig::CONFIG['bindir'],
127
- RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']
128
- ).sub(/.*\s.*/m, '"\&"')
129
- )
130
- end
131
- =end
132
-
133
- end
134
-
135
- end
136
-
137
- end