Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

MakeMaker, testing, and packages with modules

by Rhys (Pilgrim)
on Sep 06, 2004 at 00:42 UTC ( [id://388688]=perlquestion: print w/replies, xml ) Need Help??

Rhys has asked for the wisdom of the Perl Monks concerning the following question:

Okay, so I've built this big Perl app. It started a long time ago as a giant kludge, since I didn't know squat about decent package-building practices, and not that much about good programming (although enough that the thing worked and wasn't too hard to maintain).

Years have gone by, and the app now has POD (which needs updating), several included modules, and gets built/installed with MakeMaker. All very cool so far.

My questions involve testing and the modules. At present, I can't even do a simple t/Basic.t test that does use MyApp::EachMod; because I use SNMP; (from Net-SNMP). On RedHat, anyway, this fails with:

PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/Basic....Can't load '/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thr +ead-multi/auto/SNMP/SNMP.so' for module SNMP: /usr/lib/perl5/vendor_p +erl/5.8.0/i386-linux-thread-multi/auto/SNMP/SNMP.so: undefined symbol +: PerlIO_fprintf at /usr/lib/perl5/5.8.0/i386-linux-thread-multi/Dyna +Loader.pm line 229, <DATA> line 48.

According to the net-snmp-users list archive, this is fixed in Net-SNMP-5.1, whereas RHEL is still using 5.0.9, but I digress...

Anyway, I can only think of two generic tests that one can run on a given module/script/chunk of code. They are:

  1. perl -wc filename
  2. perl -e'use mod;' (modules only)

In the 'big app', my current t/Basic.t does use MyApp::EachMod; on any module that doesn't use SNMP; for the moment, and another little package I built to distribute a bunch of little scripts using a simple Makefile does perl -wc $(PERLFILES), when I do make test or make check. I also have use strict; in everything (although I don't use warnings;).

SO... aside from attempting to give each piece of code a known set of inputs and looking for a known set of outputs (stuff that Test::More is good at), are there any other generic tests or procedures that folks use to make sure their code doesn't have junk in it?

More importantly, is there a TFM I should R on this topic? :-)

--J

Replies are listed 'Best First'.
Re: MakeMaker, testing, and packages with modules
by grantm (Parson) on Sep 06, 2004 at 00:59 UTC

    The Test::Simple distribution comes with a pretty good tutorial on testing.

    Another very handy tool is Devel::Cover. It can run your test suite with debugger hooks in place to log which lines of code have been executed and which branches have been followed. It can then produce fancy HTML reports that tell you what percentage of your code is exercised by the test suite and even colour codes the lines of source. Drill down into some of the links on this page for an example.

Re: MakeMaker, testing, and packages with modules
by tachyon (Chancellor) on Sep 06, 2004 at 02:02 UTC

    A broken module install that your module depends on means it aint gonna work until that is fixed so the test results are exactly what you want. To get it to insist that you have Net::SNMP 5.1+ then just add this to your Makefile.PL and it will choke on the Makefile.PL unless Net::SNMP 5.1 is installed.

    WriteMakefile( 'NAME' => 'MyApp::EachMod', ..... 'PREREQ_PM' => { Net::SNMP => 5.1 }, ..... );

    cheers

    tachyon

      Yup. I just finished building the Net-SNMP package v5.1.2 from the src.rpm file on SourceForge. It's a bit tricky upgrading on RedHat, due to dependency issues, so I'm not sure this implementation is ready for a production server, BUT...

      Yes, you're right. Once I get this worked out, I need to update the Makefile.PL. Right now, I think it accepts SNMP >= 4.1.2...

      WARNING! Do not confuse the Net-SNMP libraries with the Net::SNMP Perl module available on CPAN!

      To tell the difference:

      use Net::SNMP; # Comes from CPAN. use SNMP; # Comes from Net-SNMP library.

      Yeah, it sucks, but at least one can tell the difference. The Net-SNMP module came first, but at the time, the library was called "UCD-SNMP". The name change make sense from the C standpoint, but is unfortunate from a Perl standpoint.

      Anyway, the thing built, with a little tweak to the specfile, and installed with --nodeps. A little more work and I'm back to the original problem. :-)

      --J

      Update: To get the net-snmp-5.1.2-1.src.rpm to build properly and install safely, I had to...

      up2date -i beecrypt-devel perl -eshell -MCPAN cpan> install Term::ReadKey cpan> install Tk rpm -ivh net-snmp-5.1.2-1.src.rpm cd /usr/src/redhat/SPECS rpmbuild -ba --clean --target i686 --with perl_modules net-snmp.spec rpm --erase net-snmp-devel net-snmp-utils net-snmp-perl cd /usr/src/redhat/RPMS/i686 rpm --nodeps -Uvh net-snmp-5.1.2-1.i686.rpm rpm -ivh net-snmp-devel-5.1.2-1.i686.rpm rpm -ivh net-snmp-perlmods-5.1.2-1.i686.rpm

      So far, Ethereal still works (and decodes SNMP packets properly), and my t/Basic.t no longer fails. Woo hoo!

Re: MakeMaker, testing, and packages with modules
by jbodoni (Monk) on Sep 06, 2004 at 04:46 UTC
    This is close to three years old, but I found it very informative.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://388688]
Approved by ikegami
Front-paged by Old_Gray_Bear
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: (2)
As of 2024-04-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found