test-unit 3.3.9 → 3.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f80bfdc786244d9be9030d614a8d5cefa4660c71e1d5f6e2697494ea5d351af9
4
- data.tar.gz: abfb9b96433fc2a35f0c886069f9ffaee3428fe04a5c8b1e8ba0d726169ec320
3
+ metadata.gz: 4bf06d094c228d2826f3ffd368b7587dad9844cb59429790157c1d00f963e527
4
+ data.tar.gz: d5d07e063a929674b11047dee03b185fdf73f926e48aa8830f2f2fa7d4c88b58
5
5
  SHA512:
6
- metadata.gz: 6f67a38fd41415415fa5d1d1d764208f9271d4073b657a1e7269a574a23dcb3696d1887c95a73f525000c9aa544bc7627fa36218a63d32957028f0e19fafe349
7
- data.tar.gz: 7efafbed54a11458d00d974b120a6be1bb73a8c773877814460329972f19ef6f45ed97817a4291517fe698d03af099218530d4b445539b4810130f58f8c909dc
6
+ metadata.gz: 63d7fa4261919b37f31bd412335cc086778622f4ff63e6f645baf7c8440493e3dc2be0206bff51f5a24bb0f5f90122a61db5cbe31b2499360045092069164605
7
+ data.tar.gz: 50238b29eda4de9e4ece1c64fe3cd9a583ceeb7cb965c4e6660d39017ded8a27579723dfe206f434ff0bbd71dba9085e4af987d83d6bf76cf3ef16a475f31e4b
data/doc/text/news.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # News
2
2
 
3
+ ## 3.4.4 - 2021-06-04 {#version-3-4-4}
4
+
5
+ ### Improvements
6
+
7
+ * Rename `assert_all?` to `assert_all`. `assert_all?` is deprecated
8
+ but is available.
9
+
10
+ ## 3.4.3 - 2021-06-04 {#version-3-4-3}
11
+
12
+ ### Improvements
13
+
14
+ * Stopped to change result value of `Test::Unit::TestCase#include`.
15
+
16
+ * Added `assert_all?`.
17
+
18
+ * Added support for `assert_raise_with_message`.
19
+
20
+ ## 3.4.2 - 2021-05-30 {#version-3-4-2}
21
+
22
+ ### Improvements
23
+
24
+ * [UI][console]: Improved diff readability for no color
25
+ case. Character based diff marks are always showed.
26
+
27
+ ## 3.4.1 - 2021-04-19 {#version-3-4-1}
28
+
29
+ ### Fixes
30
+
31
+ * Fixed a bug that `setup`/`cleanup`/`teardown` with block may be
32
+ overwritten by another `setup`/`cleanup`/`teardown` with
33
+ block. It's caused only with Ruby 2.6 or earlier.
34
+ [GitHub#179][Reported by akira yamada]
35
+
36
+ ### Thanks
37
+
38
+ * akira yamada
39
+
40
+ ## 3.4.0 - 2021-01-30 {#version-3-4-0}
41
+
42
+ ### Improvements
43
+
44
+ * Enable deprecated warnings by default.
45
+
3
46
  ## 3.3.9 - 2020-12-29 {#version-3-3-9}
4
47
 
5
48
  ### 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.
@@ -1612,6 +1677,58 @@ EOT
1612
1677
  # @since 3.0.0
1613
1678
  alias_method :refute_empty, :assert_not_empty
1614
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.4
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
+
1727
+ # Just for Ruby's tool/lib/test/unit compatibility.
1728
+ #
1729
+ # @since 3.4.3
1730
+ alias_method :assert_all?, :assert_all
1731
+
1615
1732
  ##
1616
1733
  # Builds a failure message. `user_message` is added before the
1617
1734
  # `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.9"
3
+ VERSION = "3.4.4"
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,
@@ -1606,6 +1607,66 @@ MESSAGE
1606
1607
  end
1607
1608
  end
1608
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
+
1609
1670
  class TestAssertInDelta < TestCase
1610
1671
  include AssertionCheckable
1611
1672
 
@@ -2169,6 +2230,39 @@ EOM
2169
2230
  end
2170
2231
  end
2171
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
+
2172
2266
  class TestTemplate < Test::Unit::TestCase
2173
2267
  def test_incompatible_encoding_by_diff
2174
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.9
4
+ version: 3.4.4
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-28 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.3
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.