Getopt-Long-DescriptivePod

 view release on metacpan or  search on metacpan

t/11_test_examples.t  view on Meta::CPAN

#!perl

use strict;
use warnings;

use Test::More;
use Test::Differences;
use Carp qw(confess);
use Cwd qw(getcwd chdir);
use English qw(-no_match_vars $OS_ERROR $INPUT_RECORD_SEPARATOR $CHILD_ERROR);

$ENV{AUTHOR_TESTING}
    or plan skip_all => 'Set $ENV{AUTHOR_TESTING} to run this test.';

plan tests => 2;

my @data = (
    {
        test       => '01_example',
        path       => 'example',
        filename   => '01_example.pl',
        params     => '-I../lib',
        cmd_result => <<'EOT',
01_example.pl [-?hv] [long options...] <some-arg>
    --verbose (or -v)  Print extra stuff. And here I show, how to work
                       with lots of lines as floating text.

    --help (or -h)     Print usage message and exit.
                       aka -?
EOT
        result     => <<'EOT',
    #!perl ## no critic (TidyCode)

    use strict;
    use warnings;

    our $VERSION = 0;

    use Carp qw(confess);
    use Const::Fast qw(const);
    use English qw(-no_match_vars $OS_ERROR);
    use Getopt::Long::Descriptive;
    use Getopt::Long::DescriptivePod;

    const my $INDENT => 4;

    my ($opt, $usage) = describe_options(
        '01_example.pl %o <some-arg>',
        [ 'verbose|v', trim_lines( <<'EOT' ) ],
            Print extra stuff.
            And here I show, how to work
            with lots of lines as floating text.
    EOT
        [], # an empty line
        [ 'help|h|?', 'Print usage message and exit.' ],
    );

    if ( $opt->{help} ) {
        () = print $usage;
        replace_pod({
            tag               => '=head1 USAGE',
            indent            => $INDENT,
            before_code_block => trim_lines( <<'EOT', $INDENT ),
                This is floating text in Pod before that code
                block with the usage inside.
    EOT
            code_block        => $usage->text,



( run in 2.362 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )