File: 00-new.t

package info (click to toggle)
libgetopt-lucid-perl 1.07-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 364 kB
  • ctags: 68
  • sloc: perl: 855; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,432 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use Test::More;
use Data::Dumper;
use Exception::Class::TryCatch;

# Work around win32 console buffering that can show diags out of order
Test::More->builder->failure_output(*STDOUT) if $ENV{HARNESS_VERBOSE};

use Getopt::Lucid ':all';
use Getopt::Lucid::Exception;

sub why {
    my %vars = @_;
    $Data::Dumper::Sortkeys = 1;
    return "\n" . Data::Dumper->Dump([values %vars],[keys %vars]) . "\n";
}

#--------------------------------------------------------------------------#
# Test cases
#--------------------------------------------------------------------------#

my $spec = [
    Switch('t'),
    Counter('v'),
    Param('f'),
    List('I'),
    Keypair('d'),
];

my $num_tests = 6 ;
plan tests => $num_tests ;

my ($gl, $err);

eval { $gl = Getopt::Lucid->new() };
catch $err;
is( $err, "Getopt::Lucid->new() requires an option specification array reference\n",
    "new without spec throws exception");

eval { $gl = Getopt::Lucid->new( $spec ) };
catch $err;
is( $err, undef,
    "new with spec succeeds");
isa_ok( $gl, "Getopt::Lucid" );

eval { $gl = Getopt::Lucid->getopt() };
catch $err;
is( $err, "Getopt::Lucid->getopt() requires an option specification array reference\n",
    "getopt (as class method) without spec throws exception");

eval { $gl = Getopt::Lucid->getopt( $spec ) };
catch $err;
is( $err, undef,
    "getopt (as class method) with spec succeeds");
isa_ok( $gl, "Getopt::Lucid" );