test.pl
que se generó
automáticamente con h2xs
.
En general, la filosofía aconsejable para realizar un banco de pruebas de nuestro módulo es la que se articula en la metodología denominada Extreme Programming, descrita en múltiples textos, en concreto en el libro de Scott [12]:
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
. La utilidad
h2xs
incluso deja un programa de prueba PL-Tutu.t
en ese directorio.
La jerarquía de ficherojerarquía de ficheros la que trabajamos actualmente es:
lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu$ make veryclean rm -f blib/script/tutu blib/script/tutu.pl rm -rf ./blib Makefile.aperl ... mv Makefile Makefile.old > /dev/null 2>&1 rm -rf blib/lib/auto/PL/Tutu blib/arch/auto/PL/Tutu rm -rf PL-Tutu-0.01 rm -f blib/lib/PL/.Tutu.pm.swp ... rm -f *~ *.orig */*~ */*.orig lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu$ tree . |-- Changes |-- MANIFEST |-- MANIFEST.SKIP |-- META.yml |-- Makefile.PL |-- PL-Tutu-0.01.tar.gz |-- README |-- bb.txt |-- lib | `-- PL | |-- Error.pm | |-- Lexical | | `-- Analysis.pm | `-- Tutu.pm |-- scripts | |-- test01.sal | |-- test01.tutu | |-- tutu | `-- tutu.pl `-- t `-- 01Lexical.t 5 directories, 15 filesEstos son los contenidos de nuestro primer test:
lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu$ cd t lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu/t$ ls -l total 4 -rw-r--r-- 1 lhp lhp 767 2005-10-10 11:27 01Lexical.t lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu/t$ cat -n 01Lexical.t 1 # Before `make install' is performed this script should be runnable with 2 # `make test'. After `make install' it should work as `perl PL-Tutu.t' 3 4 ######################### 5 6 # change 'tests => 1' to 'tests => last_test_to_print'; 7 8 use Test::More tests => 2; 9 BEGIN { use_ok('PL::Lexical::Analysis') }; 10 #BEGIN { use_ok('PL::Tutu') }; 11 12 ######################### 13 14 # Insert your test code below, the Test::More module is use()ed here so read 15 # its man page ( perldoc Test::More ) for help writing this test script. 16 17 my $a = 'int a,b; string c; c = "hello"; a = 4; b = a +1; p b'; 18 my @tokens = scanner($a); 19 ok("@tokens" eq 20 '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');El nombre del fichero de prueba debe cumplir que:
01
, 02
, ...nos garanticen
el orden de ejecución
lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu$ make test PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/01Lexical....ok All tests successful. Files=1, Tests=2, 0 wallclock secs ( 0.05 cusr + 0.03 csys = 0.08 CPU)O bien usamos
prove
:
lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu/t$ prove -I../lib 01Lexical.t 01Lexical....ok All tests successful. Files=1, Tests=2, 0 wallclock secs ( 0.03 cusr + 0.01 csys = 0.04 CPU)También podemos añadir la opción
verbose
a prove
:
lhp@nereida:~/Lperl/src/topdown/PL0506/03lexico/PL-Tutu/t$ prove -I../lib -v 01Lexical.t 01Lexical....1..2 ok 1 - use PL::Lexical::Analysis; ok 2 - 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 ok All tests successful. Files=1, Tests=2, 0 wallclock secs ( 0.05 cusr + 0.00 csys = 0.05 CPU)Repáse la sección 6.16.7 para un mejor conocimiento de la metodología de pruebas en Perl.