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

Dear Monks, I am trying to create a module using the h2xs utility on a Windows XP box, I faced a couple of problems that I solved but then I got stuck forever at the final steps (More explanation later), this is my first attempt ever at learning modules creation using the "h2xs" and it seems that my problem here is very tiny so nevermind the lengthy explanation which details the steps I took in hope that a monk can discover where I lost track.

First Thing: The book I am reading from has given me the example for Unix, to parallelize it equally on Windoze I discovered I had to download the nmake.exe and the UnxUtils, I did so, configured the EnvVariable for UnxUtils and put the nmake.exe in the Windows folder as specified.

Second thing: I created the template for this module called "Integer::Doubler" as "%h2xs -A -X -n Integer::Doubler" so far so good, It created a directory /Integer/Doubler with files and template. I ran the '%perl Makefile.pl' to get the 'Makefile', edited the "Doubler.pm" to include a subroutine and then ran '%nmake' which created me another directory called "blib" and the empty file pm_to_blib then it copied the package "Doubler.pm" to the "blib" directory with the appropriate path, so far, all the commands worked fine, the problem arises from command 'nmake test'

Third Thing: I needed to test the test file in the /t directory, my parallelization to *nux ended here, the book is giving me a different example all together, and the test file created in the /t folder uses the module 'Test::More', which I think is not the case on Linux according to the book example of a test.pl file, Anyways I added to the test file the code 'print "2 * 2 =", doubler(2);' where the doubler() is the subroutine I created in the "Doubler.pm" before doing 'nmake' as

#This is an excerpt from the automatically generated module template a +fter running % h2xs -A -X -n Integer::Doubler package Integer::Doubler; use 5.010000; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.01'; sub doubler { return 2 * shift; # I declared this sub } 1;
#Here is test file generated and what I added to it (Only Last Line): # Before `make install' is performed this script should be runnable wi +th # `make test'. After `make install' it should work as `perl Integer-Do +ubler.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 1; BEGIN { use_ok('Integer::Doubler') }; ######################### # Insert your test code below, the Test::More module is use()ed here s +o read # its man page ( perldoc Test::More ) for help writing this test scrip +t. print "2 * 2 =", doubler(2); #<------here, line 16
and from cmd I then typed nmake test, it gives me the error that:
"undefined subroutine &main::doubler called at t/Integer-Doubler.t lin +e 16" "#Looks like your test exited with 255 just after 1" Test returned status 255 (wstat 65280, 0xff00) after all the subtests completed successfully Failed Test Stat Wstat Total Fail List of Failed ---------------------------------------------------------------------- +--------- t/Integer-Doubler.t 255 65280 1 0 ?? Failed 1/1 test scripts. 0/1 subtests failed. Files=1, Tests=1, 0 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 C +PU)

I am totally blank and confused as to why it could possibly be that the subroutine doubler was not exported as part of the package and that the testing 'nmake test' was looking in the &main::doubler instead of it looking in the Doubler.pm..I hope revered monks can guide me to where my erroneousness is I exhausted my capacity and I need help, hoping that I was able to explain my problem clear enough, I'm not laying a blame on Windoze this time..

I googled and I supersearched the Monastery but my search returned nothing related to Windows 'nmake test'...Hence I thought I'd better Ask at SOPW.

UPDATE: After making the corrections provided gracefully by ikegami the test is successful and after running 'nmake test' I get the following output

Skip blib\lib\Integer\Doubler.pm (unchanged) C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness( +0, 'blib\lib', 'blib\arch')" t/*.t t/Integer-Doubler....ok All tests successful. Files=1, Tests=1, 0 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 C +PU)
MISSION ACCOMPLISHED AND THANK YOU....


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Replies are listed 'Best First'.
Re: "nmake test" Error...
by ikegami (Patriarch) on Nov 15, 2009 at 20:15 UTC

    The mentioned error is because you didn't export doubler. See Exporter for details. First, make it exportable:

    our %EXPORT_TAGS = ( 'all' => [ qw( doubler ) ] );

    Second, import it. A normal script would import it as follows:

    use Integer::Doubler qw( doubler ); -or- use Integer::Doubler qw( :all );

    But a test script uses use_ok as follows instead in order to report compile issues in the module more nicely:

    BEGIN { use_ok 'Integer::Doubler', qw( doubler ); -or- use_ok 'Integer::Doubler', qw( :all ); }

    Finally, I wanted to mention an issue you haven't encountered yet. Don't print from your tests. Use the functions in Test::More instead. You'll use is almost exclusively, using ok only when is isn't sufficient (since is gives more info on failures).

    For example,

    print "2 * 2 =", doubler(2);
    should be
    is( doubler(2), 2*2, 'doubler(2)' );

    (The last argument is a short description of the test.)

    Now that you have two tests (use_ok and is), you need to tell that to the test harness.

    use Test::More tests => 2;
Re: "nmake test" Error...
by Anonymous Monk on Nov 15, 2009 at 19:06 UTC
    The default namespace (default package) is main; Because you're not exporting doubler (its not in any @EXPORT* variable), there is no main::doubler sub, so you would have to use the full name, Integer::Doubler::doubler() More on this in Simple Module Tutorial