#!/usr/bin/perl -w
#
# $Id: 100.2-good.t,v 1.2 2001/04/10 02:32:04 lrclause Exp $
#

use strict;
use English;
use File::Spec;
use File::Compare;
use Fatal qw/ unlink /;

use lib 't';
use MyTest;

use constant DEBUG => 0;

TEST
{
    my $program    = 'blib/script/paraget';
    my $child_prog = 'blib/script/paraget-child';
    my $homedir    = 'test';
    my $output     = 'test/out';
    my $mirror_set = 'cpan';
    my $filepath   = 'modules/by-module/XML/XML-Parser-2.29.tar.gz';
    my $original   = 'test/XML-Parser-2.29.tar.gz';
    my $get_from   = 'ftp://ftp.cpan.org/pub/CPAN/';
    
    if ( not -e $original )
    {
	my $url = $get_from.$filepath;
	
	print STDERR "$original not found; fetching it\n";
	( system ( $child_prog,
		   '--url', $url,
		   '--output', $original,
		   '--offset', 0,
		 )
	)
	  == 0 or die "error getting $url";
    }
    
    unlink $output if -e $output;
    my $size       = -s $original;
    
    unless ( ( system
	       $program,
	       '--homedir',       $homedir,
	       '--output',        $output,
	       '--mirror-set',    $mirror_set,
	       '--child-program', $child_prog,
	       '--size',          $size,
	       '--testing',
	       $filepath,
	     )
	     == 0
	   )
    {
	print STDERR "$program exited unsuccessfully\n" if DEBUG;
	return 0;
    }
    
    unless ( compare( $original, $output  ) == 0 )
    {
	print STDERR "$original and $output differ\n";
	return 0;
    }
    
    return 1;
}


syntax highlighted by Code2HTML, v. 0.9.1