Section 16.6. Trivial make test


16.6. Trivial make test

Testing. Testing. Testing. We talk more about testing in depth in Chapters 17 and 18, but here's a brief introduction.

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.[*] Next, the perl that invoked the Makefile.PL is called upon to run the test harnessa program that manages all test invocations and reports the results at the end.[]

[] The perl that invoked the Makefile.PL is used for all configuration decisions. If you have more than one version of Perl installed on your system, be sure to execute the Makefile.PL with the correct one. From there, full paths are always used, so theres no chance of mixing anything else up.

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 manpage ( 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 17. 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 if the module had a syntax error, or 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.




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net