Skip to content

Commit 490133e

Browse files
committed
Adds preambles closes #2789
1 parent 4311d97 commit 490133e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

doc/Type/Test.pod6

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ You can also provide a C<:skip-all> named argument instead of a test count,
3333
to indicate that you want to skip all of the tests. Such a plan will
3434
call L«C<exit>|/routine/exit», unless used inside of a C<subtest>.
3535
36-
plan :skip-all<These tests are only for Windows> unless $*DISTRO.is-win;
37-
plan 1;
38-
ok dir 'C:/'; # this won't get run on non-Windows
36+
=for code :preamble<use Test;>
37+
plan :skip-all<These tests are only for Windows> unless $*DISTRO.is-win;
38+
plan 1;
39+
ok dir 'C:/'; # this won't get run on non-Windows
3940
4041
If used in a C<subtest>, it will instead C<return> from that
4142
C<subtest>'s L«C<Callable>|/type/Callable». For that reason, to be able to
4243
use C<:skip-all> inside a C<subtest>, you must use a C<sub> instead of a
4344
regular block:
4445
45-
=begin code
46+
=begin code :preamble<use Test;>
4647
plan 2;
4748
subtest "Some Windows tests" => sub { # <-- note the `sub`; can't use bare block
4849
plan :skip-all<We aren't on Windows> unless $*DISTRO.is-win;
@@ -634,7 +635,8 @@ Please note that you can only use the string form (for C<EVAL>) if you are not
634635
referencing any symbols in the surrounding scope. If you are, you should
635636
encapsulate your string with a block and an EVAL instead. For instance:
636637
637-
throws-like { EVAL q[ fac("foo") ] }, X::TypeCheck::Argument;
638+
=for code :preamble<use Test;>
639+
throws-like { EVAL q[ fac("foo") ] }, X::TypeCheck::Argument;
638640
639641
=head2 sub fails-like
640642
@@ -718,11 +720,13 @@ in which case one would C<skip> the test on other platforms.
718720
Mark C<$count> tests as TODO, giving a C<$reason> as to why. By default
719721
only one test will be marked TODO.
720722
723+
=begin code :preamble<use Test;>
721724
sub my-custom-pi { 3 };
722725
723726
todo 'not yet precise enough'; # Mark the test as TODO.
724727
is my-custom-pi(), pi, 'my-custom-pi'; # Run the test, but don't report
725728
# failure in test harness.
729+
=end code
726730
727731
The result from the test code above will be something like:
728732
@@ -804,7 +808,7 @@ the test run and mark it as failed.
804808
If you already know the tests will fail, you can bail out of the test run
805809
using C<bail-out()>:
806810
807-
=begin code
811+
=begin code :preamble<use Test;>
808812
my $has-db-connection;
809813
...
810814
$has-db-connection or bail-out 'Must have database connection for testing';
@@ -827,9 +831,9 @@ Defined as:
827831
The C<pass> function marks a test as passed. C<flunk> marks a test as
828832
B<not> passed. Both functions accept an optional test description.
829833
830-
pass "Actually, this test has passed";
831-
832-
flunk "But this one hasn't passed";
834+
=for code :preamble<use Test;>
835+
pass "Actually, this test has passed";
836+
flunk "But this one hasn't passed";
833837
834838
Since these subroutines do not provide indication of what value was received
835839
and what was expected, they should be used sparingly, such as when evaluating
@@ -851,7 +855,8 @@ provide information that the test itself did not provide. Or it can be used
851855
to provide visual markers on how the testing of a test-file is progressing
852856
(which can be important when doing stress testing).
853857
854-
diag "Yay! The tests got to here!";
858+
=for code :preamble<use Test;>
859+
diag "Yay! The tests got to here!";
855860
856861
=end pod
857862

0 commit comments

Comments
 (0)