Cada vez que hacemos make test observamos que se ejecuta el siguiente comando:
$ make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" \
"-e" "test_harness(0, 'blib/lib', 'blib/arch')" \
t/*.t
El módulo ExtUtils::Command::MM de la distribución ExtUtils::MakeMaker proporciona la función test_harness la cual tiene dos argumentos:
test_harness($verbose, @test_libs)Lo que hace es ejecutar todas las pruebas usando un módulo denominado Test::Harness. Si
verbose se pone a 1 se obtiene información
mas completa:
:~/Lperl/src/threads/knapsack/Algorithm-Knap01DP$ PERL_DL_NONLAZY=1 /usr/bin/perl \
"-MExtUtils::Command::MM" "-e" "test_harness(1, 'blib/lib', 'blib/arch')" t/*.t
t/01MartelloAndTothBook....1..11
ok 1 - use Algorithm::Knap01DP qw/Knap01DP ReadKnap/;;
ok 2 - ReadKnap knap21.dat
ok 3 - Knap01DP knap21.dat
ok 4 - ReadKnap knap22.dat
ok 5 - Knap01DP knap22.dat
ok 6 - ReadKnap knap23.dat
ok 7 - Knap01DP knap23.dat
ok 8 - ReadKnap knap25.dat
ok 9 - Knap01DP knap25.dat
ok 10
not ok 11 - Algorithm::Knap01DP->can('GenKnap') # TODO Randomly generated problem
# Failed (TODO) test (t/01MartelloAndTothBook.t at line 44)
# Algorithm::Knap01DP->can('GenKnap') failed
ok
All tests successful.
Files=1, Tests=11, 0 wallclock secs ( 0.08 cusr + 0.02 csys = 0.10 CPU)
El módulo Test::Harness
controla a los otros módulos de
la familia Test::.
Exporta la función runtests(@test_files)
la cual ejecuta todas los programas de prueba pasados en @test_files.
La función runtests intercepta la salida de las pruebas y las interpreta.
Las pruebas deben ajustar su salida al protocolo TAP: Test All Protocol
Se supone que toda prueba debe escribir primero la cadena 1..M
donde M es el número de pruebas y después, por cada prueba
la salida debe contener la cadena ok N, donde N es el numeral de
la prueba. Cuando una prueba es TODO su salida debe contener la cadena
# TODO después de not ok o de ok. El texto que sigue
después de esto es la descripción de lo que se supone que debería
hacerse.
La utilidad prove provee un acceso a las funcionalidades de
Test:Harness y constituye una alternativa a make test durante el
desarrollo del módulo.
Veamos un ejemplo e uso:
~/Lperl/src/threads/knapsack/Algorithm-Knap01DP/t$ prove -I../lib 01MartelloAndTothBook.t 01MartelloAndTothBook....ok All tests successful. Files=1, Tests=11, 0 wallclock secs ( 0.07 cusr + 0.02 csys = 0.09 CPU)La opción
v activa el modo verbose:
$ prove -v -I../lib 01MartelloAndTothBook.t
01MartelloAndTothBook....1..11
ok 1 - use Algorithm::Knap01DP qw/Knap01DP ReadKnap/;;
ok 2 - ReadKnap knap21.dat
ok 3 - Knap01DP knap21.dat
ok 4 - ReadKnap knap22.dat
ok 5 - Knap01DP knap22.dat
ok 6 - ReadKnap knap23.dat
ok 7 - Knap01DP knap23.dat
ok 8 - ReadKnap knap25.dat
ok 9 - Knap01DP knap25.dat
ok 10
not ok 11 - Algorithm::Knap01DP->can('GenKnap') # TODO Randomly generated problem
# Failed (TODO) test (01MartelloAndTothBook.t at line 44)
# Algorithm::Knap01DP->can('GenKnap') failed
ok
All tests successful.
Files=1, Tests=11, 0 wallclock secs ( 0.11 cusr + 0.00 csys = 0.11 CPU)
Si se quieren ejecutar las pruebas de un cierto programa de prueba t/*.t mientras
se está editando con vim
se puede poner el siguiente atajo en el fichero
~/.vimrc5.6:
map ,t <Esc>:!prove -vl %<CR>
El objetivo testdb del Makefile generado permite correr las pruebas
bajo el control del depurador:
pp2@nereida:~/LGRID_Machine$ make testdb TEST_FILE=t/13pipes.t
PERL_DL_NONLAZY=1 /usr/bin/perl -d "-Iblib/lib" "-Iblib/arch" t/13pipes.t
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
1..15
ok 1 - use GRID::Machine;
main::(t/13pipes.t:6): my $test_exception_installed;
main::(t/13pipes.t:7): BEGIN {
DB<1> c
Name "DB::single" used only once: possible typo at blib/lib/GRID/Machine/REMOTE.pm line 569.
ok 2 - No fatals creating a GRID::Machine object
ok 3 - No fatals opening not redirected output pipe
ok 4 - No fatals sending to pipe 10
ok 5 - No fatals sending to pipe 9
ok 6 - No fatals sending to pipe 8
ok 7 - No fatals sending to pipe 7
ok 8 - No fatals sending to pipe 6
ok 9 - No fatals sending to pipe 5
ok 10 - No fatals sending to pipe 4
ok 11 - No fatals sending to pipe 3
ok 12 - No fatals sending to pipe 2
ok 13 - No fatals sending to pipe 1
ok 14 - No fatals sending to pipe 0
0
1
2
3
4
5
6
7
8
9
10
ok 15 - No fatals closing pipe
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<1> q
pp2@nereida:~/LGRID_Machine$