App-Framework
view release on metacpan or search on metacpan
#!/usr/bin/perl
#
use strict ;
use Test::More ;
use App::Framework ;
# VERSION
our $VERSION = '1.234' ;
my $DEBUG=0;
my $VERBOSE=0;
my $stdout="" ;
my $stderr="" ;
diag( "Testing usage" );
my @man = (
'Must specify input file "source"',
'-help|h Print help',
'-man Full documentation',
'-name|n <arg> Test name',
'-nomacro Do not create test macro calls',
'-int <integer> An integer',
'-float <float> An float',
'-array <string> An array \(option may be specified multiple times\)',
'-hash <key=value> A hash \(option may be specified multiple times\)',
) ;
my @expected = (
'-verbose',
'-norun',
'-debug',
'-help',
'-man',
) ;
## start with a redirect check
eval{
local *STDOUT ;
local *STDERR ;
open(STDOUT, '>', \$stdout) or die "Can't open STDOUT: $!" ;
open(STDERR, '>', \$stderr) or die "Can't open STDERR: $!";
print "I was hoping for more!\n" ;
} ;
if (!$stdout)
{
diag("Sorry, can't redirect stdout: $@") ;
plan skip_all => 'Unable to redirect stdout (I need to redirect to check the man pages)';
exit 0 ;
}
else
{
## ok to run tests
plan tests => scalar(@man) + scalar(@expected) ;
}
## Manual pages
# Expect output (stdout):
#
#Error: Must specify input file "source"
#Usage:
# 01-Man [options] <source (input file)>
#
# Options:
#
# -debug=s Set debug level
# -h|help Print help
# -man Full documentation
# -log|L=s Log file
# -v|verbose Verbose output
# -dryrun|norun Dry run
# -n|name=s Test name
# -nomacro Do not create test macro calls
# -int <integer> An integer
# -float <float> An float
# -array <string> An array (option may be specified multiple times)
# -hash <key=value> A hash (option may be specified multiple times)
#
eval{
local *STDOUT ;
local *STDERR ;
open(STDOUT, '>', \$stdout) or die "Can't open STDOUT: $!" ;
open(STDERR, '>', \$stderr) or die "Can't open STDERR: $!";
@ARGV = () ;
App::Framework->new('exit_type'=>'die')->go() ;
# $app->go() ;
} ;
print "App: $stdout\n\n" ;
foreach my $test (@man)
{
like ($stdout, qr/$test/im, "Man page entry existance: $test");
}
## expect these options once & only once
foreach my $opt (@expected)
{
my $count = ($stdout =~ m/$opt/) ;
is ($count, 1, "Single option $opt") ;
}
#=================================================================================
# SUBROUTINES EXECUTED BY APP
#=================================================================================
#----------------------------------------------------------------------
# Main execution
#
sub app
{
my ($app) = @_ ;
}
#=================================================================================
# SUBROUTINES
#=================================================================================
#----------------------------------------------------------------------
sub split_man
{
my ($man) = @_ ;
my %man ;
my $section ;
foreach my $line (split "\n", $man)
{
if ($line =~ m/^(\S+)/)
{
$section = $1 ;
$man{$section} ||= '' ;
}
else
{
$line =~ s/^\s+//;
$line =~ s/\s+$//;
next unless $line ;
( run in 2.080 seconds using v1.01-cache-2.11-cpan-d8267643d1d )