Getopt-Long-DescriptivePod

 view release on metacpan or  search on metacpan

t/01_basics.t  view on Meta::CPAN

#!perl

use strict;
use warnings;

use Test::More tests => 7;
use Test::NoWarnings;
use Test::Exception;
use Test::Differences;

BEGIN {
    use_ok 'Getopt::Long::Descriptive';
    use_ok 'Getopt::Long::DescriptivePod';
}

my $extra_space 
    = $Getopt::Long::Descriptive::VERSION >= 0.100 ? q{}
    : $Getopt::Long::Descriptive::VERSION >= 0.099 ? q{  }
    :                                                q{ };
my $represent_v 
    = $Getopt::Long::Descriptive::VERSION >= 0.106 ? '--verbose (or -v)'
    :                                                '-v --verbose';
my $represent_h 
    = $Getopt::Long::Descriptive::VERSION >= 0.106 ? '--help           '
    :                                                '--help      ';

my $content = <<'EOT';

=head1 FOO

foo

=head1 USAGE

=head1 BAR

EOT

my ($opt, $usage);
lives_ok
    sub {
        ($opt, $usage) = describe_options(
            'my-program %o <some-arg>',
            [ 'verbose|v', 'print extra stuff'            ],
            [],
            [ 'help',      'print usage message and exit' ],
        );
    },
    'describe_options';

lives_ok
    sub {
        replace_pod({
            filename   => \$content,
            tag        => '=head1 USAGE',
            code_block => $usage->text,
            indent     => 4,
            on_verbose => sub {
                my $message = shift;
                $message =~ tr{\n}{ };
                note $message;
                ok 1, $message;
            },
        });
    },
    'replace_pod';

eq_or_diff $content, <<"EOT", 'usage in Pod';



( run in 1.323 second using v1.01-cache-2.11-cpan-39bf76dae61 )