Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Testing test function

by sedusedan (Monk)
on Sep 26, 2013 at 11:22 UTC ( #1055819=note: print w/replies, xml ) Need Help??

in reply to Re: Testing test function
in thread Testing test function

I'm referring to Test-Simple's tests (yes, like the file you mentioned, t/More.t). Basically I have this test_foo() function that uses Test::More and does several calls to ok(), is(), is_deeply() and subtest() inside it. I want to test that test_foo() works. Specifically, aside from making sure that test_foo() can pass a test, I need to test that test_foo() can also fail a test. Something like:

use Test::More;
ok( test_foo(a=>1), 'test_foo() should succeed if given a=1'); #1
ok(!test_foo(a=>2), 'test_foo() should fail if given a=2'); #2

That's the tricky part for me, since doing #2 will fail test_test_foo.t.

BTW, after looking at t/More.t, I also don't see that it tests failures like #2.

Replies are listed 'Best First'.
Re^3: Testing test function
by choroba (Bishop) on Sep 26, 2013 at 11:32 UTC
    Untested: What about
    ok(! eval { test_foo(a=>2) ; 1}, 'test_foo() should fail for a=2'); is($@, 'invalid argument', 'expected error');
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I'm afraid that wouldn't work, because test_foo() emits TAP as well as uses the same Test::Builder instance (since it uses Test::More also) and will interfere with the test script.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055819]
[LanX]: according to wp: Londoners voted in a referendum in 1998 to create new governance structures for Greater London.
[LanX]: so it was the will of the people to take back control
[LanX]: ;)
[marto]: and you still can't get a decent cup of tea in that town
[davies]: The turnout, IIRC, was about 12%.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-12-15 19:09 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (442 votes). Check out past polls.