minitest 5.20.0 → 5.27.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.
@@ -1,6 +1,12 @@
1
1
  require "shellwords"
2
2
  require "rbconfig"
3
- require "rake/tasklib"
3
+
4
+ begin
5
+ require "rake/tasklib"
6
+ rescue LoadError => e
7
+ warn e.message
8
+ return
9
+ end
4
10
 
5
11
  module Minitest # :nodoc:
6
12
 
@@ -38,8 +44,16 @@ module Minitest # :nodoc:
38
44
  WINDOWS = RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ # :nodoc:
39
45
 
40
46
  ##
41
- # Create several test-oriented tasks under +name+. Takes an
42
- # optional block to customize variables.
47
+ # Create several test-oriented tasks under +name+ (default:
48
+ # "test"). Takes an optional block to customize variables.
49
+ # Examples:
50
+ #
51
+ # Minitest::TestTask.create # named "test", all defaults
52
+ #
53
+ # Minitest::TestTask.create do |t|
54
+ # t.warning = false # my tests are noisy
55
+ # t.framework = %(require_relative "./test/helper.rb")
56
+ # end
43
57
 
44
58
  def self.create name = :test, &block
45
59
  task = new name
@@ -63,9 +77,18 @@ module Minitest # :nodoc:
63
77
 
64
78
  ##
65
79
  # The code to load the framework. Defaults to requiring
66
- # minitest/autorun...
80
+ # minitest/autorun.
81
+ #
82
+ # If you have a test helper file that requires minitest/autorun
83
+ # and anything else your project standardizes on, then you'll
84
+ # probably want to change this to:
67
85
  #
68
- # Why do I have this as an option?
86
+ # Minitest::TestTask.create do |t|
87
+ # t.framework = %(require_relative "./test/helper.rb")
88
+ # end
89
+ #
90
+ # or something similar. NOTE: if you do this, then helper must
91
+ # require "minitest/autorun" at the top to start the tests.
69
92
 
70
93
  attr_accessor :framework
71
94
 
@@ -94,6 +117,11 @@ module Minitest # :nodoc:
94
117
 
95
118
  ##
96
119
  # Optional: Additional ruby to run before the test framework is loaded.
120
+ # Example:
121
+ #
122
+ # Minitest::TestTask.create "test:cov" do |t|
123
+ # t.test_prelude = %(require "simplecov")
124
+ # end
97
125
 
98
126
  attr_accessor :test_prelude
99
127
 
@@ -114,7 +142,7 @@ module Minitest # :nodoc:
114
142
  self.test_globs = ["test/**/test_*.rb",
115
143
  "test/**/*_test.rb"]
116
144
  self.test_prelude = nil
117
- self.verbose = Rake.application.options.trace
145
+ self.verbose = Rake.application.options.trace || Rake.verbose == true
118
146
  self.warning = true
119
147
  end
120
148
 
@@ -144,7 +172,7 @@ module Minitest # :nodoc:
144
172
  ENV["N"] && ENV["N"].to_i > 0
145
173
 
146
174
  lib_extras = (ENV["MT_LIB_EXTRAS"] || "").split File::PATH_SEPARATOR
147
- self.libs[0,0] = lib_extras
175
+ self.libs[0, 0] = lib_extras
148
176
 
149
177
  extra_args << "-n" << ENV["N"] if ENV["N"]
150
178
  extra_args << "-e" << ENV["X"] if ENV["X"]
@@ -163,7 +191,7 @@ module Minitest # :nodoc:
163
191
  def define # :nodoc:
164
192
  desc "Run the test suite. Use N, X, A, and TESTOPTS to add flags/args."
165
193
  task name do
166
- ruby make_test_cmd, verbose:verbose
194
+ ruby make_test_cmd, verbose: verbose
167
195
  end
168
196
 
169
197
  desc "Print out the test command. Good for profiling and other tools."
@@ -177,7 +205,7 @@ module Minitest # :nodoc:
177
205
 
178
206
  # 3 seems to be the magic number... (tho not by that much)
179
207
  bad, good, n = {}, [], (ENV.delete("K") || 3).to_i
180
- file = ENV.delete("F")
208
+ file = ENV.delete "F"
181
209
  times = {}
182
210
 
183
211
  tt0 = Time.now
@@ -238,7 +266,7 @@ module Minitest # :nodoc:
238
266
 
239
267
  task "#{name}:deps" => "#{name}:isolated" # now just an alias
240
268
 
241
- desc "Show bottom 25 tests wrt time."
269
+ desc "Run the test suite and report the slowest 25 tests."
242
270
  task "#{name}:slow" do
243
271
  sh ["rake #{name} A=-v",
244
272
  "egrep '#test_.* s = .'",
@@ -262,11 +290,11 @@ module Minitest # :nodoc:
262
290
  runner = runner.join "; "
263
291
 
264
292
  args = []
265
- args << "-I#{libs.join(File::PATH_SEPARATOR)}" unless libs.empty?
293
+ args << "-I#{libs.join File::PATH_SEPARATOR}" unless libs.empty?
266
294
  args << "-w" if warning
267
- args << '-e'
295
+ args << "-e"
268
296
  args << "'#{runner}'"
269
- args << '--'
297
+ args << "--"
270
298
  args << extra_args.map(&:shellescape)
271
299
 
272
300
  args.join " "
@@ -275,23 +303,17 @@ module Minitest # :nodoc:
275
303
  end
276
304
 
277
305
  class Work < Queue # :nodoc:
278
- def initialize jobs = [] # :nodoc:
279
- super()
280
-
281
- jobs.each do |job|
282
- self << job
283
- end
284
-
306
+ def initialize jobs # :nodoc:
307
+ super
285
308
  close
286
309
  end
287
310
  end
288
311
 
289
312
  class Integer # :nodoc:
290
- def threads_do(jobs) # :nodoc:
291
- require "thread"
313
+ def threads_do jobs # :nodoc:
292
314
  q = Work.new jobs
293
315
 
294
- self.times.map {
316
+ Array.new(self) {
295
317
  Thread.new do
296
318
  while job = q.pop # go until quit value
297
319
  yield job
data/lib/minitest/unit.rb CHANGED
@@ -11,7 +11,7 @@ unless defined?(Minitest) then
11
11
  module Minitest # :nodoc:
12
12
  end
13
13
  MiniTest = Minitest # :nodoc: # prevents minitest.rb from requiring back to us
14
- require "minitest"
14
+ require_relative "../minitest"
15
15
  end
16
16
 
17
17
  MiniTest = Minitest unless defined?(MiniTest)