test-unit 3.3.8 → 3.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6224bf9af9a66e5759319b2b4f9fdb650f970ad4010c4f1b92cf85410df307e8
4
- data.tar.gz: d22117bf9f061839dea08df766256c7982e13d7eb1d6428c2fedff9583cd5b45
3
+ metadata.gz: '096e65b8d56779e795090f5e56e10a10bcef4f666f45702da71acb1e0e0e769e'
4
+ data.tar.gz: 31402966d552fe2c7cd960185929963e7358296e9ff5727be4c7a72781d070b7
5
5
  SHA512:
6
- metadata.gz: dfd3a287fa4496d89b11e0dc7e1d9488156ecf0158611421df03f49da3cb3130aab76ca0ecab631a00261f7766a77cde596786380b0236039dcbe0209bb29603
7
- data.tar.gz: 217463364d02fc2b93e1f689ba269345d4300519781ef6f9cf3dc3f8d8b0263d70e3065c69651398e1aec18e1b5c40e7f78e693e0eb2586e002523ba7ec43d1e
6
+ metadata.gz: e46ad14d93dadac17224d10ab58617acc4dfaae61f06067c400308d9c1b3ad060201e88a7fd097d94d93c053a1d5bed0a9f56e765bb573fe960c7086251a891c
7
+ data.tar.gz: cfa5f1b593e993ff2643cab4989428817fdae1258a357797b2e42d0d563022351349eb3648056305df8ddb6f5e9847a1084646f2edec93b7a1c519bba96c9d11
data/doc/text/news.md CHANGED
@@ -1,5 +1,52 @@
1
1
  # News
2
2
 
3
+ ## 3.4.3 - 2021-06-04 {#version-3-4-3}
4
+
5
+ ### Improvements
6
+
7
+ * Stopped to change result value of `Test::Unit::TestCase#include`.
8
+
9
+ * Added `assert_all?`.
10
+
11
+ * Added support for `assert_raise_with_message`.
12
+
13
+ ## 3.4.2 - 2021-05-30 {#version-3-4-2}
14
+
15
+ ### Improvements
16
+
17
+ * [UI][console]: Improved diff readability for no color
18
+ case. Character based diff marks are always showed.
19
+
20
+ ## 3.4.1 - 2021-04-19 {#version-3-4-1}
21
+
22
+ ### Fixes
23
+
24
+ * Fixed a bug that `setup`/`cleanup`/`teardown` with block may be
25
+ overwritten by another `setup`/`cleanup`/`teardown` with
26
+ block. It's caused only with Ruby 2.6 or earlier.
27
+ [GitHub#179][Reported by akira yamada]
28
+
29
+ ### Thanks
30
+
31
+ * akira yamada
32
+
33
+ ## 3.4.0 - 2021-01-30 {#version-3-4-0}
34
+
35
+ ### Improvements
36
+
37
+ * Enable deprecated warnings by default.
38
+
39
+ ## 3.3.9 - 2020-12-29 {#version-3-3-9}
40
+
41
+ ### Improvements
42
+
43
+ * `assert_not_match`: Add support for `String` as pattern.
44
+ [GitHub#178][Patch by David Rodríguez]
45
+
46
+ ### Thanks
47
+
48
+ * David Rodríguez
49
+
3
50
  ## 3.3.8 - 2020-12-25 {#version-3-3-8}
4
51
 
5
52
  ### Improvements
data/lib/test-unit.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # Copyright (C) 2012-2015 Kouhei Sutou <kou@clear-code.com>
2
2
 
3
+ require "test/unit/warning"
4
+
3
5
  module Test
4
6
  module Unit
5
7
  autoload :TestCase, "test/unit/testcase"
data/lib/test/unit.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "test/unit/warning"
2
+
1
3
  require 'test/unit/testcase'
2
4
  require 'test/unit/autorunner'
3
5
 
@@ -289,6 +289,71 @@ EOT
289
289
  # Just for minitest compatibility. :<
290
290
  alias_method :assert_raises, :assert_raise
291
291
 
292
+ # Passes if the block raises `expected_exception` with
293
+ # `expected_message`. `expected_message` can be a `String` or
294
+ # `Regexp`.
295
+ #
296
+ # @example Pass pattern: String
297
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
298
+ # raise "Boom!!!"
299
+ # end # -> pass
300
+ #
301
+ # @example Pass pattern: Regexp
302
+ # assert_raise_with_message(RuntimeError, /!!!/) do
303
+ # raise "Boom!!!"
304
+ # end # -> pass
305
+ #
306
+ # @example Failure pattern: Exception class isn't matched
307
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
308
+ # raise ArgumentError, "Boom!!!"
309
+ # end # -> failure
310
+ #
311
+ # @example Failure pattern: Exception message isn't matched
312
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
313
+ # raise "Hello"
314
+ # end # -> failure
315
+ #
316
+ # @since 3.4.3
317
+ def assert_raise_with_message(expected_exception_class,
318
+ expected_message,
319
+ message=nil,
320
+ &block)
321
+ assert_expected_exception = Proc.new do |*_args|
322
+ _message, assert_exception_helper, actual_exception = _args
323
+ diff = AssertionMessage.delayed_diff([
324
+ expected_exception_class,
325
+ expected_message,
326
+ ],
327
+ [
328
+ actual_exception.class,
329
+ actual_exception.message,
330
+ ])
331
+ full_message = build_message(message,
332
+ "<?>(<?>) exception expected but was\n" +
333
+ "<?>(<?>).?",
334
+ expected_exception_class,
335
+ expected_message,
336
+ actual_exception.class,
337
+ actual_exception.message,
338
+ diff)
339
+ begin
340
+ assert_block(full_message) do
341
+ assert_exception_helper.expected?(actual_exception) and
342
+ expected_message === actual_exception.message
343
+ end
344
+ rescue AssertionFailedError => failure
345
+ _set_failed_information(failure,
346
+ expected_exception_class,
347
+ actual_exception)
348
+ raise failure # For JRuby. :<
349
+ end
350
+ actual_exception
351
+ end
352
+ args = [expected_exception_class]
353
+ args << message if message
354
+ _assert_raise(assert_expected_exception, *args, &block)
355
+ end
356
+
292
357
  ##
293
358
  # Passes if the block raises one of the given
294
359
  # exceptions or sub exceptions of the given exceptions.
@@ -534,12 +599,7 @@ EOT
534
599
  # assert_match(/\d+/, 'five, 6, seven')
535
600
  def assert_match(pattern, string, message=nil)
536
601
  _wrap_assertion do
537
- pattern = case(pattern)
538
- when String
539
- Regexp.new(Regexp.escape(pattern))
540
- else
541
- pattern
542
- end
602
+ pattern = Regexp.new(Regexp.escape(pattern)) if pattern.is_a?(String)
543
603
  full_message = build_message(message,
544
604
  "<?> was expected to be =~\n<?>.",
545
605
  pattern, string)
@@ -711,15 +771,13 @@ EOT
711
771
  # @example
712
772
  # assert_not_match(/two/, 'one 2 three') # -> pass
713
773
  # assert_not_match(/three/, 'one 2 three') # -> fail
714
- def assert_not_match(regexp, string, message=nil)
774
+ def assert_not_match(pattern, string, message=nil)
715
775
  _wrap_assertion do
716
- assert_instance_of(Regexp, regexp,
717
- "<REGEXP> in assert_not_match(<REGEXP>, ...) " +
718
- "should be a Regexp.")
776
+ pattern = Regexp.new(Regexp.escape(pattern)) if pattern.is_a?(String)
719
777
  full_message = build_message(message,
720
778
  "<?> was expected to not match\n<?>.",
721
- regexp, string)
722
- assert_block(full_message) { regexp !~ string }
779
+ pattern, string)
780
+ assert_block(full_message) { pattern !~ string }
723
781
  end
724
782
  end
725
783
 
@@ -1619,6 +1677,53 @@ EOT
1619
1677
  # @since 3.0.0
1620
1678
  alias_method :refute_empty, :assert_not_empty
1621
1679
 
1680
+ # @overload assert_all?(collection, message=nil, &block)
1681
+ #
1682
+ # Asserts that all `block.call(item)` where `item` is each
1683
+ # item in `collection` are not false nor nil.
1684
+ #
1685
+ # If `collection` is empty, this assertion is always passed
1686
+ # with any `block`.
1687
+ #
1688
+ # @example Pass patterns
1689
+ # assert_all?([1, 2, 3]) {|item| item > 0} # => pass
1690
+ # assert_all?([1, 2, 3], &:positive?) # => pass
1691
+ # assert_all?([]) {|item| false} # => pass
1692
+ #
1693
+ # @example Failure pattern
1694
+ # assert_all?([0, 1, 2], &:zero?) # => failure
1695
+ #
1696
+ # @param [#each] collection The check target.
1697
+ # @param [String] message The additional user message. It is
1698
+ # showed when the assertion is failed.
1699
+ # @yield [Object] Give each item in `collection` to the block.
1700
+ # @yieldreturn [Object] The checked object.
1701
+ # @return [void]
1702
+ #
1703
+ # @since 3.4.3
1704
+ def assert_all?(collection, message=nil)
1705
+ _wrap_assertion do
1706
+ failed = false
1707
+ result = {}
1708
+ collection.each do |item|
1709
+ element_result = yield(item)
1710
+ failed = true unless element_result
1711
+ result[item] = element_result
1712
+ end
1713
+ format = <<-FORMAT
1714
+ <?> was expected to be all true values with the given block but was
1715
+ <?>
1716
+ FORMAT
1717
+ full_message = build_message(message,
1718
+ format,
1719
+ collection,
1720
+ result)
1721
+ assert_block(full_message) do
1722
+ not failed
1723
+ end
1724
+ end
1725
+ end
1726
+
1622
1727
  ##
1623
1728
  # Builds a failure message. `user_message` is added before the
1624
1729
  # `template` and `arguments` replaces the '?'s positionally in
@@ -103,6 +103,7 @@ module Test
103
103
  @test_case = test_case
104
104
  @type = type
105
105
  @default_options = default_options
106
+ @callbacks = {}
106
107
  @before_prepend_callbacks = []
107
108
  @before_append_callbacks = []
108
109
  @after_prepend_callbacks = []
@@ -130,6 +131,11 @@ module Test
130
131
  @test_case.attribute(:source_location,
131
132
  callback.source_location,
132
133
  method_name)
134
+ # For Ruby 2.6 or earlier. callback may be GC-ed. If
135
+ # callback is GC-ed, callback_method_name may be
136
+ # duplicated because callback_method_name uses callback.object_id.
137
+ # See also: https://github.com/test-unit/test-unit/issues/179
138
+ @callbacks[callback] = true
133
139
  @test_case.__send__(:define_method, method_name, &callback)
134
140
  else
135
141
  method_name = method_name_or_callback
@@ -131,12 +131,13 @@ module Test
131
131
  end
132
132
 
133
133
  def include(*modules, &block) # :nodoc:
134
- super
134
+ result = super
135
135
  modules.each do |mod|
136
136
  mod.public_instance_methods(false).each do |method_name|
137
137
  AutoRunnerLoader.check(self, method_name.to_s)
138
138
  end
139
139
  end
140
+ result
140
141
  end
141
142
 
142
143
  @@added_method_names = {}
@@ -660,6 +660,7 @@ module Test
660
660
 
661
661
  def diff_line(from_line, to_line)
662
662
  to_operations = []
663
+ mark_operations = []
663
664
  from_line, to_line, _operations = line_operations(from_line, to_line)
664
665
 
665
666
  no_replace = true
@@ -689,11 +690,22 @@ module Test
689
690
  output_single(" " * (from_width - to_width))
690
691
  end
691
692
  end
693
+ mark_operations << Proc.new do
694
+ output_single("?" * from_width,
695
+ color("diff-difference-tag"))
696
+ if (to_width < from_width)
697
+ output_single(" " * (from_width - to_width))
698
+ end
699
+ end
692
700
  when :delete
693
701
  output_single(from_line[from_start...from_end],
694
702
  color("diff-deleted"))
695
703
  unless no_replace
696
704
  to_operations << Proc.new {output_single(" " * from_width)}
705
+ mark_operations << Proc.new do
706
+ output_single("-" * from_width,
707
+ color("diff-deleted"))
708
+ end
697
709
  end
698
710
  when :insert
699
711
  if no_replace
@@ -705,11 +717,16 @@ module Test
705
717
  output_single(to_line[to_start...to_end],
706
718
  color("diff-inserted"))
707
719
  end
720
+ mark_operations << Proc.new do
721
+ output_single("+" * to_width,
722
+ color("diff-inserted"))
723
+ end
708
724
  end
709
725
  when :equal
710
726
  output_single(from_line[from_start...from_end])
711
727
  unless no_replace
712
728
  to_operations << Proc.new {output_single(" " * to_width)}
729
+ mark_operations << Proc.new {output_single(" " * to_width)}
713
730
  end
714
731
  else
715
732
  raise "unknown tag: #{tag}"
@@ -725,6 +742,15 @@ module Test
725
742
  end
726
743
  output("")
727
744
  end
745
+
746
+ unless mark_operations.empty?
747
+ output_single("?", color("diff-difference-tag"))
748
+ output_single(" ")
749
+ mark_operations.each do |operation|
750
+ operation.call
751
+ end
752
+ output("")
753
+ end
728
754
  end
729
755
  end
730
756
  end
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = "3.3.8"
3
+ VERSION = "3.4.3"
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ if defined?(Warning) and Warning.respond_to?(:[]=)
2
+ Warning[:deprecated] = true
3
+ end
@@ -98,7 +98,8 @@ module Test
98
98
 
99
99
  def check_fail_exception(expected_message, options={}, &proc)
100
100
  normalizer = lambda do |actual_message|
101
- actual_message.gsub(/^(?:<internal:core> )?[^:\n]+:\d+:.+\n/, "")
101
+ actual_message.gsub(/^(?:[a-zA-Z]:|<internal:core> )?[^:\n]+:\d+:.+\n/,
102
+ "")
102
103
  end
103
104
  check_assertions(true,
104
105
  options.merge(:expected_message => expected_message,
@@ -956,16 +957,6 @@ EOM
956
957
  end
957
958
  end
958
959
 
959
- def test_assert_not_match_fail_not_regexp
960
- check_fail("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
961
- "should be a Regexp.\n" +
962
- "<\"asdf\"> was expected to be instance_of?\n" +
963
- "<Regexp> but was\n" +
964
- "<String>.") do
965
- assert_not_match("asdf", "asdf")
966
- end
967
- end
968
-
969
960
  def test_assert_not_match_fail_match
970
961
  check_fail("</string/> was expected to not match\n" +
971
962
  "<\"string\">.") do
@@ -973,6 +964,13 @@ EOM
973
964
  end
974
965
  end
975
966
 
967
+ def test_assert_not_match_fail_match_string
968
+ check_fail("</asdf/> was expected to not match\n" +
969
+ "<\"asdf\">.") do
970
+ assert_not_match("asdf", "asdf")
971
+ end
972
+ end
973
+
976
974
  def test_assert_not_match_fail_match_with_message
977
975
  check_fail("message.\n" +
978
976
  "</string/> was expected to not match\n" +
@@ -1609,6 +1607,66 @@ MESSAGE
1609
1607
  end
1610
1608
  end
1611
1609
 
1610
+ class TestAssertRaiseWithMessage < Test::Unit::TestCase
1611
+ include AssertionCheckable
1612
+
1613
+ def test_pass_string
1614
+ check_nothing_fails(true) do
1615
+ assert_raise_with_message(RuntimeError, "Boom!!!") do
1616
+ raise "Boom!!!"
1617
+ end
1618
+ end
1619
+ end
1620
+
1621
+ def test_pass_regexp
1622
+ check_nothing_fails(true) do
1623
+ assert_raise_with_message(RuntimeError, /!!!/) do
1624
+ raise "Boom!!!"
1625
+ end
1626
+ end
1627
+ end
1628
+
1629
+ def test_pass_message
1630
+ check_nothing_fails(true) do
1631
+ assert_raise_with_message(RuntimeError, "Boom!!!", "message") do
1632
+ raise "Boom!!!"
1633
+ end
1634
+ end
1635
+ end
1636
+
1637
+ def test_fail_unmatch_class
1638
+ expected_message = <<-MESSAGE.chomp
1639
+ message.
1640
+ <LoadError>(<"Boom!!!">) exception expected but was
1641
+ <RuntimeError>(<"Boom!!!">).
1642
+
1643
+ diff:
1644
+ - [LoadError, "Boom!!!"]
1645
+ ? ^^^^
1646
+ + [RuntimeError, "Boom!!!"]
1647
+ ? ^^^^^^^
1648
+ MESSAGE
1649
+ check_fail(expected_message) do
1650
+ assert_raise_with_message(LoadError, "Boom!!!", "message") do
1651
+ raise "Boom!!!"
1652
+ end
1653
+ end
1654
+ end
1655
+
1656
+ def test_fail_unmatch_message
1657
+ expected_message = <<-MESSAGE.chomp
1658
+ message.
1659
+ <RuntimeError>(</Hello/>) exception expected but was
1660
+ <RuntimeError>(<"Boom!!!">).
1661
+ MESSAGE
1662
+ check_fail(expected_message) do
1663
+ assert_raise_with_message(RuntimeError, /Hello/, "message") do
1664
+ raise "Boom!!!"
1665
+ end
1666
+ end
1667
+ end
1668
+ end
1669
+
1612
1670
  class TestAssertInDelta < TestCase
1613
1671
  include AssertionCheckable
1614
1672
 
@@ -2172,6 +2230,39 @@ EOM
2172
2230
  end
2173
2231
  end
2174
2232
 
2233
+ class TestAssertAll < Test::Unit::TestCase
2234
+ include AssertionCheckable
2235
+
2236
+ def test_pass
2237
+ check_nothing_fails do
2238
+ assert_all?([1, 2]) {|item| item > 0}
2239
+ end
2240
+ end
2241
+
2242
+ def test_pass_message
2243
+ check_nothing_fails do
2244
+ assert_all?([1, 2], "positive") {|item| item > 0}
2245
+ end
2246
+ end
2247
+
2248
+ def test_pass_empty
2249
+ check_nothing_fails do
2250
+ assert_all?([]) {|item| false}
2251
+ end
2252
+ end
2253
+
2254
+ def test_fail
2255
+ expected_message = <<-EOM
2256
+ message.
2257
+ <[0, 1]> was expected to be all true values with the given block but was
2258
+ <{0=>true, 1=>false}>
2259
+ EOM
2260
+ check_fail(expected_message.chomp) do
2261
+ assert_all?([0, 1], "message", &:zero?)
2262
+ end
2263
+ end
2264
+ end
2265
+
2175
2266
  class TestTemplate < Test::Unit::TestCase
2176
2267
  def test_incompatible_encoding_by_diff
2177
2268
  need_encoding
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.8
4
+ version: 3.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-24 00:00:00.000000000 Z
12
+ date: 2021-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: power_assert
@@ -164,6 +164,7 @@ files:
164
164
  - lib/test/unit/util/output.rb
165
165
  - lib/test/unit/util/procwrapper.rb
166
166
  - lib/test/unit/version.rb
167
+ - lib/test/unit/warning.rb
167
168
  - sample/adder.rb
168
169
  - sample/subtracter.rb
169
170
  - sample/test_adder.rb
@@ -231,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
232
  - !ruby/object:Gem::Version
232
233
  version: '0'
233
234
  requirements: []
234
- rubygems_version: 3.2.0.rc.2
235
+ rubygems_version: 3.3.0.dev
235
236
  signing_key:
236
237
  specification_version: 4
237
238
  summary: An xUnit family unit testing framework for Ruby.