[Milan-pm] test ok :-)

marcos rebelo oleber at gmail.com
Sat Oct 23 06:53:35 PDT 2010


Hi

It depends about how you are testing.

if you do:
#> perl Foo.t

gives you 2 tests, if you do

#> prove Foo.t

gives you 3 tests

The question is that prove parses the output of 'perl Foo.t'.


if your code does prints, even this prints shall be tested since they
are output. I usually use Test::Trap for the output



Best Regards
Marcos Rebelo

2010/10/23 Gianluca Casati <casati_gianluca at yahoo.it>:
> Ciao a tutti,
>
> volevo scrivervi per segnalarvi una curiosità riguardo i test, dato che si
> tratta di un tema che vorrei approfondire il più possibile (Marcos mi ha
> "cazziato" dicendomi che prima si scrivono i test e poi il codice :-).
>
> Ho un modulo del tipo
>
> package Foo;
> use Moose;
> sub task{ print "ok\n" }
> 1
>
> e un test del tipo
>
> use strict;
> use Test::More tests => 2;
>
> use_ok( 'Foo' ); # primo test ...
> my $foo = Foo->new();
> ok( $foo->task() , 'il task ha girato' ); # secondo test ...
>
> # ... ma se faccio un prove -l mi dice che hanno girato TRE test !!!!!!!!
>
> la cosa mi ha parecchio sorpreso, anche perchè l' ho scoperta veramente per
> caso ( o meglio, per "sfiga" :-)
>
> infatti se avessi fatto print "occhei\n" al posto di print "ok\n" non avrei
> avuto problemi :-)))) .
>
> Un saluto a tutti,
>
> alla prossima pizzata.
>
>
>
>
>
> _______________________________________________
> Milan-pm mailing list
> Milan-pm at pm.org
> http://mail.pm.org/mailman/listinfo/milan-pm
>
>



-- 
Marcos Rebelo
http://oleber.freehostia.com
Milan Perl Mongers leader http://milan.pm.org
Webmaster of http://perl5notebook.oleber.com


More information about the Milan-pm mailing list