[ Team LiB ] |
13.7 Trivial make testTesting. Testing. Testing. Testing is important. First, you should at least ensure that the code you've written even compiles before you install it and start playing with it. That test is free. You can invoke it directly from the newly created Makefile by simply typing make test, as in: $ make test cp Maps.pm blib/lib/Island/Plotting/Maps.pm PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/1....ok All tests successful. Files=1, Tests=1, 1 wallclock secs ( 0.08 cusr + 0.04 csys = 0.12 CPU) But what happened there? First, the .pm file was copied to the testing staging area: the area headed by blib (build library) below the current directory.[12]
Next, the perl that invoked the Makefile.PL is called upon to run the test harness—a program that manages all test invocations and reports the results at the end.[13]
The test harness runs all files in the t subdirectory that end in .t in their natural order. You have only one file (created by h2xs), which looks like this: $ cat t/1.t # Before 'make install' is performed this script should be runnable with # 'make test'. After 'make install' it should work as 'perl 1.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 1; BEGIN { use_ok('Island::Plotting::Maps') }; ######################### # Insert your test code below, the Test::More module is use( )ed here so read # its man page ( perldoc Test::More ) for help writing this test script. It's a simple test program. The test pulls in the Test::More module, described further in Chapter 14. The import list for the module is treated specially; you're declaring that this test file consists of only one "test." The test is given in the following line and attempts to use the module. If this succeeds, you get an "OK" sign, and the overall test file succeeds. This would fail with bad syntax, or perhaps if you forgot to have that true value at the end of the file. In this example, the test succeeds, so you get a message for it and a summary of the CPU time used for the test. |
[ Team LiB ] |