Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Testing test function

by kcott (Chancellor)
on Sep 26, 2013 at 02:11 UTC ( #1055771=note: print w/replies, xml ) Need Help??

in reply to Testing test function

G'day sedusedan,

"I'm wondering if someone can point me to some simpler examples of testing a Test::Builder-based test function."

You ask for "simpler examples" but you don't indicate simpler than what. The EXAMPLES section of the Test::Builder documentation says: "CPAN can provide the best examples. Test::Simple, Test::More, Test::Exception and Test::Differences all use Test::Builder.". Are you looking for simpler examples than these? There are links to dozens of tests in the Test::Simple MANIFEST. Have you looked at those?

"I glanced at Test::More's tests once a while back and decided not to do it yet because they looked pretty hairy."

I'm not sure whether you're referring to the tests documented in Test::More or the tests written in t/More.t (or, possibly, something else). Perhaps start with Test::Tutorial. You can always ask here if there's something specific you're having problems with.

-- Ken

Replies are listed 'Best First'.
Re^2: Testing test function
by sedusedan (Monk) on Sep 26, 2013 at 11:22 UTC

    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.

      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://1055771]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-01-21 17:07 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (228 votes). Check out past polls.