File: 32_make-defaults-alt.t

package info (click to toggle)
libextutils-modulemaker-perl 0.63-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 744 kB
  • sloc: perl: 7,331; makefile: 11
file content (136 lines) | stat: -rw-r--r-- 4,505 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# t/32_make-defaults-alt.t
# tests of options to make modulemaker selections default personal values
# where the directory tree needed to store Personal::Defaults does not fully
# exist
use strict;
use warnings;
use Carp;
use Cwd;
use File::Spec;
use File::Path 2.15 qw(remove_tree);
use File::Temp qw(tempdir);
use Test::More tests => 48;
use_ok( 'ExtUtils::ModuleMaker' );
use_ok( 'ExtUtils::ModuleMaker::Auxiliary', qw(
    prepare_mockdirs
    prepare_mock_homedir
    compact_build_tests
    read_file_string
    check_MakefilePL
) );

=pod

Objective in this file is to exercise the part of
C<EU::MM::make_selections_defaults()> starting at:

    if (! -d $full_dir) {

Here, C<$full_dir()> would be
F</E<lt>mockhomeE<gt>/.modulemaker/ExtUtils/ModuleMaker/Personal/>.  The
approach to testing used in this version of EUMM, centered in
C<prepare_mockdirs()> auto-creates this directory.  Hence, we have to remove
part of this directory if we're to exercise this section of
C<make_selection_defaults()>.

=cut

my $cwd = cwd();

my ($home_dir) = prepare_mock_homedir();
local $ENV{HOME} = $home_dir;

my $mmkr_dir = File::Spec->catdir($home_dir, '.modulemaker');
for my $d ($home_dir, $mmkr_dir) {
    ok(-d $d, "$d has been created");
}

opendir my $DIRH, $mmkr_dir or croak "Unable to open dirhandle";
my @entries = grep { ! m/^\.{1,2}$/ } readdir $DIRH;
closedir $DIRH or croak "Unable to close dirhandle";
cmp_ok(@entries, '==', 1, "$mmkr_dir starts out with one entry");

my $topdir = File::Spec->catdir($mmkr_dir, $entries[0]);
ok(-d $topdir, "$topdir is underneath $mmkr_dir");

my $removed_count = remove_tree($topdir, {
    error  => \my $err_list, safe => 1, });
is($removed_count, 3, "Removed 'ExtUtils/ModuleMaker/Personal'");
ok(! -d $topdir, "$topdir has been deleted");
ok(-d $mmkr_dir, "$mmkr_dir still exists");

{
    my ($module_name, @components, $dist_name, $path_str);
    my ($module_file, $test_file);
    my ($mkfl, $bigstr);

    my $tdir = tempdir( CLEANUP => 1);
    ok(chdir $tdir, 'changed to temp directory for testing');

    @components = qw( Alpha Beta Gamma );
    $module_name = join('::' => @components);
    $dist_name = join('-' => @components);
    $path_str = File::Spec->catdir(@components);

    my $abstract = "Test make_selections_defaults()";
    my $author = 'Chango Ta Beni';
    my $email  = 'chango_ta_beni@example.com';

    my $obj1 = ExtUtils::ModuleMaker->new(
        NAME                => $module_name,
        ABSTRACT            => $abstract,
        COMPACT             => 1,
        AUTHOR              => $author,
        EMAIL               => $email,
        SAVE_AS_DEFAULTS    => 1,
    );
    isa_ok( $obj1, 'ExtUtils::ModuleMaker' );

    ok( $obj1->complete_build(), 'call complete_build()' );

    ($module_file, $test_file) = compact_build_tests(\@components);

    $mkfl = File::Spec->catfile( $dist_name, q{Makefile.PL} );
    ok(-f $mkfl, "Located Makefile.PL");
    $bigstr = read_file_string($mkfl);
    like($bigstr, qr/NAME\s+=>\s+'$module_name/s,
        "Got NAME as expected");
    like($bigstr, qr/ABSTRACT\s+=>\s+'$abstract/s,
        "Got ABSTRACT as expected");
    like($bigstr, qr/AUTHOR\s+=>\s+'$author\s+\($email\)'/s,
        "Got AUTHOR and EMAIL as expected");

    # Create a new instance which we expect will have::
    # (a) a compact top-level directory,
    # (b) author and email as in first instance, automatically populated,
    # (c) EUMM default abstract.

    my $obj2 = ExtUtils::ModuleMaker->new(
        NAME    => q{Ackus::Frackus},
    );
    isa_ok( $obj2, 'ExtUtils::ModuleMaker' );

    ok( $obj2->complete_build(), 'call complete_build()' );

    $module_name = $obj2->{NAME};
    @components = split(/::/, $module_name);
    $dist_name = join('-' => @components);
    $path_str = File::Spec->catdir(@components);
    $module_file = File::Spec->catfile(
        'lib', @components[0 .. ($#components - 1)], "$components[-1].pm");

    ($module_file, $test_file) = compact_build_tests(\@components);

    $mkfl = File::Spec->catfile( $dist_name, q{Makefile.PL} );
    ok(-f $mkfl, "Located Makefile.PL");
    $bigstr = read_file_string($mkfl);
    like($bigstr, qr/NAME\s+=>\s+'$module_name/s,
        "Got NAME as expected");
    unlike($bigstr, qr/ABSTRACT\s+=>\s+'$abstract/s,
        "Got ABSTRACT different from first object");
    like($bigstr, qr/AUTHOR\s+=>\s+'$author\s+\($email\)'/s,
        "Got AUTHOR and EMAIL as expected");

    ok(chdir $cwd, 'back to where we stared');
}