In an effort to improve testing on my modules, I am using Test::More and re-writing all of the tests. However, I am running into a small problem.

If I add Test::More to the Makefile.PL, this creates a dependency upon that module, that I would prefer it not to have. However, trying to write the test so that it if Test::More is installed it runs those tests, and runs the normal test.pl file if Test::More is not present, is giving me a headache. How would I go about implementing something like this? My attempt follows:
eval{ require Test::More; }; if(@$){ BEGIN { $| = 1; print "1..11\n"; } END {print "not ok 1\n" unless $loaded;} use Games::QuizTaker; $loaded = 1; print"Loaded ................. ok 1\n"; $Q1=Games::QuizTaker->new(FileName=>"sampleqa",Score=>1); if($$Q1{_FileName} eq "sampleqa"){ print"{_FileName} ............ ok 2\n"; }else{ print"{_FileName} ............ not ok 2\n"; } if($$Q1{_Delimiter} eq "|"){ print"{_Delimiter} ........... ok 3\n"; }else{ print"{_Delimiter} ........... not ok 3\n"; } $Q2=Games::QuizTaker->new(FileName=>"sample.csv",Delimiter=>","); if($$Q2{_Delimiter} eq ","){ print"{_Delimiter} init ...... ok 4\n"; }else{ print"{_Delimiter} init ...... not ok 4\n"; } my %hash=(); my $refhash=$Q1->load(\%hash); my $Num=keys %$refhash; if($Num == 9){ print"Load function .......... ok 5\n"; }else{ print"Load function .......... not ok 5\n"; } my($ref1,$ref2,$ref3,$ref4)=$Q1->generate(\%hash); my $num=keys %{$ref1}; if($num == 9){ print"Generate function ...... ok 6\n"; }else{ print"Generate function ...... not ok 6\n"; } my $V=$Q2->get_VERSION; if($V=~/^\d\.\d{1,3}/){ print"Version function ....... ok 7\n"; }else{ print"Version function ....... not ok 7\n"; } my $Q3=Games::QuizTaker->new(FileName=>"sample.csv",Delimiter=>",",Ans +wer_Delimi ter=>"x"); my $del=$Q3->get_Answer_Delimiter; if($del eq "x"){ print"Answer_Delimiter init .. ok 8\n"; }else{ print"Answer_Delimiter init .. not ok 8\n"; } my $Max=$Q3->get_Max_Questions; if($Max == 0){ print"Max_Questions init ..... ok 9\n"; }else{ print"Max_Questions init ..... not ok\n"; } my $Final=$Q3->get_Score; if(! defined $Final) { print"Final Score default .... ok 10\n"; }else{ print"Final Score default .... not ok 10\n"; } my $Final2=$Q1->get_Score; if(defined $Final2){ print"Final Score set ........ ok 11\n"; }else{ print"Final Score set ........ not ok 11\n"; } }else{ require Test::More; BEGIN { use_ok('Games::QuizTaker', 'Games::QuizTaker loaded'); } $Q1=Games::QuizTaker->new(FileName=>"sampleqa",Score=>1); ok($$Q1{_FileName} eq "sampleqa", 'FileName set'); ok($$Q1{_Delimiter} eq "|", 'Default delimiter set'); $Q2=Games::QuizTaker->new(FileName=>"sample.csv",Delimiter=>","); ok($$Q2{_Delimiter} eq ",",'File Delimiter set'); my %hash=(); my $refhash=$Q1->load(\%hash); my $Num=keys %$refhash; ok($Num == 9,'Load Function'); my($ref1,$ref2,$ref3,$ref4)=$Q1->generate(\%hash); my $num=keys %{$ref1}; ok($num == 9,'Generate Function'); my $V=$Q2->get_VERSION; ok($V=~/^\d\.\d{1,3}/, 'VERSION Function'); my $Q3=Games::QuizTaker->new(FileName=>"sample.csv",Delimiter=>",",A +nswer_Delimiter=>"x"); my $del=$Q3->get_Answer_Delimiter; ok($del eq "x", 'Answer_Delimiter init'); my $Max=$Q3->get_Max_Questions; ok($Max == 0,'Max Questions init'); my $Final=$Q3->get_Score; ok(! defined $Final,'Default Final Score'); my $Final2=$Q1->get_Score; ok(defined $Final2, 'Set Final Score'); }

TStanley
--------
The only thing necessary for the triumph of evil is for good men to do nothing -- Edmund Burke

In reply to Working with Test::More by TStanley

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.