minitest 5.20.0 → 5.23.1
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +91 -3
- data/Manifest.txt +3 -0
- data/README.rdoc +16 -13
- data/Rakefile +6 -0
- data/lib/minitest/assertions.rb +15 -13
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +4 -2
- data/lib/minitest/parallel.rb +1 -1
- data/lib/minitest/pride_plugin.rb +7 -10
- data/lib/minitest/test.rb +4 -3
- data/lib/minitest/test_task.rb +1 -2
- data/lib/minitest.rb +113 -37
- data/test/minitest/metametameta.rb +29 -12
- data/test/minitest/test_minitest_assertions.rb +48 -29
- data/test/minitest/test_minitest_mock.rb +15 -13
- data/test/minitest/test_minitest_reporter.rb +102 -3
- data/test/minitest/test_minitest_spec.rb +19 -17
- data/test/minitest/test_minitest_test.rb +114 -21
- data/test/minitest/test_minitest_test_task.rb +2 -0
- data.tar.gz.sig +0 -0
- metadata +17 -13
- metadata.gz.sig +0 -0
data/lib/minitest.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
require "optparse"
|
|
2
|
-
require "thread"
|
|
3
|
-
require "mutex_m"
|
|
4
|
-
require "minitest/parallel"
|
|
5
2
|
require "stringio"
|
|
6
3
|
require "etc"
|
|
7
4
|
|
|
5
|
+
require_relative "minitest/parallel"
|
|
6
|
+
require_relative "minitest/compress"
|
|
7
|
+
|
|
8
8
|
##
|
|
9
9
|
# :include: README.rdoc
|
|
10
10
|
|
|
11
11
|
module Minitest
|
|
12
|
-
VERSION = "5.
|
|
12
|
+
VERSION = "5.23.1" # :nodoc:
|
|
13
13
|
|
|
14
14
|
@@installed_at_exit ||= false
|
|
15
15
|
@@after_run = []
|
|
@@ -134,7 +134,7 @@ module Minitest
|
|
|
134
134
|
# Minitest.run(args)
|
|
135
135
|
# Minitest.__run(reporter, options)
|
|
136
136
|
# Runnable.runnables.each
|
|
137
|
-
#
|
|
137
|
+
# runnable_klass.run(reporter, options)
|
|
138
138
|
# self.runnable_methods.each
|
|
139
139
|
# self.run_one_method(self, runnable_method, reporter)
|
|
140
140
|
# Minitest.run_one_method(klass, runnable_method)
|
|
@@ -150,7 +150,7 @@ module Minitest
|
|
|
150
150
|
|
|
151
151
|
reporter = CompositeReporter.new
|
|
152
152
|
reporter << SummaryReporter.new(options[:io], options)
|
|
153
|
-
reporter << ProgressReporter.new(options[:io], options)
|
|
153
|
+
reporter << ProgressReporter.new(options[:io], options) unless options[:quiet]
|
|
154
154
|
|
|
155
155
|
self.reporter = reporter # this makes it available to plugins
|
|
156
156
|
self.init_plugins options
|
|
@@ -164,11 +164,32 @@ module Minitest
|
|
|
164
164
|
warn "Interrupted. Exiting..."
|
|
165
165
|
end
|
|
166
166
|
self.parallel_executor.shutdown
|
|
167
|
+
|
|
168
|
+
# might have been removed/replaced during init_plugins:
|
|
169
|
+
summary = reporter.reporters.grep(SummaryReporter).first
|
|
170
|
+
|
|
167
171
|
reporter.report
|
|
168
172
|
|
|
173
|
+
return empty_run! options if summary && summary.count == 0
|
|
169
174
|
reporter.passed?
|
|
170
175
|
end
|
|
171
176
|
|
|
177
|
+
def self.empty_run! options # :nodoc:
|
|
178
|
+
filter = options[:filter]
|
|
179
|
+
return true unless filter # no filter, but nothing ran == success
|
|
180
|
+
|
|
181
|
+
warn "Nothing ran for filter: %s" % [filter]
|
|
182
|
+
|
|
183
|
+
require "did_you_mean" # soft dependency, punt if it doesn't load
|
|
184
|
+
|
|
185
|
+
ms = Runnable.runnables.flat_map(&:runnable_methods)
|
|
186
|
+
cs = DidYouMean::SpellChecker.new(dictionary: ms).correct filter
|
|
187
|
+
|
|
188
|
+
warn DidYouMean::Formatter.message_for cs unless cs.empty?
|
|
189
|
+
rescue LoadError
|
|
190
|
+
# do nothing
|
|
191
|
+
end
|
|
192
|
+
|
|
172
193
|
##
|
|
173
194
|
# Internal run method. Responsible for telling all Runnable
|
|
174
195
|
# sub-classes to run.
|
|
@@ -212,6 +233,10 @@ module Minitest
|
|
|
212
233
|
options[:verbose] = true
|
|
213
234
|
end
|
|
214
235
|
|
|
236
|
+
opts.on "-q", "--quiet", "Quiet. Show no progress processing files." do
|
|
237
|
+
options[:quiet] = true
|
|
238
|
+
end
|
|
239
|
+
|
|
215
240
|
opts.on "--show-skips", "Show skipped at the end of run." do
|
|
216
241
|
options[:show_skips] = true
|
|
217
242
|
end
|
|
@@ -228,6 +253,20 @@ module Minitest
|
|
|
228
253
|
options[:skip] = s.chars.to_a
|
|
229
254
|
end
|
|
230
255
|
|
|
256
|
+
ruby27plus = ::Warning.respond_to?(:[]=)
|
|
257
|
+
|
|
258
|
+
opts.on "-W[error]", String, "Turn Ruby warnings into errors" do |s|
|
|
259
|
+
options[:Werror] = true
|
|
260
|
+
case s
|
|
261
|
+
when "error", "all", nil then
|
|
262
|
+
require "minitest/error_on_warning"
|
|
263
|
+
$VERBOSE = true
|
|
264
|
+
::Warning[:deprecated] = true if ruby27plus
|
|
265
|
+
else
|
|
266
|
+
::Warning[s.to_sym] = true if ruby27plus # check validity of category
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
231
270
|
unless extensions.empty?
|
|
232
271
|
opts.separator ""
|
|
233
272
|
opts.separator "Known extensions: #{extensions.join(", ")}"
|
|
@@ -334,25 +373,15 @@ module Minitest
|
|
|
334
373
|
# reporter to record.
|
|
335
374
|
|
|
336
375
|
def self.run reporter, options = {}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
filter = Regexp.new $1 if filter.is_a?(String) && filter =~ %r%/(.*)/%
|
|
340
|
-
|
|
341
|
-
self.runnable_methods.find_all { |m|
|
|
342
|
-
filter === m || filter === "#{self}##{m}"
|
|
343
|
-
}
|
|
344
|
-
else
|
|
345
|
-
self.runnable_methods
|
|
346
|
-
end
|
|
376
|
+
pos = options[:filter]
|
|
377
|
+
neg = options[:exclude]
|
|
347
378
|
|
|
348
|
-
if
|
|
349
|
-
|
|
350
|
-
exclude = Regexp.new $1 if exclude =~ %r%/(.*)/%
|
|
379
|
+
pos = Regexp.new $1 if pos.is_a?(String) && pos =~ %r%/(.*)/%
|
|
380
|
+
neg = Regexp.new $1 if neg.is_a?(String) && neg =~ %r%/(.*)/%
|
|
351
381
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
end
|
|
382
|
+
filtered_methods = self.runnable_methods
|
|
383
|
+
.select { |m| !pos || pos === m || pos === "#{self}##{m}" }
|
|
384
|
+
.reject { |m| neg && (neg === m || neg === "#{self}##{m}") }
|
|
356
385
|
|
|
357
386
|
return if filtered_methods.empty?
|
|
358
387
|
|
|
@@ -525,12 +554,14 @@ module Minitest
|
|
|
525
554
|
not self.failure
|
|
526
555
|
end
|
|
527
556
|
|
|
557
|
+
BASE_DIR = "#{Dir.pwd}/" # :nodoc:
|
|
558
|
+
|
|
528
559
|
##
|
|
529
560
|
# The location identifier of this test. Depends on a method
|
|
530
561
|
# existing called class_name.
|
|
531
562
|
|
|
532
563
|
def location
|
|
533
|
-
loc = " [#{self.failure.location}]" unless passed? or error?
|
|
564
|
+
loc = " [#{self.failure.location.delete_prefix BASE_DIR}]" unless passed? or error?
|
|
534
565
|
"#{self.class_name}##{self.name}#{loc}"
|
|
535
566
|
end
|
|
536
567
|
|
|
@@ -619,7 +650,10 @@ module Minitest
|
|
|
619
650
|
# you want. Go nuts.
|
|
620
651
|
|
|
621
652
|
class AbstractReporter
|
|
622
|
-
|
|
653
|
+
|
|
654
|
+
def initialize # :nodoc:
|
|
655
|
+
@mutex = Mutex.new
|
|
656
|
+
end
|
|
623
657
|
|
|
624
658
|
##
|
|
625
659
|
# Starts reporting on the run.
|
|
@@ -655,6 +689,10 @@ module Minitest
|
|
|
655
689
|
def passed?
|
|
656
690
|
true
|
|
657
691
|
end
|
|
692
|
+
|
|
693
|
+
def synchronize(&block) # :nodoc:
|
|
694
|
+
@mutex.synchronize(&block)
|
|
695
|
+
end
|
|
658
696
|
end
|
|
659
697
|
|
|
660
698
|
class Reporter < AbstractReporter # :nodoc:
|
|
@@ -758,6 +796,11 @@ module Minitest
|
|
|
758
796
|
|
|
759
797
|
attr_accessor :errors
|
|
760
798
|
|
|
799
|
+
##
|
|
800
|
+
# Total number of tests that warned.
|
|
801
|
+
|
|
802
|
+
attr_accessor :warnings
|
|
803
|
+
|
|
761
804
|
##
|
|
762
805
|
# Total number of tests that where skipped.
|
|
763
806
|
|
|
@@ -773,6 +816,7 @@ module Minitest
|
|
|
773
816
|
self.total_time = nil
|
|
774
817
|
self.failures = nil
|
|
775
818
|
self.errors = nil
|
|
819
|
+
self.warnings = nil
|
|
776
820
|
self.skips = nil
|
|
777
821
|
end
|
|
778
822
|
|
|
@@ -801,6 +845,7 @@ module Minitest
|
|
|
801
845
|
self.total_time = Minitest.clock_time - start_time
|
|
802
846
|
self.failures = aggregate[Assertion].size
|
|
803
847
|
self.errors = aggregate[UnexpectedError].size
|
|
848
|
+
self.warnings = aggregate[UnexpectedWarning].size
|
|
804
849
|
self.skips = aggregate[Skip].size
|
|
805
850
|
end
|
|
806
851
|
end
|
|
@@ -828,7 +873,7 @@ module Minitest
|
|
|
828
873
|
io.puts "# Running:"
|
|
829
874
|
io.puts
|
|
830
875
|
|
|
831
|
-
self.sync = io.respond_to? :"sync="
|
|
876
|
+
self.sync = io.respond_to? :"sync="
|
|
832
877
|
self.old_sync, io.sync = io.sync, true if self.sync
|
|
833
878
|
end
|
|
834
879
|
|
|
@@ -876,6 +921,8 @@ module Minitest
|
|
|
876
921
|
results.any?(&:skipped?) unless
|
|
877
922
|
options[:verbose] or options[:show_skips] or ENV["MT_NO_SKIP_MSG"]
|
|
878
923
|
|
|
924
|
+
extra.prepend ", %d warnings" % [warnings] if options[:Werror]
|
|
925
|
+
|
|
879
926
|
"%d runs, %d assertions, %d failures, %d errors, %d skips%s" %
|
|
880
927
|
[count, assertions, failures, errors, skips, extra]
|
|
881
928
|
end
|
|
@@ -936,6 +983,8 @@ module Minitest
|
|
|
936
983
|
# Represents run failures.
|
|
937
984
|
|
|
938
985
|
class Assertion < Exception
|
|
986
|
+
RE = /in [`'](?:[^']+[#.])?(?:assert|refute|flunk|pass|fail|raise|must|wont)/ # :nodoc:
|
|
987
|
+
|
|
939
988
|
def error # :nodoc:
|
|
940
989
|
self
|
|
941
990
|
end
|
|
@@ -944,12 +993,11 @@ module Minitest
|
|
|
944
993
|
# Where was this run before an assertion was raised?
|
|
945
994
|
|
|
946
995
|
def location
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
last_before_assertion.sub(/:in .*$/, "")
|
|
996
|
+
bt = Minitest.filter_backtrace self.backtrace
|
|
997
|
+
idx = bt.rindex { |s| s.match? RE } || -1 # fall back to first item
|
|
998
|
+
loc = bt[idx+1] || bt.last || "unknown:-1"
|
|
999
|
+
|
|
1000
|
+
loc.sub(/:in .*$/, "")
|
|
953
1001
|
end
|
|
954
1002
|
|
|
955
1003
|
def result_code # :nodoc:
|
|
@@ -974,11 +1022,21 @@ module Minitest
|
|
|
974
1022
|
# Assertion wrapping an unexpected error that was raised during a run.
|
|
975
1023
|
|
|
976
1024
|
class UnexpectedError < Assertion
|
|
1025
|
+
include Minitest::Compress
|
|
1026
|
+
|
|
977
1027
|
# TODO: figure out how to use `cause` instead
|
|
978
1028
|
attr_accessor :error # :nodoc:
|
|
979
1029
|
|
|
980
1030
|
def initialize error # :nodoc:
|
|
981
1031
|
super "Unexpected exception"
|
|
1032
|
+
|
|
1033
|
+
if SystemStackError === error then
|
|
1034
|
+
bt = error.backtrace
|
|
1035
|
+
new_bt = compress bt
|
|
1036
|
+
error = error.exception "#{bt.size} -> #{new_bt.size}"
|
|
1037
|
+
error.set_backtrace new_bt
|
|
1038
|
+
end
|
|
1039
|
+
|
|
982
1040
|
self.error = error
|
|
983
1041
|
end
|
|
984
1042
|
|
|
@@ -986,8 +1044,11 @@ module Minitest
|
|
|
986
1044
|
self.error.backtrace
|
|
987
1045
|
end
|
|
988
1046
|
|
|
1047
|
+
BASE_RE = %r%#{Dir.pwd}/% # :nodoc:
|
|
1048
|
+
|
|
989
1049
|
def message # :nodoc:
|
|
990
|
-
bt = Minitest.filter_backtrace(self.backtrace).join
|
|
1050
|
+
bt = Minitest.filter_backtrace(self.backtrace).join("\n ")
|
|
1051
|
+
.gsub(BASE_RE, "")
|
|
991
1052
|
"#{self.error.class}: #{self.error.message}\n #{bt}"
|
|
992
1053
|
end
|
|
993
1054
|
|
|
@@ -996,6 +1057,15 @@ module Minitest
|
|
|
996
1057
|
end
|
|
997
1058
|
end
|
|
998
1059
|
|
|
1060
|
+
##
|
|
1061
|
+
# Assertion raised on warning when running in -Werror mode.
|
|
1062
|
+
|
|
1063
|
+
class UnexpectedWarning < Assertion
|
|
1064
|
+
def result_label # :nodoc:
|
|
1065
|
+
"Warning"
|
|
1066
|
+
end
|
|
1067
|
+
end
|
|
1068
|
+
|
|
999
1069
|
##
|
|
1000
1070
|
# Provides a simple set of guards that you can use in your tests
|
|
1001
1071
|
# to skip execution if it is not applicable. These methods are
|
|
@@ -1069,7 +1139,13 @@ module Minitest
|
|
|
1069
1139
|
|
|
1070
1140
|
class BacktraceFilter
|
|
1071
1141
|
|
|
1072
|
-
MT_RE = %r%lib/minitest% #:nodoc:
|
|
1142
|
+
MT_RE = %r%lib/minitest|internal:warning% #:nodoc:
|
|
1143
|
+
|
|
1144
|
+
attr_accessor :regexp
|
|
1145
|
+
|
|
1146
|
+
def initialize regexp = MT_RE
|
|
1147
|
+
self.regexp = regexp
|
|
1148
|
+
end
|
|
1073
1149
|
|
|
1074
1150
|
##
|
|
1075
1151
|
# Filter +bt+ to something useful. Returns the whole thing if
|
|
@@ -1080,9 +1156,9 @@ module Minitest
|
|
|
1080
1156
|
|
|
1081
1157
|
return bt.dup if $DEBUG || ENV["MT_DEBUG"]
|
|
1082
1158
|
|
|
1083
|
-
new_bt = bt.take_while { |line| line !~
|
|
1084
|
-
new_bt = bt.select { |line| line !~
|
|
1085
|
-
new_bt = bt.dup
|
|
1159
|
+
new_bt = bt.take_while { |line| line.to_s !~ regexp }
|
|
1160
|
+
new_bt = bt.select { |line| line.to_s !~ regexp } if new_bt.empty?
|
|
1161
|
+
new_bt = bt.dup if new_bt.empty?
|
|
1086
1162
|
|
|
1087
1163
|
new_bt
|
|
1088
1164
|
end
|
|
@@ -8,24 +8,36 @@ class Minitest::Test
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def with_empty_backtrace_filter
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
obj = Minitest::BacktraceFilter.new
|
|
14
|
-
def obj.filter _bt
|
|
15
|
-
[]
|
|
11
|
+
with_backtrace_filter Minitest::BacktraceFilter.new %r%.% do
|
|
12
|
+
yield
|
|
16
13
|
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def with_backtrace_filter filter
|
|
17
|
+
original = Minitest.backtrace_filter
|
|
17
18
|
|
|
18
19
|
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
|
19
20
|
begin
|
|
20
|
-
Minitest.backtrace_filter =
|
|
21
|
+
Minitest.backtrace_filter = filter
|
|
21
22
|
yield
|
|
22
23
|
ensure
|
|
23
24
|
Minitest.backtrace_filter = original
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
|
-
end
|
|
28
28
|
|
|
29
|
+
def error_on_warn?
|
|
30
|
+
defined?(Minitest::ErrorOnWarning)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def assert_deprecation re = /DEPRECATED/
|
|
34
|
+
assert_output "", re do
|
|
35
|
+
yield
|
|
36
|
+
end
|
|
37
|
+
rescue Minitest::UnexpectedWarning => e # raised if -Werror was used
|
|
38
|
+
assert_match re, e.message
|
|
39
|
+
end
|
|
40
|
+
end
|
|
29
41
|
|
|
30
42
|
class FakeNamedTest < Minitest::Test
|
|
31
43
|
@@count = 0
|
|
@@ -55,7 +67,7 @@ class MetaMetaMetaTestCase < Minitest::Test
|
|
|
55
67
|
def run_tu_with_fresh_reporter flags = %w[--seed 42]
|
|
56
68
|
options = Minitest.process_args flags
|
|
57
69
|
|
|
58
|
-
@output = StringIO.new("".encode(
|
|
70
|
+
@output = StringIO.new("".encode(Encoding::UTF_8))
|
|
59
71
|
|
|
60
72
|
self.reporter = Minitest::CompositeReporter.new
|
|
61
73
|
reporter << Minitest::SummaryReporter.new(@output, options)
|
|
@@ -105,15 +117,20 @@ class MetaMetaMetaTestCase < Minitest::Test
|
|
|
105
117
|
output.gsub!(/0x[A-Fa-f0-9]+/, "0xXXX")
|
|
106
118
|
output.gsub!(/ +$/, "")
|
|
107
119
|
|
|
120
|
+
file = ->(s) { s.start_with?("/") ? "FULLFILE" : "FILE" }
|
|
121
|
+
|
|
108
122
|
if windows? then
|
|
109
123
|
output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, "[FILE:LINE]")
|
|
110
|
-
output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in/, '\1FILE:LINE:in')
|
|
124
|
+
output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in [`']/, '\1FILE:LINE:in \'')
|
|
111
125
|
else
|
|
112
|
-
output.gsub!(/\[[^\]:]
|
|
113
|
-
output.gsub!(/^(\s+)[^:]
|
|
126
|
+
output.gsub!(/\[([^\]:]+):\d+\]/) { "[#{file[$1]}:LINE]" }
|
|
127
|
+
output.gsub!(/^(\s+)([^:]+):\d+:in [`']/) { "#{$1}#{file[$2]}:LINE:in '" }
|
|
114
128
|
end
|
|
115
129
|
|
|
116
|
-
output.gsub!(/
|
|
130
|
+
output.gsub!(/in [`']block in (?:([^']+)[#.])?/, "in 'block in")
|
|
131
|
+
output.gsub!(/in [`'](?:([^']+)[#.])?/, "in '")
|
|
132
|
+
|
|
133
|
+
output.gsub!(/( at )[^:]+:\d+/) { "#{$1}[#{file[$2]}:LINE]" } # eval?
|
|
117
134
|
|
|
118
135
|
output
|
|
119
136
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
|
|
3
3
|
require "minitest/autorun"
|
|
4
|
+
require_relative "metametameta"
|
|
4
5
|
|
|
5
6
|
if defined? Encoding then
|
|
6
7
|
e = Encoding.default_external
|
|
@@ -33,7 +34,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
33
34
|
|
|
34
35
|
class DummyTest
|
|
35
36
|
include Minitest::Assertions
|
|
36
|
-
# include Minitest::Reportable # TODO: why do I really need this?
|
|
37
37
|
|
|
38
38
|
attr_accessor :assertions, :failure
|
|
39
39
|
|
|
@@ -58,15 +58,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
58
58
|
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}")
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
def assert_deprecated name
|
|
62
|
-
dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/
|
|
63
|
-
dep = "" if $-w.nil?
|
|
64
|
-
|
|
65
|
-
assert_output nil, dep do
|
|
66
|
-
yield
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
61
|
def assert_triggered expected, klass = Minitest::Assertion
|
|
71
62
|
e = assert_raises klass do
|
|
72
63
|
yield
|
|
@@ -301,7 +292,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
301
292
|
err_re = /Use assert_nil if expecting nil from .*test_minitest_\w+.rb/
|
|
302
293
|
err_re = "" if $-w.nil?
|
|
303
294
|
|
|
304
|
-
|
|
295
|
+
assert_deprecation err_re do
|
|
305
296
|
@tc.assert_equal nil, nil
|
|
306
297
|
end
|
|
307
298
|
end
|
|
@@ -379,7 +370,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
379
370
|
EOM
|
|
380
371
|
|
|
381
372
|
assert_triggered msg do
|
|
382
|
-
x = "bad-utf8-\xF1.txt".force_encoding
|
|
373
|
+
x = "bad-utf8-\xF1.txt".dup.force_encoding Encoding::ASCII
|
|
383
374
|
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
|
|
384
375
|
@tc.assert_equal x, y
|
|
385
376
|
end
|
|
@@ -762,12 +753,13 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
762
753
|
Class: <SomeError>
|
|
763
754
|
Message: <\"blah\">
|
|
764
755
|
---Backtrace---
|
|
765
|
-
FILE:LINE:in
|
|
756
|
+
FILE:LINE:in \'block in test_assert_raises_default_triggered\'
|
|
766
757
|
---------------
|
|
767
758
|
EOM
|
|
768
759
|
|
|
769
760
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
770
761
|
actual.gsub!(RE_LEVELS, "") unless jruby?
|
|
762
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
771
763
|
|
|
772
764
|
assert_equal expected, actual
|
|
773
765
|
end
|
|
@@ -841,12 +833,13 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
841
833
|
Class: <AnError>
|
|
842
834
|
Message: <\"some message\">
|
|
843
835
|
---Backtrace---
|
|
844
|
-
FILE:LINE:in
|
|
836
|
+
FILE:LINE:in \'block in test_assert_raises_subclass_triggered\'
|
|
845
837
|
---------------
|
|
846
838
|
EOM
|
|
847
839
|
|
|
848
840
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
849
841
|
actual.gsub!(RE_LEVELS, "") unless jruby?
|
|
842
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
850
843
|
|
|
851
844
|
assert_equal expected.chomp, actual
|
|
852
845
|
end
|
|
@@ -863,12 +856,13 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
863
856
|
Class: <SyntaxError>
|
|
864
857
|
Message: <\"icky\">
|
|
865
858
|
---Backtrace---
|
|
866
|
-
FILE:LINE:in
|
|
859
|
+
FILE:LINE:in \'block in test_assert_raises_triggered_different\'
|
|
867
860
|
---------------
|
|
868
861
|
EOM
|
|
869
862
|
|
|
870
863
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
871
864
|
actual.gsub!(RE_LEVELS, "") unless jruby?
|
|
865
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
872
866
|
|
|
873
867
|
assert_equal expected, actual
|
|
874
868
|
end
|
|
@@ -886,12 +880,13 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
886
880
|
Class: <SyntaxError>
|
|
887
881
|
Message: <\"icky\">
|
|
888
882
|
---Backtrace---
|
|
889
|
-
FILE:LINE:in
|
|
883
|
+
FILE:LINE:in \'block in test_assert_raises_triggered_different_msg\'
|
|
890
884
|
---------------
|
|
891
885
|
EOM
|
|
892
886
|
|
|
893
887
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
894
888
|
actual.gsub!(RE_LEVELS, "") unless jruby?
|
|
889
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
895
890
|
|
|
896
891
|
assert_equal expected.chomp, actual
|
|
897
892
|
end
|
|
@@ -936,6 +931,16 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
936
931
|
end
|
|
937
932
|
end
|
|
938
933
|
|
|
934
|
+
def test_assert_respond_to__include_all
|
|
935
|
+
@tc.assert_respond_to @tc, :exit, include_all: true
|
|
936
|
+
end
|
|
937
|
+
|
|
938
|
+
def test_assert_respond_to__include_all_triggered
|
|
939
|
+
assert_triggered(/Expected .+::DummyTest. to respond to #exit\?/) do
|
|
940
|
+
@tc.assert_respond_to @tc, :exit?, include_all: true
|
|
941
|
+
end
|
|
942
|
+
end
|
|
943
|
+
|
|
939
944
|
def test_assert_same
|
|
940
945
|
@assertion_count = 3
|
|
941
946
|
|
|
@@ -961,16 +966,24 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
961
966
|
end
|
|
962
967
|
|
|
963
968
|
def test_assert_send
|
|
964
|
-
|
|
969
|
+
@assertion_count = 0 if error_on_warn?
|
|
970
|
+
assert_deprecation(/DEPRECATED: assert_send/) do
|
|
965
971
|
@tc.assert_send [1, :<, 2]
|
|
966
972
|
end
|
|
967
973
|
end
|
|
968
974
|
|
|
969
975
|
def test_assert_send_bad
|
|
970
|
-
|
|
971
|
-
|
|
976
|
+
if error_on_warn? then
|
|
977
|
+
@assertion_count = 0
|
|
978
|
+
assert_deprecation(/DEPRECATED: assert_send/) do
|
|
972
979
|
@tc.assert_send [1, :>, 2]
|
|
973
980
|
end
|
|
981
|
+
else
|
|
982
|
+
assert_triggered "Expected 1.>(*[2]) to return true." do
|
|
983
|
+
assert_deprecation(/DEPRECATED: assert_send/) do
|
|
984
|
+
@tc.assert_send [1, :>, 2]
|
|
985
|
+
end
|
|
986
|
+
end
|
|
974
987
|
end
|
|
975
988
|
end
|
|
976
989
|
|
|
@@ -1153,18 +1166,14 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1153
1166
|
def test_class_asserts_match_refutes
|
|
1154
1167
|
@assertion_count = 0
|
|
1155
1168
|
|
|
1156
|
-
methods = Minitest::Assertions.public_instance_methods
|
|
1157
|
-
methods.map!(&:to_s) if Symbol === methods.first
|
|
1169
|
+
methods = Minitest::Assertions.public_instance_methods.map(&:to_s)
|
|
1158
1170
|
|
|
1159
1171
|
# These don't have corresponding refutes _on purpose_. They're
|
|
1160
1172
|
# useless and will never be added, so don't bother.
|
|
1161
1173
|
ignores = %w[assert_output assert_raises assert_send
|
|
1162
1174
|
assert_silent assert_throws assert_mock]
|
|
1163
1175
|
|
|
1164
|
-
|
|
1165
|
-
ignores += %w[assert_no_match assert_not_equal assert_not_nil
|
|
1166
|
-
assert_not_same assert_nothing_raised
|
|
1167
|
-
assert_nothing_thrown assert_raise]
|
|
1176
|
+
ignores += %w[assert_allocations] # for minitest-gcstats
|
|
1168
1177
|
|
|
1169
1178
|
asserts = methods.grep(/^assert/).sort - ignores
|
|
1170
1179
|
refutes = methods.grep(/^refute/).sort - ignores
|
|
@@ -1444,6 +1453,16 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1444
1453
|
end
|
|
1445
1454
|
end
|
|
1446
1455
|
|
|
1456
|
+
def test_refute_respond_to__include_all
|
|
1457
|
+
@tc.refute_respond_to "blah", :missing, include_all: true
|
|
1458
|
+
end
|
|
1459
|
+
|
|
1460
|
+
def test_refute_respond_to__include_all_triggered
|
|
1461
|
+
assert_triggered(/Expected .*DummyTest.* to not respond to exit./) do
|
|
1462
|
+
@tc.refute_respond_to @tc, :exit, include_all: true
|
|
1463
|
+
end
|
|
1464
|
+
end
|
|
1465
|
+
|
|
1447
1466
|
def test_refute_same
|
|
1448
1467
|
@tc.refute_same 1, 2
|
|
1449
1468
|
end
|
|
@@ -1482,7 +1501,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1482
1501
|
d0 = Time.now
|
|
1483
1502
|
d1 = d0 + 86_400 # I am an idiot
|
|
1484
1503
|
|
|
1485
|
-
|
|
1504
|
+
assert_deprecation(/Stale skip_until \"not yet\" at .*?:\d+$/) do
|
|
1486
1505
|
assert_skip_until d0, "not yet"
|
|
1487
1506
|
end
|
|
1488
1507
|
|
|
@@ -1626,14 +1645,14 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1626
1645
|
end
|
|
1627
1646
|
|
|
1628
1647
|
def test_mu_pp_for_diff_str_bad_encoding
|
|
1629
|
-
str = "\666".force_encoding Encoding::UTF_8
|
|
1648
|
+
str = "\666".dup.force_encoding Encoding::UTF_8
|
|
1630
1649
|
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
|
|
1631
1650
|
|
|
1632
1651
|
assert_mu_pp_for_diff exp, str, :raw
|
|
1633
1652
|
end
|
|
1634
1653
|
|
|
1635
1654
|
def test_mu_pp_for_diff_str_bad_encoding_both
|
|
1636
|
-
str = "\666A\\n\nB".force_encoding Encoding::UTF_8
|
|
1655
|
+
str = "\666A\\n\nB".dup.force_encoding Encoding::UTF_8
|
|
1637
1656
|
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\nB\""
|
|
1638
1657
|
|
|
1639
1658
|
assert_mu_pp_for_diff exp, str, :raw
|
|
@@ -1680,7 +1699,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1680
1699
|
end
|
|
1681
1700
|
|
|
1682
1701
|
def test_mu_pp_str_bad_encoding
|
|
1683
|
-
str = "\666".force_encoding Encoding::UTF_8
|
|
1702
|
+
str = "\666".dup.force_encoding Encoding::UTF_8
|
|
1684
1703
|
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
|
|
1685
1704
|
|
|
1686
1705
|
assert_mu_pp exp, str, :raw
|