oktest 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/misc_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.0.0 $
4
+ ### $Release: 1.1.1 $
5
5
  ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
6
6
  ### $License: MIT License $
7
7
  ###
data/test/node_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.0.0 $
4
+ ### $Release: 1.1.1 $
5
5
  ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
6
6
  ### $License: MIT License $
7
7
  ###
@@ -315,6 +315,25 @@ class ScopeFunctions_TC < TC
315
315
  Oktest::THE_GLOBAL_SCOPE.clear_children()
316
316
  end
317
317
 
318
+ def with_dummy_location(location)
319
+ $_dummy_location = location
320
+ Oktest.module_eval do
321
+ class << self
322
+ def caller(n)
323
+ return [$_dummy_location]
324
+ end
325
+ end
326
+ end
327
+ yield
328
+ ensure
329
+ Oktest.module_eval do
330
+ class << self
331
+ remove_method :caller
332
+ end
333
+ end
334
+ $_dummy_location = nil
335
+ end
336
+
318
337
  describe 'Oktest.scope()' do
319
338
  it "[!vxoy1] creates new scope object." do
320
339
  x = Oktest.scope() { nil }
@@ -341,6 +360,20 @@ class ScopeFunctions_TC < TC
341
360
  assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, true
342
361
  assert_eq Oktest::THE_GLOBAL_SCOPE.each_child.to_a, [so]
343
362
  end
363
+ it "[!kem4y] detects test script filename." do
364
+ sc = Oktest.scope() { nil }
365
+ assert_eq sc.filename, "test/node_test.rb"
366
+ end
367
+ it "[!6ullm] changes test script filename from absolute path to relative path." do
368
+ with_dummy_location(Dir.pwd + "/tests/foo_test.rb:123") do
369
+ sc = Oktest.scope() { nil }
370
+ assert_eq sc.filename, "tests/foo_test.rb"
371
+ end
372
+ with_dummy_location("./t/bar_test.rb:456") do
373
+ sc = Oktest.scope() { nil }
374
+ assert_eq sc.filename, "t/bar_test.rb"
375
+ end
376
+ end
344
377
  end
345
378
 
346
379
  describe '#global_scope()' do
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.0.0 $
4
+ ### $Release: 1.1.1 $
5
5
  ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
6
6
  ### $License: MIT License $
7
7
  ###
@@ -418,6 +418,10 @@ Oktest.scope do
418
418
  end
419
419
  end
420
420
 
421
+ spec "last spec" do
422
+ ok {1+1} == 2
423
+ end
424
+
421
425
  end
422
426
 
423
427
  end
@@ -443,10 +447,11 @@ ZeroDivisionError: divided by 0
443
447
  END
444
448
 
445
449
  FOOTER = <<'END'
446
- ## total:8 (<B>pass:4</B>, <R>fail:1</R>, <R>error:1</R>, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
450
+ ## total:9 (<B>pass:5</B>, <R>fail:1</R>, <R>error:1</R>, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
447
451
  END
448
452
 
449
453
  VERBOSE_PART = <<'END'
454
+ ## _test.tmp
450
455
  * <b>Parent</b>
451
456
  * <b>Child1</b>
452
457
  - [<B>pass</B>] 1+1 should be 2
@@ -463,16 +468,28 @@ END
463
468
  - [<B>pass</B>] x*x is positive.
464
469
  - <b>Else</b>
465
470
  - [<B>pass</B>] x*x is also positive.
471
+ - [<B>pass</B>] last spec
466
472
  END
467
473
  VERBOSE_OUTPUT = VERBOSE_PART + ERROR_PART + VERBOSE_PART2 + FOOTER
468
474
 
469
475
  SIMPLE_PART = <<'END'
470
- _test.tmp: <B>.</B><B>.</B><R>f</R><R>E</R><Y>s</Y><Y>t</Y><B>.</B><B>.</B>
476
+ ## _test.tmp
477
+ * <b>Parent</b>: <B>.</B><B>.</B><B>.</B>
478
+ * <b>Child1</b>: <B>.</B><B>.</B>
479
+ * <b>Child2</b>: <R>f</R><R>E</R>
471
480
  END
472
- SIMPLE_OUTPUT = SIMPLE_PART + ERROR_PART + FOOTER
481
+ SIMPLE_PART2 = <<'END'
482
+ * <b>Child3</b>: <Y>s</Y><Y>t</Y>
483
+ END
484
+ SIMPLE_OUTPUT = SIMPLE_PART + ERROR_PART + SIMPLE_PART2 + FOOTER
485
+
486
+ COMPACT_PART = <<'END'
487
+ _test.tmp: <B>.</B><B>.</B><R>f</R><R>E</R><Y>s</Y><Y>t</Y><B>.</B><B>.</B><B>.</B>
488
+ END
489
+ COMPACT_OUTPUT = COMPACT_PART + ERROR_PART + FOOTER
473
490
 
474
491
  PLAIN_PART = <<'END'
475
- <B>.</B><B>.</B><R>f</R><R>E</R><Y>s</Y><Y>t</Y><B>.</B><B>.</B>
492
+ <B>.</B><B>.</B><R>f</R><R>E</R><Y>s</Y><Y>t</Y><B>.</B><B>.</B><B>.</B>
476
493
  END
477
494
  PLAIN_OUTPUT = PLAIN_PART + ERROR_PART + FOOTER
478
495
 
@@ -516,7 +533,7 @@ end
516
533
 
517
534
  class SimpleReporter_TC < Reporter_TC
518
535
 
519
- it "[!xfd5o] reports filename." do
536
+ it "[!jxa1b] reports topics and progress." do
520
537
  sout, serr = run("-ss", @filename)
521
538
  assert_eq edit_actual(sout), edit_expected(SIMPLE_OUTPUT)
522
539
  assert_eq serr, ""
@@ -525,6 +542,17 @@ class SimpleReporter_TC < Reporter_TC
525
542
  end
526
543
 
527
544
 
545
+ class CompactReporter_TC < Reporter_TC
546
+
547
+ it "[!xfd5o] reports filename." do
548
+ sout, serr = run("-sc", @filename)
549
+ assert_eq edit_actual(sout), edit_expected(COMPACT_OUTPUT)
550
+ assert_eq serr, ""
551
+ end
552
+
553
+ end
554
+
555
+
528
556
  class PlainReporter_TC < Reporter_TC
529
557
 
530
558
  it "[!w842j] reports progress." do
data/test/runner_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.0.0 $
4
+ ### $Release: 1.1.1 $
5
5
  ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
6
6
  ### $License: MIT License $
7
7
  ###
@@ -44,6 +44,10 @@ class Runner_TC < TC
44
44
  def counts; {}; end
45
45
  end
46
46
 
47
+ class DummyReporter2 < DummyReporter
48
+ def order_policy; :spec_first; end
49
+ end
50
+
47
51
  describe "#start()" do
48
52
  build_topics = proc {
49
53
  Oktest.scope do
@@ -389,6 +393,47 @@ topic: "Parent"
389
393
  /topic
390
394
  [all] after_all
391
395
  /file
396
+ END
397
+ assert_eq sout, expected
398
+ assert_eq serr, ""
399
+ end
400
+ it "[!p3a5o] run specs and case_when in advance of specs and topics when SimpleReporter." do
401
+ sout, serr = capture do
402
+ Oktest.scope do
403
+ topic "T1" do
404
+ topic "T2" do
405
+ spec("S1") { ok {1+1} == 2 }
406
+ end
407
+ spec("S2") { ok {1+1} == 2 }
408
+ topic "T3" do
409
+ spec("S3") { ok {1+1} == 2 }
410
+ end
411
+ case_when "T4" do
412
+ spec("S4") { ok {1+1} == 2 }
413
+ end
414
+ end
415
+ end
416
+ Oktest::Runner.new(DummyReporter2.new).start()
417
+ end
418
+ expected = <<'END'
419
+ file: "test/runner_test.rb"
420
+ topic: "T1"
421
+ spec: "S2"
422
+ /spec: status=:PASS
423
+ topic: "When T4"
424
+ spec: "S4"
425
+ /spec: status=:PASS
426
+ /topic
427
+ topic: "T2"
428
+ spec: "S1"
429
+ /spec: status=:PASS
430
+ /topic
431
+ topic: "T3"
432
+ spec: "S3"
433
+ /spec: status=:PASS
434
+ /topic
435
+ /topic
436
+ /file
392
437
  END
393
438
  assert_eq sout, expected
394
439
  assert_eq serr, ""
@@ -417,6 +462,46 @@ file: "test/runner_test.rb"
417
462
  [all] before_all#2
418
463
  [all] after_all#2
419
464
  /file
465
+ END
466
+ assert_eq sout, expected
467
+ assert_eq serr, ""
468
+ end
469
+ it "[!c5cw0] run specs and case_when in advance of specs and topics when SimpleReporter." do
470
+ sout, serr = capture do
471
+ Oktest.scope do
472
+ topic "T1" do
473
+ spec("S1") { ok {1+1} == 2 }
474
+ end
475
+ spec("S2") { ok {1+1} == 2 }
476
+ case_when "T2" do
477
+ spec("S3") { ok {1+1} == 2 }
478
+ end
479
+ topic "T3" do
480
+ spec("S4") { ok {1+1} == 2 }
481
+ end
482
+ spec("S5") { ok {1+1} == 2 }
483
+ end
484
+ Oktest::Runner.new(DummyReporter2.new).start()
485
+ end
486
+ expected = <<'END'
487
+ file: "test/runner_test.rb"
488
+ spec: "S2"
489
+ /spec: status=:PASS
490
+ topic: "When T2"
491
+ spec: "S3"
492
+ /spec: status=:PASS
493
+ /topic
494
+ spec: "S5"
495
+ /spec: status=:PASS
496
+ topic: "T1"
497
+ spec: "S1"
498
+ /spec: status=:PASS
499
+ /topic
500
+ topic: "T3"
501
+ spec: "S4"
502
+ /spec: status=:PASS
503
+ /topic
504
+ /file
420
505
  END
421
506
  assert_eq sout, expected
422
507
  assert_eq serr, ""
@@ -474,12 +559,13 @@ class RunnerFunctions_TC < TC
474
559
  end
475
560
 
476
561
  VERBOSE_OUTPUT = <<'END'
562
+ ## test/runner_test.rb
477
563
  * <b>Example</b>
478
564
  - [<B>pass</B>] 1+1 should be 2
479
565
  - [<B>pass</B>] 1-1 should be 0
480
566
  ## total:2 (<B>pass:2</B>, fail:0, error:0, skip:0, todo:0) in 0.000s
481
567
  END
482
- SIMPLE_OUTPUT = <<'END'
568
+ COMPACT_OUTPUT = <<'END'
483
569
  test/runner_test.rb: <B>.</B><B>.</B>
484
570
  ## total:2 (<B>pass:2</B>, fail:0, error:0, skip:0, todo:0) in 0.000s
485
571
  END
@@ -497,11 +583,6 @@ END
497
583
  assert_eq edit_actual(sout), edit_expected(expected)
498
584
  assert_eq serr, ""
499
585
  end
500
- it "[!kfi8b] do nothing when 'Oktest.scope()' not called." do
501
- sout, serr = capture { Oktest.run() }
502
- assert_eq sout, ""
503
- assert_eq serr, ""
504
- end
505
586
  it "[!6xn3t] creates reporter object according to 'style:' keyword arg." do
506
587
  expected = VERBOSE_OUTPUT
507
588
  prepare()
@@ -509,9 +590,9 @@ END
509
590
  assert_eq edit_actual(sout), edit_expected(expected)
510
591
  assert_eq serr, ""
511
592
  #
512
- expected = SIMPLE_OUTPUT
593
+ expected = COMPACT_OUTPUT
513
594
  prepare()
514
- sout, serr = capture { Oktest.run(:style=>"simple") }
595
+ sout, serr = capture { Oktest.run(:style=>"compact") }
515
596
  assert_eq edit_actual(sout), edit_expected(expected)
516
597
  assert_eq serr, ""
517
598
  #
data/test/util_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.0.0 $
4
+ ### $Release: 1.1.1 $
5
5
  ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
6
6
  ### $License: MIT License $
7
7
  ###
data/test/visitor_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.0.0 $
4
+ ### $Release: 1.1.1 $
5
5
  ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
6
6
  ### $License: MIT License $
7
7
  ###
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oktest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kwatch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-13 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs
@@ -70,6 +70,7 @@ files:
70
70
  - test/helper_test.rb
71
71
  - test/initialize.rb
72
72
  - test/mainapp_test.rb
73
+ - test/matcher_test.rb
73
74
  - test/misc_test.rb
74
75
  - test/node_test.rb
75
76
  - test/reporter_test.rb