File: 02-build.t

package info (click to toggle)
libmoox-file-configdir-perl 0.008-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 226; makefile: 2; sh: 1
file content (79 lines) | stat: -rw-r--r-- 1,476 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
#!perl

use strict;
use warnings FATAL => "all";

eval {
    require local::lib;
    #local::lib->import();
};

use FindBin qw/$Script/;

{
    package    #
      My;

    use Moo;

    with "MooX::File::ConfigDir";
}

{
    package    #
      Mine;

    use Moo;

    sub _build_config_identifier { $FindBin::Script }

    with "MooX::File::ConfigDir";
}

{
    package    #
      Fail;

    use Moo;

    with "MooX::File::ConfigDir";

    around BUILDARGS => sub {
        my $next  = shift;
        my $class = shift;
        $class->$next(
            @_,
            config_dirs => $class->_build_config_dirs,
        );
    };
}

use Test::More;

my $mxfcd_ = My->new(config_identifier => $FindBin::Script);
my $_mxfcd = Mine->new();

my @supported_functions = (
    qw(system_cfg_dir desktop_cfg_dir),
    qw(core_cfg_dir site_cfg_dir vendor_cfg_dir),
    qw(local_cfg_dir here_cfg_dir singleapp_cfg_dir vendorapp_cfg_dir),
    qw(xdg_config_dirs xdg_config_home user_cfg_dir),
);

my $diag = Test::More->can('diag');
my $note = Test::More->can('note');

foreach my $fn (@supported_functions)
{
    my $dirs_  = $mxfcd_->$fn;
    my $_dirs  = $_mxfcd->$fn;
    my $report = is_deeply($dirs_, $_dirs, "$fn") ? $note : $diag;
    $report->("$fn", explain($dirs_), explain($_dirs));
}

eval { my $fail = Fail->new; };
# either $self or $params must be valid
my $err = $@;
like($err, qr/either \$self or \$params must be valid/, "Load fails expectedly");

done_testing();