minitest 5.10.3 → 5.15.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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +193 -4
- data/Manifest.txt +1 -0
- data/README.rdoc +87 -14
- data/Rakefile +4 -16
- data/lib/hoe/minitest.rb +0 -4
- data/lib/minitest/assertions.rb +145 -32
- data/lib/minitest/benchmark.rb +34 -3
- data/lib/minitest/expectations.rb +54 -35
- data/lib/minitest/mock.rb +11 -10
- data/lib/minitest/parallel.rb +1 -1
- data/lib/minitest/spec.rb +20 -8
- data/lib/minitest/test.rb +15 -69
- data/lib/minitest.rb +241 -31
- data/test/minitest/metametameta.rb +43 -8
- data/test/minitest/test_minitest_assertions.rb +1588 -0
- data/test/minitest/test_minitest_mock.rb +380 -7
- data/test/minitest/test_minitest_reporter.rb +45 -21
- data/test/minitest/test_minitest_spec.rb +220 -143
- data/test/minitest/test_minitest_test.rb +119 -1120
- data.tar.gz.sig +0 -0
- metadata +34 -24
- metadata.gz.sig +0 -0
@@ -15,10 +15,11 @@ if defined? Encoding then
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
class Minitest::Runnable
|
19
|
+
def whatever # faked for testing
|
20
|
+
assert true
|
21
|
+
end
|
22
|
+
end
|
22
23
|
|
23
24
|
class TestMinitestUnit < MetaMetaMetaTestCase
|
24
25
|
parallelize_me!
|
@@ -74,12 +75,16 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
74
75
|
assert_equal ex, fu
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
def test_filter_backtrace__empty
|
79
|
+
with_empty_backtrace_filter do
|
80
|
+
bt = %w[first second third]
|
81
|
+
fu = Minitest.filter_backtrace bt.dup
|
82
|
+
assert_equal bt, fu
|
83
|
+
end
|
84
|
+
end
|
80
85
|
|
81
86
|
def test_infectious_binary_encoding
|
82
|
-
@tu = Class.new
|
87
|
+
@tu = Class.new FakeNamedTest do
|
83
88
|
def test_this_is_not_ascii_assertion
|
84
89
|
assert_equal "ЁЁЁ", "ёёё"
|
85
90
|
end
|
@@ -95,12 +100,12 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
95
100
|
Finished in 0.00
|
96
101
|
|
97
102
|
1) Error:
|
98
|
-
|
103
|
+
FakeNamedTestXX#test_this_is_non_ascii_failure_message:
|
99
104
|
RuntimeError: ЁЁЁ
|
100
105
|
FILE:LINE:in `test_this_is_non_ascii_failure_message'
|
101
106
|
|
102
107
|
2) Failure:
|
103
|
-
|
108
|
+
FakeNamedTestXX#test_this_is_not_ascii_assertion [FILE:LINE]:
|
104
109
|
Expected: \"ЁЁЁ\"
|
105
110
|
Actual: \"ёёё\"
|
106
111
|
|
@@ -118,7 +123,10 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
118
123
|
|
119
124
|
test = test_class.new :test_omg
|
120
125
|
test.run
|
121
|
-
|
126
|
+
|
127
|
+
refute_predicate test, :error?
|
128
|
+
assert_predicate test, :passed?
|
129
|
+
refute_predicate test, :skipped?
|
122
130
|
end
|
123
131
|
|
124
132
|
def test_passed_eh_teardown_skipped
|
@@ -130,8 +138,9 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
130
138
|
test = test_class.new :test_omg
|
131
139
|
test.run
|
132
140
|
|
133
|
-
|
134
|
-
|
141
|
+
refute_predicate test, :error?
|
142
|
+
refute_predicate test, :passed?
|
143
|
+
assert_predicate test, :skipped?
|
135
144
|
end
|
136
145
|
|
137
146
|
def test_passed_eh_teardown_flunked
|
@@ -142,7 +151,10 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
142
151
|
|
143
152
|
test = test_class.new :test_omg
|
144
153
|
test.run
|
145
|
-
|
154
|
+
|
155
|
+
refute_predicate test, :error?
|
156
|
+
refute_predicate test, :passed?
|
157
|
+
refute_predicate test, :skipped?
|
146
158
|
end
|
147
159
|
|
148
160
|
def util_expand_bt bt
|
@@ -207,10 +219,10 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
207
219
|
|
208
220
|
def run
|
209
221
|
@foo = "hi mom!"
|
210
|
-
super
|
222
|
+
r = super
|
211
223
|
@foo = "okay"
|
212
224
|
|
213
|
-
|
225
|
+
r
|
214
226
|
end
|
215
227
|
|
216
228
|
def test_something
|
@@ -247,7 +259,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
247
259
|
Finished in 0.00
|
248
260
|
|
249
261
|
1) Error:
|
250
|
-
|
262
|
+
FakeNamedTestXX#test_error:
|
251
263
|
RuntimeError: unhandled exception
|
252
264
|
FILE:LINE:in \`test_error\'
|
253
265
|
|
@@ -275,7 +287,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
275
287
|
Finished in 0.00
|
276
288
|
|
277
289
|
1) Error:
|
278
|
-
|
290
|
+
FakeNamedTestXX#test_something:
|
279
291
|
RuntimeError: unhandled exception
|
280
292
|
FILE:LINE:in \`teardown\'
|
281
293
|
|
@@ -294,7 +306,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
294
306
|
Finished in 0.00
|
295
307
|
|
296
308
|
1) Failure:
|
297
|
-
|
309
|
+
FakeNamedTestXX#test_failure [FILE:LINE]:
|
298
310
|
Expected false to be truthy.
|
299
311
|
|
300
312
|
2 runs, 2 assertions, 1 failures, 0 errors, 0 skips
|
@@ -500,13 +512,13 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
500
512
|
end
|
501
513
|
|
502
514
|
expected = clean <<-EOM
|
503
|
-
|
504
|
-
|
515
|
+
FakeNamedTestXX#test_skip = 0.00 s = S
|
516
|
+
FakeNamedTestXX#test_something = 0.00 s = .
|
505
517
|
|
506
518
|
Finished in 0.00
|
507
519
|
|
508
520
|
1) Skipped:
|
509
|
-
|
521
|
+
FakeNamedTestXX#test_skip [FILE:LINE]:
|
510
522
|
not yet
|
511
523
|
|
512
524
|
2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
|
@@ -574,8 +586,6 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
574
586
|
end
|
575
587
|
|
576
588
|
def test_run_parallel
|
577
|
-
skip "I don't have ParallelEach debugged yet" if maglev?
|
578
|
-
|
579
589
|
test_count = 2
|
580
590
|
test_latch = Latch.new test_count
|
581
591
|
wait_latch = Latch.new test_count
|
@@ -754,7 +764,7 @@ class TestMinitestRunnable < Minitest::Test
|
|
754
764
|
end
|
755
765
|
tc.setup
|
756
766
|
|
757
|
-
@tc = tc
|
767
|
+
@tc = Minitest::Result.from tc
|
758
768
|
end
|
759
769
|
|
760
770
|
def assert_marshal expected_ivars
|
@@ -772,7 +782,45 @@ class TestMinitestRunnable < Minitest::Test
|
|
772
782
|
def test_marshal
|
773
783
|
setup_marshal Minitest::Runnable
|
774
784
|
|
775
|
-
assert_marshal %w[@NAME @assertions @failures]
|
785
|
+
assert_marshal %w[@NAME @assertions @failures @klass @source_location @time]
|
786
|
+
end
|
787
|
+
|
788
|
+
def test_spec_marshal
|
789
|
+
klass = describe("whatever") { it("passes") { assert true } }
|
790
|
+
rm = klass.runnable_methods.first
|
791
|
+
|
792
|
+
# Run the test
|
793
|
+
@tc = klass.new(rm).run
|
794
|
+
|
795
|
+
assert_kind_of Minitest::Result, @tc
|
796
|
+
|
797
|
+
# Pass it over the wire
|
798
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
799
|
+
|
800
|
+
assert_equal @tc.time, over_the_wire.time
|
801
|
+
assert_equal @tc.name, over_the_wire.name
|
802
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
803
|
+
assert_equal @tc.failures, over_the_wire.failures
|
804
|
+
assert_equal @tc.klass, over_the_wire.klass
|
805
|
+
end
|
806
|
+
|
807
|
+
def test_spec_marshal_with_exception
|
808
|
+
klass = describe("whatever") { it("passes") { raise Class.new(StandardError)} }
|
809
|
+
rm = klass.runnable_methods.first
|
810
|
+
|
811
|
+
# Run the test
|
812
|
+
@tc = klass.new(rm).run
|
813
|
+
|
814
|
+
assert_kind_of Minitest::Result, @tc
|
815
|
+
|
816
|
+
# Pass it over the wire
|
817
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
818
|
+
|
819
|
+
assert_equal @tc.time, over_the_wire.time
|
820
|
+
assert_equal @tc.name, over_the_wire.name
|
821
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
822
|
+
assert_equal @tc.failures, over_the_wire.failures
|
823
|
+
assert_equal @tc.klass, over_the_wire.klass
|
776
824
|
end
|
777
825
|
end
|
778
826
|
|
@@ -782,7 +830,7 @@ class TestMinitestTest < TestMinitestRunnable
|
|
782
830
|
tc.time = 3.14
|
783
831
|
end
|
784
832
|
|
785
|
-
assert_marshal %w[@NAME @assertions @failures @time] do |new_tc|
|
833
|
+
assert_marshal %w[@NAME @assertions @failures @klass @source_location @time] do |new_tc|
|
786
834
|
assert_in_epsilon 3.14, new_tc.time
|
787
835
|
end
|
788
836
|
end
|
@@ -819,1078 +867,25 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
819
867
|
$VERBOSE = orig_verbose
|
820
868
|
end
|
821
869
|
|
822
|
-
def
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
def test_assert__triggered
|
829
|
-
assert_triggered "Expected false to be truthy." do
|
830
|
-
@tc.assert false
|
831
|
-
end
|
832
|
-
end
|
833
|
-
|
834
|
-
def test_assert__triggered_message
|
835
|
-
assert_triggered @zomg do
|
836
|
-
@tc.assert false, @zomg
|
837
|
-
end
|
838
|
-
end
|
839
|
-
|
840
|
-
def test_assert_empty
|
841
|
-
@assertion_count = 2
|
842
|
-
|
843
|
-
@tc.assert_empty []
|
844
|
-
end
|
845
|
-
|
846
|
-
def test_assert_empty_triggered
|
847
|
-
@assertion_count = 2
|
848
|
-
|
849
|
-
assert_triggered "Expected [1] to be empty." do
|
850
|
-
@tc.assert_empty [1]
|
851
|
-
end
|
852
|
-
end
|
853
|
-
|
854
|
-
def test_assert_equal
|
855
|
-
@tc.assert_equal 1, 1
|
856
|
-
end
|
857
|
-
|
858
|
-
def test_assert_equal_different_collection_array_hex_invisible
|
859
|
-
object1 = Object.new
|
860
|
-
object2 = Object.new
|
861
|
-
msg = "No visible difference in the Array#inspect output.
|
862
|
-
You should look at the implementation of #== on Array or its members.
|
863
|
-
[#<Object:0xXXXXXX>]".gsub(/^ +/, "")
|
864
|
-
assert_triggered msg do
|
865
|
-
@tc.assert_equal [object1], [object2]
|
866
|
-
end
|
867
|
-
end
|
868
|
-
|
869
|
-
def test_assert_equal_different_collection_hash_hex_invisible
|
870
|
-
h1, h2 = {}, {}
|
871
|
-
h1[1] = Object.new
|
872
|
-
h2[1] = Object.new
|
873
|
-
msg = "No visible difference in the Hash#inspect output.
|
874
|
-
You should look at the implementation of #== on Hash or its members.
|
875
|
-
{1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
|
876
|
-
|
877
|
-
assert_triggered msg do
|
878
|
-
@tc.assert_equal h1, h2
|
879
|
-
end
|
880
|
-
end
|
881
|
-
|
882
|
-
def test_assert_equal_string_encodings
|
883
|
-
msg = <<-EOM.gsub(/^ {10}/, "")
|
884
|
-
--- expected
|
885
|
-
+++ actual
|
886
|
-
@@ -1 +1,2 @@
|
887
|
-
+# encoding: ASCII-8BIT
|
888
|
-
"bad-utf8-\\xF1.txt"
|
889
|
-
EOM
|
890
|
-
|
891
|
-
assert_triggered msg do
|
892
|
-
x = "bad-utf8-\xF1.txt"
|
893
|
-
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
|
894
|
-
@tc.assert_equal x, y
|
895
|
-
end
|
896
|
-
end unless RUBY18
|
897
|
-
|
898
|
-
def test_assert_equal_string_encodings_both_different
|
899
|
-
msg = <<-EOM.gsub(/^ {10}/, "")
|
900
|
-
--- expected
|
901
|
-
+++ actual
|
902
|
-
@@ -1,2 +1,2 @@
|
903
|
-
-# encoding: US-ASCII
|
904
|
-
+# encoding: ASCII-8BIT
|
905
|
-
"bad-utf8-\\xF1.txt"
|
906
|
-
EOM
|
907
|
-
|
908
|
-
assert_triggered msg do
|
909
|
-
x = "bad-utf8-\xF1.txt".force_encoding "ASCII"
|
910
|
-
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
|
911
|
-
@tc.assert_equal x, y
|
912
|
-
end
|
913
|
-
end unless RUBY18
|
914
|
-
|
915
|
-
def test_assert_equal_different_diff_deactivated
|
916
|
-
skip "https://github.com/MagLev/maglev/issues/209" if maglev?
|
917
|
-
|
918
|
-
without_diff do
|
919
|
-
assert_triggered util_msg("haha" * 10, "blah" * 10) do
|
920
|
-
o1 = "haha" * 10
|
921
|
-
o2 = "blah" * 10
|
922
|
-
|
923
|
-
@tc.assert_equal o1, o2
|
924
|
-
end
|
925
|
-
end
|
926
|
-
end
|
927
|
-
|
928
|
-
def test_assert_equal_different_hex
|
929
|
-
c = Class.new do
|
930
|
-
def initialize s; @name = s; end
|
931
|
-
end
|
932
|
-
|
933
|
-
o1 = c.new "a"
|
934
|
-
o2 = c.new "b"
|
935
|
-
msg = "--- expected
|
936
|
-
+++ actual
|
937
|
-
@@ -1 +1 @@
|
938
|
-
-#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
|
939
|
-
+#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
|
940
|
-
".gsub(/^ +/, "")
|
941
|
-
|
942
|
-
assert_triggered msg do
|
943
|
-
@tc.assert_equal o1, o2
|
944
|
-
end
|
945
|
-
end
|
946
|
-
|
947
|
-
def test_assert_equal_different_hex_invisible
|
948
|
-
o1 = Object.new
|
949
|
-
o2 = Object.new
|
950
|
-
|
951
|
-
msg = "No visible difference in the Object#inspect output.
|
952
|
-
You should look at the implementation of #== on Object or its members.
|
953
|
-
#<Object:0xXXXXXX>".gsub(/^ +/, "")
|
954
|
-
|
955
|
-
assert_triggered msg do
|
956
|
-
@tc.assert_equal o1, o2
|
957
|
-
end
|
958
|
-
end
|
959
|
-
|
960
|
-
def test_assert_equal_different_long
|
961
|
-
msg = "--- expected
|
962
|
-
+++ actual
|
963
|
-
@@ -1 +1 @@
|
964
|
-
-\"hahahahahahahahahahahahahahahahahahahaha\"
|
965
|
-
+\"blahblahblahblahblahblahblahblahblahblah\"
|
966
|
-
".gsub(/^ +/, "")
|
967
|
-
|
968
|
-
assert_triggered msg do
|
969
|
-
o1 = "haha" * 10
|
970
|
-
o2 = "blah" * 10
|
971
|
-
|
972
|
-
@tc.assert_equal o1, o2
|
973
|
-
end
|
974
|
-
end
|
975
|
-
|
976
|
-
def test_assert_equal_different_long_invisible
|
977
|
-
msg = "No visible difference in the String#inspect output.
|
978
|
-
You should look at the implementation of #== on String or its members.
|
979
|
-
\"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
|
980
|
-
|
981
|
-
assert_triggered msg do
|
982
|
-
o1 = "blah" * 10
|
983
|
-
o2 = "blah" * 10
|
984
|
-
def o1.== _
|
985
|
-
false
|
986
|
-
end
|
987
|
-
@tc.assert_equal o1, o2
|
988
|
-
end
|
989
|
-
end
|
990
|
-
|
991
|
-
def test_assert_equal_different_long_msg
|
992
|
-
msg = "message.
|
993
|
-
--- expected
|
994
|
-
+++ actual
|
995
|
-
@@ -1 +1 @@
|
996
|
-
-\"hahahahahahahahahahahahahahahahahahahaha\"
|
997
|
-
+\"blahblahblahblahblahblahblahblahblahblah\"
|
998
|
-
".gsub(/^ +/, "")
|
999
|
-
|
1000
|
-
assert_triggered msg do
|
1001
|
-
o1 = "haha" * 10
|
1002
|
-
o2 = "blah" * 10
|
1003
|
-
@tc.assert_equal o1, o2, "message"
|
1004
|
-
end
|
1005
|
-
end
|
1006
|
-
|
1007
|
-
def test_assert_equal_different_short
|
1008
|
-
assert_triggered util_msg(1, 2) do
|
1009
|
-
@tc.assert_equal 1, 2
|
1010
|
-
end
|
1011
|
-
end
|
1012
|
-
|
1013
|
-
def test_assert_equal_different_short_msg
|
1014
|
-
assert_triggered util_msg(1, 2, "message") do
|
1015
|
-
@tc.assert_equal 1, 2, "message"
|
1016
|
-
end
|
1017
|
-
end
|
1018
|
-
|
1019
|
-
def test_assert_equal_different_short_multiline
|
1020
|
-
msg = "--- expected\n+++ actual\n@@ -1,2 +1,2 @@\n \"a\n-b\"\n+c\"\n"
|
1021
|
-
assert_triggered msg do
|
1022
|
-
@tc.assert_equal "a\nb", "a\nc"
|
1023
|
-
end
|
1024
|
-
end
|
1025
|
-
|
1026
|
-
def test_assert_equal_does_not_allow_lhs_nil
|
1027
|
-
if Minitest::VERSION =~ /^6/ then
|
1028
|
-
warn "Time to strip the MT5 test"
|
1029
|
-
|
1030
|
-
@assertion_count += 1
|
1031
|
-
assert_triggered(/Use assert_nil if expecting nil/) do
|
1032
|
-
@tc.assert_equal nil, nil
|
1033
|
-
end
|
1034
|
-
else
|
1035
|
-
err_re = /Use assert_nil if expecting nil from .*test_minitest_test.rb/
|
1036
|
-
err_re = "" if $-w.nil?
|
1037
|
-
|
1038
|
-
assert_output "", err_re do
|
1039
|
-
@tc.assert_equal nil, nil
|
1040
|
-
end
|
1041
|
-
end
|
1042
|
-
end
|
1043
|
-
|
1044
|
-
def test_assert_equal_does_not_allow_lhs_nil_triggered
|
1045
|
-
assert_triggered "Expected: nil\n Actual: false" do
|
1046
|
-
@tc.assert_equal nil, false
|
1047
|
-
end
|
1048
|
-
end
|
1049
|
-
|
1050
|
-
def test_assert_in_delta
|
1051
|
-
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.1
|
1052
|
-
end
|
1053
|
-
|
1054
|
-
def test_delta_consistency
|
1055
|
-
@assertion_count = 2
|
1056
|
-
|
1057
|
-
@tc.assert_in_delta 0, 1, 1
|
1058
|
-
|
1059
|
-
assert_triggered "Expected |0 - 1| (1) to not be <= 1." do
|
1060
|
-
@tc.refute_in_delta 0, 1, 1
|
1061
|
-
end
|
1062
|
-
end
|
1063
|
-
|
1064
|
-
def test_assert_in_delta_triggered
|
1065
|
-
x = maglev? ? "9.999999xxxe-07" : "1.0e-06"
|
1066
|
-
assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
|
1067
|
-
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
|
1068
|
-
end
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
def test_assert_in_epsilon
|
1072
|
-
@assertion_count = 10
|
1073
|
-
|
1074
|
-
@tc.assert_in_epsilon 10_000, 9991
|
1075
|
-
@tc.assert_in_epsilon 9991, 10_000
|
1076
|
-
@tc.assert_in_epsilon 1.0, 1.001
|
1077
|
-
@tc.assert_in_epsilon 1.001, 1.0
|
1078
|
-
|
1079
|
-
@tc.assert_in_epsilon 10_000, 9999.1, 0.0001
|
1080
|
-
@tc.assert_in_epsilon 9999.1, 10_000, 0.0001
|
1081
|
-
@tc.assert_in_epsilon 1.0, 1.0001, 0.0001
|
1082
|
-
@tc.assert_in_epsilon 1.0001, 1.0, 0.0001
|
1083
|
-
|
1084
|
-
@tc.assert_in_epsilon(-1, -1)
|
1085
|
-
@tc.assert_in_epsilon(-10_000, -9991)
|
1086
|
-
end
|
1087
|
-
|
1088
|
-
def test_epsilon_consistency
|
1089
|
-
@assertion_count = 2
|
1090
|
-
|
1091
|
-
@tc.assert_in_epsilon 1.0, 1.001
|
1092
|
-
|
1093
|
-
msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001."
|
1094
|
-
assert_triggered msg do
|
1095
|
-
@tc.refute_in_epsilon 1.0, 1.001
|
1096
|
-
end
|
1097
|
-
end
|
1098
|
-
|
1099
|
-
def test_assert_in_epsilon_triggered
|
1100
|
-
assert_triggered "Expected |10000 - 9990| (10) to be <= 9.99." do
|
1101
|
-
@tc.assert_in_epsilon 10_000, 9990
|
1102
|
-
end
|
1103
|
-
end
|
1104
|
-
|
1105
|
-
def test_assert_in_epsilon_triggered_negative_case
|
1106
|
-
x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
|
1107
|
-
y = maglev? ? "0.100000xxx" : "0.1"
|
1108
|
-
assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
|
1109
|
-
@tc.assert_in_epsilon(-1.1, -1, 0.1)
|
1110
|
-
end
|
1111
|
-
end
|
1112
|
-
|
1113
|
-
def test_assert_includes
|
1114
|
-
@assertion_count = 2
|
1115
|
-
|
1116
|
-
@tc.assert_includes [true], true
|
1117
|
-
end
|
1118
|
-
|
1119
|
-
def test_assert_includes_triggered
|
1120
|
-
@assertion_count = 3
|
1121
|
-
|
1122
|
-
e = @tc.assert_raises Minitest::Assertion do
|
1123
|
-
@tc.assert_includes [true], false
|
1124
|
-
end
|
1125
|
-
|
1126
|
-
expected = "Expected [true] to include false."
|
1127
|
-
assert_equal expected, e.message
|
1128
|
-
end
|
1129
|
-
|
1130
|
-
def test_assert_instance_of
|
1131
|
-
@tc.assert_instance_of String, "blah"
|
1132
|
-
end
|
1133
|
-
|
1134
|
-
def test_assert_instance_of_triggered
|
1135
|
-
assert_triggered 'Expected "blah" to be an instance of Array, not String.' do
|
1136
|
-
@tc.assert_instance_of Array, "blah"
|
1137
|
-
end
|
1138
|
-
end
|
1139
|
-
|
1140
|
-
def test_assert_kind_of
|
1141
|
-
@tc.assert_kind_of String, "blah"
|
1142
|
-
end
|
1143
|
-
|
1144
|
-
def test_assert_kind_of_triggered
|
1145
|
-
assert_triggered 'Expected "blah" to be a kind of Array, not String.' do
|
1146
|
-
@tc.assert_kind_of Array, "blah"
|
1147
|
-
end
|
1148
|
-
end
|
1149
|
-
|
1150
|
-
def test_assert_match
|
1151
|
-
@assertion_count = 2
|
1152
|
-
@tc.assert_match(/\w+/, "blah blah blah")
|
1153
|
-
end
|
1154
|
-
|
1155
|
-
def test_assert_match_matcher_object
|
1156
|
-
@assertion_count = 2
|
1157
|
-
|
1158
|
-
pattern = Object.new
|
1159
|
-
def pattern.=~ _; true end
|
1160
|
-
|
1161
|
-
@tc.assert_match pattern, 5
|
1162
|
-
end
|
1163
|
-
|
1164
|
-
def test_assert_match_matchee_to_str
|
1165
|
-
@assertion_count = 2
|
1166
|
-
|
1167
|
-
obj = Object.new
|
1168
|
-
def obj.to_str; "blah" end
|
1169
|
-
|
1170
|
-
@tc.assert_match "blah", obj
|
1171
|
-
end
|
1172
|
-
|
1173
|
-
def test_assert_match_object_triggered
|
1174
|
-
@assertion_count = 2
|
1175
|
-
|
1176
|
-
pattern = Object.new
|
1177
|
-
def pattern.=~ _; false end
|
1178
|
-
def pattern.inspect; "[Object]" end
|
1179
|
-
|
1180
|
-
assert_triggered "Expected [Object] to match 5." do
|
1181
|
-
@tc.assert_match pattern, 5
|
1182
|
-
end
|
1183
|
-
end
|
1184
|
-
|
1185
|
-
def test_assert_match_triggered
|
1186
|
-
@assertion_count = 2
|
1187
|
-
assert_triggered 'Expected /\d+/ to match "blah blah blah".' do
|
1188
|
-
@tc.assert_match(/\d+/, "blah blah blah")
|
1189
|
-
end
|
1190
|
-
end
|
1191
|
-
|
1192
|
-
def test_assert_nil
|
1193
|
-
@tc.assert_nil nil
|
1194
|
-
end
|
1195
|
-
|
1196
|
-
def test_assert_nil_triggered
|
1197
|
-
assert_triggered "Expected 42 to be nil." do
|
1198
|
-
@tc.assert_nil 42
|
1199
|
-
end
|
1200
|
-
end
|
1201
|
-
|
1202
|
-
def test_assert_operator
|
1203
|
-
@tc.assert_operator 2, :>, 1
|
1204
|
-
end
|
1205
|
-
|
1206
|
-
def test_assert_operator_bad_object
|
1207
|
-
bad = Object.new
|
1208
|
-
def bad.== _; true end
|
1209
|
-
|
1210
|
-
@tc.assert_operator bad, :equal?, bad
|
1211
|
-
end
|
1212
|
-
|
1213
|
-
def test_assert_operator_triggered
|
1214
|
-
assert_triggered "Expected 2 to be < 1." do
|
1215
|
-
@tc.assert_operator 2, :<, 1
|
1216
|
-
end
|
1217
|
-
end
|
1218
|
-
|
1219
|
-
def test_assert_output_both
|
1220
|
-
@assertion_count = 2
|
1221
|
-
|
1222
|
-
@tc.assert_output "yay", "blah" do
|
1223
|
-
print "yay"
|
1224
|
-
$stderr.print "blah"
|
1225
|
-
end
|
1226
|
-
end
|
1227
|
-
|
1228
|
-
def test_assert_output_both_regexps
|
1229
|
-
@assertion_count = 4
|
1230
|
-
|
1231
|
-
@tc.assert_output(/y.y/, /bl.h/) do
|
1232
|
-
print "yay"
|
1233
|
-
$stderr.print "blah"
|
1234
|
-
end
|
1235
|
-
end
|
1236
|
-
|
1237
|
-
def test_assert_output_err
|
1238
|
-
@tc.assert_output nil, "blah" do
|
1239
|
-
$stderr.print "blah"
|
1240
|
-
end
|
1241
|
-
end
|
1242
|
-
|
1243
|
-
def test_assert_output_neither
|
1244
|
-
@assertion_count = 0
|
1245
|
-
|
1246
|
-
@tc.assert_output do
|
1247
|
-
# do nothing
|
1248
|
-
end
|
1249
|
-
end
|
1250
|
-
|
1251
|
-
def test_assert_output_out
|
1252
|
-
@tc.assert_output "blah" do
|
1253
|
-
print "blah"
|
1254
|
-
end
|
1255
|
-
end
|
1256
|
-
|
1257
|
-
def test_assert_output_triggered_both
|
1258
|
-
assert_triggered util_msg("blah", "blah blah", "In stderr") do
|
1259
|
-
@tc.assert_output "yay", "blah" do
|
1260
|
-
print "boo"
|
1261
|
-
$stderr.print "blah blah"
|
1262
|
-
end
|
1263
|
-
end
|
1264
|
-
end
|
1265
|
-
|
1266
|
-
def test_assert_output_triggered_err
|
1267
|
-
assert_triggered util_msg("blah", "blah blah", "In stderr") do
|
1268
|
-
@tc.assert_output nil, "blah" do
|
1269
|
-
$stderr.print "blah blah"
|
1270
|
-
end
|
1271
|
-
end
|
1272
|
-
end
|
1273
|
-
|
1274
|
-
def test_assert_output_triggered_out
|
1275
|
-
assert_triggered util_msg("blah", "blah blah", "In stdout") do
|
1276
|
-
@tc.assert_output "blah" do
|
1277
|
-
print "blah blah"
|
1278
|
-
end
|
1279
|
-
end
|
1280
|
-
end
|
1281
|
-
|
1282
|
-
def test_assert_predicate
|
1283
|
-
@tc.assert_predicate "", :empty?
|
1284
|
-
end
|
1285
|
-
|
1286
|
-
def test_assert_predicate_triggered
|
1287
|
-
assert_triggered 'Expected "blah" to be empty?.' do
|
1288
|
-
@tc.assert_predicate "blah", :empty?
|
1289
|
-
end
|
1290
|
-
end
|
1291
|
-
|
1292
|
-
def test_assert_raises
|
1293
|
-
@tc.assert_raises RuntimeError do
|
1294
|
-
raise "blah"
|
1295
|
-
end
|
1296
|
-
end
|
1297
|
-
|
1298
|
-
def test_assert_raises_default
|
1299
|
-
@tc.assert_raises do
|
1300
|
-
raise StandardError, "blah"
|
1301
|
-
end
|
1302
|
-
end
|
1303
|
-
|
1304
|
-
def test_assert_raises_default_triggered
|
1305
|
-
e = assert_raises Minitest::Assertion do
|
1306
|
-
@tc.assert_raises do
|
1307
|
-
raise SomeError, "blah"
|
1308
|
-
end
|
1309
|
-
end
|
1310
|
-
|
1311
|
-
expected = clean <<-EOM.chomp
|
1312
|
-
[StandardError] exception expected, not
|
1313
|
-
Class: <SomeError>
|
1314
|
-
Message: <\"blah\">
|
1315
|
-
---Backtrace---
|
1316
|
-
FILE:LINE:in \`test_assert_raises_default_triggered\'
|
1317
|
-
---------------
|
1318
|
-
EOM
|
1319
|
-
|
1320
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
1321
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
1322
|
-
|
1323
|
-
assert_equal expected, actual
|
1324
|
-
end
|
1325
|
-
|
1326
|
-
def test_assert_raises_module
|
1327
|
-
@tc.assert_raises MyModule do
|
1328
|
-
raise AnError
|
1329
|
-
end
|
1330
|
-
end
|
1331
|
-
|
1332
|
-
##
|
1333
|
-
# *sigh* This is quite an odd scenario, but it is from real (albeit
|
1334
|
-
# ugly) test code in ruby-core:
|
1335
|
-
#
|
1336
|
-
# http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
|
1337
|
-
|
1338
|
-
def test_assert_raises_skip
|
1339
|
-
@assertion_count = 0
|
1340
|
-
|
1341
|
-
assert_triggered "skipped", Minitest::Skip do
|
1342
|
-
@tc.assert_raises ArgumentError do
|
1343
|
-
begin
|
1344
|
-
raise "blah"
|
1345
|
-
rescue
|
1346
|
-
skip "skipped"
|
1347
|
-
end
|
1348
|
-
end
|
1349
|
-
end
|
1350
|
-
end
|
1351
|
-
|
1352
|
-
def test_assert_raises_triggered_different
|
1353
|
-
e = assert_raises Minitest::Assertion do
|
1354
|
-
@tc.assert_raises RuntimeError do
|
1355
|
-
raise SyntaxError, "icky"
|
1356
|
-
end
|
1357
|
-
end
|
1358
|
-
|
1359
|
-
expected = clean <<-EOM.chomp
|
1360
|
-
[RuntimeError] exception expected, not
|
1361
|
-
Class: <SyntaxError>
|
1362
|
-
Message: <\"icky\">
|
1363
|
-
---Backtrace---
|
1364
|
-
FILE:LINE:in \`test_assert_raises_triggered_different\'
|
1365
|
-
---------------
|
1366
|
-
EOM
|
1367
|
-
|
1368
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
1369
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
1370
|
-
|
1371
|
-
assert_equal expected, actual
|
1372
|
-
end
|
1373
|
-
|
1374
|
-
def test_assert_raises_triggered_different_msg
|
1375
|
-
e = assert_raises Minitest::Assertion do
|
1376
|
-
@tc.assert_raises RuntimeError, "XXX" do
|
1377
|
-
raise SyntaxError, "icky"
|
1378
|
-
end
|
1379
|
-
end
|
1380
|
-
|
1381
|
-
expected = clean <<-EOM
|
1382
|
-
XXX.
|
1383
|
-
[RuntimeError] exception expected, not
|
1384
|
-
Class: <SyntaxError>
|
1385
|
-
Message: <\"icky\">
|
1386
|
-
---Backtrace---
|
1387
|
-
FILE:LINE:in \`test_assert_raises_triggered_different_msg\'
|
1388
|
-
---------------
|
1389
|
-
EOM
|
1390
|
-
|
1391
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
1392
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
1393
|
-
|
1394
|
-
assert_equal expected.chomp, actual
|
1395
|
-
end
|
1396
|
-
|
1397
|
-
def test_assert_raises_triggered_none
|
1398
|
-
e = assert_raises Minitest::Assertion do
|
1399
|
-
@tc.assert_raises Minitest::Assertion do
|
1400
|
-
# do nothing
|
1401
|
-
end
|
1402
|
-
end
|
1403
|
-
|
1404
|
-
expected = "Minitest::Assertion expected but nothing was raised."
|
1405
|
-
|
1406
|
-
assert_equal expected, e.message
|
1407
|
-
end
|
1408
|
-
|
1409
|
-
def test_assert_raises_triggered_none_msg
|
1410
|
-
e = assert_raises Minitest::Assertion do
|
1411
|
-
@tc.assert_raises Minitest::Assertion, "XXX" do
|
1412
|
-
# do nothing
|
1413
|
-
end
|
1414
|
-
end
|
1415
|
-
|
1416
|
-
expected = "XXX.\nMinitest::Assertion expected but nothing was raised."
|
1417
|
-
|
1418
|
-
assert_equal expected, e.message
|
1419
|
-
end
|
1420
|
-
|
1421
|
-
def test_assert_raises_subclass
|
1422
|
-
@tc.assert_raises StandardError do
|
1423
|
-
raise AnError
|
1424
|
-
end
|
1425
|
-
end
|
1426
|
-
|
1427
|
-
def test_assert_raises_subclass_triggered
|
1428
|
-
e = assert_raises Minitest::Assertion do
|
1429
|
-
@tc.assert_raises SomeError do
|
1430
|
-
raise AnError, "some message"
|
1431
|
-
end
|
1432
|
-
end
|
1433
|
-
|
1434
|
-
expected = clean <<-EOM
|
1435
|
-
[SomeError] exception expected, not
|
1436
|
-
Class: <AnError>
|
1437
|
-
Message: <\"some message\">
|
1438
|
-
---Backtrace---
|
1439
|
-
FILE:LINE:in \`test_assert_raises_subclass_triggered\'
|
1440
|
-
---------------
|
1441
|
-
EOM
|
1442
|
-
|
1443
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
1444
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
1445
|
-
|
1446
|
-
assert_equal expected.chomp, actual
|
1447
|
-
end
|
1448
|
-
|
1449
|
-
def test_assert_raises_exit
|
1450
|
-
@tc.assert_raises SystemExit do
|
1451
|
-
exit 1
|
1452
|
-
end
|
1453
|
-
end
|
1454
|
-
|
1455
|
-
def test_assert_raises_signals
|
1456
|
-
@tc.assert_raises SignalException do
|
1457
|
-
raise SignalException, :INT
|
1458
|
-
end
|
1459
|
-
end
|
1460
|
-
|
1461
|
-
def test_assert_respond_to
|
1462
|
-
@tc.assert_respond_to "blah", :empty?
|
1463
|
-
end
|
1464
|
-
|
1465
|
-
def test_assert_respond_to_triggered
|
1466
|
-
assert_triggered 'Expected "blah" (String) to respond to #rawr!.' do
|
1467
|
-
@tc.assert_respond_to "blah", :rawr!
|
1468
|
-
end
|
1469
|
-
end
|
1470
|
-
|
1471
|
-
def test_assert_same
|
1472
|
-
@assertion_count = 3
|
1473
|
-
|
1474
|
-
o = "blah"
|
1475
|
-
@tc.assert_same 1, 1
|
1476
|
-
@tc.assert_same :blah, :blah
|
1477
|
-
@tc.assert_same o, o
|
1478
|
-
end
|
1479
|
-
|
1480
|
-
def test_assert_same_triggered
|
1481
|
-
@assertion_count = 2
|
1482
|
-
|
1483
|
-
assert_triggered "Expected 2 (oid=N) to be the same as 1 (oid=N)." do
|
1484
|
-
@tc.assert_same 1, 2
|
1485
|
-
end
|
1486
|
-
|
1487
|
-
s1 = "blah"
|
1488
|
-
s2 = "blah"
|
1489
|
-
|
1490
|
-
assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
|
1491
|
-
@tc.assert_same s1, s2
|
1492
|
-
end
|
1493
|
-
end
|
1494
|
-
|
1495
|
-
def assert_deprecated name
|
1496
|
-
dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/
|
1497
|
-
dep = "" if $-w.nil?
|
1498
|
-
|
1499
|
-
assert_output nil, dep do
|
1500
|
-
yield
|
1501
|
-
end
|
1502
|
-
end
|
1503
|
-
|
1504
|
-
def test_assert_send
|
1505
|
-
assert_deprecated :assert_send do
|
1506
|
-
@tc.assert_send [1, :<, 2]
|
1507
|
-
end
|
1508
|
-
end
|
1509
|
-
|
1510
|
-
def test_assert_send_bad
|
1511
|
-
assert_deprecated :assert_send do
|
1512
|
-
assert_triggered "Expected 1.>(*[2]) to return true." do
|
1513
|
-
@tc.assert_send [1, :>, 2]
|
1514
|
-
end
|
1515
|
-
end
|
1516
|
-
end
|
1517
|
-
|
1518
|
-
def test_assert_silent
|
1519
|
-
@assertion_count = 2
|
1520
|
-
|
1521
|
-
@tc.assert_silent do
|
1522
|
-
# do nothing
|
1523
|
-
end
|
1524
|
-
end
|
1525
|
-
|
1526
|
-
def test_assert_silent_triggered_err
|
1527
|
-
assert_triggered util_msg("", "blah blah", "In stderr") do
|
1528
|
-
@tc.assert_silent do
|
1529
|
-
$stderr.print "blah blah"
|
1530
|
-
end
|
1531
|
-
end
|
1532
|
-
end
|
1533
|
-
|
1534
|
-
def test_assert_silent_triggered_out
|
1535
|
-
@assertion_count = 2
|
1536
|
-
|
1537
|
-
assert_triggered util_msg("", "blah blah", "In stdout") do
|
1538
|
-
@tc.assert_silent do
|
1539
|
-
print "blah blah"
|
1540
|
-
end
|
1541
|
-
end
|
1542
|
-
end
|
1543
|
-
|
1544
|
-
def test_assert_throws
|
1545
|
-
@tc.assert_throws :blah do
|
1546
|
-
throw :blah
|
1547
|
-
end
|
1548
|
-
end
|
1549
|
-
|
1550
|
-
def test_assert_throws_name_error
|
1551
|
-
@tc.assert_raises NameError do
|
1552
|
-
@tc.assert_throws :blah do
|
1553
|
-
raise NameError
|
1554
|
-
end
|
1555
|
-
end
|
1556
|
-
end
|
1557
|
-
|
1558
|
-
def test_assert_throws_argument_exception
|
1559
|
-
@tc.assert_raises ArgumentError do
|
1560
|
-
@tc.assert_throws :blah do
|
1561
|
-
raise ArgumentError
|
1562
|
-
end
|
1563
|
-
end
|
1564
|
-
end
|
1565
|
-
|
1566
|
-
def test_assert_throws_different
|
1567
|
-
assert_triggered "Expected :blah to have been thrown, not :not_blah." do
|
1568
|
-
@tc.assert_throws :blah do
|
1569
|
-
throw :not_blah
|
1570
|
-
end
|
1571
|
-
end
|
1572
|
-
end
|
1573
|
-
|
1574
|
-
def test_assert_throws_unthrown
|
1575
|
-
assert_triggered "Expected :blah to have been thrown." do
|
1576
|
-
@tc.assert_throws :blah do
|
1577
|
-
# do nothing
|
1578
|
-
end
|
1579
|
-
end
|
1580
|
-
end
|
1581
|
-
|
1582
|
-
def test_capture_io
|
1583
|
-
@assertion_count = 0
|
1584
|
-
|
1585
|
-
non_verbose do
|
1586
|
-
out, err = capture_io do
|
1587
|
-
puts "hi"
|
1588
|
-
$stderr.puts "bye!"
|
1589
|
-
end
|
1590
|
-
|
1591
|
-
assert_equal "hi\n", out
|
1592
|
-
assert_equal "bye!\n", err
|
1593
|
-
end
|
1594
|
-
end
|
1595
|
-
|
1596
|
-
def test_capture_subprocess_io
|
1597
|
-
@assertion_count = 0
|
1598
|
-
|
1599
|
-
non_verbose do
|
1600
|
-
out, err = capture_subprocess_io do
|
1601
|
-
system("echo hi")
|
1602
|
-
system("echo bye! 1>&2")
|
870
|
+
def sample_test_case(rand)
|
871
|
+
srand rand
|
872
|
+
Class.new FakeNamedTest do
|
873
|
+
100.times do |i|
|
874
|
+
define_method("test_#{i}") { assert true }
|
1603
875
|
end
|
1604
|
-
|
1605
|
-
assert_equal "hi\n", out
|
1606
|
-
assert_equal "bye!", err.strip
|
1607
|
-
end
|
1608
|
-
end
|
1609
|
-
|
1610
|
-
def test_class_asserts_match_refutes
|
1611
|
-
@assertion_count = 0
|
1612
|
-
|
1613
|
-
methods = Minitest::Assertions.public_instance_methods
|
1614
|
-
methods.map!(&:to_s) if Symbol === methods.first
|
1615
|
-
|
1616
|
-
# These don't have corresponding refutes _on purpose_. They're
|
1617
|
-
# useless and will never be added, so don't bother.
|
1618
|
-
ignores = %w[assert_output assert_raises assert_send
|
1619
|
-
assert_silent assert_throws assert_mock]
|
1620
|
-
|
1621
|
-
# These are test/unit methods. I'm not actually sure why they're still here
|
1622
|
-
ignores += %w[assert_no_match assert_not_equal assert_not_nil
|
1623
|
-
assert_not_same assert_nothing_raised
|
1624
|
-
assert_nothing_thrown assert_raise]
|
1625
|
-
|
1626
|
-
asserts = methods.grep(/^assert/).sort - ignores
|
1627
|
-
refutes = methods.grep(/^refute/).sort - ignores
|
1628
|
-
|
1629
|
-
assert_empty refutes.map { |n| n.sub(/^refute/, "assert") } - asserts
|
1630
|
-
assert_empty asserts.map { |n| n.sub(/^assert/, "refute") } - refutes
|
1631
|
-
end
|
1632
|
-
|
1633
|
-
def test_flunk
|
1634
|
-
assert_triggered "Epic Fail!" do
|
1635
|
-
@tc.flunk
|
1636
|
-
end
|
1637
|
-
end
|
1638
|
-
|
1639
|
-
def test_flunk_message
|
1640
|
-
assert_triggered @zomg do
|
1641
|
-
@tc.flunk @zomg
|
1642
|
-
end
|
1643
|
-
end
|
1644
|
-
|
1645
|
-
def test_message
|
1646
|
-
@assertion_count = 0
|
1647
|
-
|
1648
|
-
assert_equal "blah2.", @tc.message { "blah2" }.call
|
1649
|
-
assert_equal "blah2.", @tc.message("") { "blah2" }.call
|
1650
|
-
assert_equal "blah1.\nblah2.", @tc.message(:blah1) { "blah2" }.call
|
1651
|
-
assert_equal "blah1.\nblah2.", @tc.message("blah1") { "blah2" }.call
|
1652
|
-
|
1653
|
-
message = proc { "blah1" }
|
1654
|
-
assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
|
1655
|
-
|
1656
|
-
message = @tc.message { "blah1" }
|
1657
|
-
assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
|
1658
|
-
end
|
1659
|
-
|
1660
|
-
def test_message_message
|
1661
|
-
assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
|
1662
|
-
@tc.assert_equal 1, 2, message { "whoops" }
|
1663
|
-
end
|
1664
|
-
end
|
1665
|
-
|
1666
|
-
def test_message_lambda
|
1667
|
-
assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
|
1668
|
-
@tc.assert_equal 1, 2, lambda { "whoops" }
|
1669
|
-
end
|
1670
|
-
end
|
1671
|
-
|
1672
|
-
def test_message_deferred
|
1673
|
-
@assertion_count, var = 0, nil
|
1674
|
-
|
1675
|
-
msg = message { var = "blah" }
|
1676
|
-
|
1677
|
-
assert_nil var
|
1678
|
-
|
1679
|
-
msg.call
|
1680
|
-
|
1681
|
-
assert_equal "blah", var
|
1682
|
-
end
|
1683
|
-
|
1684
|
-
def test_pass
|
1685
|
-
@tc.pass
|
1686
|
-
end
|
1687
|
-
|
1688
|
-
def test_prints
|
1689
|
-
printer = Class.new { extend Minitest::Assertions }
|
1690
|
-
@tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new "test")
|
1691
|
-
end
|
1692
|
-
|
1693
|
-
def test_refute
|
1694
|
-
@assertion_count = 2
|
1695
|
-
|
1696
|
-
@tc.assert_equal false, @tc.refute(false), "returns false on success"
|
1697
|
-
end
|
1698
|
-
|
1699
|
-
def test_refute_empty
|
1700
|
-
@assertion_count = 2
|
1701
|
-
|
1702
|
-
@tc.refute_empty [1]
|
1703
|
-
end
|
1704
|
-
|
1705
|
-
def test_refute_empty_triggered
|
1706
|
-
@assertion_count = 2
|
1707
|
-
|
1708
|
-
assert_triggered "Expected [] to not be empty." do
|
1709
|
-
@tc.refute_empty []
|
1710
|
-
end
|
1711
|
-
end
|
1712
|
-
|
1713
|
-
def test_refute_equal
|
1714
|
-
@tc.refute_equal "blah", "yay"
|
1715
|
-
end
|
1716
|
-
|
1717
|
-
def test_refute_equal_triggered
|
1718
|
-
assert_triggered 'Expected "blah" to not be equal to "blah".' do
|
1719
|
-
@tc.refute_equal "blah", "blah"
|
1720
|
-
end
|
1721
|
-
end
|
1722
|
-
|
1723
|
-
def test_refute_in_delta
|
1724
|
-
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.000001
|
1725
|
-
end
|
1726
|
-
|
1727
|
-
def test_refute_in_delta_triggered
|
1728
|
-
x = maglev? ? "0.100000xxx" : "0.1"
|
1729
|
-
assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do
|
1730
|
-
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
|
1731
|
-
end
|
1732
|
-
end
|
1733
|
-
|
1734
|
-
def test_refute_in_epsilon
|
1735
|
-
@tc.refute_in_epsilon 10_000, 9990-1
|
1736
|
-
end
|
1737
|
-
|
1738
|
-
def test_refute_in_epsilon_triggered
|
1739
|
-
assert_triggered "Expected |10000 - 9990| (10) to not be <= 10.0." do
|
1740
|
-
@tc.refute_in_epsilon 10_000, 9990
|
1741
|
-
flunk
|
1742
|
-
end
|
1743
|
-
end
|
1744
|
-
|
1745
|
-
def test_refute_includes
|
1746
|
-
@assertion_count = 2
|
1747
|
-
|
1748
|
-
@tc.refute_includes [true], false
|
1749
|
-
end
|
1750
|
-
|
1751
|
-
def test_refute_includes_triggered
|
1752
|
-
@assertion_count = 3
|
1753
|
-
|
1754
|
-
e = @tc.assert_raises Minitest::Assertion do
|
1755
|
-
@tc.refute_includes [true], true
|
1756
|
-
end
|
1757
|
-
|
1758
|
-
expected = "Expected [true] to not include true."
|
1759
|
-
assert_equal expected, e.message
|
1760
|
-
end
|
1761
|
-
|
1762
|
-
def test_refute_instance_of
|
1763
|
-
@tc.refute_instance_of Array, "blah"
|
1764
|
-
end
|
1765
|
-
|
1766
|
-
def test_refute_instance_of_triggered
|
1767
|
-
assert_triggered 'Expected "blah" to not be an instance of String.' do
|
1768
|
-
@tc.refute_instance_of String, "blah"
|
1769
|
-
end
|
1770
|
-
end
|
1771
|
-
|
1772
|
-
def test_refute_kind_of
|
1773
|
-
@tc.refute_kind_of Array, "blah"
|
1774
|
-
end
|
1775
|
-
|
1776
|
-
def test_refute_kind_of_triggered
|
1777
|
-
assert_triggered 'Expected "blah" to not be a kind of String.' do
|
1778
|
-
@tc.refute_kind_of String, "blah"
|
1779
|
-
end
|
1780
|
-
end
|
1781
|
-
|
1782
|
-
def test_refute_match
|
1783
|
-
@assertion_count = 2
|
1784
|
-
@tc.refute_match(/\d+/, "blah blah blah")
|
1785
|
-
end
|
1786
|
-
|
1787
|
-
def test_refute_match_matcher_object
|
1788
|
-
@assertion_count = 2
|
1789
|
-
@tc.refute_match Object.new, 5 # default #=~ returns false
|
1790
|
-
end
|
1791
|
-
|
1792
|
-
def test_refute_match_object_triggered
|
1793
|
-
@assertion_count = 2
|
1794
|
-
|
1795
|
-
pattern = Object.new
|
1796
|
-
def pattern.=~ _; true end
|
1797
|
-
def pattern.inspect; "[Object]" end
|
1798
|
-
|
1799
|
-
assert_triggered "Expected [Object] to not match 5." do
|
1800
|
-
@tc.refute_match pattern, 5
|
1801
|
-
end
|
1802
|
-
end
|
1803
|
-
|
1804
|
-
def test_refute_match_triggered
|
1805
|
-
@assertion_count = 2
|
1806
|
-
assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do
|
1807
|
-
@tc.refute_match(/\w+/, "blah blah blah")
|
1808
|
-
end
|
1809
|
-
end
|
1810
|
-
|
1811
|
-
def test_refute_nil
|
1812
|
-
@tc.refute_nil 42
|
1813
|
-
end
|
1814
|
-
|
1815
|
-
def test_refute_nil_triggered
|
1816
|
-
assert_triggered "Expected nil to not be nil." do
|
1817
|
-
@tc.refute_nil nil
|
1818
|
-
end
|
1819
|
-
end
|
1820
|
-
|
1821
|
-
def test_refute_predicate
|
1822
|
-
@tc.refute_predicate "42", :empty?
|
1823
|
-
end
|
1824
|
-
|
1825
|
-
def test_refute_predicate_triggered
|
1826
|
-
assert_triggered 'Expected "" to not be empty?.' do
|
1827
|
-
@tc.refute_predicate "", :empty?
|
1828
|
-
end
|
1829
|
-
end
|
1830
|
-
|
1831
|
-
def test_refute_operator
|
1832
|
-
@tc.refute_operator 2, :<, 1
|
1833
|
-
end
|
1834
|
-
|
1835
|
-
def test_refute_operator_bad_object
|
1836
|
-
bad = Object.new
|
1837
|
-
def bad.== _; true end
|
1838
|
-
|
1839
|
-
@tc.refute_operator true, :equal?, bad
|
1840
|
-
end
|
1841
|
-
|
1842
|
-
def test_refute_operator_triggered
|
1843
|
-
assert_triggered "Expected 2 to not be > 1." do
|
1844
|
-
@tc.refute_operator 2, :>, 1
|
1845
|
-
end
|
1846
|
-
end
|
1847
|
-
|
1848
|
-
def test_refute_respond_to
|
1849
|
-
@tc.refute_respond_to "blah", :rawr!
|
1850
|
-
end
|
1851
|
-
|
1852
|
-
def test_refute_respond_to_triggered
|
1853
|
-
assert_triggered 'Expected "blah" to not respond to empty?.' do
|
1854
|
-
@tc.refute_respond_to "blah", :empty?
|
1855
|
-
end
|
1856
|
-
end
|
1857
|
-
|
1858
|
-
def test_refute_same
|
1859
|
-
@tc.refute_same 1, 2
|
1860
|
-
end
|
1861
|
-
|
1862
|
-
def test_refute_same_triggered
|
1863
|
-
assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
|
1864
|
-
@tc.refute_same 1, 1
|
1865
|
-
end
|
1866
|
-
end
|
1867
|
-
|
1868
|
-
def test_skip
|
1869
|
-
@assertion_count = 0
|
1870
|
-
|
1871
|
-
assert_triggered "haha!", Minitest::Skip do
|
1872
|
-
@tc.skip "haha!"
|
1873
|
-
end
|
876
|
+
end.runnable_methods
|
1874
877
|
end
|
1875
878
|
|
879
|
+
# srand varies with OS
|
1876
880
|
def test_runnable_methods_random
|
1877
881
|
@assertion_count = 0
|
1878
882
|
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
def test_test2; assert "does not matter" end
|
1883
|
-
def test_test3; assert "does not matter" end
|
1884
|
-
end
|
883
|
+
random_tests_1 = sample_test_case 42
|
884
|
+
random_tests_2 = sample_test_case 42
|
885
|
+
random_tests_3 = sample_test_case 1_000
|
1885
886
|
|
1886
|
-
|
1887
|
-
|
1888
|
-
when maglev? then
|
1889
|
-
%w[test_test2 test_test3 test_test1]
|
1890
|
-
else
|
1891
|
-
%w[test_test2 test_test1 test_test3]
|
1892
|
-
end
|
1893
|
-
assert_equal expected, sample_test_case.runnable_methods
|
887
|
+
assert_equal random_tests_1, random_tests_2
|
888
|
+
refute_equal random_tests_1, random_tests_3
|
1894
889
|
end
|
1895
890
|
|
1896
891
|
def test_runnable_methods_sorted
|
@@ -1929,32 +924,18 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
1929
924
|
end
|
1930
925
|
end
|
1931
926
|
|
1932
|
-
def
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
|
1938
|
-
msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
|
1939
|
-
msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
|
1940
|
-
|
1941
|
-
assert_msg = Regexp === expected ? :assert_match : :assert_equal
|
1942
|
-
self.send assert_msg, expected, msg
|
1943
|
-
end
|
1944
|
-
|
1945
|
-
def util_msg exp, act, msg = nil
|
1946
|
-
s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}"
|
1947
|
-
s = "#{msg}.\n#{s}" if msg
|
1948
|
-
s
|
927
|
+
def test_autorun_does_not_affect_fork_success_status
|
928
|
+
@assertion_count = 0
|
929
|
+
skip "windows doesn't have skip" unless Process.respond_to?(:fork)
|
930
|
+
Process.waitpid(fork {})
|
931
|
+
assert_equal true, $?.success?
|
1949
932
|
end
|
1950
933
|
|
1951
|
-
def
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
ensure
|
1957
|
-
Minitest::Assertions.diff = old_diff
|
934
|
+
def test_autorun_does_not_affect_fork_exit_status
|
935
|
+
@assertion_count = 0
|
936
|
+
skip "windows doesn't have skip" unless Process.respond_to?(:fork)
|
937
|
+
Process.waitpid(fork { exit 42 })
|
938
|
+
assert_equal 42, $?.exitstatus
|
1958
939
|
end
|
1959
940
|
end
|
1960
941
|
|
@@ -1972,8 +953,26 @@ class TestMinitestGuard < Minitest::Test
|
|
1972
953
|
end
|
1973
954
|
|
1974
955
|
def test_rubinius_eh
|
1975
|
-
|
1976
|
-
|
956
|
+
assert_output "", /DEPRECATED/ do
|
957
|
+
assert self.class.rubinius? "rbx"
|
958
|
+
end
|
959
|
+
assert_output "", /DEPRECATED/ do
|
960
|
+
assert self.rubinius? "rbx"
|
961
|
+
end
|
962
|
+
end
|
963
|
+
|
964
|
+
def test_maglev_eh
|
965
|
+
assert_output "", /DEPRECATED/ do
|
966
|
+
assert self.class.maglev? "maglev"
|
967
|
+
end
|
968
|
+
assert_output "", /DEPRECATED/ do
|
969
|
+
assert self.maglev? "maglev"
|
970
|
+
end
|
971
|
+
end
|
972
|
+
|
973
|
+
def test_osx_eh
|
974
|
+
assert self.class.osx? "darwin"
|
975
|
+
assert self.osx? "darwin"
|
1977
976
|
end
|
1978
977
|
|
1979
978
|
def test_windows_eh
|
@@ -2087,12 +1086,12 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
2087
1086
|
|
2088
1087
|
exp = clean "
|
2089
1088
|
Error:
|
2090
|
-
|
1089
|
+
FakeNamedTestXX#test_method:
|
2091
1090
|
AnError: AnError
|
2092
1091
|
FILE:LINE:in `test_method'
|
2093
1092
|
|
2094
1093
|
Error:
|
2095
|
-
|
1094
|
+
FakeNamedTestXX#test_method:
|
2096
1095
|
RuntimeError: unhandled exception
|
2097
1096
|
FILE:LINE:in `teardown'
|
2098
1097
|
"
|