Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Can I use Test::Differences with Test::LectroTest?

by fergal (Chaplain)
on Feb 01, 2005 at 17:46 UTC ( [id://426977]=note: print w/replies, xml ) Need Help??


in reply to Can I use Test::Differences with Test::LectroTest?

I haven't used LectroTest but if you could explain what goes wrong when you try to use Test::Deep then I might be able to tell you what to do or change Test::Deep so that it just works.

Update. After a quick look at LT's docs it seems that using eq_deeply() is the right thing to do and the following should just work.

use Test::Deep; Property { ##[ x <- Int, y <- Int #]## my @expected = map { $x * $_ } 0 .. $y; # Or something ... my @result = getDataAsArray( $x, $y ); eq_deeply( \@result, \@expected ); }, name => "Transmogrifer parameters ok";
Does something bad happen when you try this?

Replies are listed 'Best First'.
Re^2: Can I use Test::Differences with Test::LectroTest?
by pernod (Chaplain) on Feb 01, 2005 at 18:15 UTC

    Oh! Seems like I should have fiddled more ...

    I built a little on my square example, and made this trivial snippet.

    #! /usr/bin/perl use Test::LectroTest; use Test::Deep; sub square { my $square = $_[ 0 ] * $_[ 0 ]; return [ $square, $square ]; } Property { ##[ x <- Int #]## my $sq = $x * $x; eq_deeply( square( $x ), [ $sq, $sq ] ); }, name => "Finding \$x's square. Twice!";

    This passes, and gives the normal output of:

    c:/dev/fun $ perl lec.pl 1..1 ok 1 - 'Finding $x's square. Twice!' (1000 attempts)

    Not enough research on my part evidently. My bad. At least it answers my original question. Yes, you can use other testing modules with Test::LectroTest :)

    But if I try the same with Test::Differences (by changing Test::Deep to Test::Differences and swapping eq_or_diff with eq_deeply), I get the following:

    c:/dev/fun $ perl lec.pl 1..1 Can't identify test lib in use, doesn't seem to be Test.pm or Test::Bu +ilder based at c:/perl/site/lib/Test/Differences.pm line 409 Test::Differences::eq_or_diff('ARRAY(0x11c9fec)', 'ARRAY(0x11c9fe0 +)') called at lec.pl line 15 main::__ANON__('Test::LectroTest::TestRunner::testcontroller=ARRAY +(0x11c9fb0)', 1) called at c:/perl/site/lib/Test/LectroTest/TestRunne +r.pm line 196 eval {...} called at c:/perl/site/lib/Test/LectroTest/TestRunner.p +m line 193 Test::LectroTest::TestRunner::run('Test::LectroTest::TestRunner=HA +SH(0x1263fbc)', 'Test::LectroTest::Property=HASH(0x11c9f68)') called +at c:/perl/site/lib/Test/LectroTest/TestRunner.pm line 289 Test::LectroTest::TestRunner::run_suite('Test::LectroTest::TestRun +ner=HASH(0x1263fbc)', 'Test::LectroTest::Property=HASH(0x11c9f68)') c +alled at c:/perl/site/lib/Test/LectroTest.pm line 157 Test::LectroTest::run() called at c:/perl/site/lib/Test/LectroTest +.pm line 160 Test::LectroTest::END() called at lec.pl line 0 eval {...} called at lec.pl line 0 ok ok ok . . . # Followed by 997 more ok's

    Looks like this is something related to how Test::Differences reports results. A Test::Builder issue, perhaps? I'll have a look into the code and see if I can figure something out.

    Thanks for the quick reply, fergal, and for pointing me in the right direction.

    pernod
    --
    Mischief. Mayhem. Soap.

      Both Test::Differences::eq_or_diff and Test::Deep::is_deeply want to call Test::Builder->ok($pass_or_fail) after they do their comparison, they also output diagnostics each time. They are not suitable for use with LT as LT wants to call them 1000s of times for each call to Test::Builder->ok.

      Test::Deep::eq_deeply is different, it just returns the result, no diagnostics, no talking to the test framework, it's designed for use independently of the test framework. Test::Differences may have a similar function, I'm not sure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found