oktest 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -5
- data/Rakefile.rb +1 -1
- data/lib/oktest.rb +32 -9
- data/oktest.gemspec +3 -3
- data/test/assertion_test.rb +229 -227
- data/test/filter_test.rb +122 -120
- data/test/fixture_test.rb +33 -32
- data/test/generator_test.rb +20 -19
- data/test/helper_test.rb +280 -274
- data/test/init.rb +44 -0
- data/test/mainapp_test.rb +194 -190
- data/test/matcher_test.rb +156 -126
- data/test/misc_test.rb +31 -30
- data/test/nanot.rb +307 -0
- data/test/node_test.rb +296 -252
- data/test/reporter_test.rb +249 -208
- data/test/runner_test.rb +101 -100
- data/test/util_test.rb +196 -193
- data/test/utilhelper_test.rb +35 -38
- data/test/visitor_test.rb +54 -50
- metadata +10 -10
- data/test/initialize.rb +0 -22
- data/test/tc.rb +0 -128
- /data/test/{run_all.rb → all.rb} +0 -0
data/test/runner_test.rb
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
###
|
5
|
-
### $Release: 1.
|
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 './
|
10
|
+
require_relative './init'
|
11
11
|
|
12
12
|
|
13
|
-
class
|
13
|
+
class Runner__Test
|
14
|
+
extend NanoTest
|
14
15
|
|
15
16
|
class DummyReporter < Oktest::Reporter
|
16
17
|
def enter_all(runner); end
|
@@ -49,7 +50,7 @@ class Runner_TC < TC
|
|
49
50
|
def order_policy; :spec_first; end
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
+
test_target 'Oktest::Runner#start()' do
|
53
54
|
build_topics = proc {
|
54
55
|
Oktest.scope do
|
55
56
|
topic "Parent" do
|
@@ -61,8 +62,8 @@ class Runner_TC < TC
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
}
|
64
|
-
|
65
|
-
sout, serr =
|
65
|
+
test_subject "[!xrisl] runs topics and specs." do
|
66
|
+
sout, serr = capture_output! do
|
66
67
|
build_topics.call
|
67
68
|
Oktest::Runner.new(DummyReporter.new).start()
|
68
69
|
end
|
@@ -76,22 +77,22 @@ topic: "Parent"
|
|
76
77
|
/topic
|
77
78
|
/file
|
78
79
|
END
|
79
|
-
|
80
|
-
|
80
|
+
test_eq? sout, expected
|
81
|
+
test_eq? serr, ""
|
81
82
|
end
|
82
|
-
|
83
|
-
|
84
|
-
sout, serr =
|
83
|
+
test_subject "[!dth2c] clears toplvel scope list." do
|
84
|
+
test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, false
|
85
|
+
sout, serr = capture_output! do
|
85
86
|
build_topics.call
|
86
|
-
|
87
|
+
test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, true
|
87
88
|
Oktest::Runner.new(DummyReporter.new).start()
|
88
89
|
end
|
89
|
-
|
90
|
+
test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, false
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
test_target 'Oktest::Runner#visit_spec()' do
|
95
|
+
test_subject "[!yd24o] runs spec body, catching assertions or exceptions." do
|
95
96
|
Oktest.scope do
|
96
97
|
topic "Parent" do
|
97
98
|
topic "Child" do
|
@@ -105,7 +106,7 @@ END
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
end
|
108
|
-
sout, serr =
|
109
|
+
sout, serr = capture_output! do
|
109
110
|
runner = Oktest::Runner.new(DummyReporter.new).start()
|
110
111
|
end
|
111
112
|
expected = <<'END'
|
@@ -149,10 +150,10 @@ END
|
|
149
150
|
/topic
|
150
151
|
/file
|
151
152
|
END
|
152
|
-
|
153
|
-
|
153
|
+
test_eq? sout, expected
|
154
|
+
test_eq? serr, ""
|
154
155
|
end
|
155
|
-
|
156
|
+
test_subject "[!u45di] runs spec block with context object which allows to call methods defined in topics." do
|
156
157
|
Oktest.scope do
|
157
158
|
def v1; "V1"; end
|
158
159
|
topic "Parent" do
|
@@ -160,14 +161,14 @@ END
|
|
160
161
|
topic "Child" do
|
161
162
|
def v3; "V3"; end
|
162
163
|
spec "spec#1" do
|
163
|
-
p v1
|
164
|
-
p v2
|
165
|
-
p v3
|
164
|
+
p v1()
|
165
|
+
p v2()
|
166
|
+
p v3()
|
166
167
|
end
|
167
168
|
end
|
168
169
|
end
|
169
170
|
end
|
170
|
-
sout, serr =
|
171
|
+
sout, serr = capture_output! do
|
171
172
|
runner = Oktest::Runner.new(DummyReporter.new).start()
|
172
173
|
end
|
173
174
|
expected = <<'END'
|
@@ -183,11 +184,11 @@ topic: "Parent"
|
|
183
184
|
/topic
|
184
185
|
/file
|
185
186
|
END
|
186
|
-
|
187
|
-
|
187
|
+
test_eq? sout, expected
|
188
|
+
test_eq? serr, ""
|
188
189
|
end
|
189
|
-
|
190
|
-
sout, serr =
|
190
|
+
test_subject "[!yagka] calls 'before' and 'after' blocks with context object as self." do
|
191
|
+
sout, serr = capture_output! do
|
191
192
|
Oktest.scope do
|
192
193
|
before { @x ||= 1; puts " [all] before: @x=#{@x}" }
|
193
194
|
after { puts " [all] after: @x=#{@x}" }
|
@@ -250,11 +251,11 @@ topic: "Parent"
|
|
250
251
|
/topic
|
251
252
|
/file
|
252
253
|
END
|
253
|
-
|
254
|
-
|
254
|
+
test_eq? sout, expected
|
255
|
+
test_eq? serr, ""
|
255
256
|
end
|
256
|
-
|
257
|
-
sout, serr =
|
257
|
+
test_subject "[!76g7q] calls 'after' blocks even when exception raised." do
|
258
|
+
sout, serr = capture_output! do
|
258
259
|
Oktest.scope do
|
259
260
|
after { puts "[all] after" }
|
260
261
|
topic "Parent" do
|
@@ -282,11 +283,11 @@ topic: "Parent"
|
|
282
283
|
/topic
|
283
284
|
/file
|
284
285
|
END
|
285
|
-
|
286
|
-
|
286
|
+
test_eq? sout, expected
|
287
|
+
test_eq? serr, ""
|
287
288
|
end
|
288
|
-
|
289
|
-
sout, serr =
|
289
|
+
test_subject "[!dihkr] calls 'at_end' blocks, even when exception raised." do
|
290
|
+
sout, serr = capture_output! do
|
290
291
|
Oktest.scope do
|
291
292
|
topic "topic#A" do
|
292
293
|
spec("spec#1") { at_end { puts " - at_end A1" } }
|
@@ -324,17 +325,17 @@ END
|
|
324
325
|
/topic
|
325
326
|
/file
|
326
327
|
END
|
327
|
-
|
328
|
-
|
328
|
+
test_eq? sout, expected
|
329
|
+
test_eq? serr, ""
|
329
330
|
end
|
330
|
-
|
331
|
-
|
331
|
+
test_when "[!68cnr] if TODO() called in spec..." do
|
332
|
+
test_subject "[!6ol3p] changes PASS status to FAIL because test passed unexpectedly." do
|
332
333
|
Oktest.scope do
|
333
334
|
topic "topic#A" do
|
334
335
|
spec("spec#1") { TODO(); ok {1+1} == 2 } # passed unexpectedly
|
335
336
|
end
|
336
337
|
end
|
337
|
-
sout, serr =
|
338
|
+
sout, serr = capture_output! { Oktest::Runner.new(DummyReporter.new).start() }
|
338
339
|
expected = <<'END'
|
339
340
|
file: "test/runner_test.rb"
|
340
341
|
topic: "topic#A"
|
@@ -343,15 +344,15 @@ topic: "topic#A"
|
|
343
344
|
/topic
|
344
345
|
/file
|
345
346
|
END
|
346
|
-
|
347
|
+
test_eq? sout, expected
|
347
348
|
end
|
348
|
-
|
349
|
+
test_subject "[!6syw4] changes FAIL status to TODO because test failed expectedly." do
|
349
350
|
Oktest.scope do
|
350
351
|
topic "topic#A" do
|
351
352
|
spec("spec#1") { TODO(); ok {1+1} == 1 } # failed expectedly
|
352
353
|
end
|
353
354
|
end
|
354
|
-
sout, serr =
|
355
|
+
sout, serr = capture_output! { Oktest::Runner.new(DummyReporter.new).start() }
|
355
356
|
expected = <<'END'
|
356
357
|
file: "test/runner_test.rb"
|
357
358
|
topic: "topic#A"
|
@@ -360,15 +361,15 @@ topic: "topic#A"
|
|
360
361
|
/topic
|
361
362
|
/file
|
362
363
|
END
|
363
|
-
|
364
|
+
test_eq? sout, expected
|
364
365
|
end
|
365
|
-
|
366
|
+
test_subject "[!4aecm] changes also ERROR status to TODO because test failed expectedly." do
|
366
367
|
Oktest.scope do
|
367
368
|
topic "topic#B" do
|
368
369
|
spec("spec#2") { TODO(); ok {foobar} == nil } # will be error expectedly
|
369
370
|
end
|
370
371
|
end
|
371
|
-
sout, serr =
|
372
|
+
sout, serr = capture_output! { Oktest::Runner.new(DummyReporter.new).start() }
|
372
373
|
expected = <<'END'
|
373
374
|
file: "test/runner_test.rb"
|
374
375
|
topic: "topic#B"
|
@@ -377,14 +378,14 @@ topic: "topic#B"
|
|
377
378
|
/topic
|
378
379
|
/file
|
379
380
|
END
|
380
|
-
|
381
|
+
test_eq? sout, expected
|
381
382
|
end
|
382
383
|
end
|
383
384
|
end
|
384
385
|
|
385
|
-
|
386
|
-
|
387
|
-
sout, serr =
|
386
|
+
test_target 'Oktest::Runner#visit_topic()' do
|
387
|
+
test_subject "[!i3yfv] calls 'before_all' and 'after_all' blocks." do
|
388
|
+
sout, serr = capture_output! do
|
388
389
|
Oktest.scope do
|
389
390
|
before_all { puts "[all] before_all" }
|
390
391
|
after_all { puts "[all] after_all" }
|
@@ -429,11 +430,11 @@ topic: "Parent"
|
|
429
430
|
[all] after_all
|
430
431
|
/file
|
431
432
|
END
|
432
|
-
|
433
|
-
|
433
|
+
test_eq? sout, expected
|
434
|
+
test_eq? serr, ""
|
434
435
|
end
|
435
|
-
|
436
|
-
sout, serr =
|
436
|
+
test_subject "[!p3a5o] run specs and case_when in advance of specs and topics when SimpleReporter." do
|
437
|
+
sout, serr = capture_output! do
|
437
438
|
Oktest.scope do
|
438
439
|
topic "T1" do
|
439
440
|
topic "T2" do
|
@@ -470,14 +471,14 @@ topic: "T1"
|
|
470
471
|
/topic
|
471
472
|
/file
|
472
473
|
END
|
473
|
-
|
474
|
-
|
474
|
+
test_eq? sout, expected
|
475
|
+
test_eq? serr, ""
|
475
476
|
end
|
476
477
|
end
|
477
478
|
|
478
|
-
|
479
|
-
|
480
|
-
sout, serr =
|
479
|
+
test_target 'Oktest::Runner#visit_scope()' do
|
480
|
+
test_subject "[!5anr7] calls before_all and after_all blocks." do
|
481
|
+
sout, serr = capture_output! do
|
481
482
|
Oktest.scope do
|
482
483
|
before_all { puts "[all] before_all#1" }
|
483
484
|
after_all { puts "[all] after_all#1" }
|
@@ -498,11 +499,11 @@ file: "test/runner_test.rb"
|
|
498
499
|
[all] after_all#2
|
499
500
|
/file
|
500
501
|
END
|
501
|
-
|
502
|
-
|
502
|
+
test_eq? sout, expected
|
503
|
+
test_eq? serr, ""
|
503
504
|
end
|
504
|
-
|
505
|
-
sout, serr =
|
505
|
+
test_subject "[!c5cw0] run specs and case_when in advance of specs and topics when SimpleReporter." do
|
506
|
+
sout, serr = capture_output! do
|
506
507
|
Oktest.scope do
|
507
508
|
topic "T1" do
|
508
509
|
spec("S1") { ok {1+1} == 2 }
|
@@ -538,8 +539,8 @@ topic: "T3"
|
|
538
539
|
/topic
|
539
540
|
/file
|
540
541
|
END
|
541
|
-
|
542
|
-
|
542
|
+
test_eq? sout, expected
|
543
|
+
test_eq? serr, ""
|
543
544
|
end
|
544
545
|
end
|
545
546
|
|
@@ -547,16 +548,16 @@ END
|
|
547
548
|
end
|
548
549
|
|
549
550
|
|
550
|
-
class
|
551
|
+
class OktestFunctions__Test
|
552
|
+
extend NanoTest
|
551
553
|
|
552
|
-
def
|
553
|
-
|
554
|
-
|
555
|
-
def teardown()
|
554
|
+
def self.test_subject(desc, &b)
|
555
|
+
super
|
556
|
+
ensure
|
556
557
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
557
558
|
end
|
558
559
|
|
559
|
-
def edit_actual(output)
|
560
|
+
def self.edit_actual(output)
|
560
561
|
bkup = output.dup
|
561
562
|
output = output.gsub(/^.*\r/, '')
|
562
563
|
output = output.gsub(/^ .*(_test\.tmp:\d+)/, ' \1')
|
@@ -565,13 +566,13 @@ class RunnerFunctions_TC < TC
|
|
565
566
|
return output
|
566
567
|
end
|
567
568
|
|
568
|
-
def edit_expected(expected)
|
569
|
+
def self.edit_expected(expected)
|
569
570
|
expected = expected.gsub(/^ (.*:\d+)(:in `block .*)/, ' \1') if RUBY_VERSION < "1.9"
|
570
571
|
expected = plain2colored(expected)
|
571
572
|
return expected
|
572
573
|
end
|
573
574
|
|
574
|
-
def prepare()
|
575
|
+
def self.prepare()
|
575
576
|
Oktest.scope do
|
576
577
|
topic 'Example' do
|
577
578
|
spec '1+1 should be 2' do
|
@@ -584,55 +585,55 @@ class RunnerFunctions_TC < TC
|
|
584
585
|
end
|
585
586
|
end
|
586
587
|
|
587
|
-
|
588
|
+
verbose_output = <<'END'
|
588
589
|
## test/runner_test.rb
|
589
590
|
* <b>Example</b>
|
590
591
|
- [<C>pass</C>] 1+1 should be 2
|
591
592
|
- [<C>pass</C>] 1-1 should be 0
|
592
593
|
## total:2 (<C>pass:2</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
593
594
|
END
|
594
|
-
|
595
|
+
compact_output = <<'END'
|
595
596
|
test/runner_test.rb: <C>.</C><C>.</C>
|
596
597
|
## total:2 (<C>pass:2</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
597
598
|
END
|
598
|
-
|
599
|
+
plain_output = <<'END'
|
599
600
|
<C>.</C><C>.</C>
|
600
601
|
## total:2 (<C>pass:2</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
601
602
|
END
|
602
603
|
|
603
604
|
|
604
|
-
|
605
|
-
|
606
|
-
expected =
|
605
|
+
test_target 'Oktest.run()' do
|
606
|
+
test_subject "[!mn451] run test cases." do
|
607
|
+
expected = verbose_output
|
607
608
|
prepare()
|
608
|
-
sout, serr =
|
609
|
-
|
610
|
-
|
609
|
+
sout, serr = capture_output! { Oktest.run() }
|
610
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
611
|
+
test_eq? serr, ""
|
611
612
|
end
|
612
|
-
|
613
|
-
expected =
|
613
|
+
test_subject "[!6xn3t] creates reporter object according to 'style:' keyword arg." do
|
614
|
+
expected = verbose_output
|
614
615
|
prepare()
|
615
|
-
sout, serr =
|
616
|
-
|
617
|
-
|
616
|
+
sout, serr = capture_output! { Oktest.run(:style=>"verbose") }
|
617
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
618
|
+
test_eq? serr, ""
|
618
619
|
#
|
619
|
-
expected =
|
620
|
+
expected = compact_output
|
620
621
|
prepare()
|
621
|
-
sout, serr =
|
622
|
-
|
623
|
-
|
622
|
+
sout, serr = capture_output! { Oktest.run(:style=>"compact") }
|
623
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
624
|
+
test_eq? serr, ""
|
624
625
|
#
|
625
|
-
expected =
|
626
|
+
expected = plain_output
|
626
627
|
prepare()
|
627
|
-
sout, serr =
|
628
|
-
|
629
|
-
|
628
|
+
sout, serr = capture_output! { Oktest.run(:style=>"plain") }
|
629
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
630
|
+
test_eq? serr, ""
|
630
631
|
end
|
631
|
-
|
632
|
+
test_subject "[!p52se] returns total number of failures and errors." do
|
632
633
|
prepare()
|
633
634
|
ret = nil
|
634
|
-
_ =
|
635
|
-
|
635
|
+
_ = capture_output! { ret = Oktest.run() }
|
636
|
+
test_eq? ret, 0 # no failures, no errors
|
636
637
|
#
|
637
638
|
Oktest.scope do
|
638
639
|
topic 'Example' do
|
@@ -643,8 +644,8 @@ END
|
|
643
644
|
spec('todo')
|
644
645
|
end
|
645
646
|
end
|
646
|
-
_ =
|
647
|
-
|
647
|
+
_ = capture_output! { ret = Oktest.run() }
|
648
|
+
test_eq? ret, 2 # 1 failure, 1 error
|
648
649
|
end
|
649
650
|
end
|
650
651
|
|