Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Testing test function

by tobyink (Abbot)
on Sep 26, 2013 at 20:09 UTC ( #1055891=note: print w/ replies, xml ) Need Help??


in reply to Testing test function

Test::More comes with Test::Builder::Tester for testing testing modules. It's horrible. Just horrible.

Use Test::Tester instead. Here's an example of using Test::Tester to test the is_deeply function from Test::More, and make sure there isn't some insane bug in is_deeply that nobody's ever noticed...

use strict; use warnings; use Test::Tester; use Test::More 0.96; subtest "two identical structures" => sub { my (undef, $result1) = run_tests sub { is_deeply( [1,2,3], [1..3] +) }; ok( $result1->{ok}, 'is_deeply passes', ); is( $result1->{diag}, '', 'no unnecessary diagnostics printed', ); done_testing; }; subtest "two different structures" => sub { my (undef, $result2) = run_tests sub { is_deeply( [1,3], [1..3] ) +}; ok( !$result2->{ok}, 'is_deeply fails' ); like( $result2->{diag}, qr{Structures begin differing}, 'expected diagnostics ok' ); done_testing; }; done_testing;

TL;DR: run_tests runs some tests in a coderef, captures the TAP output, and turns it into a list of hashrefs of test results. You can then use plain old Test::More functions to test those test results.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re: Testing test function
Select or Download Code
Replies are listed 'Best First'.
Re^2: Testing test function
by sedusedan (Monk) on Sep 27, 2013 at 06:24 UTC
    Thanks Toby, Test::Tester is exactly what I want. I'm gonna take your word on Test::Builder::Tester being horrible, besides it's a bit too low-level for my taste.
Re^2: Testing test function
by sedusedan (Monk) on Sep 27, 2013 at 17:20 UTC
    I ended up not using Test::Tester because it has problems with subtests (submitted as wishlist to RT), so I currently run the test in a subprocess and parse the TAP output manually.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2015-07-31 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls