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

Re: Unit test of script fails unless Test::Warnings is used‽

by 1nickt (Canon)
on Oct 13, 2019 at 01:10 UTC ( [id://11107392]=note: print w/replies, xml ) Need Help??


in reply to Unit test of script fails unless Test::Warnings is used?!

Hi, you should use Test::Exception:

#!perl use 5.010; use strict; use lib qw(bin); use Test::More; use Test::Exception; lives_ok sub { require 'script' }; done_testing;

Or better yet, always use Test::Most.

(Your test gets a fail result under prove because you declare done_testing with no tests run so the harness sees no passes. Add ok 1; and you'll get success.)

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Unit test of script fails unless Test::Warnings is used?!
by wanna_code_perl (Friar) on Oct 13, 2019 at 01:17 UTC

    I use Test::Exception all over this test suite. In fact, it was one of the use lines I deleted. :-)

    Using it for the require test hadn't occurred to me, though. I'll switch to that. Thanks. Edit: How would I replicate the OP's BAIL_OUT semantics when using lives_ok?

    Edit: Either you edited your reply, or I didn't see you answering the bit about why the test failed unless Test::Warnings was included. That makes perfect sense.

      "Edit: How would I replicate the OP's BAIL_OUT semantics when using lives_ok?"

      lives_ok sub { require 'script' } or BAIL_OUT("bin/script did not load: $@");
      :-)

      To make your test suite stop any time a test fails:

      use Test::Most 'die';
      (Although you cannot control the output as with BAIL_OUT, and it will apply to all tests in the file.)

      (Note that Test::Most loads Test::More and Test::Exception as well as others and warnings and strict.)

      Hope this helps!

      Update: showed one-test solution first


      The way forward always starts with a minimal test.

      Because Test::Warnings runs a test of its own, so the harness is satisfied. Output of your test script using Test::Warnings under --verbose:

      $ prove -lrv 11107390.t 11107390.t .. ok 1 - no (unexpected) warnings (via done_testing) 1..1 ok All tests successful.

      Hope this helps!


      The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-23 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found