oktest 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/filter_test.rb CHANGED
@@ -2,166 +2,168 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 1.4.0 $
5
+ ### $Release: 1.5.0 $
6
6
  ### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
7
7
  ### $License: MIT License $
8
8
  ###
9
9
 
10
- require_relative './initialize'
10
+ require_relative './init'
11
11
 
12
12
 
13
- class Filter_TC < TC
13
+ Object.new.instance_eval do # Oktest::Filter
14
+ extend NanoTest
14
15
 
15
- describe '.create_from()' do
16
- def parse_filter_str(str)
16
+ test_target 'Oktest::Filter.create_from()' do
17
+ def self.parse_filter_str(str)
17
18
  return Oktest::Filter.create_from(str)
18
19
  end
19
- def filter_attrs(ft)
20
+ def self.filter_attrs(ft)
20
21
  #return ft.topic_pattern, ft.spec_pattern, ft.tag_pattern, ft.negative
21
22
  return ft.instance_eval {
22
23
  [@topic_pattern, @spec_pattern, @tag_pattern, @negative]
23
24
  }
24
25
  end
25
26
  #
26
- it "[!9dzmg] returns filter object." do
27
+ test_subject "[!9dzmg] returns filter object." do
27
28
  ft = parse_filter_str("topic=*pat*")
28
- assert ft.is_a?(Oktest::Filter), "should be a filter object."
29
+ test_ok? ft.is_a?(Oktest::Filter), msg: "should be a filter object."
29
30
  end
30
- it "[!xt364] parses 'topic=...' as filter pattern for topic." do
31
+ test_subject "[!xt364] parses 'topic=...' as filter pattern for topic." do
31
32
  ft = parse_filter_str("topic=*pat*")
32
- assert_eq filter_attrs(ft), ['*pat*', nil, nil, false]
33
+ test_eq? filter_attrs(ft), ['*pat*', nil, nil, false]
33
34
  end
34
- it "[!53ega] parses 'spec=...' as filter pattern for spec." do
35
+ test_subject "[!53ega] parses 'spec=...' as filter pattern for spec." do
35
36
  ft = parse_filter_str("spec=*pat*")
36
- assert_eq filter_attrs(ft), [nil, '*pat*', nil, false]
37
+ test_eq? filter_attrs(ft), [nil, '*pat*', nil, false]
37
38
  end
38
- it "[!go6us] parses 'tag=...' as filter pattern for tag." do
39
+ test_subject "[!go6us] parses 'tag=...' as filter pattern for tag." do
39
40
  ft = parse_filter_str("tag={exp,old}")
40
- assert_eq filter_attrs(ft), [nil, nil, '{exp,old}', false]
41
+ test_eq? filter_attrs(ft), [nil, nil, '{exp,old}', false]
41
42
  end
42
- it "[!gtpt1] parses 'sid=...' as filter pattern for spec." do
43
+ test_subject "[!gtpt1] parses 'sid=...' as filter pattern for spec." do
43
44
  ft = parse_filter_str("sid=abc123")
44
- assert_eq filter_attrs(ft), [nil, '\[!abc123\]*', nil, false]
45
+ test_eq? filter_attrs(ft), [nil, '\[!abc123\]*', nil, false]
45
46
  end
46
- it "[!cmp6e] raises ArgumentError when invalid argument." do
47
- assert_exc(ArgumentError, '"abc123": unexpected pattern string.') do
47
+ test_subject "[!cmp6e] raises ArgumentError when invalid argument." do
48
+ exc = test_exception? ArgumentError do
48
49
  parse_filter_str("abc123")
49
50
  end
51
+ test_eq? exc.message, '"abc123": unexpected pattern string.'
50
52
  end
51
- it "[!5hl7z] parses 'xxx!=...' as negative filter pattern." do
53
+ test_subject "[!5hl7z] parses 'xxx!=...' as negative filter pattern." do
52
54
  ft = parse_filter_str("topic!=*pat*")
53
- assert_eq filter_attrs(ft), ['*pat*', nil, nil, true]
55
+ test_eq? filter_attrs(ft), ['*pat*', nil, nil, true]
54
56
  ft = parse_filter_str("spec!=*pat*")
55
- assert_eq filter_attrs(ft), [nil, '*pat*', nil, true]
57
+ test_eq? filter_attrs(ft), [nil, '*pat*', nil, true]
56
58
  ft = parse_filter_str("tag!={exp,old}")
57
- assert_eq filter_attrs(ft), [nil, nil, '{exp,old}', true]
59
+ test_eq? filter_attrs(ft), [nil, nil, '{exp,old}', true]
58
60
  ft = parse_filter_str("sid!=abc123")
59
- assert_eq filter_attrs(ft), [nil, '\[!abc123\]*', nil, true]
61
+ test_eq? filter_attrs(ft), [nil, '\[!abc123\]*', nil, true]
60
62
  end
61
63
  end
62
64
 
63
- def new_filter(topic_pat=nil, spec_pat=nil, tag_pat=nil, negative: false)
65
+ def self.new_filter(topic_pat=nil, spec_pat=nil, tag_pat=nil, negative: false)
64
66
  ft = Oktest::Filter.new(topic_pat, spec_pat, tag_pat, negative: negative)
65
67
  return ft
66
68
  end
67
69
 
68
- describe '#_match?()' do
69
- it "[!h90x3] returns true if str matched to pattern." do
70
+ test_target 'Oktest::Filter#_match?()' do
71
+ test_subject "[!h90x3] returns true if str matched to pattern." do
70
72
  ft = new_filter()
71
- assert_eq ft.instance_eval { _match?('foo', 'foo') }, true
72
- assert_eq ft.instance_eval { _match?('foo', 'f*') }, true
73
- assert_eq ft.instance_eval { _match?('foo', '*o*') }, true
74
- assert_eq ft.instance_eval { _match?('foo', '{foo,bar}') }, true
73
+ test_eq? ft.instance_eval { _match?('foo', 'foo') }, true
74
+ test_eq? ft.instance_eval { _match?('foo', 'f*') }, true
75
+ test_eq? ft.instance_eval { _match?('foo', '*o*') }, true
76
+ test_eq? ft.instance_eval { _match?('foo', '{foo,bar}') }, true
75
77
  #
76
- assert_eq ft.instance_eval { _match?('foo', 'bar') }, false
77
- assert_eq ft.instance_eval { _match?('foo', 'F*') }, false
78
- assert_eq ft.instance_eval { _match?('foo', '*x*') }, false
79
- assert_eq ft.instance_eval { _match?('foo', '{x,y}') }, false
78
+ test_eq? ft.instance_eval { _match?('foo', 'bar') }, false
79
+ test_eq? ft.instance_eval { _match?('foo', 'F*') }, false
80
+ test_eq? ft.instance_eval { _match?('foo', '*x*') }, false
81
+ test_eq? ft.instance_eval { _match?('foo', '{x,y}') }, false
80
82
  end
81
83
  end
82
84
 
83
- describe '#_match_tag?()' do
84
- it "[!lyo18] returns false if tag is nil." do
85
+ test_target 'Oktest::Filter#_match_tag?()' do
86
+ test_subject "[!lyo18] returns false if tag is nil." do
85
87
  ft = new_filter()
86
- assert_eq ft.instance_eval { _match_tag?(nil, '*') }, false
88
+ test_eq? ft.instance_eval { _match_tag?(nil, '*') }, false
87
89
  end
88
- it "[!8lxin] returns true if tag matched to pattern." do
90
+ test_subject "[!8lxin] returns true if tag matched to pattern." do
89
91
  ft = new_filter()
90
- assert_eq ft.instance_eval { _match_tag?('foo', 'foo') }, true
91
- assert_eq ft.instance_eval { _match_tag?('foo', 'f*') }, true
92
- assert_eq ft.instance_eval { _match_tag?('foo', '*o*') }, true
93
- assert_eq ft.instance_eval { _match_tag?('foo', '{foo,bar}') }, true
92
+ test_eq? ft.instance_eval { _match_tag?('foo', 'foo') }, true
93
+ test_eq? ft.instance_eval { _match_tag?('foo', 'f*') }, true
94
+ test_eq? ft.instance_eval { _match_tag?('foo', '*o*') }, true
95
+ test_eq? ft.instance_eval { _match_tag?('foo', '{foo,bar}') }, true
94
96
  #
95
- assert_eq ft.instance_eval { _match_tag?('foo', 'bar') }, false
96
- assert_eq ft.instance_eval { _match_tag?('foo', 'F*') }, false
97
- assert_eq ft.instance_eval { _match_tag?('foo', '*x*') }, false
98
- assert_eq ft.instance_eval { _match_tag?('foo', '{x,y}') }, false
97
+ test_eq? ft.instance_eval { _match_tag?('foo', 'bar') }, false
98
+ test_eq? ft.instance_eval { _match_tag?('foo', 'F*') }, false
99
+ test_eq? ft.instance_eval { _match_tag?('foo', '*x*') }, false
100
+ test_eq? ft.instance_eval { _match_tag?('foo', '{x,y}') }, false
99
101
  end
100
- it "[!7wxmh] supports multiple tag names." do
102
+ test_subject "[!7wxmh] supports multiple tag names." do
101
103
  ft = new_filter()
102
104
  tag = ['foo', 'bar']
103
- assert_eq ft.instance_eval { _match_tag?(tag, 'foo') }, true
104
- assert_eq ft.instance_eval { _match_tag?(tag, 'f*') }, true
105
- assert_eq ft.instance_eval { _match_tag?(tag, '*o*') }, true
106
- assert_eq ft.instance_eval { _match_tag?(tag, '{fooooo,bar,baz}') }, true
105
+ test_eq? ft.instance_eval { _match_tag?(tag, 'foo') }, true
106
+ test_eq? ft.instance_eval { _match_tag?(tag, 'f*') }, true
107
+ test_eq? ft.instance_eval { _match_tag?(tag, '*o*') }, true
108
+ test_eq? ft.instance_eval { _match_tag?(tag, '{fooooo,bar,baz}') }, true
107
109
  #
108
- assert_eq ft.instance_eval { _match_tag?(tag, 'foooo') }, false
109
- assert_eq ft.instance_eval { _match_tag?(tag, 'F*') }, false
110
- assert_eq ft.instance_eval { _match_tag?(tag, '*x*') }, false
111
- assert_eq ft.instance_eval { _match_tag?(tag, '{x,y}') }, false
110
+ test_eq? ft.instance_eval { _match_tag?(tag, 'foooo') }, false
111
+ test_eq? ft.instance_eval { _match_tag?(tag, 'F*') }, false
112
+ test_eq? ft.instance_eval { _match_tag?(tag, '*x*') }, false
113
+ test_eq? ft.instance_eval { _match_tag?(tag, '{x,y}') }, false
112
114
  end
113
115
  end
114
116
 
115
- describe '#scope_match?()' do
116
- it "[!zkq6r] returns true only if tag name matched to pattern." do
117
+ test_target 'Oktest::Filter#scope_match?()' do
118
+ test_subject "[!zkq6r] returns true only if tag name matched to pattern." do
117
119
  sc = Oktest::ScopeNode.new(nil, 'file.rb', tag: 'foo')
118
- assert_eq new_filter('*', '*', 'foo').scope_match?(sc), true
119
- assert_eq new_filter('*', '*', 'f*' ).scope_match?(sc), true
120
- assert_eq new_filter('*', '*', 'x*' ).scope_match?(sc), false
120
+ test_eq? new_filter('*', '*', 'foo').scope_match?(sc), true
121
+ test_eq? new_filter('*', '*', 'f*' ).scope_match?(sc), true
122
+ test_eq? new_filter('*', '*', 'x*' ).scope_match?(sc), false
121
123
  #
122
124
  sc = Oktest::ScopeNode.new(nil, 'file.rb', tag: nil)
123
- assert_eq new_filter('*', '*', 'foo').scope_match?(sc), false
124
- assert_eq new_filter('*', '*', '*' ).scope_match?(sc), false
125
+ test_eq? new_filter('*', '*', 'foo').scope_match?(sc), false
126
+ test_eq? new_filter('*', '*', '*' ).scope_match?(sc), false
125
127
  end
126
128
  end
127
129
 
128
- describe '#topic_match?()' do
129
- it "[!jpycj] returns true if topic target name matched to pattern." do
130
+ test_target 'Oktest::Filter#topic_match?()' do
131
+ test_subject "[!jpycj] returns true if topic target name matched to pattern." do
130
132
  to = Oktest::TopicNode.new(nil, Time)
131
- assert_eq new_filter('Time' , nil, nil).topic_match?(to), true
132
- assert_eq new_filter('*ime*', nil, nil).topic_match?(to), true
133
- assert_eq new_filter('*xy*' , nil, nil).topic_match?(to), false
133
+ test_eq? new_filter('Time' , nil, nil).topic_match?(to), true
134
+ test_eq? new_filter('*ime*', nil, nil).topic_match?(to), true
135
+ test_eq? new_filter('*xy*' , nil, nil).topic_match?(to), false
134
136
  end
135
- it "[!6lfp1] returns true if tag name matched to pattern." do
137
+ test_subject "[!6lfp1] returns true if tag name matched to pattern." do
136
138
  to = Oktest::TopicNode.new(nil, Time, tag: 'foo')
137
139
  [nil, '*bar*'].each do |pat|
138
- assert_eq new_filter(pat, nil, 'foo' ).topic_match?(to), true
139
- assert_eq new_filter(pat, nil, 'f*' ).topic_match?(to), true
140
- assert_eq new_filter(pat, nil, '{foo,bar}').topic_match?(to), true
141
- assert_eq new_filter(pat, nil, 'fooooo' ).topic_match?(to), false
140
+ test_eq? new_filter(pat, nil, 'foo' ).topic_match?(to), true
141
+ test_eq? new_filter(pat, nil, 'f*' ).topic_match?(to), true
142
+ test_eq? new_filter(pat, nil, '{foo,bar}').topic_match?(to), true
143
+ test_eq? new_filter(pat, nil, 'fooooo' ).topic_match?(to), false
142
144
  end
143
145
  end
144
146
  end
145
147
 
146
- describe '#spec_match?()' do
147
- it "[!k45p3] returns true if spec description matched to pattern." do
148
+ test_target 'Oktest::Filter#spec_match?()' do
149
+ test_subject "[!k45p3] returns true if spec description matched to pattern." do
148
150
  sp = Oktest::SpecLeaf.new(nil, "sample", tag: 'foo')
149
- assert_eq new_filter(nil, 'sample', nil).spec_match?(sp), true
150
- assert_eq new_filter(nil, '*samp*', nil).spec_match?(sp), true
151
- assert_eq new_filter(nil, '*abc*' , nil).spec_match?(sp), false
151
+ test_eq? new_filter(nil, 'sample', nil).spec_match?(sp), true
152
+ test_eq? new_filter(nil, '*samp*', nil).spec_match?(sp), true
153
+ test_eq? new_filter(nil, '*abc*' , nil).spec_match?(sp), false
152
154
  end
153
- it "[!li3pd] returns true if tag name matched to pattern." do
155
+ test_subject "[!li3pd] returns true if tag name matched to pattern." do
154
156
  sp = Oktest::SpecLeaf.new(nil, "sample", tag: 'foo')
155
157
  [nil, '*bar*'].each do |pat|
156
- assert_eq new_filter(nil, pat, 'foo' ).spec_match?(sp), true
157
- assert_eq new_filter(nil, pat, 'f*' ).spec_match?(sp), true
158
- assert_eq new_filter(nil, pat, '{foo,bar}').spec_match?(sp), true
159
- assert_eq new_filter(nil, pat, 'fooooo' ).spec_match?(sp), false
158
+ test_eq? new_filter(nil, pat, 'foo' ).spec_match?(sp), true
159
+ test_eq? new_filter(nil, pat, 'f*' ).spec_match?(sp), true
160
+ test_eq? new_filter(nil, pat, '{foo,bar}').spec_match?(sp), true
161
+ test_eq? new_filter(nil, pat, 'fooooo' ).spec_match?(sp), false
160
162
  end
161
163
  end
162
164
  end
163
165
 
164
- def prepare()
166
+ def self.prepare()
165
167
  Oktest.scope do
166
168
  topic 'Hello' do
167
169
  spec "hello spec", tag: 'new' do ok {"hello"} == "hello" end
@@ -180,32 +182,32 @@ class Filter_TC < TC
180
182
  end
181
183
  end
182
184
 
183
- def run_filter(topic_pattern, spec_pattern, tag_pattern, negative: false)
184
- prepare()
185
+ def self.run_filter(topic_pattern, spec_pattern, tag_pattern, negative: false)
186
+ self.prepare()
185
187
  filter = Oktest::Filter.new(topic_pattern, spec_pattern, tag_pattern, negative: negative)
186
188
  Oktest.filter(filter)
187
189
  reporter = Oktest::VerboseReporter.new()
188
- sout, serr = capture('', tty: false) do
190
+ sout, serr = capture_output! '', tty: false do
189
191
  Oktest::Runner.new(reporter).start()
190
192
  end
191
- assert_eq serr, ""
192
- return sout.sub(/^## total:.*\n/, '').sub(/^## test\/filter_test\.rb\n/, '')
193
+ test_eq? serr, ""
194
+ return sout.sub(/^## total:.*\n/, '').sub(/^## test\d?\/filter_test\.rb\n/, '')
193
195
  end
194
196
 
195
- def uncolor(s)
196
- return s.gsub(/\x1b.*?m/, '')
197
+ def self.uncolor(s)
198
+ return s.gsub(/\e\[.*?m/, '')
197
199
  end
198
200
 
199
- describe '#filter_children!()' do
200
- it "[!osoq2] can filter topics by full name." do
201
+ test_target 'Oktest::Filter#filter_children!()' do
202
+ test_subject "[!osoq2] can filter topics by full name." do
201
203
  expected = <<END
202
204
  * Hello
203
205
  - [pass] hello spec
204
206
  END
205
207
  sout = run_filter('Hello', nil, nil)
206
- assert_eq uncolor(sout), expected
208
+ test_eq? uncolor(sout), expected
207
209
  end
208
- it "[!wzcco] can filter topics by pattern." do
210
+ test_subject "[!wzcco] can filter topics by pattern." do
209
211
  expected = <<END
210
212
  * Topic 832795
211
213
  * Integer
@@ -217,9 +219,9 @@ END
217
219
  - [pass] spec example #5
218
220
  END
219
221
  sout = run_filter('*832795*', nil, nil)
220
- assert_eq uncolor(sout), expected
222
+ test_eq? uncolor(sout), expected
221
223
  end
222
- it "[!mz6id] can filter nested topics." do
224
+ test_subject "[!mz6id] can filter nested topics." do
223
225
  expected = <<END
224
226
  * Topic 832795
225
227
  * Float
@@ -227,23 +229,23 @@ END
227
229
  - [pass] spec example #4
228
230
  END
229
231
  sout = run_filter('*loat*', nil, nil)
230
- assert_eq uncolor(sout), expected
232
+ test_eq? uncolor(sout), expected
231
233
  end
232
- it "[!0kw9c] can filter specs by full name." do
234
+ test_subject "[!0kw9c] can filter specs by full name." do
233
235
  expected = <<END
234
236
  * Hello
235
237
  - [pass] hello spec
236
238
  END
237
239
  sout = run_filter(nil, 'hello spec', nil)
238
- assert_eq uncolor(sout), expected
240
+ test_eq? uncolor(sout), expected
239
241
  end
240
- it "[!fd8wt] can filter specs by pattern." do
242
+ test_subject "[!fd8wt] can filter specs by pattern." do
241
243
  expected = <<END
242
244
  * Topic 832795
243
245
  - [pass] spec example #5
244
246
  END
245
247
  sout = run_filter(nil, '*#5', nil)
246
- assert_eq uncolor(sout), expected
248
+ test_eq? uncolor(sout), expected
247
249
  #
248
250
  expected = <<END
249
251
  * Topic 832795
@@ -256,18 +258,18 @@ END
256
258
  - [pass] spec example #5
257
259
  END
258
260
  sout = run_filter(nil, 'spec example*', nil)
259
- assert_eq uncolor(sout), expected
261
+ test_eq? uncolor(sout), expected
260
262
  end
261
- it "[!1jphf] can filter specs from nested topics." do
263
+ test_subject "[!1jphf] can filter specs from nested topics." do
262
264
  expected = <<END
263
265
  * Topic 832795
264
266
  * Float
265
267
  - [pass] spec example #4
266
268
  END
267
269
  sout = run_filter(nil, '*#4', nil)
268
- assert_eq uncolor(sout), expected
270
+ test_eq? uncolor(sout), expected
269
271
  end
270
- it "[!eirmu] can filter topics by tag name." do
272
+ test_subject "[!eirmu] can filter topics by tag name." do
271
273
  expected = <<END
272
274
  * Topic 832795
273
275
  * Float
@@ -276,9 +278,9 @@ END
276
278
  - [pass] spec example #5
277
279
  END
278
280
  sout = run_filter(nil, nil, 'exp')
279
- assert_eq uncolor(sout), expected
281
+ test_eq? uncolor(sout), expected
280
282
  end
281
- it "[!6sq7g] can filter specs by tag name." do
283
+ test_subject "[!6sq7g] can filter specs by tag name." do
282
284
  expected = <<END
283
285
  * Hello
284
286
  - [pass] hello spec
@@ -288,9 +290,9 @@ END
288
290
  - [pass] spec example #5
289
291
  END
290
292
  sout = run_filter(nil, nil, 'new')
291
- assert_eq uncolor(sout), expected
293
+ test_eq? uncolor(sout), expected
292
294
  end
293
- it "[!6to6n] can filter by multiple tag name." do
295
+ test_subject "[!6to6n] can filter by multiple tag name." do
294
296
  expected = <<END
295
297
  * Hello
296
298
  - [pass] hello spec
@@ -303,15 +305,15 @@ END
303
305
  - [pass] spec example #5
304
306
  END
305
307
  sout = run_filter(nil, nil, '{new,exp}')
306
- assert_eq uncolor(sout), expected
308
+ test_eq? uncolor(sout), expected
307
309
  end
308
- it "[!r6g6a] supports negative filter by topic." do
310
+ test_subject "[!r6g6a] supports negative filter by topic." do
309
311
  expected = <<END
310
312
  * Hello
311
313
  - [pass] hello spec
312
314
  END
313
315
  sout = run_filter('Topic 832795', nil, nil, negative: true)
314
- assert_eq uncolor(sout), expected
316
+ test_eq? uncolor(sout), expected
315
317
  #
316
318
  expected = <<END
317
319
  * Hello
@@ -320,9 +322,9 @@ END
320
322
  - [pass] spec example #5
321
323
  END
322
324
  sout = run_filter('{Integer,Float}', nil, nil, negative: true)
323
- assert_eq uncolor(sout), expected
325
+ test_eq? uncolor(sout), expected
324
326
  end
325
- it "[!doozg] supports negative filter by spec." do
327
+ test_subject "[!doozg] supports negative filter by spec." do
326
328
  expected = <<END
327
329
  * Topic 832795
328
330
  * Integer
@@ -334,16 +336,16 @@ END
334
336
  - [pass] spec example #5
335
337
  END
336
338
  sout = run_filter(nil, '*hello*', nil, negative: true)
337
- assert_eq uncolor(sout), expected
339
+ test_eq? uncolor(sout), expected
338
340
  #
339
341
  expected = <<END
340
342
  * Hello
341
343
  - [pass] hello spec
342
344
  END
343
345
  sout = run_filter(nil, 'spec example #[1-5]', nil, negative: true)
344
- assert_eq uncolor(sout), expected
346
+ test_eq? uncolor(sout), expected
345
347
  end
346
- it "[!ntv44] supports negative filter by tag name." do
348
+ test_subject "[!ntv44] supports negative filter by tag name." do
347
349
  expected = <<END
348
350
  * Topic 832795
349
351
  * Integer
@@ -353,7 +355,7 @@ END
353
355
  - [pass] spec example #4
354
356
  END
355
357
  sout = run_filter(nil, nil, 'new', negative: true)
356
- assert_eq uncolor(sout), expected
358
+ test_eq? uncolor(sout), expected
357
359
  #
358
360
  expected = <<END
359
361
  * Hello
@@ -364,7 +366,7 @@ END
364
366
  - [pass] spec example #2
365
367
  END
366
368
  sout = run_filter(nil, nil, 'exp', negative: true)
367
- assert_eq uncolor(sout), expected
369
+ test_eq? uncolor(sout), expected
368
370
  #
369
371
  expected = <<END
370
372
  * Topic 832795
@@ -372,7 +374,7 @@ END
372
374
  - [pass] spec example #1
373
375
  END
374
376
  sout = run_filter(nil, nil, '{exp,new}', negative: true)
375
- assert_eq uncolor(sout), expected
377
+ test_eq? uncolor(sout), expected
376
378
  end
377
379
 
378
380
  end
data/test/fixture_test.rb CHANGED
@@ -2,34 +2,35 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 1.4.0 $
5
+ ### $Release: 1.5.0 $
6
6
  ### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
7
7
  ### $License: MIT License $
8
8
  ###
9
9
 
10
- require_relative './initialize'
10
+ require_relative './init'
11
11
 
12
12
 
13
- class FixtureManager_TC < TC
13
+ class FixtureManager__Test
14
+ extend NanoTest
14
15
 
15
- class DummyReporter2 < Oktest::Reporter
16
+ class DummyReporter5 < Oktest::Reporter
16
17
  def exit_spec(spec, depth, status, error, parent)
17
18
  puts error.inspect if error
18
19
  end
19
20
  end
20
21
 
21
- def run_all(dummy: false)
22
- reporter = dummy ? DummyReporter2.new : Oktest::Reporter.new
23
- sout, serr = capture do
22
+ def self.run_all(dummy: false)
23
+ reporter = dummy ? DummyReporter5.new : Oktest::Reporter.new
24
+ sout, serr = capture_output! do
24
25
  Oktest::Runner.new(reporter).start()
25
26
  end
26
- assert_eq serr, ""
27
+ test_eq? serr, ""
27
28
  return sout
28
29
  end
29
30
 
30
- describe '#get_fixture_values()' do
31
+ test_target 'Oktest::FixtureManager#get_fixture_values()' do
31
32
 
32
- it "[!v587k] resolves fixtures." do
33
+ test_subject "[!v587k] resolves fixtures." do
33
34
  Oktest.scope do
34
35
  fixture(:x) { 10 }
35
36
  topic "Parent" do
@@ -44,10 +45,10 @@ class FixtureManager_TC < TC
44
45
  end
45
46
  expected = "[10, 20, 30]\n"
46
47
  sout = run_all()
47
- assert_eq sout, expected
48
+ test_eq? sout, expected
48
49
  end
49
50
 
50
- it "[!ja2ew] resolves 'this_spec' fixture name as description of current spec." do
51
+ test_subject "[!ja2ew] resolves 'this_spec' fixture name as description of current spec." do
51
52
  Oktest.scope do
52
53
  topic Integer do
53
54
  spec "1+1 should be 2." do |this_spec|
@@ -56,10 +57,10 @@ class FixtureManager_TC < TC
56
57
  end
57
58
  end
58
59
  sout = run_all()
59
- assert_eq sout, "this_spec=\"1+1 should be 2.\"\n"
60
+ test_eq? sout, "this_spec=\"1+1 should be 2.\"\n"
60
61
  end
61
62
 
62
- it "[!w6ffs] resolves 'this_topic' fixture name as target objec of current topic." do
63
+ test_subject "[!w6ffs] resolves 'this_topic' fixture name as target objec of current topic." do
63
64
  Oktest.scope do
64
65
  topic Integer do
65
66
  spec "1+1 should be 2." do |this_topic|
@@ -68,10 +69,10 @@ class FixtureManager_TC < TC
68
69
  end
69
70
  end
70
71
  sout = run_all()
71
- assert_eq sout, "this_topic=Integer\n"
72
+ test_eq? sout, "this_topic=Integer\n"
72
73
  end
73
74
 
74
- it "[!np4p9] raises error when loop exists in dependency." do
75
+ test_subject "[!np4p9] raises error when loop exists in dependency." do
75
76
  Oktest.scope do
76
77
  topic "Parent" do
77
78
  fixture(:a) {|b| nil }
@@ -85,14 +86,14 @@ class FixtureManager_TC < TC
85
86
  end
86
87
  expected = "\#<Oktest::LoopedDependencyError: fixture dependency is looped: a->b=>c=>d=>b>\n"
87
88
  sout = run_all(dummy: true)
88
- assert_eq sout, expected
89
+ test_eq? sout, expected
89
90
  end
90
91
 
91
92
  end
92
93
 
93
- describe '#get_fixture_value()' do
94
+ test_target 'Oktest::FixtureManager#get_fixture_value()' do
94
95
 
95
- it "[!2esaf] resolves fixture dependencies." do
96
+ test_subject "[!2esaf] resolves fixture dependencies." do
96
97
  Oktest.scope do
97
98
  topic "Parent" do
98
99
  fixture(:a) {|b, c| ["A"] + b + c }
@@ -114,10 +115,10 @@ class FixtureManager_TC < TC
114
115
  ["A", "B", "C", "D"]
115
116
  END
116
117
  sout = run_all()
117
- assert_eq sout, expected
118
+ test_eq? sout, expected
118
119
  end
119
120
 
120
- it "[!gyyst] overwrites keyword params by fixture values." do
121
+ test_subject "[!gyyst] overwrites keyword params by fixture values." do
121
122
  Oktest.scope do
122
123
  topic "topic#1" do
123
124
  fixture(:x) {|y, z: 3| {y: y, z: z} }
@@ -127,10 +128,10 @@ END
127
128
  end
128
129
  end
129
130
  sout = run_all()
130
- assert_eq sout, "{:y=>2, :z=>3}\n{:y=>4, :z=>5}\n"
131
+ test_eq? sout, "{:y=>2, :z=>3}\n{:y=>4, :z=>5}\n"
131
132
  end
132
133
 
133
- it "[!4xghy] calls fixture block with context object as self." do
134
+ test_subject "[!4xghy] calls fixture block with context object as self." do
134
135
  Oktest.scope do
135
136
  topic "Parent" do
136
137
  fixture(:x) { @x = 10; 20 }
@@ -141,10 +142,10 @@ END
141
142
  10
142
143
  END
143
144
  sout = run_all()
144
- assert_eq sout, expected
145
+ test_eq? sout, expected
145
146
  end
146
147
 
147
- it "[!8t3ul] caches fixture value to call fixture block only once per spec." do
148
+ test_subject "[!8t3ul] caches fixture value to call fixture block only once per spec." do
148
149
  Oktest.scope do
149
150
  topic "Parent" do
150
151
  fixture(:x) { puts "** x called."; 10 }
@@ -162,10 +163,10 @@ END
162
163
  12
163
164
  END
164
165
  sout = run_all()
165
- assert_eq sout, expected
166
+ test_eq? sout, expected
166
167
  end
167
168
 
168
- it "[!4chb9] traverses parent topics if fixture not found in current topic." do
169
+ test_subject "[!4chb9] traverses parent topics if fixture not found in current topic." do
169
170
  Oktest.scope do
170
171
  topic 'Parent' do
171
172
  fixture(:x) { 10 }
@@ -179,10 +180,10 @@ END
179
180
  end
180
181
  end
181
182
  sout = run_all()
182
- assert_eq sout, "\"x=10, y=11, z=12\"\n"
183
+ test_eq? sout, "\"x=10, y=11, z=12\"\n"
183
184
  end
184
185
 
185
- it "[!wt3qk] suports global scope." do
186
+ test_subject "[!wt3qk] suports global scope." do
186
187
  Oktest.global_scope do
187
188
  fixture :gf1592 do {id: "gf1592"} end
188
189
  fixture :gf6535 do |gf1592| {id: "gf6535", parent: gf1592} end
@@ -197,10 +198,10 @@ END
197
198
  end
198
199
  end
199
200
  _ = run_all()
200
- assert_eq data, {:id=>"gf8979", :parent=>{:id=>"gf6535", :parent=>{:id=>"gf1592"}}}
201
+ test_eq? data, {:id=>"gf8979", :parent=>{:id=>"gf6535", :parent=>{:id=>"gf1592"}}}
201
202
  end
202
203
 
203
- it "[!nr79z] raises error when fixture not found." do
204
+ test_subject "[!nr79z] raises error when fixture not found." do
204
205
  Oktest.scope do
205
206
  topic "Parent" do
206
207
  fixture(:x) { 10 }
@@ -211,7 +212,7 @@ END
211
212
  end
212
213
  expected = "#<Oktest::FixtureNotFoundError: y: fixture not found. (spec: spec#1)>\n"
213
214
  sout = run_all(dummy: true)
214
- assert_eq sout, expected
215
+ test_eq? sout, expected
215
216
  end
216
217
 
217
218
  end