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