Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Optional modules for tests?

by tachyon (Chancellor)
on Sep 06, 2003 at 06:33 UTC ( [id://289429]=note: print w/replies, xml ) Need Help??


in reply to Optional modules for tests?

# Test::More SKIP: { eval { require Some::Module }; skip "Some::Module not installed", 2 if $@; my $obj = new Some::Module; isa_ok( $obj, "Some::Module" ); $obj->parse( $stuff ); is( $obj->errors, 0, "No errors found" ); } # Test syntax eval{ require Some::Module } if ( $@ ) { skip( 'Some Module not installed' ); } else { ok( $some_test ); }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Optional modules for tests?
by sutch (Curate) on Sep 07, 2003 at 02:21 UTC
    Thanks for the response.

    I've been experimenting with this and have minimized my test code to the following:

    use Test::More tests => 1; SKIP: { eval{ require Data::Dummy }; skip "Data::Dummy not installed", 2 if $@; ok( 1 ); }
    This works fine when the required module is present, but in the case of a non-existant module (such as with the above Data::Dummy), the following is reported:
    C:\>nmake test Microsoft (R) Program Maintenance Utility Version 1.50 Copyright (c) Microsoft Corp 1988-94. All rights reserved. C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harn +ess(0, 'blib\lib', 'blib\arch')" t\test.t t\test....# Looks like you planned 1 tests but ran 1 extra. t\test....dubious Test returned status 1 (wstat 256, 0x100) DIED. FAILED test Failed 0/1 tests, 100.00% okay (less 2 skipped tests: -1 okay, + -100.00%) Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t\test.t 1 256 1 0 0.00% 2 subtests skipped. Failed 1/1 test scripts, 0.00% okay. -1/1 subtests failed, 200.00% oka +y. NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code + '0x2' Stop.
    I don't understand why this would complain of skipping two subtests, nor why it says that I planned 1 test but ran 1 extra. Is this what normally happens when tests are skipped?
      skip "Data::Dummy not installed", 2 if $@; # ^ ^ # MESSAGE, NUM_TESTS_TO_SKIP

      You are only skipping 1 test but you are telling Test::More you are skipping 2 but your plan was only to do 1 test.....

      skip "Data::Dummy not installed", 1 if $@; ^ ^

      Will work just fine.....I even tested it ;-) Test::Harness hates plan != number of tests reported. See my Autogenerate Test Scripts for a neat little widget that will re-number your tests and fix your plan as well as writing most of the Test code for you.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-28 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found