oktest 1.4.0 → 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.
data/test/runner_test.rb CHANGED
@@ -2,15 +2,16 @@
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 Runner_TC < TC
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
- describe "#start()" do
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
- it "[!xrisl] runs topics and specs." do
65
- sout, serr = capture do
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
- assert_eq sout, expected
80
- assert_eq serr, ""
80
+ test_eq? sout, expected
81
+ test_eq? serr, ""
81
82
  end
82
- it "[!dth2c] clears toplvel scope list." do
83
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, false
84
- sout, serr = capture do
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
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, true
87
+ test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, true
87
88
  Oktest::Runner.new(DummyReporter.new).start()
88
89
  end
89
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, false
90
+ test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, false
90
91
  end
91
92
  end
92
93
 
93
- describe "#visit_spec()" do
94
- it "[!yd24o] runs spec body, catching assertions or exceptions." do
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 = capture do
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
- assert_eq sout, expected
153
- assert_eq serr, ""
153
+ test_eq? sout, expected
154
+ test_eq? serr, ""
154
155
  end
155
- it "[!u45di] runs spec block with context object which allows to call methods defined in topics." do
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 = capture do
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
- assert_eq sout, expected
187
- assert_eq serr, ""
187
+ test_eq? sout, expected
188
+ test_eq? serr, ""
188
189
  end
189
- it "[!yagka] calls 'before' and 'after' blocks with context object as self." do
190
- sout, serr = capture do
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
- assert_eq sout, expected
254
- assert_eq serr, ""
254
+ test_eq? sout, expected
255
+ test_eq? serr, ""
255
256
  end
256
- it "[!76g7q] calls 'after' blocks even when exception raised." do
257
- sout, serr = capture do
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
- assert_eq sout, expected
286
- assert_eq serr, ""
286
+ test_eq? sout, expected
287
+ test_eq? serr, ""
287
288
  end
288
- it "[!dihkr] calls 'at_end' blocks, even when exception raised." do
289
- sout, serr = capture do
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
- assert_eq sout, expected
328
- assert_eq serr, ""
328
+ test_eq? sout, expected
329
+ test_eq? serr, ""
329
330
  end
330
- describe "[!68cnr] if TODO() called in spec..." do
331
- it "[!6ol3p] changes PASS status to FAIL because test passed unexpectedly." do
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 = capture { Oktest::Runner.new(DummyReporter.new).start() }
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
- assert_eq sout, expected
347
+ test_eq? sout, expected
347
348
  end
348
- it "[!6syw4] changes FAIL status to TODO because test failed expectedly." do
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 = capture { Oktest::Runner.new(DummyReporter.new).start() }
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
- assert_eq sout, expected
364
+ test_eq? sout, expected
364
365
  end
365
- it "[!4aecm] changes also ERROR status to TODO because test failed expectedly." do
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 = capture { Oktest::Runner.new(DummyReporter.new).start() }
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
- assert_eq sout, expected
381
+ test_eq? sout, expected
381
382
  end
382
383
  end
383
384
  end
384
385
 
385
- describe "#visit_topic()" do
386
- it "[!i3yfv] calls 'before_all' and 'after_all' blocks." do
387
- sout, serr = capture do
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
- assert_eq sout, expected
433
- assert_eq serr, ""
433
+ test_eq? sout, expected
434
+ test_eq? serr, ""
434
435
  end
435
- it "[!p3a5o] run specs and case_when in advance of specs and topics when SimpleReporter." do
436
- sout, serr = capture do
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
- assert_eq sout, expected
474
- assert_eq serr, ""
474
+ test_eq? sout, expected
475
+ test_eq? serr, ""
475
476
  end
476
477
  end
477
478
 
478
- describe "#visit_scope()" do
479
- it "[!5anr7] calls before_all and after_all blocks." do
480
- sout, serr = capture do
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
- assert_eq sout, expected
502
- assert_eq serr, ""
502
+ test_eq? sout, expected
503
+ test_eq? serr, ""
503
504
  end
504
- it "[!c5cw0] run specs and case_when in advance of specs and topics when SimpleReporter." do
505
- sout, serr = capture do
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
- assert_eq sout, expected
542
- assert_eq serr, ""
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 RunnerFunctions_TC < TC
551
+ class OktestFunctions__Test
552
+ extend NanoTest
551
553
 
552
- def setup()
553
- end
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
- VERBOSE_OUTPUT = <<'END'
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
- COMPACT_OUTPUT = <<'END'
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
- PLAIN_OUTPUT = <<'END'
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
- describe 'Oktest.run()' do
605
- it "[!mn451] run test cases." do
606
- expected = VERBOSE_OUTPUT
605
+ test_target 'Oktest.run()' do
606
+ test_subject "[!mn451] run test cases." do
607
+ expected = verbose_output
607
608
  prepare()
608
- sout, serr = capture { Oktest.run() }
609
- assert_eq edit_actual(sout), edit_expected(expected)
610
- assert_eq serr, ""
609
+ sout, serr = capture_output! { Oktest.run() }
610
+ test_eq? edit_actual(sout), edit_expected(expected)
611
+ test_eq? serr, ""
611
612
  end
612
- it "[!6xn3t] creates reporter object according to 'style:' keyword arg." do
613
- expected = VERBOSE_OUTPUT
613
+ test_subject "[!6xn3t] creates reporter object according to 'style:' keyword arg." do
614
+ expected = verbose_output
614
615
  prepare()
615
- sout, serr = capture { Oktest.run(:style=>"verbose") }
616
- assert_eq edit_actual(sout), edit_expected(expected)
617
- assert_eq serr, ""
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 = COMPACT_OUTPUT
620
+ expected = compact_output
620
621
  prepare()
621
- sout, serr = capture { Oktest.run(:style=>"compact") }
622
- assert_eq edit_actual(sout), edit_expected(expected)
623
- assert_eq serr, ""
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 = PLAIN_OUTPUT
626
+ expected = plain_output
626
627
  prepare()
627
- sout, serr = capture { Oktest.run(:style=>"plain") }
628
- assert_eq edit_actual(sout), edit_expected(expected)
629
- assert_eq serr, ""
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
- it "[!p52se] returns total number of failures and errors." do
632
+ test_subject "[!p52se] returns total number of failures and errors." do
632
633
  prepare()
633
634
  ret = nil
634
- _ = capture { ret = Oktest.run() }
635
- assert_eq ret, 0 # no failures, no errors
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
- _ = capture { ret = Oktest.run() }
647
- assert_eq ret, 2 # 1 failure, 1 error
647
+ _ = capture_output! { ret = Oktest.run() }
648
+ test_eq? ret, 2 # 1 failure, 1 error
648
649
  end
649
650
  end
650
651