I have an application which uses interchangeable backends. For normal use you have to pick one, since they each define the same subs in the same package that do different things.

During testing I usually start with a single test file, which tries to use all the modules. But, when I do that for this project, I get subroutine redefinition warnings. As you can see below, I tried some variations of no warnings without much luck. Is there a way to suppress these, or do I have to use separate test files?

Here are some of my attempts (all of them led directly to redefined warnings):

use Test::More tests => 2; no warnings; BEGIN { use_ok( 'Backend::A' ); } BEGIN { use_ok( 'Backend::B' ); }

use Test::More tests => 2; no warnings qw( redefine ); BEGIN { use_ok( 'Backend::A' ); } BEGIN { use_ok( 'Backend::B' ); }

use Test::More tests => 2; BEGIN { use_ok( 'Backend::A' ); } BEGIN { no warnings qw( redefine ); use_ok( 'Backend::B' ); }

# having given up on testing temporarily: no warnings qw( redefine ); require Backend::A; require Backend::B;
Phil

In reply to Suppressing Subroutine redefined warning by philcrow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.