Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds preambles closes #2789
  • Loading branch information
JJ committed May 12, 2019
1 parent 4311d97 commit 490133e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions doc/Type/Test.pod6
Expand Up @@ -33,16 +33,17 @@ You can also provide a C<:skip-all> named argument instead of a test count,
to indicate that you want to skip all of the tests. Such a plan will
call L«C<exit>|/routine/exit», unless used inside of a C<subtest>.
plan :skip-all<These tests are only for Windows> unless $*DISTRO.is-win;
plan 1;
ok dir 'C:/'; # this won't get run on non-Windows
=for code :preamble<use Test;>
plan :skip-all<These tests are only for Windows> unless $*DISTRO.is-win;
plan 1;
ok dir 'C:/'; # this won't get run on non-Windows
If used in a C<subtest>, it will instead C<return> from that
C<subtest>'s L«C<Callable>|/type/Callable». For that reason, to be able to
use C<:skip-all> inside a C<subtest>, you must use a C<sub> instead of a
regular block:
=begin code
=begin code :preamble<use Test;>
plan 2;
subtest "Some Windows tests" => sub { # <-- note the `sub`; can't use bare block
plan :skip-all<We aren't on Windows> unless $*DISTRO.is-win;
Expand Down Expand Up @@ -634,7 +635,8 @@ Please note that you can only use the string form (for C<EVAL>) if you are not
referencing any symbols in the surrounding scope. If you are, you should
encapsulate your string with a block and an EVAL instead. For instance:
throws-like { EVAL q[ fac("foo") ] }, X::TypeCheck::Argument;
=for code :preamble<use Test;>
throws-like { EVAL q[ fac("foo") ] }, X::TypeCheck::Argument;
=head2 sub fails-like
Expand Down Expand Up @@ -718,11 +720,13 @@ in which case one would C<skip> the test on other platforms.
Mark C<$count> tests as TODO, giving a C<$reason> as to why. By default
only one test will be marked TODO.
=begin code :preamble<use Test;>
sub my-custom-pi { 3 };
todo 'not yet precise enough'; # Mark the test as TODO.
is my-custom-pi(), pi, 'my-custom-pi'; # Run the test, but don't report
# failure in test harness.
=end code
The result from the test code above will be something like:
Expand Down Expand Up @@ -804,7 +808,7 @@ the test run and mark it as failed.
If you already know the tests will fail, you can bail out of the test run
using C<bail-out()>:
=begin code
=begin code :preamble<use Test;>
my $has-db-connection;
...
$has-db-connection or bail-out 'Must have database connection for testing';
Expand All @@ -827,9 +831,9 @@ Defined as:
The C<pass> function marks a test as passed. C<flunk> marks a test as
B<not> passed. Both functions accept an optional test description.
pass "Actually, this test has passed";
flunk "But this one hasn't passed";
=for code :preamble<use Test;>
pass "Actually, this test has passed";
flunk "But this one hasn't passed";
Since these subroutines do not provide indication of what value was received
and what was expected, they should be used sparingly, such as when evaluating
Expand All @@ -851,7 +855,8 @@ provide information that the test itself did not provide. Or it can be used
to provide visual markers on how the testing of a test-file is progressing
(which can be important when doing stress testing).
diag "Yay! The tests got to here!";
=for code :preamble<use Test;>
diag "Yay! The tests got to here!";
=end pod

Expand Down

0 comments on commit 490133e

Please sign in to comment.