next up previous contents index practicapracticaPP2moodleLHPmoodlepserratacpanmodulospauseperlgoogleetsiiullpcgull
Sig: Práctica: Construcción de una Sup: Bancos de Pruebas y Ant: Versiones anteriores a la Err: Si hallas una errata ...

Versiones posteriores a la 5.8

Si usas una versión de Perl posterior la 5.8.0, entonces tu versión del programa h2xs creará un subdirectorio /t en el que guardar los ficheros de prueba Estos ficheros deberán ser programas Perl de prueba con el tipo .t. El programa test.pl desaparece. La estructura queda como sigue:
$ perl -V | grep -i summary
Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
$ h2xs -AXn PL::Tutu
Defaulting to backwards compatibility with perl 5.8.4
If you intend this module to be compatible with earlier perl versions, please
specify a minimum perl version with the -b option.

Writing PL-Tutu/lib/PL/Tutu.pm
Writing PL-Tutu/Makefile.PL
Writing PL-Tutu/README
Writing PL-Tutu/t/PL-Tutu.t
Writing PL-Tutu/Changes
Writing PL-Tutu/MANIFEST
$ tree
.
`-- PL-Tutu
    |-- Changes
    |-- MANIFEST
    |-- Makefile.PL
    |-- README
    |-- lib
    |   `-- PL
    |       `-- Tutu.pm
    `-- t
        `-- PL-Tutu.t

4 directories, 6 files
Nos cambiamos al directorio:
$ cd PL-Tutu/
$ ls -l
total 24
-rw-r--r--  1 lhp lhp  154 Nov  3 12:59 Changes
-rw-r--r--  1 lhp lhp   63 Nov  3 12:59 MANIFEST
-rw-r--r--  1 lhp lhp  552 Nov  3 12:59 Makefile.PL
-rw-r--r--  1 lhp lhp 1196 Nov  3 12:59 README
drwxr-xr-x  3 lhp lhp 4096 Nov  3 12:59 lib
drwxr-xr-x  2 lhp lhp 4096 Nov  3 12:59 t
$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for PL::Tutu
$ ls -ltr
total 44
drwxr-xr-x  2 lhp lhp  4096 Nov  3 12:59 t
drwxr-xr-x  3 lhp lhp  4096 Nov  3 12:59 lib
-rw-r--r--  1 lhp lhp  1196 Nov  3 12:59 README
-rw-r--r--  1 lhp lhp   552 Nov  3 12:59 Makefile.PL
-rw-r--r--  1 lhp lhp    63 Nov  3 12:59 MANIFEST
-rw-r--r--  1 lhp lhp   154 Nov  3 12:59 Changes
-rw-r--r--  1 lhp lhp 19471 Nov  3 13:03 Makefile
Ahora podemos ejecutar el primer test:
$ make test
cp lib/PL/Tutu.pm blib/lib/PL/Tutu.pm
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/PL-Tutu....ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.04 cusr +  0.02 csys =  0.06 CPU)
Observe que, como consecuencia de esta primera ejecución se han creado nuevos directorios:
$ tree
.
|-- Changes
|-- MANIFEST
|-- Makefile
|-- Makefile.PL
|-- README
|-- blib
|   |-- arch
|   |   `-- auto
|   |       `-- PL
|   |           `-- Tutu
|   |-- lib
|   |   |-- PL
|   |   |   `-- Tutu.pm
|   |   `-- auto
|   |       `-- PL
|   |           `-- Tutu
|   `-- man3
|-- lib
|   `-- PL
|       `-- Tutu.pm
|-- pm_to_blib
`-- t
    `-- PL-Tutu.t

14 directories, 9 files

Los contenidos del fichero de prueba son similares al de las versiones previas:

$ cat t/PL-Tutu.t
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl PL-Tutu.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use Test::More tests => 1;
BEGIN { use_ok('PL::Tutu') };

#########################

# 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.
Sólo que en vez de usar el módulo Test se usa el módulo Test::More el cual, como su nombre indica nos provee con un variado conjunto de funciones de prueba. Para mas información escriba perldoc Test::More.

Ahora ampliamos la batería de pruebas con una prueba mas 02lex.t:

$ pwd
/home/lhp/perl/src/topdown/PL/5.8/PL-Tutu/t
$ ls -l
total 8
-rw-r--r--  1 lhp lhp 446 Nov  3 15:03 02lex.t
-rw-r--r--  1 lhp lhp 465 Nov  3 13:11 PL-Tutu.t
Pero antes renombramos el fichero PL-Tutu.t:
$ mv PL-Tutu.t 01load.t
Esto lo hacemos con dos objetivos en mente: El programa 02lex.t pone a prueba el analizador léxico:
$ cat 02lex.t
# change 'tests => 1' to 'tests => last_test_to_print';

use Test::More tests => 2;
BEGIN { use_ok('PL::Tutu') };

#########################

my $a = 'int a,b; string c; c = "hello"; a = 4; b = a +1; p b';
local @PL::Tutu::tokens = ();
Lexical::Analysis::scanner($a);
ok("@PL::Tutu::tokens" eq
'INT INT ID a PUN , ID b PUN ; STRING STRING ID c PUN ; ID c PUN = STR "hello" PUN ; 
ID a PUN = NUM 4 PUN ; ID b PUN = ID a PUN + NUM 1 PUN ; P P ID b');
Ahora probamos de nuevo los tests:
$ make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" 
                  "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/01load....ok
t/02lex.....ok
All tests successful.
Files=2, Tests=3,  0 wallclock secs ( 0.15 cusr +  0.02 csys =  0.17 CPU)


next up previous contents index practicapracticaPP2moodleLHPmoodlepserratacpanmodulospauseperlgoogleetsiiullpcgull
Sig: Práctica: Construcción de una Sup: Bancos de Pruebas y Ant: Versiones anteriores a la Err: Si hallas una errata ...
Casiano Rodríguez León
2006-02-21