[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Run mode that won't run...


Tim,

I know you got some great ideas but if you still don't
know what it is then make a test for it ...
interactively debug it:  perl -d t/mytest.cgi

Set the method to 'GET' so you see exactly what is
passed.  Now you can create a test for that same call
by creating a CGI query with those parameters and
calling your routine.  Then you can interactively deug
it.

David Scott

Attached is a template I use for testing
CGI::Applications ... I use both CGI::FormBuilder and
CGI.pm.

#!/usr/bin/perl -w

package main;
use strict;

use Test::More tests => 6;
use constant DEBUG => 0;

# force the output to return for testing
$ENV{CGI_APP_RETURN_ONLY} = 1;

# make explicit the query string
$ENV{REQUEST_METHOD} = 'GET';

BEGIN {
  use_ok('CGI::Application');
  use_ok('CGI');
  use_ok('CGI::FormBuilder');
  use_ok('WebApp');
  use_ok('File::Slurp');
}
{
        my $param = shift || "";
        my $redo = ( $param =~ /-r/ ) || 0;

        my $wa = WebApp->new( QUERY => CGI->new( { rm
=> 'mode',
                                ...
                                _submit => 'action',
                                 } ) );

        my $source = "";
        my @lines  = ();
        my @items  = ();
        my $okay   = 0;

        # registion confirmed output: 22dw from cut
and paste
        $ENV{QUERY_STRING}   = '';
        print "QS: $ENV{QUERY_STRING}\n" if DEBUG;
        $source = $0;                           #
program name
        $source =~ s/cgi$/out/;
        $okay = run( $source, $wa, suppressed, suppressed );
        my $name = $source;
        $name =~ s/\.out$//;
        $name =~ s/^t\///;
        $name =~ s/_/ /g;
        ok($okay, "Test " . $name );

# run_command($command,$host,$init_timeout,$timeout);
    sub run {
        my ($source, $ca, $lines, $items) = @_;

        my $target = $source;
        $target =~ s/out$/run/;
        unlink $target;

        # create target output
        @$lines = $ca->run();
        # replace any changeable data here like
time/date for DATE
#        $lines->[0] =~ s/received ... ...  \d+
\d+:\d+:\d+ \d+\./received DA
TE./;
        # read and write to have lines of data
        File::Slurp::write_file($target, @$lines);
        @$lines = File::Slurp::read_file($target);

        # Re-create source only if told or it is not
there

        # Re-create source only if told or it is not
there
        if ( ! -e $source || $redo ) {
            @$items = $ca->run();
            # replace any changeable data here like
time/date for DATE
#           $items->[0] =~ s/received ... ...  \d+
\d+:\d+:\d+ \d+\./received
 DATE./;
            File::Slurp::write_file($source, @$items);
            @$items = File::Slurp::read_file($source);
        } else {
            @$items = File::Slurp::read_file($source);
        }

        # compare sources
        my $okay = eq_array($lines,$items);
        if ( $okay ) {
            unlink $target;
        } else {
            diag("Source differed, see $target");
        }
        return $okay;
    }
}





__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.