@@ -71,10 +71,10 @@ Specify that testing has finished. Use this function when you don't
71
71
have a C < plan > with the number of tests to run. A C < plan > is not
72
72
required when using C < done-testing > .
73
73
74
- It's recommended that the C < done-testing > function be removed and replaced
75
- with a C < plan > function when all tests are finalized. Use of C < plan > can help
76
- detect test failures otherwise not reported because tests were accidentally skipped
77
- due to bugs in the tests or bugs in the compiler. For example:
74
+ It's recommended that the C < done-testing > function be removed and replaced with
75
+ a C < plan > function when all tests are finalized. Use of C < plan > can help detect
76
+ test failures otherwise not reported because tests were accidentally skipped due
77
+ to bugs in the tests or bugs in the compiler. For example:
78
78
79
79
sub do-stuff {@};
80
80
use Test;
@@ -85,8 +85,9 @@ due to bugs in the tests or bugs in the compiler. For example:
85
85
1..0
86
86
87
87
The above example is where a C < done-testing > fails. C < do-stuff() > returned
88
- nothing and tested nothing, even though it should've returned results to test. But
89
- the test suite doesn't know how many tests were meant to be run, so it passes.
88
+ nothing and tested nothing, even though it should've returned results to test.
89
+ But the test suite doesn't know how many tests were meant to be run, so it
90
+ passes.
90
91
91
92
Adding C < plan > gives a true picture of the test:
92
93
@@ -166,9 +167,10 @@ L«C<is-deeply> routine|/language/testing#index-entry-is-deeply-is-deeply($value
166
167
my Int $a;
167
168
is $a, Int, 'The variable $a is an unassigned Int';
168
169
169
- B < Note: > if I < only > whitespace differs between the values, C < is() > will output failure
170
- message differently, to show the whitespace in each values. For example, in the
171
- output below, the second test shows the literal C < \t > in the C < got: > line:
170
+ B < Note: > if I < only > whitespace differs between the values, C < is() > will output
171
+ failure message differently, to show the whitespace in each values. For example,
172
+ in the output below, the second test shows the literal C < \t > in the C < got: >
173
+ line:
172
174
173
175
= for code
174
176
is "foo\tbar", "foo\tbaz"; # expected: 'foo baz'# got: 'foo bar'
@@ -512,7 +514,7 @@ sub saruman(Bool :$ents-destroy-isengard) {
512
514
dies-ok { saruman(ents-destroy-isengard => True) }, "Saruman dies";
513
515
= end code
514
516
515
- = head2 lives-ok
517
+ = head2 sub lives-ok
516
518
517
519
Defined as:
518
520
@@ -531,7 +533,7 @@ sub frodo(Bool :$destroys-ring) {
531
533
lives-ok { frodo(destroys-ring => True) }, "Frodo survives";
532
534
= end code
533
535
534
- = head2 eval-dies-ok
536
+ = head2 sub eval-dies-ok
535
537
536
538
Defined as:
537
539
@@ -548,7 +550,7 @@ eval-dies-ok q[my $joffrey = "nasty";
548
550
"Ned Stark dies";
549
551
= end code
550
552
551
- = head2 eval-lives-ok
553
+ = head2 sub eval-lives-ok
552
554
553
555
Defined as:
554
556
@@ -565,7 +567,7 @@ eval-lives-ok q[my $daenerys-burns = False;
565
567
"Dany is blood of the dragon";
566
568
= end code
567
569
568
- = head2 throws-like
570
+ = head2 sub throws-like
569
571
570
572
Defined as:
571
573
@@ -593,38 +595,41 @@ positional argument.
593
595
The routine makes L < Failures|/type/Failure > fatal. If you wish to avoid that,
594
596
use L « C < no fatal > pragma|/language/pragmas#index-entry-fatal-fatal» and ensure
595
597
the tested code does not sink the possible L < Failures|/type/Failure > . If you
596
- wish to test that the code returns a L < Failure|/type/Failure > instead of throwing, use
597
- C < fails-like > routine instead.
598
+ wish to test that the code returns a L < Failure|/type/Failure > instead of
599
+ throwing, use C < fails-like > routine instead.
598
600
599
- sub fails-not-throws { +"a" }
600
- # test passes, even though it's just a Failure and would not always throw:
601
- throws-like { fails-not-throws }, Exception;
601
+ = begin code
602
+ sub fails-not-throws { +"a" }
603
+ # test passes, even though it's just a Failure and would not always throw:
604
+ throws-like { fails-not-throws }, Exception;
602
605
603
- # test detects nothing got thrown, because our Failure wasn't sunk or made fatal:
604
- throws-like { no fatal; my $ = fails-not-throws; Nil }, Exception;
606
+ # test detects nothing thrown, because our Failure wasn't sunk or made fatal:
607
+ throws-like { no fatal; my $ = fails-not-throws; Nil }, Exception;
608
+ = end code
605
609
606
- Please note that you can only use the string form (for C < EVAL > ) if you are not referencing
607
- any symbols in the surrounding scope. If you are, you should encapsulate
608
- your string with a block and an EVAL instead. For instance:
610
+ Please note that you can only use the string form (for C < EVAL > ) if you are not
611
+ referencing any symbols in the surrounding scope. If you are, you should
612
+ encapsulate your string with a block and an EVAL instead. For instance:
609
613
610
614
throws-like { EVAL q[ fac("foo") ] }, X::TypeCheck::Argument;
611
615
612
- = head2 fails-like
616
+ = head2 sub fails-like
613
617
614
618
Defined as:
615
619
616
- sub fails-like ( \test where Callable:D|Str:D, $ex-type, $reason?, *%matcher)
620
+ = for code
621
+ sub fails-like ( \test where Callable:D|Str:D, $ex-type, $reason?, *%matcher)
617
622
618
623
Same interface as C < throws-like > , except checks that the code returns a
619
- L < Failure|/type/Failure > instead of throwing. If the code does throw or if the returned
620
- L < Failure|/type/Failure > has already been L < handled|/routine/handled > , that will be considered as a failed
621
- test.
624
+ L < Failure|/type/Failure > instead of throwing. If the code does throw or if the
625
+ returned L < Failure|/type/Failure > has already been L < handled|/routine/handled > ,
626
+ that will be considered as a failed test.
622
627
623
628
fails-like { +"a" }, X::Str::Numeric,
624
629
:message(/'Cannot convert string to number'/),
625
630
'converting non-numeric string to number fails';
626
631
627
- = head2 subtest
632
+ = head2 sub subtest
628
633
629
634
Defined as:
630
635
@@ -656,8 +661,9 @@ subtest {
656
661
}, "Check Great Uncle Bulgaria";
657
662
= end code
658
663
659
- You can also place the description as the first positional argument, or use a C < Pair > with description as the key and subtest's code
660
- as the value. This can be useful for subtests with large bodies.
664
+ You can also place the description as the first positional argument, or use a
665
+ C < Pair > with description as the key and subtest's code as the value. This can be
666
+ useful for subtests with large bodies.
661
667
662
668
= begin code
663
669
subtest 'A bunch of tests', {
@@ -673,8 +679,7 @@ subtest 'Another bunch of tests' => {
673
679
}
674
680
= end code
675
681
676
-
677
- = head2 todo
682
+ = head2 sub todo
678
683
679
684
Defined as:
680
685
@@ -709,7 +714,7 @@ Note that if you C<todo> a C<subtest>, all of the failing tests inside of it
709
714
will be automatically marked TODO as well and will I < not > count towards your
710
715
original TODO count.
711
716
712
- = head2 skip
717
+ = head2 sub skip
713
718
714
719
Defined as:
715
720
@@ -735,7 +740,7 @@ else {
735
740
Note that if you mark a test as skipped, you must also prevent that
736
741
test from running.
737
742
738
- = head2 skip-rest
743
+ = head2 sub skip-rest
739
744
740
745
Defined as:
741
746
@@ -767,7 +772,7 @@ to avoid running any tests at all and
767
772
L « C < bail-out > |/language/testing#index-entry-bail-out-bail-out($reason?)» to abort
768
773
the test run and mark it as failed.
769
774
770
- = head2 bail-out
775
+ = head2 sub bail-out
771
776
772
777
sub bail-out ($desc?)
773
778
@@ -788,7 +793,7 @@ If you want to abort the test run, but without marking it as failed, see
788
793
L « C < skip-rest > |/language/testing#index-entry-skip-rest-skip-rest($reason?)»
789
794
or L « C < plan :skip-all('...') > |/language/testing#index-entry-plan-plan($count)»
790
795
791
- = head2 pass
796
+ = head2 sub pass
792
797
793
798
Defined as:
794
799
@@ -805,13 +810,13 @@ Since these subroutines do not provide indication of what value was received
805
810
and what was expected, they should be used sparingly, such as when evaluating
806
811
a complex test condition.
807
812
808
- = head2 flunk
813
+ = head2 sub flunk
809
814
810
815
multi sub flunk($reason = '')
811
816
812
817
The opposite of C < pass > , makes a test fail with an optional message.
813
818
814
- = head2 diag
819
+ = head2 sub diag
815
820
816
821
sub diag($message)
817
822
0 commit comments