Versiones posteriores a la 5.8



Subsecciones

Lenguajes y Herramientas de Programacion 2011-02-02
1 # Before `make install' is performed this script should be runnable with 2 # `make test'. After `make install' it should work as `perl test.pl' 3 4 ######################### 5 6 # change 'tests => 1' to 'tests => last_test_to_print'; 7 8 use Test; 9 BEGIN { plan tests => 1 }; 10 use PL::Tutu; 11 ok(1); # If we made it this far, we're ok. 12 13 ######################### 14 15 # Insert your test code below, the Test module is use()ed here so read 16 # its man page ( perldoc Test ) for help writing this test script. 17 En la línea 9 se establece el número de pruebas a realizar. La primera prueba aparece en la línea 11. Puede parecer que no es una prueba, ¡pero lo es!. Si se ha alcanzado la línea 11 es que se pudo cargar el módulo PL::Tutu y eso ¡tiene algún mérito!.

Seguiremos el consejo de la línea 15 y escribiremos nuestra segunda prueba al final del fichero test.pl:

$ cat -n test.pl | tail -7
16  # its man page ( perldoc Test ) for help writing this test script.
17
18  my $a = 'int a,b; string c; c = "hello"; a = 4; b = a +1; p b';
19  local @PL::Tutu::tokens = ();
20  Lexical::Analysis::scanner($a);
21  ok("@PL::Tutu::tokens" eq
22  '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');
La línea 22 ha sido partida por razones de legibilidad, pero constituye una sóla línea. Ahora podemos ejecutar make test y comprobar que las dos pruebas funcionan:
$ make test
PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/usr/lib/perl/5.6.1 \
                                -I/usr/share/perl/5.6.1 test.pl
1..2
ok 1
ok 2
¿Recordaste cambiar la línea 9 de test.pl? ¿Añadiste los nuevos ficheros a la lista en MANIFEST?

Lenguajes y Herramientas de Programacion 2011-02-03