minitest 5.11.3 → 5.25.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,8 +47,6 @@ module Minitest
47
47
 
48
48
  def self.bench_linear min, max, step = 10
49
49
  (min..max).step(step).to_a
50
- rescue LocalJumpError # 1.8.6
51
- r = []; (min..max).step(step) { |n| r << n }; r
52
50
  end
53
51
 
54
52
  ##
@@ -83,7 +81,7 @@ module Minitest
83
81
  def assert_performance validation, &work
84
82
  range = self.class.bench_range
85
83
 
86
- io.print "#{self.name}"
84
+ io.print self.name
87
85
 
88
86
  times = []
89
87
 
@@ -109,8 +107,8 @@ module Minitest
109
107
  # is applied against the slope itself. As such, you probably want
110
108
  # to tighten it from the default.
111
109
  #
112
- # See http://www.graphpad.com/curvefit/goodness_of_fit.htm for
113
- # more details.
110
+ # See https://www.graphpad.com/guides/prism/8/curve-fitting/reg_intepretingnonlinr2.htm
111
+ # for more details.
114
112
  #
115
113
  # Fit is calculated by #fit_linear.
116
114
  #
@@ -217,7 +215,7 @@ module Minitest
217
215
  ##
218
216
  # Takes an array of x/y pairs and calculates the general R^2 value.
219
217
  #
220
- # See: http://en.wikipedia.org/wiki/Coefficient_of_determination
218
+ # See: https://en.wikipedia.org/wiki/Coefficient_of_determination
221
219
 
222
220
  def fit_error xys
223
221
  y_bar = sigma(xys) { |_, y| y } / xys.size.to_f
@@ -232,11 +230,11 @@ module Minitest
232
230
  #
233
231
  # Takes x and y values and returns [a, b, r^2].
234
232
  #
235
- # See: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html
233
+ # See: https://mathworld.wolfram.com/LeastSquaresFittingExponential.html
236
234
 
237
235
  def fit_exponential xs, ys
238
236
  n = xs.size
239
- xys = xs.zip(ys)
237
+ xys = xs.zip ys
240
238
  sxlny = sigma(xys) { |x, y| x * Math.log(y) }
241
239
  slny = sigma(xys) { |_, y| Math.log(y) }
242
240
  sx2 = sigma(xys) { |x, _| x * x }
@@ -254,11 +252,11 @@ module Minitest
254
252
  #
255
253
  # Takes x and y values and returns [a, b, r^2].
256
254
  #
257
- # See: http://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
255
+ # See: https://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
258
256
 
259
257
  def fit_logarithmic xs, ys
260
258
  n = xs.size
261
- xys = xs.zip(ys)
259
+ xys = xs.zip ys
262
260
  slnx2 = sigma(xys) { |x, _| Math.log(x) ** 2 }
263
261
  slnx = sigma(xys) { |x, _| Math.log(x) }
264
262
  sylnx = sigma(xys) { |x, y| y * Math.log(x) }
@@ -276,11 +274,11 @@ module Minitest
276
274
  #
277
275
  # Takes x and y values and returns [a, b, r^2].
278
276
  #
279
- # See: http://mathworld.wolfram.com/LeastSquaresFitting.html
277
+ # See: https://mathworld.wolfram.com/LeastSquaresFitting.html
280
278
 
281
279
  def fit_linear xs, ys
282
280
  n = xs.size
283
- xys = xs.zip(ys)
281
+ xys = xs.zip ys
284
282
  sx = sigma xs
285
283
  sy = sigma ys
286
284
  sx2 = sigma(xs) { |x| x ** 2 }
@@ -298,11 +296,11 @@ module Minitest
298
296
  #
299
297
  # Takes x and y values and returns [a, b, r^2].
300
298
  #
301
- # See: http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
299
+ # See: https://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
302
300
 
303
301
  def fit_power xs, ys
304
302
  n = xs.size
305
- xys = xs.zip(ys)
303
+ xys = xs.zip ys
306
304
  slnxlny = sigma(xys) { |x, y| Math.log(x) * Math.log(y) }
307
305
  slnx = sigma(xs) { |x | Math.log(x) }
308
306
  slny = sigma(ys) { | y| Math.log(y) }
@@ -323,7 +321,7 @@ module Minitest
323
321
 
324
322
  def sigma enum, &block
325
323
  enum = enum.map(&block) if block
326
- enum.inject { |sum, n| sum + n }
324
+ enum.sum
327
325
  end
328
326
 
329
327
  ##
@@ -419,7 +417,6 @@ module Minitest
419
417
  end
420
418
  end
421
419
 
422
-
423
420
  ##
424
421
  # Create a benchmark that verifies that the performance is logarithmic.
425
422
  #
@@ -0,0 +1,94 @@
1
+ module Minitest
2
+ ##
3
+ # Compresses backtraces.
4
+
5
+ module Compress
6
+
7
+ ##
8
+ # Takes a backtrace (array of strings) and compresses repeating
9
+ # cycles in it to make it more readable.
10
+
11
+ def compress orig
12
+ ary = orig
13
+
14
+ eswo = ->(a, n, off) { # each_slice_with_offset
15
+ if off.zero? then
16
+ a.each_slice n
17
+ else
18
+ # [ ...off... [...n...] [...n...] ... ]
19
+ front, back = a.take(off), a.drop(off)
20
+ [front].chain back.each_slice n
21
+ end
22
+ }
23
+
24
+ 3.times do # maybe don't use loop do here?
25
+ index = ary # [ a b c b c b c d ]
26
+ .size
27
+ .times # 0...size
28
+ .group_by { |i| ary[i] } # { a: [0] b: [1 3 5], c: [2 4 6], d: [7] }
29
+
30
+ order = index
31
+ .reject { |k, v| v.size == 1 } # { b: [1 3 5], c: [2 4 6] }
32
+ .sort_by { |k, a1| ### sort by max dist + min offset
33
+ d = a1.each_cons(2).sum { |a2, b| b-a2 }
34
+ [-d, a1.first]
35
+ } # b: [1 3 5] c: [2 4 6]
36
+
37
+ ranges = order
38
+ .map { |k, a1| # [[1..2 3..4] [2..3 4..5]]
39
+ a1
40
+ .each_cons(2)
41
+ .map { |a2, b| a2..b-1 }
42
+ }
43
+
44
+ big_ranges = ranges
45
+ .flat_map { |a| # [1..2 3..4 2..3 4..5]
46
+ a.sort_by { |r| [-r.size, r.first] }.first 5
47
+ }
48
+ .first(100)
49
+
50
+ culprits = big_ranges
51
+ .map { |r|
52
+ eswo[ary, r.size, r.begin] # [o1 s1 s1 s2 s2]
53
+ .chunk_while { |a, b| a == b } # [[o1] [s1 s1] [s2 s2]]
54
+ .map { |a| [a.size, a.first] } # [[1 o1] [2 s1] [2 s2]]
55
+ }
56
+ .select { |chunks|
57
+ chunks.any? { |a| a.first > 1 } # compressed anything?
58
+ }
59
+
60
+ min = culprits
61
+ .min_by { |a| a.flatten.size } # most compressed
62
+
63
+ break unless min
64
+
65
+ ary = min.flat_map { |(n, lines)|
66
+ if n > 1 then
67
+ [[n, compress(lines)]] # [o1 [2 s1] [2 s2]]
68
+ else
69
+ lines
70
+ end
71
+ }
72
+ end
73
+
74
+ format = ->(lines) {
75
+ lines.flat_map { |line|
76
+ case line
77
+ when Array then
78
+ n, lines = line
79
+ lines = format[lines]
80
+ [
81
+ " +->> #{n} cycles of #{lines.size} lines:",
82
+ *lines.map { |s| " | #{s}" },
83
+ " +-<<",
84
+ ]
85
+ else
86
+ line
87
+ end
88
+ }
89
+ }
90
+
91
+ format[ary]
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,11 @@
1
+ module Minitest
2
+
3
+ module ErrorOnWarning # :nodoc:
4
+ def warn message, category: nil
5
+ message = "[#{category}] #{message}" if category
6
+ raise UnexpectedWarning, message
7
+ end
8
+ end
9
+
10
+ ::Warning.singleton_class.prepend ErrorOnWarning
11
+ end
@@ -9,10 +9,11 @@
9
9
  #
10
10
  # it "should still work in threads" do
11
11
  # my_threaded_thingy do
12
- # (1+1).must_equal 2 # bad
13
- # assert_equal 2, 1+1 # good
14
- # _(1 + 1).must_equal 2 # good
15
- # value(1 + 1).must_equal 2 # good, also #expect
12
+ # (1+1).must_equal 2 # bad
13
+ # assert_equal 2, 1+1 # good
14
+ # _(1 + 1).must_equal 2 # good
15
+ # value(1 + 1).must_equal 2 # good, also #expect
16
+ # _ { 1 + "1" }.must_raise TypeError # good
16
17
  # end
17
18
  # end
18
19
 
@@ -21,7 +22,7 @@ module Minitest::Expectations
21
22
  ##
22
23
  # See Minitest::Assertions#assert_empty.
23
24
  #
24
- # collection.must_be_empty
25
+ # _(collection).must_be_empty
25
26
  #
26
27
  # :method: must_be_empty
27
28
 
@@ -30,7 +31,7 @@ module Minitest::Expectations
30
31
  ##
31
32
  # See Minitest::Assertions#assert_equal
32
33
  #
33
- # a.must_equal b
34
+ # _(a).must_equal b
34
35
  #
35
36
  # :method: must_equal
36
37
 
@@ -39,18 +40,18 @@ module Minitest::Expectations
39
40
  ##
40
41
  # See Minitest::Assertions#assert_in_delta
41
42
  #
42
- # n.must_be_close_to m [, delta]
43
+ # _(n).must_be_close_to m [, delta]
43
44
  #
44
45
  # :method: must_be_close_to
45
46
 
46
47
  infect_an_assertion :assert_in_delta, :must_be_close_to
47
48
 
48
- alias :must_be_within_delta :must_be_close_to # :nodoc:
49
+ infect_an_assertion :assert_in_delta, :must_be_within_delta # :nodoc:
49
50
 
50
51
  ##
51
52
  # See Minitest::Assertions#assert_in_epsilon
52
53
  #
53
- # n.must_be_within_epsilon m [, epsilon]
54
+ # _(n).must_be_within_epsilon m [, epsilon]
54
55
  #
55
56
  # :method: must_be_within_epsilon
56
57
 
@@ -59,7 +60,7 @@ module Minitest::Expectations
59
60
  ##
60
61
  # See Minitest::Assertions#assert_includes
61
62
  #
62
- # collection.must_include obj
63
+ # _(collection).must_include obj
63
64
  #
64
65
  # :method: must_include
65
66
 
@@ -68,7 +69,7 @@ module Minitest::Expectations
68
69
  ##
69
70
  # See Minitest::Assertions#assert_instance_of
70
71
  #
71
- # obj.must_be_instance_of klass
72
+ # _(obj).must_be_instance_of klass
72
73
  #
73
74
  # :method: must_be_instance_of
74
75
 
@@ -77,7 +78,7 @@ module Minitest::Expectations
77
78
  ##
78
79
  # See Minitest::Assertions#assert_kind_of
79
80
  #
80
- # obj.must_be_kind_of mod
81
+ # _(obj).must_be_kind_of mod
81
82
  #
82
83
  # :method: must_be_kind_of
83
84
 
@@ -86,7 +87,7 @@ module Minitest::Expectations
86
87
  ##
87
88
  # See Minitest::Assertions#assert_match
88
89
  #
89
- # a.must_match b
90
+ # _(a).must_match b
90
91
  #
91
92
  # :method: must_match
92
93
 
@@ -95,7 +96,7 @@ module Minitest::Expectations
95
96
  ##
96
97
  # See Minitest::Assertions#assert_nil
97
98
  #
98
- # obj.must_be_nil
99
+ # _(obj).must_be_nil
99
100
  #
100
101
  # :method: must_be_nil
101
102
 
@@ -104,11 +105,11 @@ module Minitest::Expectations
104
105
  ##
105
106
  # See Minitest::Assertions#assert_operator
106
107
  #
107
- # n.must_be :<=, 42
108
+ # _(n).must_be :<=, 42
108
109
  #
109
110
  # This can also do predicates:
110
111
  #
111
- # str.must_be :empty?
112
+ # _(str).must_be :empty?
112
113
  #
113
114
  # :method: must_be
114
115
 
@@ -117,16 +118,25 @@ module Minitest::Expectations
117
118
  ##
118
119
  # See Minitest::Assertions#assert_output
119
120
  #
120
- # proc { ... }.must_output out_or_nil [, err]
121
+ # _ { ... }.must_output out_or_nil [, err]
121
122
  #
122
123
  # :method: must_output
123
124
 
124
125
  infect_an_assertion :assert_output, :must_output, :block
125
126
 
127
+ ##
128
+ # See Minitest::Assertions#assert_pattern_match
129
+ #
130
+ # _ { ... }.must_pattern_match [...]
131
+ #
132
+ # :method: must_pattern_match
133
+
134
+ infect_an_assertion :assert_pattern, :must_pattern_match, :block
135
+
126
136
  ##
127
137
  # See Minitest::Assertions#assert_raises
128
138
  #
129
- # proc { ... }.must_raise exception
139
+ # _ { ... }.must_raise exception
130
140
  #
131
141
  # :method: must_raise
132
142
 
@@ -135,7 +145,7 @@ module Minitest::Expectations
135
145
  ##
136
146
  # See Minitest::Assertions#assert_respond_to
137
147
  #
138
- # obj.must_respond_to msg
148
+ # _(obj).must_respond_to msg
139
149
  #
140
150
  # :method: must_respond_to
141
151
 
@@ -144,7 +154,7 @@ module Minitest::Expectations
144
154
  ##
145
155
  # See Minitest::Assertions#assert_same
146
156
  #
147
- # a.must_be_same_as b
157
+ # _(a).must_be_same_as b
148
158
  #
149
159
  # :method: must_be_same_as
150
160
 
@@ -153,7 +163,7 @@ module Minitest::Expectations
153
163
  ##
154
164
  # See Minitest::Assertions#assert_silent
155
165
  #
156
- # proc { ... }.must_be_silent
166
+ # _ { ... }.must_be_silent
157
167
  #
158
168
  # :method: must_be_silent
159
169
 
@@ -162,16 +172,34 @@ module Minitest::Expectations
162
172
  ##
163
173
  # See Minitest::Assertions#assert_throws
164
174
  #
165
- # proc { ... }.must_throw sym
175
+ # _ { ... }.must_throw sym
166
176
  #
167
177
  # :method: must_throw
168
178
 
169
179
  infect_an_assertion :assert_throws, :must_throw, :block
170
180
 
181
+ ##
182
+ # See Minitest::Assertions#assert_path_exists
183
+ #
184
+ # _(some_path).path_must_exist
185
+ #
186
+ # :method: path_must_exist
187
+
188
+ infect_an_assertion :assert_path_exists, :path_must_exist, :unary
189
+
190
+ ##
191
+ # See Minitest::Assertions#refute_path_exists
192
+ #
193
+ # _(some_path).path_wont_exist
194
+ #
195
+ # :method: path_wont_exist
196
+
197
+ infect_an_assertion :refute_path_exists, :path_wont_exist, :unary
198
+
171
199
  ##
172
200
  # See Minitest::Assertions#refute_empty
173
201
  #
174
- # collection.wont_be_empty
202
+ # _(collection).wont_be_empty
175
203
  #
176
204
  # :method: wont_be_empty
177
205
 
@@ -180,7 +208,7 @@ module Minitest::Expectations
180
208
  ##
181
209
  # See Minitest::Assertions#refute_equal
182
210
  #
183
- # a.wont_equal b
211
+ # _(a).wont_equal b
184
212
  #
185
213
  # :method: wont_equal
186
214
 
@@ -189,18 +217,18 @@ module Minitest::Expectations
189
217
  ##
190
218
  # See Minitest::Assertions#refute_in_delta
191
219
  #
192
- # n.wont_be_close_to m [, delta]
220
+ # _(n).wont_be_close_to m [, delta]
193
221
  #
194
222
  # :method: wont_be_close_to
195
223
 
196
224
  infect_an_assertion :refute_in_delta, :wont_be_close_to
197
225
 
198
- alias :wont_be_within_delta :wont_be_close_to # :nodoc:
226
+ infect_an_assertion :refute_in_delta, :wont_be_within_delta # :nodoc:
199
227
 
200
228
  ##
201
229
  # See Minitest::Assertions#refute_in_epsilon
202
230
  #
203
- # n.wont_be_within_epsilon m [, epsilon]
231
+ # _(n).wont_be_within_epsilon m [, epsilon]
204
232
  #
205
233
  # :method: wont_be_within_epsilon
206
234
 
@@ -209,7 +237,7 @@ module Minitest::Expectations
209
237
  ##
210
238
  # See Minitest::Assertions#refute_includes
211
239
  #
212
- # collection.wont_include obj
240
+ # _(collection).wont_include obj
213
241
  #
214
242
  # :method: wont_include
215
243
 
@@ -218,7 +246,7 @@ module Minitest::Expectations
218
246
  ##
219
247
  # See Minitest::Assertions#refute_instance_of
220
248
  #
221
- # obj.wont_be_instance_of klass
249
+ # _(obj).wont_be_instance_of klass
222
250
  #
223
251
  # :method: wont_be_instance_of
224
252
 
@@ -227,7 +255,7 @@ module Minitest::Expectations
227
255
  ##
228
256
  # See Minitest::Assertions#refute_kind_of
229
257
  #
230
- # obj.wont_be_kind_of mod
258
+ # _(obj).wont_be_kind_of mod
231
259
  #
232
260
  # :method: wont_be_kind_of
233
261
 
@@ -236,7 +264,7 @@ module Minitest::Expectations
236
264
  ##
237
265
  # See Minitest::Assertions#refute_match
238
266
  #
239
- # a.wont_match b
267
+ # _(a).wont_match b
240
268
  #
241
269
  # :method: wont_match
242
270
 
@@ -245,7 +273,7 @@ module Minitest::Expectations
245
273
  ##
246
274
  # See Minitest::Assertions#refute_nil
247
275
  #
248
- # obj.wont_be_nil
276
+ # _(obj).wont_be_nil
249
277
  #
250
278
  # :method: wont_be_nil
251
279
 
@@ -254,7 +282,7 @@ module Minitest::Expectations
254
282
  ##
255
283
  # See Minitest::Assertions#refute_operator
256
284
  #
257
- # n.wont_be :<=, 42
285
+ # _(n).wont_be :<=, 42
258
286
  #
259
287
  # This can also do predicates:
260
288
  #
@@ -264,10 +292,19 @@ module Minitest::Expectations
264
292
 
265
293
  infect_an_assertion :refute_operator, :wont_be, :reverse
266
294
 
295
+ ##
296
+ # See Minitest::Assertions#refute_pattern_match
297
+ #
298
+ # _ { ... }.wont_pattern_match [...]
299
+ #
300
+ # :method: wont_pattern_match
301
+
302
+ infect_an_assertion :refute_pattern, :wont_pattern_match, :block
303
+
267
304
  ##
268
305
  # See Minitest::Assertions#refute_respond_to
269
306
  #
270
- # obj.wont_respond_to msg
307
+ # _(obj).wont_respond_to msg
271
308
  #
272
309
  # :method: wont_respond_to
273
310
 
@@ -276,7 +313,7 @@ module Minitest::Expectations
276
313
  ##
277
314
  # See Minitest::Assertions#refute_same
278
315
  #
279
- # a.wont_be_same_as b
316
+ # _(a).wont_be_same_as b
280
317
  #
281
318
  # :method: wont_be_same_as
282
319
 
@@ -0,0 +1,16 @@
1
+ require "minitest"
2
+
3
+ ARGV << "--no-plugins"
4
+
5
+ module Minitest
6
+ ##
7
+ # Manually load plugins by name.
8
+
9
+ def self.load *names
10
+ names.each do |name|
11
+ require "minitest/#{name}_plugin"
12
+
13
+ self.extensions << name.to_s
14
+ end
15
+ end
16
+ end