File: 04_test_args.t

package info (click to toggle)
libmodule-build-pluggable-perl 0.10-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 434; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use strict;
use warnings;
use utf8;
use Test::More;
use File::Spec;
use lib File::Spec->rel2abs('lib');
use File::Path;
use Test::Module::Build::Pluggable;

BEGIN { *describe = *context = *it = *Test::More::subtest }

describe 'Test::Module::Build::Pluggable::run_build_pl passes @ARGV' => sub {
    context 'with no args' => sub {
        my $test = setup();
        $test->run_build_pl();
        my $params = $test->read_file('ddd');
        is($params, '0', 'arguments for read_file is passed to @ARGV');
        ok(-f 'called');
        note $params;
    };
    context 'with -g option' => sub {
        my $test = setup();
        $test->run_build_pl('-g');
        my $params = $test->read_file('ddd');
        is($params, '1', 'arguments for read_file is passed to @ARGV');
        ok(-f 'called');
        note $params;
    };
};

done_testing;

sub setup {
    my $test = Test::Module::Build::Pluggable->new();

    $test->write_plugin('Module::Build::Pluggable::Extra', <<'...');
package Module::Build::Pluggable::Extra;
use strict;
use warnings;
use utf8;
use parent qw/Module::Build::Pluggable::Base/;

sub HOOK_prepare {
    my ($class, $args) = @_;

    open my $fh, '>', 'called';
    print {$fh} 1;
    close $fh;

    die "Other plugins uses -g option" if $args->{get_options}->{g};
    $args->{get_options}->{g} = { type => '!' };
}

1;
...

    $test->write_file('Build.PL', <<'...');
use strict;
use Module::Build::Pluggable (
    'Extra'
);

my $builder = Module::Build::Pluggable->new(
    dist_name => 'Eg',
    dist_version => 0.01,
    dist_abstract => 'test',
    dynamic_config => 0,
    module_name => 'Eg',
    requires => {},
    provides => {},
    author => 1,
    dist_author => 'test',
);
$builder->create_build_script();

open my $fh, '>', 'ddd' or die $!;
print {$fh} ($builder->args('g') ? 1 : 0);
close $fh;
...

    $test->write_file('MANIFEST', join("\n", qw(MANIFEST)));

    return $test;
}