oktest 1.0.0
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 +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +1856 -0
- data/Rakefile.rb +61 -0
- data/benchmark/Rakefile.rb +230 -0
- data/benchmark/run_all.rb +6 -0
- data/bin/oktest +3 -0
- data/lib/oktest.rb +2359 -0
- data/oktest.gemspec +45 -0
- data/test/assertion_test.rb +817 -0
- data/test/filter_test.rb +379 -0
- data/test/fixture_test.rb +205 -0
- data/test/generator_test.rb +123 -0
- data/test/helper_test.rb +542 -0
- data/test/initialize.rb +14 -0
- data/test/mainapp_test.rb +625 -0
- data/test/misc_test.rb +80 -0
- data/test/node_test.rb +669 -0
- data/test/reporter_test.rb +547 -0
- data/test/run_all.rb +13 -0
- data/test/runner_test.rb +544 -0
- data/test/tc.rb +115 -0
- data/test/util_test.rb +258 -0
- data/test/visitor_test.rb +292 -0
- metadata +105 -0
data/test/misc_test.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
###
|
4
|
+
### $Release: 1.0.0 $
|
5
|
+
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
|
+
### $License: MIT License $
|
7
|
+
###
|
8
|
+
|
9
|
+
require_relative './initialize'
|
10
|
+
|
11
|
+
|
12
|
+
class Misc_TC < TC
|
13
|
+
|
14
|
+
def setup()
|
15
|
+
@_auto_run = Oktest::Config.auto_run
|
16
|
+
Oktest::Config.auto_run = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown()
|
20
|
+
Oktest::Config.auto_run = @_auto_run
|
21
|
+
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'Oktest.auto_run?()' do
|
25
|
+
it "[!7vm4d] returns false if error raised when loading test scripts." do
|
26
|
+
Oktest.scope do
|
27
|
+
end
|
28
|
+
begin
|
29
|
+
1/0
|
30
|
+
rescue => exc
|
31
|
+
assert_eq Oktest.auto_run?, false
|
32
|
+
end
|
33
|
+
assert exc != nil, "exception not raised"
|
34
|
+
end
|
35
|
+
it "[!oae85] returns true if exit() called." do
|
36
|
+
Oktest.scope do
|
37
|
+
end
|
38
|
+
#
|
39
|
+
begin
|
40
|
+
exit(0)
|
41
|
+
rescue SystemExit => exc
|
42
|
+
assert_eq Oktest.auto_run?, true
|
43
|
+
end
|
44
|
+
assert exc != nil, "exception not raised"
|
45
|
+
end
|
46
|
+
it "[!rg5aw] returns false if Oktest.scope() never been called." do
|
47
|
+
assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, false
|
48
|
+
assert_eq Oktest.auto_run?, false
|
49
|
+
end
|
50
|
+
it "[!0j3ek] returns true if Config.auto_run is enabled." do
|
51
|
+
Oktest.scope do
|
52
|
+
end
|
53
|
+
bkup = Oktest::Config.auto_run
|
54
|
+
begin
|
55
|
+
Oktest::Config.auto_run = true
|
56
|
+
assert_eq Oktest.auto_run?, true
|
57
|
+
Oktest::Config.auto_run = false
|
58
|
+
assert_eq Oktest.auto_run?, false
|
59
|
+
ensure
|
60
|
+
Oktest::Config.auto_run = bkup
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
class Color_TC < TC
|
69
|
+
|
70
|
+
describe '.status()' do
|
71
|
+
it "[!yev5y] returns string containing color escape sequence." do
|
72
|
+
assert_eq Oktest::Color.status(:PASS , "Pass" ), "\e[1;34mPass\e[0m"
|
73
|
+
assert_eq Oktest::Color.status(:FAIL , "Fail" ), "\e[1;31mFail\e[0m"
|
74
|
+
assert_eq Oktest::Color.status(:ERROR, "Error"), "\e[1;31mError\e[0m"
|
75
|
+
assert_eq Oktest::Color.status(:SKIP , "Skip" ), "\e[1;33mSkip\e[0m"
|
76
|
+
assert_eq Oktest::Color.status(:TODO , "Todo" ), "\e[1;33mTodo\e[0m"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/test/node_test.rb
ADDED
@@ -0,0 +1,669 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
###
|
4
|
+
### $Release: 1.0.0 $
|
5
|
+
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
|
+
### $License: MIT License $
|
7
|
+
###
|
8
|
+
|
9
|
+
require_relative './initialize'
|
10
|
+
|
11
|
+
|
12
|
+
class Item_TC < TC
|
13
|
+
|
14
|
+
describe '#accept_visitor()' do
|
15
|
+
it "[!b0e20] raises NotImplementedError." do
|
16
|
+
assert_exc(NotImplementedError, "Oktest::Item#accept_visitor(): not implemented yet.") do
|
17
|
+
Oktest::Item.new().accept_visitor(nil)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#unlink_parent()' do
|
23
|
+
it "[!5a0i9] raises NotImplementedError." do
|
24
|
+
assert_exc(NotImplementedError, "Oktest::Item#unlink_parent(): not implemented yet.") do
|
25
|
+
Oktest::Item.new().unlink_parent()
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#_repr()' do
|
31
|
+
it "[!qi1af] raises NotImplementedError." do
|
32
|
+
assert_exc(NotImplementedError, "Oktest::Item#_repr(): not implemented yet.") do
|
33
|
+
Oktest::Item.new()._repr(0)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
class Node_TC < TC
|
42
|
+
|
43
|
+
def setup()
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown()
|
47
|
+
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe '#add_child()' do
|
52
|
+
it "[!1fyk9] keeps children." do
|
53
|
+
p = Oktest::Node.new(nil)
|
54
|
+
c = Oktest::Node.new(nil)
|
55
|
+
p.add_child(c)
|
56
|
+
assert_eq p.instance_eval('@children'), [c]
|
57
|
+
end
|
58
|
+
it "[!w5r6l] returns self." do
|
59
|
+
p = Oktest::Node.new(nil)
|
60
|
+
c = Oktest::Node.new(nil)
|
61
|
+
ret = p.add_child(c)
|
62
|
+
assert ret.equal?(p), "should be same"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#has_child?' do
|
67
|
+
it "[!xb30d] return true when no children, else false." do
|
68
|
+
p = Oktest::Node.new(nil)
|
69
|
+
c = Oktest::Node.new(nil)
|
70
|
+
p.add_child(c)
|
71
|
+
assert_eq p.has_child?, true
|
72
|
+
assert_eq c.has_child?, false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#each_child()' do
|
77
|
+
it "[!osoep] returns enumerator if block not given." do
|
78
|
+
node = Oktest::Node.new(nil)
|
79
|
+
assert_eq node.each_child.class, Enumerator
|
80
|
+
end
|
81
|
+
it "[!pve8m] yields block for each child." do
|
82
|
+
p = Oktest::Node.new(nil)
|
83
|
+
c1 = Oktest::Node.new(p)
|
84
|
+
c2 = Oktest::Node.new(p)
|
85
|
+
arr = []
|
86
|
+
p.each_child {|x| arr << x }
|
87
|
+
assert_eq arr.length, 2
|
88
|
+
assert_eq arr[0], c1
|
89
|
+
assert_eq arr[1], c2
|
90
|
+
end
|
91
|
+
it "[!8z6un] returns nil." do
|
92
|
+
p = Oktest::Node.new(nil)
|
93
|
+
c1 = Oktest::Node.new(p)
|
94
|
+
c2 = Oktest::Node.new(p)
|
95
|
+
ret = p.each_child {|c| 123 }
|
96
|
+
assert_eq ret, nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#remove_child()' do
|
101
|
+
it "[!hsomo] removes child at index." do
|
102
|
+
p = Oktest::Node.new(nil)
|
103
|
+
c1 = Oktest::Node.new(p)
|
104
|
+
c2 = Oktest::Node.new(p)
|
105
|
+
p.remove_child_at(0)
|
106
|
+
children = p.each_child.to_a
|
107
|
+
assert_eq children.length, 1
|
108
|
+
assert_eq children[0], c2
|
109
|
+
end
|
110
|
+
it "[!hiz1b] returns removed child." do
|
111
|
+
p = Oktest::Node.new(nil)
|
112
|
+
c1 = Oktest::Node.new(p)
|
113
|
+
c2 = Oktest::Node.new(p)
|
114
|
+
ret = p.remove_child_at(0)
|
115
|
+
assert_eq ret, c1
|
116
|
+
end
|
117
|
+
it "[!7fhx1] unlinks reference between parent and child." do
|
118
|
+
p = Oktest::Node.new(nil)
|
119
|
+
c1 = Oktest::Node.new(p)
|
120
|
+
c2 = Oktest::Node.new(p)
|
121
|
+
p.remove_child_at(1)
|
122
|
+
assert_eq c2.parent, nil
|
123
|
+
assert_eq c1.parent, p
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#clear_children()' do
|
128
|
+
it "[!o8xfb] removes all children." do
|
129
|
+
p = Oktest::Node.new(nil)
|
130
|
+
p.add_child(Oktest::Node.new(nil))
|
131
|
+
p.add_child(Oktest::Node.new(nil))
|
132
|
+
assert_eq p.has_child?, true
|
133
|
+
p.clear_children()
|
134
|
+
assert_eq p.has_child?, false
|
135
|
+
end
|
136
|
+
it "[!cvaq1] return self." do
|
137
|
+
p = Oktest::Node.new(nil)
|
138
|
+
assert p.clear_children().equal?(p)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#unlink_parent()' do
|
143
|
+
it "[!59m52] clears '@parent' instance variable." do
|
144
|
+
p = Oktest::Node.new(nil)
|
145
|
+
c = Oktest::Node.new(p)
|
146
|
+
assert_eq c.parent, p
|
147
|
+
c.unlink_parent()
|
148
|
+
assert_eq c.parent, nil
|
149
|
+
end
|
150
|
+
it "[!qksxv] returns parent object." do
|
151
|
+
p = Oktest::Node.new(nil)
|
152
|
+
c = Oktest::Node.new(p)
|
153
|
+
ret = c.unlink_parent()
|
154
|
+
assert_eq ret, p
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#run_block_in_context_class()' do
|
159
|
+
it "[!j9qdh] run block in context class." do
|
160
|
+
x = Oktest::Node.new(nil)
|
161
|
+
x.run_block_in_context_class { @_tmpvar = "<<00807>>" }
|
162
|
+
val = x.context_class.instance_variable_get('@_tmpvar')
|
163
|
+
assert_eq val, "<<00807>>"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '#new_context_object()' do
|
168
|
+
it "[!p271z] creates new context object." do
|
169
|
+
x = Oktest::Node.new(nil)
|
170
|
+
ctx = x.new_context_object()
|
171
|
+
assert_eq ctx.class, x.context_class
|
172
|
+
assert ctx.is_a?(Oktest::Context)
|
173
|
+
end
|
174
|
+
it "[!9hbxn] context object has 'ok()' method." do
|
175
|
+
x = Oktest::Node.new(nil)
|
176
|
+
ctx = x.new_context_object()
|
177
|
+
assert ctx.respond_to?(:ok)
|
178
|
+
assert ctx.respond_to?(:not_ok)
|
179
|
+
assert ctx.respond_to?(:skip_when)
|
180
|
+
assert ctx.respond_to?(:at_end)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#register_fixture_block()' do
|
185
|
+
it "[!5ctsn] registers fixture name, block, and location." do
|
186
|
+
x = Oktest::Node.new(nil)
|
187
|
+
x.register_fixture_block(:foo, "file:123") {|a, b| "foobar" }
|
188
|
+
assert x.fixtures[:foo][0].is_a?(Proc), "proc object expected"
|
189
|
+
assert_eq x.fixtures[:foo][0].call(1, 2), "foobar"
|
190
|
+
assert_eq x.fixtures[:foo][1], [:a, :b]
|
191
|
+
assert_eq x.fixtures[:foo][2], "file:123"
|
192
|
+
#
|
193
|
+
x.register_fixture_block(:bar, "file:345") { "barbar" }
|
194
|
+
assert_eq x.fixtures[:bar][0].call(), "barbar"
|
195
|
+
assert_eq x.fixtures[:bar][1], nil
|
196
|
+
assert_eq x.fixtures[:bar][2], "file:345"
|
197
|
+
end
|
198
|
+
it "[!hfcvo] returns self." do
|
199
|
+
x = Oktest::Node.new(nil)
|
200
|
+
ret = x.register_fixture_block(:foo, "file:123") { "foobar" }
|
201
|
+
assert ret.equal?(x)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe '#get_fixture_block()' do
|
206
|
+
it "[!f0105] returns fixture info." do
|
207
|
+
x = Oktest::Node.new(nil)
|
208
|
+
x.fixtures[:foo] = ["block", [:a, :b], "file:123"]
|
209
|
+
assert_eq x.get_fixture_block(:foo), ["block", [:a, :b], "file:123"]
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#register_hook_block()' do
|
214
|
+
it "[!zb66o] registers block with key." do
|
215
|
+
x = Oktest::Node.new(nil)
|
216
|
+
x.register_hook_block(:before) { "<<42533>>" }
|
217
|
+
x.register_hook_block(:after) { "<<46675>>" }
|
218
|
+
assert_eq x.hooks[:before].call(), "<<42533>>"
|
219
|
+
assert_eq x.hooks[:after].call(), "<<46675>>"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe '#get_hook_block()' do
|
224
|
+
it "[!u3fc6] returns block corresponding to key." do
|
225
|
+
x = Oktest::Node.new(nil)
|
226
|
+
x.register_hook_block(:before) { "<<42533>>" }
|
227
|
+
x.register_hook_block(:after) { "<<46675>>" }
|
228
|
+
assert_eq x.get_hook_block(:before).call(), "<<42533>>"
|
229
|
+
assert_eq x.get_hook_block(:after).call(), "<<46675>>"
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe '#_repr()' do
|
234
|
+
it "[!bt5j8] builds debug string." do
|
235
|
+
p = Oktest::Node.new(nil)
|
236
|
+
c = Oktest::Node.new(p)
|
237
|
+
p.add_child(c)
|
238
|
+
expected = <<'END'
|
239
|
+
- #<Oktest::Node:0x[0-9a-f]+>
|
240
|
+
@context_class: #<Class:0x[0-9a-f]+>
|
241
|
+
- #<Oktest::Node:0x[0-9a-f]+>
|
242
|
+
@context_class: #<Class:0x[0-9a-f]+>
|
243
|
+
@parent: #<Oktest::Node:0x[0-9a-f]+>
|
244
|
+
END
|
245
|
+
result = p._repr()
|
246
|
+
#assert_eq result, expected
|
247
|
+
assert result =~ Regexp.compile('\A'+expected), "not matched"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
class ScopeNode_TC < TC
|
255
|
+
|
256
|
+
describe '#accept_visitor()' do
|
257
|
+
class DummyVisitor
|
258
|
+
def visit_scope(*args)
|
259
|
+
@_args = args
|
260
|
+
"<<43746>>"
|
261
|
+
end
|
262
|
+
attr_reader :_args
|
263
|
+
end
|
264
|
+
it "[!vr6ko] invokes 'visit_spec()' method of visitor and returns result of it." do
|
265
|
+
dummy = DummyVisitor.new()
|
266
|
+
sc = Oktest::ScopeNode.new(nil, __FILE__)
|
267
|
+
ret = sc.accept_visitor(dummy, 1, 2, 3)
|
268
|
+
assert_eq dummy._args, [sc, 1, 2, 3]
|
269
|
+
assert_eq ret, "<<43746>>"
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
class TopicNode_TC < TC
|
277
|
+
|
278
|
+
def new_topic(target, tag: nil)
|
279
|
+
return Oktest::TopicNode.new(nil, target, tag: tag)
|
280
|
+
end
|
281
|
+
|
282
|
+
describe '#accept_visitor()' do
|
283
|
+
class DummyVisitor2
|
284
|
+
def visit_topic(*args)
|
285
|
+
@_args = args
|
286
|
+
"<<55977>>"
|
287
|
+
end
|
288
|
+
attr_reader :_args
|
289
|
+
end
|
290
|
+
it "[!c1b33] invokes 'visit_topic()' method of visitor and returns result of it." do
|
291
|
+
dummy = DummyVisitor2.new
|
292
|
+
to = Oktest::TopicNode.new(nil, Array)
|
293
|
+
ret = to.accept_visitor(dummy, 4, 5)
|
294
|
+
assert_eq dummy._args, [to, 4, 5]
|
295
|
+
assert_eq ret, "<<55977>>"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
describe '#@+' do
|
300
|
+
it "[!tzorv] returns self." do
|
301
|
+
to = new_topic('#foobar()')
|
302
|
+
assert (+ to).equal?(to), "should be same"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
|
309
|
+
class ScopeFunctions_TC < TC
|
310
|
+
|
311
|
+
def startup
|
312
|
+
end
|
313
|
+
|
314
|
+
def teardown
|
315
|
+
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
316
|
+
end
|
317
|
+
|
318
|
+
describe 'Oktest.scope()' do
|
319
|
+
it "[!vxoy1] creates new scope object." do
|
320
|
+
x = Oktest.scope() { nil }
|
321
|
+
assert_eq x.class, Oktest::ScopeNode
|
322
|
+
end
|
323
|
+
it "[!jmc4q] raises error when nested called." do
|
324
|
+
begin ; x = 0
|
325
|
+
assert_exc(Oktest::OktestError, "scope() and global_scope() are not nestable.") do
|
326
|
+
; x = 1
|
327
|
+
Oktest.scope do ; x = 2
|
328
|
+
Oktest.scope do ; x = 3
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
assert_eq x, 2
|
333
|
+
ensure
|
334
|
+
Oktest.module_eval { @_in_scope = false }
|
335
|
+
end
|
336
|
+
end
|
337
|
+
it "[!rsimc] adds scope object as child of THE_GLOBAL_SCOPE." do
|
338
|
+
assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, false
|
339
|
+
so = Oktest.scope do
|
340
|
+
end
|
341
|
+
assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, true
|
342
|
+
assert_eq Oktest::THE_GLOBAL_SCOPE.each_child.to_a, [so]
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
describe '#global_scope()' do
|
347
|
+
it "[!fcmt2] not create new scope object." do
|
348
|
+
go1 = Oktest.global_scope() { nil }
|
349
|
+
assert_eq go1.class, Oktest::ScopeNode
|
350
|
+
go2 = Oktest.global_scope() { nil }
|
351
|
+
assert_eq go2, go1
|
352
|
+
assert_eq go2, Oktest::THE_GLOBAL_SCOPE
|
353
|
+
end
|
354
|
+
it "[!flnpc] run block in the THE_GLOBAL_SCOPE object." do
|
355
|
+
Oktest.global_scope do
|
356
|
+
fixture :tmp_37531 do
|
357
|
+
{id: 37531}
|
358
|
+
end
|
359
|
+
end
|
360
|
+
assert Oktest::THE_GLOBAL_SCOPE.fixtures.key?(:tmp_37531)
|
361
|
+
v = Oktest::THE_GLOBAL_SCOPE.fixtures[:tmp_37531][0].call
|
362
|
+
assert_eq v, {id: 37531}
|
363
|
+
end
|
364
|
+
it "[!pe0g2] raises error when nested called." do
|
365
|
+
args = [Oktest::OktestError, "scope() and global_scope() are not nestable."]
|
366
|
+
begin ; x = 0
|
367
|
+
assert_exc(*args) do ; x = 1
|
368
|
+
Oktest.global_scope do ; x = 2
|
369
|
+
Oktest.global_scope do ; x = 3
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
assert_eq x, 2
|
374
|
+
ensure
|
375
|
+
Oktest.module_eval { @_in_scope = false }
|
376
|
+
end
|
377
|
+
#
|
378
|
+
begin ; x = 0
|
379
|
+
assert_exc(*args) do ; x = 1
|
380
|
+
Oktest.scope do ; x = 2
|
381
|
+
Oktest.global_scope do ; x = 3
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
assert_eq x, 2
|
386
|
+
ensure
|
387
|
+
Oktest.module_eval { @_in_scope = false }
|
388
|
+
end
|
389
|
+
#
|
390
|
+
begin ; x = 0
|
391
|
+
assert_exc(*args) do ; x = 1
|
392
|
+
Oktest.global_scope do ; x = 2
|
393
|
+
Oktest.scope do ; x = 3
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
assert_eq x, 2
|
398
|
+
ensure
|
399
|
+
Oktest.module_eval { @_in_scope = false }
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
406
|
+
|
407
|
+
class Context_TC < TC
|
408
|
+
|
409
|
+
def new_node_with(&b)
|
410
|
+
node = Oktest::Node.new(nil)
|
411
|
+
cls = Class.new(Oktest::Context)
|
412
|
+
cls.__node = node
|
413
|
+
cls.class_eval(&b)
|
414
|
+
return node
|
415
|
+
end
|
416
|
+
|
417
|
+
describe '#topic()' do
|
418
|
+
it "[!0gfvq] creates new topic node." do
|
419
|
+
node = new_node_with() do
|
420
|
+
topic Dir, tag: "exp" do
|
421
|
+
end
|
422
|
+
end
|
423
|
+
assert_eq node.each_child.to_a.length, 1
|
424
|
+
to = node.each_child.first
|
425
|
+
assert_eq to.class, Oktest::TopicNode
|
426
|
+
assert_eq to.target, Dir
|
427
|
+
assert_eq to.tag, "exp"
|
428
|
+
assert_eq to._prefix, "*"
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
describe '#case_when()' do
|
433
|
+
it "[!g3cvh] returns topic object." do
|
434
|
+
node = new_node_with() do
|
435
|
+
case_when "condition..." do
|
436
|
+
end
|
437
|
+
end
|
438
|
+
assert_eq node.each_child.to_a.length, 1
|
439
|
+
to = node.each_child.first
|
440
|
+
assert_eq to.class, Oktest::TopicNode
|
441
|
+
assert_eq to.target, "When condition..."
|
442
|
+
assert_eq to.tag, nil
|
443
|
+
assert_eq to._prefix, "-"
|
444
|
+
end
|
445
|
+
it "[!ofw1i] target is a description starting with 'When '." do
|
446
|
+
node = new_node_with() do
|
447
|
+
case_when "condition..." do
|
448
|
+
end
|
449
|
+
end
|
450
|
+
to = node.each_child.first
|
451
|
+
assert_eq to.target, "When condition..."
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
describe '#case_else()' do
|
456
|
+
it "[!oww4b] returns topic object." do
|
457
|
+
node = new_node_with() do
|
458
|
+
case_else tag: "dev" do
|
459
|
+
end
|
460
|
+
end
|
461
|
+
assert_eq node.each_child.to_a.length, 1
|
462
|
+
to = node.each_child.first
|
463
|
+
assert_eq to.class, Oktest::TopicNode
|
464
|
+
assert_eq to.target, "Else"
|
465
|
+
assert_eq to.tag, "dev"
|
466
|
+
assert_eq to._prefix, "-"
|
467
|
+
end
|
468
|
+
it "[!j5gnp] target is a description which is 'Else'." do
|
469
|
+
node = new_node_with() do
|
470
|
+
case_else do
|
471
|
+
end
|
472
|
+
end
|
473
|
+
assert_eq node.each_child.to_a.length, 1
|
474
|
+
to = node.each_child.first
|
475
|
+
assert_eq to.class, Oktest::TopicNode
|
476
|
+
assert_eq to.target, "Else"
|
477
|
+
end
|
478
|
+
it "[!hs1to] 1st parameter is optional." do
|
479
|
+
node = new_node_with() do
|
480
|
+
case_else "(x < 0)" do
|
481
|
+
end
|
482
|
+
end
|
483
|
+
assert_eq node.each_child.to_a.length, 1
|
484
|
+
to = node.each_child.first
|
485
|
+
assert_eq to.class, Oktest::TopicNode
|
486
|
+
assert_eq to.target, "Else (x < 0)"
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
describe '#scope()' do
|
491
|
+
it "[!c8c8o] creates new spec object." do
|
492
|
+
node = new_node_with() do
|
493
|
+
spec "example #1", tag: "exp" do
|
494
|
+
end
|
495
|
+
end
|
496
|
+
assert_eq node.each_child.to_a.length, 1
|
497
|
+
sp = node.each_child.first
|
498
|
+
assert_eq sp.class, Oktest::SpecLeaf
|
499
|
+
assert_eq sp.desc, "example #1"
|
500
|
+
assert_eq sp.tag, "exp"
|
501
|
+
assert_eq sp._prefix, "-"
|
502
|
+
end
|
503
|
+
it "[!ala78] provides raising TodoException block if block not given." do
|
504
|
+
node = new_node_with() do
|
505
|
+
spec "example #3"
|
506
|
+
end
|
507
|
+
assert_eq node.each_child.to_a.length, 1
|
508
|
+
sp = node.each_child.first
|
509
|
+
assert_exc(Oktest::TodoException, "not implemented yet") do
|
510
|
+
sp.block.call
|
511
|
+
end
|
512
|
+
end
|
513
|
+
it "[!x48db] keeps called location only when block has parameters." do
|
514
|
+
lineno = __LINE__ + 3
|
515
|
+
node = new_node_with() do
|
516
|
+
spec "example #4" do nil end
|
517
|
+
spec "example #5" do |x| nil end
|
518
|
+
end
|
519
|
+
sp1, sp2 = node.each_child.to_a
|
520
|
+
assert_eq sp1.location, nil
|
521
|
+
assert sp2.location != nil, "not nil"
|
522
|
+
assert sp2.location.start_with?("#{__FILE__}:#{lineno}:in")
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
describe '#fixture()' do
|
527
|
+
it "[!8wfrq] registers fixture factory block." do
|
528
|
+
lineno = __LINE__ + 2
|
529
|
+
node = new_node_with() do
|
530
|
+
fixture :alice do
|
531
|
+
{name: "alice"}
|
532
|
+
end
|
533
|
+
end
|
534
|
+
assert_eq node.fixtures.length, 1
|
535
|
+
assert node.fixtures.key?(:alice), "key not registerd"
|
536
|
+
assert node.fixtures[:alice][0].is_a?(Proc), "block expected"
|
537
|
+
assert_eq node.fixtures[:alice][1], nil
|
538
|
+
assert node.fixtures[:alice][2].start_with?("#{__FILE__}:#{lineno}:in ")
|
539
|
+
end
|
540
|
+
it "[!y3ks3] retrieves block parameter names." do
|
541
|
+
node = new_node_with() do
|
542
|
+
fixture :bob do |x, y|
|
543
|
+
{name: "bob"}
|
544
|
+
end
|
545
|
+
end
|
546
|
+
assert_eq node.fixtures[:bob][1], [:x, :y]
|
547
|
+
#
|
548
|
+
node = new_node_with() do
|
549
|
+
fixture :charlie do
|
550
|
+
{name: "charlie"}
|
551
|
+
end
|
552
|
+
end
|
553
|
+
assert_eq node.fixtures[:charlie][1], nil
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
describe '#before() ' do
|
558
|
+
it "[!275zr] registers 'before' hook block." do
|
559
|
+
x = new_node_with() do
|
560
|
+
before { "<<78059>>" }
|
561
|
+
end
|
562
|
+
assert_eq x.get_hook_block(:before).call(), "<<78059>>"
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
describe '#after() ' do
|
567
|
+
it "[!ngkvz] registers 'after' hook block." do
|
568
|
+
x = new_node_with() do
|
569
|
+
after { "<<52091>>" }
|
570
|
+
end
|
571
|
+
assert_eq x.get_hook_block(:after).call(), "<<52091>>"
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
describe '#before_all() ' do
|
576
|
+
it "[!8v1y4] registers 'before_all' hook block." do
|
577
|
+
x = new_node_with() do
|
578
|
+
before_all { "<<42577>>" }
|
579
|
+
end
|
580
|
+
assert_eq x.get_hook_block(:before_all).call(), "<<42577>>"
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
describe '#after_all() ' do
|
585
|
+
it "[!0w5ik] registers 'after_all' hook block." do
|
586
|
+
x = new_node_with() do
|
587
|
+
after_all { "<<33326>>" }
|
588
|
+
end
|
589
|
+
assert_eq x.get_hook_block(:after_all).call(), "<<33326>>"
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
end
|
594
|
+
|
595
|
+
|
596
|
+
class SpecLeafTC < TC
|
597
|
+
|
598
|
+
def startup
|
599
|
+
end
|
600
|
+
|
601
|
+
def teardown
|
602
|
+
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
603
|
+
end
|
604
|
+
|
605
|
+
def new_spec_object(desc="sample #1", tag: nil)
|
606
|
+
sp = nil
|
607
|
+
Oktest.scope do
|
608
|
+
topic 'Example' do
|
609
|
+
sp = spec(desc, tag: tag) { nil }
|
610
|
+
end
|
611
|
+
end
|
612
|
+
return sp
|
613
|
+
end
|
614
|
+
|
615
|
+
describe '#run_block_in_context_object()' do
|
616
|
+
it "[!tssim] run spec block in text object." do
|
617
|
+
to = Oktest::TopicNode.new(nil, 'Example')
|
618
|
+
sp = Oktest::SpecLeaf.new(to, "#sample 2") { @called = "<<29193>>" }
|
619
|
+
ctx = to.new_context_object()
|
620
|
+
assert_eq ctx.instance_variable_get('@called'), nil
|
621
|
+
sp.run_block_in_context_object(ctx)
|
622
|
+
assert_eq ctx.instance_variable_get('@called'), "<<29193>>"
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
describe '#accept_visitor()' do
|
627
|
+
class DummyVisitor3
|
628
|
+
def visit_spec(*args)
|
629
|
+
@_args = args
|
630
|
+
"<<82980>>"
|
631
|
+
end
|
632
|
+
attr_reader :_args
|
633
|
+
end
|
634
|
+
it "[!ya32z] invokes 'visit_spec()' method of visitor and returns result of it." do
|
635
|
+
dummy = DummyVisitor3.new
|
636
|
+
sc = Oktest::SpecLeaf.new(nil, "sample")
|
637
|
+
ret = sc.accept_visitor(dummy, 7, 8)
|
638
|
+
assert_eq dummy._args, [sc, 7, 8]
|
639
|
+
assert_eq ret, "<<82980>>"
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
describe '#unlink_parent()' do
|
644
|
+
it "[!e9sv9] do nothing." do
|
645
|
+
to = Oktest::TopicNode.new(nil, "sample")
|
646
|
+
sp = Oktest::SpecLeaf.new(to, "sample")
|
647
|
+
ret = sp.unlink_parent()
|
648
|
+
assert_eq ret, nil
|
649
|
+
end
|
650
|
+
end
|
651
|
+
|
652
|
+
describe '#_repr()' do
|
653
|
+
it "[!6nsgy] builds debug string." do
|
654
|
+
sp1 = new_spec_object("sample #1")
|
655
|
+
assert_eq sp1._repr(), "- sample #1\n"
|
656
|
+
sp2 = new_spec_object("sample #2", tag: "exp")
|
657
|
+
assert_eq sp2._repr(), "- sample #2 (tag: \"exp\")\n"
|
658
|
+
assert_eq sp2._repr(2), " - sample #2 (tag: \"exp\")\n"
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
describe '#@-' do
|
663
|
+
it "[!bua80] returns self." do
|
664
|
+
sp = new_spec_object("sample #1")
|
665
|
+
assert (- sp).equal?(sp), "should be same"
|
666
|
+
end
|
667
|
+
end
|
668
|
+
|
669
|
+
end
|