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/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.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 Runner_TC < TC
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
- describe "#start()" do
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
- it "[!xrisl] runs topics and specs." do
64
- sout, serr = capture do
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
- assert_eq sout, expected
79
- assert_eq serr, ""
80
+ test_eq? sout, expected
81
+ test_eq? serr, ""
80
82
  end
81
- it "[!dth2c] clears toplvel scope list." do
82
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, false
83
- 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
84
86
  build_topics.call
85
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, true
87
+ test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, true
86
88
  Oktest::Runner.new(DummyReporter.new).start()
87
89
  end
88
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, false
90
+ test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, false
89
91
  end
90
92
  end
91
93
 
92
- describe "#visit_spec()" do
93
- 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
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 = capture do
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
- assert_eq sout, expected
152
- assert_eq serr, ""
153
+ test_eq? sout, expected
154
+ test_eq? serr, ""
153
155
  end
154
- 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
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 = capture do
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
- assert_eq sout, expected
186
- assert_eq serr, ""
187
+ test_eq? sout, expected
188
+ test_eq? serr, ""
187
189
  end
188
- it "[!yagka] calls 'before' and 'after' blocks with context object as self." do
189
- 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
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
- assert_eq sout, expected
253
- assert_eq serr, ""
254
+ test_eq? sout, expected
255
+ test_eq? serr, ""
254
256
  end
255
- it "[!76g7q] calls 'after' blocks even when exception raised." do
256
- sout, serr = capture do
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
- assert_eq sout, expected
285
- assert_eq serr, ""
286
+ test_eq? sout, expected
287
+ test_eq? serr, ""
286
288
  end
287
- it "[!dihkr] calls 'at_end' blocks, even when exception raised." do
288
- sout, serr = capture do
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
- assert_eq sout, expected
327
- assert_eq serr, ""
328
+ test_eq? sout, expected
329
+ test_eq? serr, ""
328
330
  end
329
- describe "[!68cnr] if TODO() called in spec..." do
330
- 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
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 = capture { Oktest::Runner.new(DummyReporter.new).start() }
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
- assert_eq sout, expected
347
+ test_eq? sout, expected
346
348
  end
347
- 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
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 = capture { Oktest::Runner.new(DummyReporter.new).start() }
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
- assert_eq sout, expected
364
+ test_eq? sout, expected
363
365
  end
364
- 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
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 = capture { Oktest::Runner.new(DummyReporter.new).start() }
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
- assert_eq sout, expected
381
+ test_eq? sout, expected
380
382
  end
381
383
  end
382
384
  end
383
385
 
384
- describe "#visit_topic()" do
385
- it "[!i3yfv] calls 'before_all' and 'after_all' blocks." do
386
- 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
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
- assert_eq sout, expected
432
- assert_eq serr, ""
433
+ test_eq? sout, expected
434
+ test_eq? serr, ""
433
435
  end
434
- it "[!p3a5o] run specs and case_when in advance of specs and topics when SimpleReporter." do
435
- 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
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
- assert_eq sout, expected
473
- assert_eq serr, ""
474
+ test_eq? sout, expected
475
+ test_eq? serr, ""
474
476
  end
475
477
  end
476
478
 
477
- describe "#visit_scope()" do
478
- it "[!5anr7] calls before_all and after_all blocks." do
479
- 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
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
- assert_eq sout, expected
501
- assert_eq serr, ""
502
+ test_eq? sout, expected
503
+ test_eq? serr, ""
502
504
  end
503
- it "[!c5cw0] run specs and case_when in advance of specs and topics when SimpleReporter." do
504
- 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
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
- assert_eq sout, expected
541
- assert_eq serr, ""
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 RunnerFunctions_TC < TC
551
+ class OktestFunctions__Test
552
+ extend NanoTest
550
553
 
551
- def setup()
552
- end
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
- VERBOSE_OUTPUT = <<'END'
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
- COMPACT_OUTPUT = <<'END'
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
- PLAIN_OUTPUT = <<'END'
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
- describe 'Oktest.run()' do
604
- it "[!mn451] run test cases." do
605
- expected = VERBOSE_OUTPUT
605
+ test_target 'Oktest.run()' do
606
+ test_subject "[!mn451] run test cases." do
607
+ expected = verbose_output
606
608
  prepare()
607
- sout, serr = capture { Oktest.run() }
608
- assert_eq edit_actual(sout), edit_expected(expected)
609
- assert_eq serr, ""
609
+ sout, serr = capture_output! { Oktest.run() }
610
+ test_eq? edit_actual(sout), edit_expected(expected)
611
+ test_eq? serr, ""
610
612
  end
611
- it "[!6xn3t] creates reporter object according to 'style:' keyword arg." do
612
- expected = VERBOSE_OUTPUT
613
+ test_subject "[!6xn3t] creates reporter object according to 'style:' keyword arg." do
614
+ expected = verbose_output
613
615
  prepare()
614
- sout, serr = capture { Oktest.run(:style=>"verbose") }
615
- assert_eq edit_actual(sout), edit_expected(expected)
616
- 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, ""
617
619
  #
618
- expected = COMPACT_OUTPUT
620
+ expected = compact_output
619
621
  prepare()
620
- sout, serr = capture { Oktest.run(:style=>"compact") }
621
- assert_eq edit_actual(sout), edit_expected(expected)
622
- 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, ""
623
625
  #
624
- expected = PLAIN_OUTPUT
626
+ expected = plain_output
625
627
  prepare()
626
- sout, serr = capture { Oktest.run(:style=>"plain") }
627
- assert_eq edit_actual(sout), edit_expected(expected)
628
- 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, ""
629
631
  end
630
- it "[!p52se] returns total number of failures and errors." do
632
+ test_subject "[!p52se] returns total number of failures and errors." do
631
633
  prepare()
632
634
  ret = nil
633
- _ = capture { ret = Oktest.run() }
634
- assert_eq ret, 0 # no failures, no errors
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
- _ = capture { ret = Oktest.run() }
646
- assert_eq ret, 2 # 1 failure, 1 error
647
+ _ = capture_output! { ret = Oktest.run() }
648
+ test_eq? ret, 2 # 1 failure, 1 error
647
649
  end
648
650
  end
649
651