test-unit 3.2.8 → 3.2.9

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: 2a4feb161fab1f115df6c63a92032e2d96ac85e0a341842b83b91247cf51248d
4
- data.tar.gz: 5a51478bd366026b371bc203176a59c20c94692b15f44a50316311a14db2963b
3
+ metadata.gz: eebbbc103686122dad1c46de5d2cf1b481c072594dcaf0ec7e2b8b3b06f40845
4
+ data.tar.gz: be70b1db775b562d54aa4e24fec9fbc607f13604850dde5064232163dc6c2992
5
5
  SHA512:
6
- metadata.gz: 10db186432bc8f15f3c44eef4cfeead4a6621eec2cfdd74e43a2ca3b1de23002b51ca74c8eac6d666f3abc6c3d31a64b825f62ded1481eb6034179784f34846b
7
- data.tar.gz: '05079d4f328d0bad66c7473b0a4fe595a9b1a9d3a27e9b0a44e3ec121f67ad33a92ca22ba2ccb2a7a142f24c5160bf4d1fbed1f13b2dd74a5062660e8969cb93'
6
+ metadata.gz: f55eac7e767c89b5434d6ff8f19824a2509d0e6d25e48d2494df30dd9178b7e231063c95ba3399806e0e0bd98b0de947f2b35522a1e2867246eca7420e3e5aec
7
+ data.tar.gz: bd1e47fbd0ddb58908b9b95df05d95960ccf90aa7b89a4ff93ec5de979f01af75b3662dd746be20e6bc9dc2ef1780aa77448a769124dd305109fbb2020ee0df5
@@ -1,5 +1,76 @@
1
1
  # News
2
2
 
3
+ ## 3.2.9 - 2018-12-01 {#version-3-2-9}
4
+
5
+ ### Improvements
6
+
7
+ * Added support for data generation by method. `data_#{test_name}`
8
+ is called to generate data for `test_name` test.
9
+
10
+ * Added support for data matrix generation.
11
+
12
+ Example:
13
+
14
+ ```ruby
15
+ data(:a, [0, 1, 2])
16
+ data(:b, [:x, :y])
17
+ def test_data(data)
18
+ end
19
+ ```
20
+
21
+ This example generates the following data matrix:
22
+
23
+ * label: `"a: 0, b: :x"`, data: `{a: 0, b: :x}`
24
+ * label: `"a: 0, b: :y"`, data: `{a: 0, b: :y}`
25
+ * label: `"a: 1, b: :x"`, data: `{a: 1, b: :x}`
26
+ * label: `"a: 1, b: :y"`, data: `{a: 1, b: :y}`
27
+ * label: `"a: 2, b: :x"`, data: `{a: 2, b: :x}`
28
+ * label: `"a: 2, b: :y"`, data: `{a: 2, b: :y}`
29
+
30
+ * Added `Test::Unit::TestCase#data` that returns the current data.
31
+
32
+ * Added support for using test method that doesn't have no
33
+ parameters as data driven test.
34
+
35
+ Example:
36
+
37
+ ```ruby
38
+ data("label", :value)
39
+ def test_data # Available since this release
40
+ p data # :value
41
+ end
42
+ ```
43
+
44
+ * Added support for `:keep` option to `Test::Unit::TestCase.data`.
45
+
46
+ * Added support for `:group` option to
47
+ `Test::Unit::TestCase.data`. It's useful to generate multiple data
48
+ matrix groups.
49
+
50
+ ```ruby
51
+ # Group1
52
+ data(:a, [0, 1, 2], group: :g1)
53
+ data(:b, [:x, :y], group: :g1)
54
+ # Group2
55
+ data(:a, [:x, :y], group: :g2)
56
+ data(:c, [-1, -2], group: :g2)
57
+ def test_data(data)
58
+ end
59
+ ```
60
+
61
+ This example generates the following data matrix:
62
+
63
+ * label: `"group: :g1, a: 0, b: :x"`, data: `{a: 0, b: :x}`
64
+ * label: `"group: :g1, a: 0, b: :y"`, data: `{a: 0, b: :y}`
65
+ * label: `"group: :g1, a: 1, b: :x"`, data: `{a: 1, b: :x}`
66
+ * label: `"group: :g1, a: 1, b: :y"`, data: `{a: 1, b: :y}`
67
+ * label: `"group: :g1, a: 2, b: :x"`, data: `{a: 2, b: :x}`
68
+ * label: `"group: :g1, a: 2, b: :y"`, data: `{a: 2, b: :y}`
69
+ * label: `"group: :g2, a: :x, b: -1"`, data: `{a: :x, b: -1}`
70
+ * label: `"group: :g2, a: :x, b: -2"`, data: `{a: :x, b: -2}`
71
+ * label: `"group: :g2, a: :y, b: -1"`, data: `{a: :y, b: -1}`
72
+ * label: `"group: :g2, a: :y, b: -2"`, data: `{a: :y, b: -2}`
73
+
3
74
  ## 3.2.8 - 2018-05-13 {#version-3-2-8}
4
75
 
5
76
  ### Improvements
@@ -43,7 +43,11 @@ module Test
43
43
  kept_attributes = StringifyKeyHash.new
44
44
  @current_attributes.each do |attribute_name, attribute|
45
45
  attributes[attribute_name] = attribute[:value]
46
- kept_attributes[attribute_name] = attribute if attribute[:keep]
46
+ if attribute[:keep]
47
+ keep_hook = attribute[:keep_hook]
48
+ attribute = keep_hook.call(attribute) if keep_hook
49
+ kept_attributes[attribute_name] = attribute
50
+ end
47
51
  end
48
52
  set_attributes(name, attributes)
49
53
  @current_attributes = kept_attributes
@@ -0,0 +1,116 @@
1
+ module Test
2
+ module Unit
3
+ class DataSets
4
+ def initialize
5
+ @variables = []
6
+ @procs = []
7
+ @value_sets = []
8
+ end
9
+
10
+ def add(data_set, options=nil)
11
+ options ||= {}
12
+ if data_set.respond_to?(:call)
13
+ @procs << [data_set, options]
14
+ elsif data_set.is_a?(Array)
15
+ @variables << [data_set, options]
16
+ else
17
+ @value_sets << [data_set, options]
18
+ end
19
+ end
20
+
21
+ def <<(data_set)
22
+ add(data_set)
23
+ end
24
+
25
+ def keep
26
+ new_data_sets = self.class.new
27
+ all_data_sets = Enumerator.new do |yielder|
28
+ block = lambda do |(data_set, options)|
29
+ yielder << [data_set, options]
30
+ end
31
+ @procs.each(&block)
32
+ @variables.each(&block)
33
+ @value_sets.each(&block)
34
+ end
35
+ all_data_sets.each do |data_set, options|
36
+ next if options.nil?
37
+ next unless options[:keep]
38
+ new_data_sets.add(data_set, options)
39
+ end
40
+ new_data_sets
41
+ end
42
+
43
+ def each
44
+ variables = @variables
45
+ value_sets = @value_sets
46
+ @procs.each do |proc, options|
47
+ data_set = proc.call
48
+ case data_set
49
+ when Array
50
+ variables += [[data_set, options]]
51
+ else
52
+ value_sets += [[data_set, options]]
53
+ end
54
+ end
55
+
56
+ value_sets.each do |values, _options|
57
+ values.each do |label, data|
58
+ yield(label, data)
59
+ end
60
+ end
61
+
62
+ each_pattern(variables) do |label, data|
63
+ yield(label, data)
64
+ end
65
+ end
66
+
67
+ def ==(other)
68
+ @variables == other.instance_variable_get(:@variables) and
69
+ @procs == other.instance_variable_get(:@procs) and
70
+ @value_sets == other.instance_variable_get(:@value_sets)
71
+ end
72
+
73
+ def eql?(other)
74
+ self == other
75
+ end
76
+
77
+ def hash
78
+ [@variables, @procs, @value_sets].hash
79
+ end
80
+
81
+ private
82
+ def each_pattern(variables)
83
+ grouped_variables = variables.group_by do |_, options|
84
+ options[:group]
85
+ end
86
+ grouped_variables.each do |group, variables|
87
+ each_raw_pattern(variables) do |cell|
88
+ label = String.new
89
+ label << "group: #{group.inspect}" unless group.nil?
90
+ data = {}
91
+ cell.each do |variable, pattern|
92
+ label << ", " unless label.empty?
93
+ label << "#{variable}: #{pattern.inspect}"
94
+ data[variable] = pattern
95
+ end
96
+ yield(label, data)
97
+ end
98
+ end
99
+ end
100
+
101
+ def each_raw_pattern(variables, &block)
102
+ return if variables.empty?
103
+
104
+ sorted_variables = variables.sort_by do |(variable, _), _|
105
+ variable
106
+ end
107
+ all_patterns = sorted_variables.collect do |(variable, patterns), _|
108
+ patterns.collect do |pattern|
109
+ [variable, pattern]
110
+ end
111
+ end
112
+ all_patterns[0].product(*all_patterns[1..-1], &block)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -1,3 +1,5 @@
1
+ require "test/unit/data-sets"
2
+
1
3
  module Test
2
4
  module Unit
3
5
  module Data
@@ -12,9 +14,12 @@ module Test
12
14
  #
13
15
  # Define test data in the test code.
14
16
  #
15
- # @overload data(label, data)
17
+ # @overload data(label, data, options={})
16
18
  # @param [String] label specify test case name.
17
19
  # @param data specify test data.
20
+ # @param [Hash] options specify options.
21
+ # @option options [Boolean] :keep whether or not to use
22
+ # this data in the following test methods
18
23
  #
19
24
  # @example data(label, data)
20
25
  # data("empty string", [true, ""])
@@ -24,9 +29,39 @@ module Test
24
29
  # assert_equal(expected, target.empty?)
25
30
  # end
26
31
  #
27
- # @overload data(data_set)
32
+ # @overload data(variable, patterns, options={})
33
+ # @param [Symbol] variable specify test pattern variable name.
34
+ # @param [Array] patterns specify test patterns for the variable.
35
+ # @param [Hash] options specify options.
36
+ # @option options [Boolean] :keep whether or not to use
37
+ # this data in the following test methods
38
+ # @option options [Object] :group the test pattern group.
39
+ # Test matrix is generated for each test pattern group separately.
40
+ #
41
+ # @example data(variable, patterns)
42
+ # data(:x, [1, 2, 3])
43
+ # data(:y, ["a", "b"])
44
+ # def test_patterns(data)
45
+ # # 3 * 2 times executed
46
+ # # 3: the number of patterns of :x
47
+ # # 2: the number of patterns of :y
48
+ # p data
49
+ # # => {:x => 1, :y => "a"}
50
+ # # => {:x => 1, :y => "b"}
51
+ # # => {:x => 2, :y => "a"}
52
+ # # => {:x => 2, :y => "b"}
53
+ # # => {:x => 3, :y => "a"}
54
+ # # => {:x => 3, :y => "b"}
55
+ # end
56
+ #
57
+ # Generates test matrix from variable and patterns pairs.
58
+ #
59
+ # @overload data(data_set, options={})
28
60
  # @param [Hash] data_set specify test data as a Hash that
29
61
  # key is test label and value is test data.
62
+ # @param [Hash] options specify options.
63
+ # @option options [Boolean] :keep whether or not to use
64
+ # this data in the following test methods
30
65
  #
31
66
  # @example data(data_set)
32
67
  # data("empty string" => [true, ""],
@@ -36,9 +71,12 @@ module Test
36
71
  # assert_equal(expected, target.empty?)
37
72
  # end
38
73
  #
39
- # @overload data(&block)
40
- # @yieldreturn [Hash] return test data set as a Hash that
41
- # key is test label and value is test data.
74
+ # @overload data(options={}, &block)
75
+ # @param [Hash] options specify options.
76
+ # @option options [Boolean] :keep whether or not to use
77
+ # this data in the following test methods
78
+ # @yieldreturn [Hash<String, Object>] return test data set
79
+ # as a Hash that key is test label and value is test data.
42
80
  #
43
81
  # @example data(&block)
44
82
  # data do
@@ -52,22 +90,93 @@ module Test
52
90
  # assert_equal(expected, target.empty?)
53
91
  # end
54
92
  #
93
+ # @overload data(options={}, &block)
94
+ # @param [Hash] options specify options.
95
+ # @option options [Boolean] :keep whether or not to use
96
+ # this data in the following test methods
97
+ # @yieldreturn [Array<Symbol, Array>] return test data set
98
+ # as an Array of variable and patterns.
99
+ #
100
+ # @example data(&block)
101
+ # data do
102
+ # patterns = 3.times.to_a
103
+ # [:x, patterns]
104
+ # end
105
+ # data do
106
+ # patterns = []
107
+ # character = "a"
108
+ # 2.times.each do
109
+ # patterns << character
110
+ # character = character.succ
111
+ # end
112
+ # [:y, patterns]
113
+ # end
114
+ # def test_patterns(data)
115
+ # # 3 * 2 times executed
116
+ # # 3: the number of patterns of :x
117
+ # # 2: the number of patterns of :y
118
+ # p data
119
+ # # => {:x => 0, :y => "a"}
120
+ # # => {:x => 0, :y => "b"}
121
+ # # => {:x => 1, :y => "a"}
122
+ # # => {:x => 1, :y => "b"}
123
+ # # => {:x => 2, :y => "a"}
124
+ # # => {:x => 2, :y => "b"}
125
+ # end
126
+ #
127
+ # Generates test matrix from variable and patterns pairs.
128
+ #
55
129
  def data(*arguments, &block)
130
+ options = nil
56
131
  n_arguments = arguments.size
57
132
  case n_arguments
58
133
  when 0
59
134
  raise ArgumentError, "no block is given" unless block_given?
60
135
  data_set = block
61
136
  when 1
62
- data_set = arguments[0]
137
+ if block_given?
138
+ data_set = block
139
+ options = arguments[1]
140
+ else
141
+ data_set = arguments[0]
142
+ end
63
143
  when 2
64
- data_set = {arguments[0] => arguments[1]}
144
+ case arguments[0]
145
+ when String
146
+ data_set = {arguments[0] => arguments[1]}
147
+ when Hash
148
+ data_set = arguments[0]
149
+ options = arguments[1]
150
+ else
151
+ variable = arguments[0]
152
+ patterns = arguments[1]
153
+ data_set = [variable, patterns]
154
+ end
155
+ when 3
156
+ case arguments[0]
157
+ when String
158
+ data_set = {arguments[0] => arguments[1]}
159
+ options = arguments[2]
160
+ else
161
+ variable = arguments[0]
162
+ patterns = arguments[1]
163
+ data_set = [variable, patterns]
164
+ options = arguments[2]
165
+ end
65
166
  else
66
- message = "wrong number arguments(#{n_arguments} for 1..2)"
167
+ message = "wrong number arguments(#{n_arguments} for 0..3)"
67
168
  raise ArgumentError, message
68
169
  end
69
- current_data = current_attribute(:data)[:value] || []
70
- attribute(:data, current_data + [data_set])
170
+ options ||= {}
171
+ data_sets = current_attribute(:data)[:value] || DataSets.new
172
+ data_sets.add(data_set, options)
173
+ if options[:keep]
174
+ keep_hook = lambda do |attr|
175
+ attr.merge(value: attr[:value].keep)
176
+ end
177
+ options = options.merge(keep_hook: keep_hook)
178
+ end
179
+ attribute(:data, data_sets, options)
71
180
  end
72
181
 
73
182
  # This method provides Data-Driven-Test functionality.
@@ -5,6 +5,8 @@
5
5
  # * Copyright (c) 2011 Kouhei Sutou <tt><kou@clear-code.com></tt>
6
6
  # License:: Ruby license.
7
7
 
8
+ require "test/unit/data-sets"
9
+
8
10
  module Test
9
11
  module Unit
10
12
  class TestSuiteCreator # :nodoc:
@@ -22,15 +24,11 @@ module Test
22
24
  def create
23
25
  suite = TestSuite.new(@test_case.name, @test_case)
24
26
  collect_test_names.each do |test_name|
25
- data_sets = @test_case.find_attribute(test_name, :data,
26
- :recursive => false)
27
+ data_sets = extract_data_sets(test_name)
27
28
  if data_sets
28
- data_sets.each do |data_set|
29
- data_set = data_set.call if data_set.respond_to?(:call)
30
- data_set.each do |label, data|
31
- append_test(suite, test_name) do |test|
32
- test.assign_test_data(label, data)
33
- end
29
+ data_sets.each do |label, data|
30
+ append_test(suite, test_name) do |test|
31
+ test.assign_test_data(label, data)
34
32
  end
35
33
  end
36
34
  else
@@ -42,6 +40,22 @@ module Test
42
40
  end
43
41
 
44
42
  private
43
+ def extract_data_sets(test_name)
44
+ data_sets = @test_case.find_attribute(test_name,
45
+ :data,
46
+ :recursive => false)
47
+ data_method_name = "data_#{test_name}"
48
+ test = @test_case.new(test_name)
49
+ if test.respond_to?(data_method_name)
50
+ data_method = test.method(data_method_name)
51
+ if data_method.arity <= 0
52
+ data_sets ||= DataSets.new
53
+ data_sets << data_method
54
+ end
55
+ end
56
+ data_sets
57
+ end
58
+
45
59
  def append_test(suite, test_name)
46
60
  test = @test_case.new(test_name)
47
61
  yield(test) if block_given?
@@ -678,6 +678,12 @@ module Test
678
678
  @internal_data.test_data_label
679
679
  end
680
680
 
681
+ # Returns test data for the test. If the test isn't associated
682
+ # with any test data, it returns +nil+.
683
+ def data
684
+ @internal_data.test_data
685
+ end
686
+
681
687
  # Returns a human-readable name for the specific test that
682
688
  # this instance of TestCase represents.
683
689
  def name
@@ -779,15 +785,11 @@ module Test
779
785
  end
780
786
  if @internal_data.have_test_data?
781
787
  test_method = method(@method_name)
782
- if test_method.arity == 1 or test_method.arity < 0
783
- __send__(@method_name, @internal_data.test_data)
788
+ arity = test_method.arity
789
+ if arity.zero?
790
+ __send__(@method_name)
784
791
  else
785
- locations = self.class.find_locations(:method_name => @method_name)
786
- backtrace = locations.collect do |location|
787
- "#{location[:path]}:#{location[:line]}"
788
- end
789
- notify("<#{signature}> misses a parameter to take test data",
790
- :backtrace => backtrace)
792
+ __send__(@method_name, @internal_data.test_data)
791
793
  end
792
794
  else
793
795
  __send__(@method_name)
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = "3.2.8"
3
+ VERSION = "3.2.9"
4
4
  end
5
5
  end
@@ -46,7 +46,7 @@ class TestData < Test::Unit::TestCase
46
46
  end
47
47
 
48
48
  class TestDynamicDataSet < TestCalc
49
- data do
49
+ DATA_PROC = lambda do
50
50
  data_set = {}
51
51
  data_set["positive positive"] = {
52
52
  :expected => 3,
@@ -60,7 +60,8 @@ class TestData < Test::Unit::TestCase
60
60
  }
61
61
  data_set
62
62
  end
63
- DATA_PROC = current_attribute(:data)[:value].first
63
+
64
+ data(&DATA_PROC)
64
65
  def test_plus(data)
65
66
  assert_equal(data[:expected],
66
67
  @calc.plus(data[:augend], data[:addend]))
@@ -90,6 +91,48 @@ class TestData < Test::Unit::TestCase
90
91
  end
91
92
  end
92
93
  end
94
+
95
+ class TestMethod < TestCalc
96
+ def data_test_plus
97
+ {
98
+ "positive positive" => {:expected => 4, :augend => 3, :addend => 1},
99
+ "positive negative" => {:expected => -1, :augend => 1, :addend => -2},
100
+ }
101
+ end
102
+
103
+ def test_plus(data)
104
+ assert_equal(data[:expected],
105
+ @calc.plus(data[:augend], data[:addend]))
106
+ end
107
+ end
108
+
109
+ class TestPatterns < TestCalc
110
+ data(:x, [-1, 1, 0])
111
+ data(:y, [-100, 100])
112
+ data(:z, ["a", "b", "c"])
113
+ def test_use_data(data)
114
+ end
115
+ end
116
+
117
+ class TestPatternsKeep < TestCalc
118
+ data(:x, [-1, 1, 0], keep: true)
119
+ data(:y, [-100, 100])
120
+ data(:z, ["a", "b", "c"], keep: true)
121
+ def test_use_data(data)
122
+ end
123
+
124
+ def test_use_data_keep(data)
125
+ end
126
+ end
127
+
128
+ class TestPatternsGroup < TestCalc
129
+ data(:a, [-1, 1, 0], group: 1)
130
+ data(:b, [:a, :b], group: 1)
131
+ data(:x, [2, 9], group: :z)
132
+ data(:y, ["a", "b", "c"], group: :z)
133
+ def test_use_data(data)
134
+ end
135
+ end
93
136
  end
94
137
 
95
138
  def setup
@@ -109,64 +152,90 @@ class TestData < Test::Unit::TestCase
109
152
  data("data set",
110
153
  {
111
154
  :test_case => TestCalc::TestDataSet,
112
- :data_set => [{
113
- "positive positive" => {
114
- :expected => 4,
115
- :augend => 3,
116
- :addend => 1,
117
- },
118
- "positive negative" => {
119
- :expected => -1,
120
- :augend => 1,
121
- :addend => -2,
122
- },
123
- }],
155
+ :data_sets => [
156
+ {
157
+ "positive positive" => {
158
+ :expected => 4,
159
+ :augend => 3,
160
+ :addend => 1,
161
+ },
162
+ "positive negative" => {
163
+ :expected => -1,
164
+ :augend => 1,
165
+ :addend => -2,
166
+ },
167
+ },
168
+ ],
124
169
  })
125
170
  data("n-data",
126
171
  {
127
172
  :test_case => TestCalc::TestNData,
128
- :data_set => [{
129
- "positive positive" => {
130
- :expected => 4,
131
- :augend => 3,
132
- :addend => 1,
133
- },
134
- },
135
- {
136
- "positive negative" => {
137
- :expected => -1,
138
- :augend => 1,
139
- :addend => -2,
140
- },
141
- }],
173
+ :data_sets => [
174
+ {
175
+ "positive positive" => {
176
+ :expected => 4,
177
+ :augend => 3,
178
+ :addend => 1,
179
+ },
180
+ },
181
+ {
182
+ "positive negative" => {
183
+ :expected => -1,
184
+ :augend => 1,
185
+ :addend => -2,
186
+ },
187
+ },
188
+ ],
142
189
  })
143
190
  data("dynamic-data-set",
144
191
  {
145
192
  :test_case => TestCalc::TestDynamicDataSet,
146
- :data_set => [TestCalc::TestDynamicDataSet::DATA_PROC],
193
+ :data_sets => [TestCalc::TestDynamicDataSet::DATA_PROC],
147
194
  })
148
195
  data("load-data-set",
149
196
  {
150
197
  :test_case => TestCalc::TestLoadDataSet,
151
- :data_set => [{
152
- "positive positive" => {
153
- "expected" => 4,
154
- "augend" => 3,
155
- "addend" => 1,
156
- },
157
- },
158
- {
159
- "positive negative" => {
160
- "expected" => -1,
161
- "augend" => 1,
162
- "addend" => -2,
163
- },
164
- }],
165
- })
198
+ :data_sets => [
199
+ {
200
+ "positive positive" => {
201
+ "expected" => 4,
202
+ "augend" => 3,
203
+ "addend" => 1,
204
+ },
205
+ },
206
+ {
207
+ "positive negative" => {
208
+ "expected" => -1,
209
+ "augend" => 1,
210
+ "addend" => -2,
211
+ },
212
+ },
213
+ ],
214
+ })
166
215
  def test_data(data)
167
216
  test_plus = data[:test_case].new("test_plus")
168
- assert_equal(data[:data_set], test_plus[:data])
169
- assert_not_nil(data[:data_set])
217
+ data_sets = Test::Unit::DataSets.new
218
+ data[:data_sets].each do |data_set|
219
+ data_sets.add(data_set)
220
+ end
221
+ assert_equal(data_sets, test_plus[:data])
222
+ end
223
+
224
+ def test_data_patterns
225
+ test = TestCalc::TestPatterns.new("test_use_data")
226
+ data_sets = Test::Unit::DataSets.new
227
+ data_sets << [:x, [-1, 1, 0]]
228
+ data_sets << [:y, [-100, 100]]
229
+ data_sets << [:z, ["a", "b", "c"]]
230
+ assert_equal(data_sets, test[:data])
231
+ end
232
+
233
+ def test_data_patterns_keep
234
+ test = TestCalc::TestPatternsKeep.new("test_use_data_keep")
235
+ data_sets = Test::Unit::DataSets.new
236
+ data_sets.add([:x, [-1, 1, 0]], {keep: true})
237
+ data_sets.add([:z, ["a", "b", "c"]], {keep: true})
238
+ assert_equal(data_sets, test[:data])
170
239
  end
171
240
 
172
241
  data("data set" => TestCalc::TestDataSet,
@@ -180,11 +249,58 @@ class TestData < Test::Unit::TestCase
180
249
  suite.tests.collect {|test| test.name}.sort)
181
250
  end
182
251
 
252
+ def test_suite_patterns
253
+ test_case = TestCalc::TestPatterns
254
+ suite = test_case.suite
255
+ assert_equal([
256
+ "test_use_data[x: -1, y: -100, z: \"a\"](#{test_case.name})",
257
+ "test_use_data[x: -1, y: -100, z: \"b\"](#{test_case.name})",
258
+ "test_use_data[x: -1, y: -100, z: \"c\"](#{test_case.name})",
259
+ "test_use_data[x: -1, y: 100, z: \"a\"](#{test_case.name})",
260
+ "test_use_data[x: -1, y: 100, z: \"b\"](#{test_case.name})",
261
+ "test_use_data[x: -1, y: 100, z: \"c\"](#{test_case.name})",
262
+ "test_use_data[x: 0, y: -100, z: \"a\"](#{test_case.name})",
263
+ "test_use_data[x: 0, y: -100, z: \"b\"](#{test_case.name})",
264
+ "test_use_data[x: 0, y: -100, z: \"c\"](#{test_case.name})",
265
+ "test_use_data[x: 0, y: 100, z: \"a\"](#{test_case.name})",
266
+ "test_use_data[x: 0, y: 100, z: \"b\"](#{test_case.name})",
267
+ "test_use_data[x: 0, y: 100, z: \"c\"](#{test_case.name})",
268
+ "test_use_data[x: 1, y: -100, z: \"a\"](#{test_case.name})",
269
+ "test_use_data[x: 1, y: -100, z: \"b\"](#{test_case.name})",
270
+ "test_use_data[x: 1, y: -100, z: \"c\"](#{test_case.name})",
271
+ "test_use_data[x: 1, y: 100, z: \"a\"](#{test_case.name})",
272
+ "test_use_data[x: 1, y: 100, z: \"b\"](#{test_case.name})",
273
+ "test_use_data[x: 1, y: 100, z: \"c\"](#{test_case.name})",
274
+ ],
275
+ suite.tests.collect {|test| test.name}.sort)
276
+ end
277
+
278
+ def test_suite_patterns_group
279
+ test_case = TestCalc::TestPatternsGroup
280
+ suite = test_case.suite
281
+ assert_equal([
282
+ "test_use_data[group: 1, a: -1, b: :a](#{test_case.name})",
283
+ "test_use_data[group: 1, a: -1, b: :b](#{test_case.name})",
284
+ "test_use_data[group: 1, a: 0, b: :a](#{test_case.name})",
285
+ "test_use_data[group: 1, a: 0, b: :b](#{test_case.name})",
286
+ "test_use_data[group: 1, a: 1, b: :a](#{test_case.name})",
287
+ "test_use_data[group: 1, a: 1, b: :b](#{test_case.name})",
288
+ "test_use_data[group: :z, x: 2, y: \"a\"](#{test_case.name})",
289
+ "test_use_data[group: :z, x: 2, y: \"b\"](#{test_case.name})",
290
+ "test_use_data[group: :z, x: 2, y: \"c\"](#{test_case.name})",
291
+ "test_use_data[group: :z, x: 9, y: \"a\"](#{test_case.name})",
292
+ "test_use_data[group: :z, x: 9, y: \"b\"](#{test_case.name})",
293
+ "test_use_data[group: :z, x: 9, y: \"c\"](#{test_case.name})",
294
+ ],
295
+ suite.tests.collect {|test| test.name}.sort)
296
+ end
297
+
183
298
  data("data set" => TestCalc::TestDataSet,
184
299
  "n-data" => TestCalc::TestNData,
185
300
  "dynamic-data-set" => TestCalc::TestDynamicDataSet,
186
301
  "load-data-set" => TestCalc::TestLoadDataSet,
187
- "superclass" => TestCalc::TestSuperclass)
302
+ "superclass" => TestCalc::TestSuperclass,
303
+ "method" => TestCalc::TestMethod)
188
304
  def test_run(test_case)
189
305
  result = _run_test(test_case)
190
306
  assert_equal("2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, " \
@@ -249,20 +365,20 @@ class TestData < Test::Unit::TestCase
249
365
  "tsv" => "header.tsv")
250
366
  def test_normal(file_name)
251
367
  self.class.load_data(fixture_file_path(file_name))
252
- assert_equal([
253
- {
254
- "empty string" => {
255
- "expected" => true,
256
- "target" => ""
257
- }
258
- },
259
- {
260
- "plain string" => {
261
- "expected" => false,
262
- "target" => "hello"
263
- }
264
- }
265
- ],
368
+ data_sets = Test::Unit::DataSets.new
369
+ data_sets << {
370
+ "empty string" => {
371
+ "expected" => true,
372
+ "target" => ""
373
+ }
374
+ }
375
+ data_sets << {
376
+ "plain string" => {
377
+ "expected" => false,
378
+ "target" => "hello"
379
+ }
380
+ }
381
+ assert_equal(data_sets,
266
382
  self.class.current_attribute(:data)[:value])
267
383
  end
268
384
 
@@ -270,20 +386,20 @@ class TestData < Test::Unit::TestCase
270
386
  "tsv" => "header-label.tsv")
271
387
  def test_label(file_name)
272
388
  self.class.load_data(fixture_file_path(file_name))
273
- assert_equal([
274
- {
275
- "upper case" => {
276
- "expected" => "HELLO",
277
- "label" => "HELLO"
278
- }
279
- },
280
- {
281
- "lower case" => {
282
- "expected" => "Hello",
283
- "label" => "hello"
284
- }
285
- }
286
- ],
389
+ data_sets = Test::Unit::DataSets.new
390
+ data_sets << {
391
+ "upper case" => {
392
+ "expected" => "HELLO",
393
+ "label" => "HELLO"
394
+ }
395
+ }
396
+ data_sets << {
397
+ "lower case" => {
398
+ "expected" => "Hello",
399
+ "label" => "hello"
400
+ }
401
+ }
402
+ assert_equal(data_sets,
287
403
  self.class.current_attribute(:data)[:value])
288
404
  end
289
405
  end
@@ -292,10 +408,10 @@ class TestData < Test::Unit::TestCase
292
408
  "tsv" => "no-header.tsv")
293
409
  def test_without_header(file_name)
294
410
  self.class.load_data(fixture_file_path(file_name))
295
- assert_equal([
296
- {"empty string" => [true, ""]},
297
- {"plain string" => [false, "hello"]}
298
- ],
411
+ data_sets = Test::Unit::DataSets.new
412
+ data_sets << {"empty string" => [true, ""]}
413
+ data_sets << {"plain string" => [false, "hello"]}
414
+ assert_equal(data_sets,
299
415
  self.class.current_attribute(:data)[:value])
300
416
  end
301
417
  end
@@ -546,6 +546,7 @@ module Test
546
546
  test_case = Class.new(TestCase) do
547
547
  data("label" => "value")
548
548
  def test_without_parameter
549
+ assert_equal("value", data)
549
550
  end
550
551
  end
551
552
 
@@ -554,8 +555,8 @@ module Test
554
555
  suite.tests.collect {|test| test.method_name})
555
556
  result = TestResult.new
556
557
  suite.run(result) {}
557
- assert_equal("1 tests, 0 assertions, 0 failures, " +
558
- "0 errors, 0 pendings, 0 omissions, 1 notifications",
558
+ assert_equal("1 tests, 1 assertions, 0 failures, " +
559
+ "0 errors, 0 pendings, 0 omissions, 0 notifications",
559
560
  result.summary)
560
561
  end
561
562
 
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.2.8
4
+ version: 3.2.9
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: 2018-05-13 00:00:00.000000000 Z
12
+ date: 2018-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: power_assert
@@ -133,6 +133,7 @@ files:
133
133
  - lib/test/unit/collector/xml.rb
134
134
  - lib/test/unit/color-scheme.rb
135
135
  - lib/test/unit/color.rb
136
+ - lib/test/unit/data-sets.rb
136
137
  - lib/test/unit/data.rb
137
138
  - lib/test/unit/diff.rb
138
139
  - lib/test/unit/error.rb
@@ -231,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
232
  version: '0'
232
233
  requirements: []
233
234
  rubyforge_project:
234
- rubygems_version: 2.7.6
235
+ rubygems_version: 3.0.0.beta2
235
236
  signing_key:
236
237
  specification_version: 4
237
238
  summary: An xUnit family unit testing framework for Ruby.