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