App-Framework
view release on metacpan or search on metacpan
t/04-ArgsOpen.t view on Meta::CPAN
#!/usr/bin/perl
#
use strict ;
use Test::More;
use App::Framework ;
# VERSION
our $VERSION = '2.01' ;
my $DEBUG=0;
my $VERBOSE=0;
my $stdout="" ;
my $stderr="" ;
diag( "Testing args (open handles)" );
# 0 = arg name
# 1 = arg value (filename/dirname)
# 2 = check for opened
# 3 = check output file
# 4 = output file append
# 5 = input file
my @args = (
# 0 1 2 3 4 5
['src1', 't/args/file.txt', 1, 0, 0, 1],
['src2', 't/args/dir', 0, 0, 0, 0],
['src3', 't/args/exists.txt', 1, 0, 0, 1],
['out1', 't/args/outfile', 1, 1, 0, 0],
['out2', 't/args/outdir', 0, 0, 0, 0],
['out3', 't/args/outfile2', 1, 1, 1, 0],
) ;
my $open_checks = 0 ;
foreach my $arg_aref (@args)
{
$open_checks++ if $arg_aref->[2] ;
}
my $infile = 0 ;
my %contents ;
foreach my $arg_aref (@args)
{
if ($arg_aref->[5])
{
$infile++ ;
$contents{$arg_aref->[0]} = getfile($arg_aref->[1]) ;
}
}
my $outfile = 0 ;
foreach my $arg_aref (@args)
{
if ($arg_aref->[3])
{
my $file = $arg_aref->[1] ;
unlink $file if -f $file ;
$outfile++ ;
# create some contents
open my $fh, ">$file" ;
print $fh $contents{'src1'} ;
close $fh ;
}
}
plan tests => 2 + ((2 + (scalar(@args) * 2)) * 2 * 2) + (2 * $open_checks) + 2+2 + (1 * $outfile) + (1 * $infile) + $outfile + 1 ;
@ARGV = () ;
foreach my $arg_aref (@args)
{
push @ARGV, $arg_aref->[1] ;
}
( run in 0.627 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )