Getopt-Class

 view release on metacpan or  search on metacpan

t/001_basic.t  view on Meta::CPAN

    dictionary => $dict,
    debug => $MODULE_DEBUG,
}) || BAIL_OUT( Getopt::Class->error, "\n" );
# $opt->message( $opt->dumper( $dict ) ); exit;
# my $params = $opt->parameters;
# my $options = $opt->options;
# $opt->message( $opt->dumper( $params ) ); exit;
isa_ok( $opt, 'Getopt::Class' );

{
    local @ARGV = qw( --debug 3 --dry-run --name Bob --created 2020-04-12T07:30:10 --langs en ja  --with-zlib --disable-compress --enable-logging );
    my $opts = $opt->exec || diag( "Error: " . $opt->error );
    ok( defined( $opts ), 'No Getopt::Long error' );
    is( Scalar::Util::reftype( $opts ), 'HASH', 'Expecting a hash reference' );
    is( $opts->{dry_run}, 1, 'Boolean option enabled' );
    is( $opts->{debug}, 3, 'Scalar reference of integer set' );
    is( $opts->{name}, 'Bob', 'String assignment' );
    isa_ok( $opts->{created}, 'DateTime', 'DateTime object set' );
    SKIP:
    {
        if( !ref( $opts->{created} ) || ref( $opts->{created} ) ne 'DateTime' )

t/002_help.t  view on Meta::CPAN

use lib './lib';
use Scalar::Util ();

BEGIN { use_ok( 'Getopt::Class' ) || BAIL_OUT( "Unable to load Getopt::Class" ); }

our( $dict, $DEBUG, $VERBOSE, $VERSION, $HELP, $MAN );

require( './t/dictionary.pl' );

{
    local @ARGV = qw( --help );
    my $opt2 = Getopt::Class->new({
        dictionary => $dict,
        debug => 0,
    });
    my $opts2 = $opt2->exec;
    is( $HELP, 'pod2usage help', 'Help code' );
}

t/003_man.t  view on Meta::CPAN

use lib './lib';
use Scalar::Util ();

BEGIN { use_ok( 'Getopt::Class' ) || BAIL_OUT( "Unable to load Getopt::Class" ); }

our( $dict, $DEBUG, $VERBOSE, $VERSION, $HELP, $MAN );

require( './t/dictionary.pl' );

{
    local @ARGV = qw( --man );
    my $opt3 = Getopt::Class->new({
        dictionary => $dict,
        debug => 0,
    });
    my $opts3 = $opt3->exec;
    is( $MAN, 'pod2usage man', 'Man code' );
}

t/004_missing.t  view on Meta::CPAN

use Scalar::Util ();

BEGIN { use_ok( 'Getopt::Class' ) || BAIL_OUT( "Unable to load Getopt::Class" ); }

our( $dict, $DEBUG, $VERBOSE, $VERSION, $HELP, $MAN );

require( './t/dictionary.pl' );

# Missing option
{
    local @ARGV = qw();
    my $opt4 = Getopt::Class->new({
        dictionary => $dict,
        debug => 0,
    });
    $opt4->required( [qw( name )] );
    my $opts4 = $opt4->exec;
    my $missing = $opt4->missing;
    is( $missing->[0], 'name', 'Missing check' );
}

t/005_regexp_mismatch.t  view on Meta::CPAN


BEGIN { use_ok( 'Getopt::Class' ) || BAIL_OUT( "Unable to load Getopt::Class" ); }

our( $dict, $DEBUG, $VERBOSE, $VERSION, $HELP, $MAN );

require( './t/dictionary.pl' );

# Wrong patter for language
{
    # diag( "\@ARGV value is '" . join( "', '", @ARGV ) . "'." );
    local @ARGV = qw( --langs FR );
    # diag( "\@ARGV value now is '" . join( "', '", @ARGV ) . "'." );
    my $opt5 = Getopt::Class->new({
        dictionary => $dict,
        debug => 0,
    });
    my $opts5 = $opt5->exec;
    my $err = $opt5->check_class_data( 'person' );
    is( exists( $err->{regexp}->{langs} ), 1, 'Data regular expression check' );
}

t/007_object.t  view on Meta::CPAN

our $_DEBUG = exists( $ENV{AUTHOR_TESTING} ) ? $ENV{AUTHOR_TESTING} : 0;

require( './t/dictionary.pl' );

my $opt = Getopt::Class->new({
    dictionary => $dict,
    debug => $_DEBUG,
}) || BAIL_OUT( Getopt::Class->error, "\n" );

{
    local @ARGV = qw( --debug 3 --dry-run --name Bob --created 2020-04-12T07:30:10 --langs en ja --define transaction_id=123 --define customer_id=456 --age 30 );
    my $obj = $opt->exec || diag( "Error: " . $opt->error );
    diag( "\$obj is $obj (", overload::StrVal( $obj ), ")" ) if( $_DEBUG );
    isa_ok( $obj, 'Getopt::Class::Values', 'Returning a Getopt::Class::Values' );
    my $rv = $obj->debug;
    diag( "\$obj->debug returned '", ( $rv // 'undef' ), "' (", overload::StrVal( $rv ), ")" ) if( $_DEBUG );
    diag( "debug value is $obj->{debug}" ) if( $_DEBUG );
    is( $obj->debug, 3, 'Checking option value for scalar' );
    isa_ok( $obj->debug, 'Module::Generic::Scalar', 'Class for scalar' );
    isa_ok( $obj->dry_run, 'Module::Generic::Boolean', 'Class for boolean' );
    isa_ok( $obj->created, 'DateTime', 'Class for datetime' );

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.172 second using v1.00-cache-2.02-grep-82fe00e-cpan-da92000dfeb )