Lines Matching full:test

3 package Test::Tester;
7 if (*Test::Builder::new{CODE})
9 warn "You should load Test::Tester before Test::Builder (or anything that loads Test::Builder)"
13 use Test::Builder;
14 use Test::Tester::CaptureRunner;
15 use Test::Tester::Delegate;
26 my $Test = Test::Builder->new;
27 my $Capture = Test::Tester::Capture->new;
28 my $Delegator = Test::Tester::Delegate->new;
29 $Delegator->{Object} = $Test;
31 my $runner = Test::Tester::CaptureRunner->new;
62 return Test::Tester::Capture->new;
68 $runner = Test::Tester::FHRunner->new;
70 return $Test;
80 $found = ($sub eq "Test::Tester::run_tests");
99 my $test = shift;
104 @_ = ($test, [$expect], $name);
110 my $test = shift;
115 my ($prem, @results) = eval { run_tests($test, $name) };
117 $Test->ok(! $@, "Test '$name' completed") || $Test->diag($@);
118 $Test->ok(! length($prem), "Test '$name' no premature diagnostication") ||
119 $Test->diag("Before any testing anything, your tests said\n$prem");
121 local $Test::Builder::Level = $Test::Builder::Level + 1;
132 $Test->is_eq($result->{$field}, $expect->{$field},
147 local $Test::Builder::Level = $Test::Builder::Level + 1;
167 # if depth was explicitly undef then don't test it
170 $Test->is_eq($result->{depth}, $depth, "checking depth") ||
171 $Test->diag('You need to change $Test::Builder::Level');
180 if (not $Test->like($result->{diag}, $exp,
192 if (not $Test->ok($result->{diag} eq $exp,
217 $Test->diag(<<EOM);
250 $Test->is_num(scalar @$results, scalar @$expects, "Test '$name' result count");
257 local $Test::Builder::Level = $Test::Builder::Level + 1;
262 ######## nicked from Test::More
268 $Test->exported_to($caller);
279 $Test->plan(@plan);
288 *Test::Builder::new = \&new_new;
311 Test::Tester - Ease testing test modules built with Test::Builder
315 use Test::Tester tests => 6;
317 use Test::MyStyle;
332 use Test::Tester tests => 6;
334 use Test::MyStyle;
349 use Test::Tester;
351 use Test::More tests => 3;
352 use Test::MyStyle;
360 # now use Test::More::like to check the diagnostic output
366 If you have written a test module based on Test::Builder then Test::Tester
367 allows you to test it with the minimum of effort.
371 From version 0.08 Test::Tester no longer requires you to included anything
372 special in your test modules. All you need to do is
374 use Test::Tester;
376 in your test script B<before> any other Test::Builder based modules and away
379 Other modules based on Test::Builder can be used to help with the
380 testing. In fact you can even use functions from your module to test
383 using it to test itself may give the wrong answers).
385 The easiest way to test is to do something like
390 ok => 0, # we expect the test to fail
396 this will execute the is_mystyle_eq test, capturing its results and
399 You may need to examine the test results in a more flexible way, for
402 you can get direct access to the test results:
417 ok => 0, # we expect the test to fail
424 Test::More's like() test to check that the diagnostic string is of the right
431 Make your module use the Test::Tester::Capture object instead of the
432 Test::Builder one. How to do this depends on your module but assuming that
433 your module holds the Test::Builder object in $Test and that all your test
434 routines access it through $Test then providing a function something like this
438 $Test = shift;
441 should allow your test scripts to do
443 Test::YourModule::set_builder(Test::Tester->capture);
447 =head1 TEST RESULTS
449 The result of each test is captured in a hash. These hashes are the same as
450 the hashes returned by Test::Builder->details but with a couple of extra
453 These fields are documented in L<Test::Builder> in the details() function
459 Did the test pass?
463 Did the test really pass? That is, did the pass come from
464 Test::Builder->ok() or did it pass because it was a TODO test?
468 The name supplied for the test.
472 What kind of test? Possibilities include, skip, todo etc. See
473 L<Test::Builder> for more details.
477 The reason for the skip, todo etc. See L<Test::Builder> for more details.
481 These fields are exclusive to Test::Tester.
487 Any diagnostics that were output for the test. This only includes
488 diagnostics output B<after> the test result is declared.
490 Note that Test::Builder ensures that any diagnostics end in a \n and
491 it in earlier versions of Test::Tester it was essential that you have
493 Test::Tester will add the \n if you forgot it. It will not add a \n if
499 This allows you to check that your test module is setting the correct value
500 for $Test::Builder::Level and thus giving the correct file and line number
501 when a test fails. It is calculated by looking at caller() and
502 $Test::Builder::Level. It should count how many subroutines there are before
516 always be 1 and that's what Test::Tester expects by default.
520 test then pass in undef.
527 Some of Test::Tester's functions return arrays of these hashes, just
528 like Test::Builder->details. That is, the hash for the first test will
531 test. This should usually be empty, if it's not, it means something
532 output diagnostics before any test results showed up.
537 are scratching your head trying to work out why Test::Tester is saying that
539 probably whitespace. From version 0.10 on, Test::Tester surrounds the
555 switch Test::Tester into a mode whereby all "tricky" characters are shown as
559 C<show_space()> in your test script or set the C<TESTTESTERSPACE> environment
586 tests inside it. You can run more than 1 test inside this subroutine if you
590 the first test.
592 @results is an array of test result hashes.
596 \%result is a ref to a test result hash.
598 \%expect is a ref to a hash of expected values for the test result.
606 \@results is a ref to an array of test results.
620 \@expect is a ref to an array of hash refs which are expected test results.
625 It returns the same values as run_tests, so you can further examine the test
632 \%expect is a ref to an hash of expected values for the test result.
635 cmp_tests into a single call, checking if the test died. It assumes
636 that only a single test is run inside \&test_sub and include a test to
639 It returns the same values as run_tests, so you can further examine the test
649 Normally, a test module (let's call it Test:MyStyle) calls
650 Test::Builder->new to get the Test::Builder object. Test::MyStyle calls
651 methods on this object to record information about test results. When
652 Test::Tester is loaded, it replaces Test::Builder's new() method with one
653 which returns a Test::Tester::Delegate object. Most of the time this object
654 behaves as the real Test::Builder object. Any methods that are called are
655 delegated to the real Test::Builder object so everything works perfectly.
656 However once we go into test mode, the method calls are no longer passed to
657 the real Test::Builder object, instead they go to the Test::Tester::Capture
658 object. This object seems exactly like the real Test::Builder object,
659 except, instead of outputting test results and diagnostics, it just records
664 Support for calling Test::Builder->note is minimal. It's implemented
671 L<Test::Builder> the source of testing goodness. L<Test::Builder::Tester>
672 for an alternative approach to the problem tackled by Test::Tester -
673 captures the strings output by Test::Builder. This means you cannot get
675 B<exactly> what your test will output.
682 Plan handling lifted from Test::More. written by Michael G Schwern
685 Test::Tester::Capture is a cut down and hacked up version of Test::Builder.
686 Test::Builder was written by chromatic <chromatic@wgz.org> and Michael G