A lot of people here uses CGI::Application, Class::DBI and HTML::Template for their development, and i wonder how do they write their tests suites.

Testing Class::DBI its easy and I usually use a pipe to get CGI::Application STDOUT:
$dades=run('rm=login login=test password=foo'); ok( $dades =~ /No such login/,'Webapp login bad login successful'); $dades=run('rm=stats'); ok( $dades =~ /Invalid cookie/,'Webapp stats no cookie successful'); $dades=run('rm=stats',1); ok( $dades =~ /Resume for/,'Webapp stats running successful'); ##################################### sub run { pipe(STDIN,STDOUT); ### unless(fork()) { close(STDIN); local $_ = shift; if(shift) { *CGI::cookie = sub { 'a_valid_session_for_test' }; } while (/([^=&\s]+)=([^=&\s]+)/g) { $webapp->query->param($1,$2); } $webapp->run(); $_ = *CGI::cookie; # Just to avoid warnings exit; } else { close(STDOUT); return join "\n",<STDIN>; } }

How do you write your own tests?

$anarion=\$anarion;

s==q^QBY_^=,$_^=$[x7,print

In reply to Tests for CGI::Application by Anarion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.