File: 02-plugg.t

package info (click to toggle)
libfile-configdir-perl 0.021-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 489; sh: 6; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 2,014 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
#!perl

use strict;
use warnings;

use Carp qw(croak);

use Test::More;
use File::Basename;
use File::Path;
use File::Spec;

use File::ConfigDir 'config_dirs';

my $test_dir;
END { defined($test_dir) and rmtree $test_dir; }

sub test_dir
{
    unless (defined($test_dir))
    {
        $test_dir = File::Spec->rel2abs(File::Spec->curdir());
        $test_dir = File::Spec->catdir($test_dir, "test_output_" . $$);
        $^O eq 'VMS' and $test_dir = VMS::Filespec::unixify($test_dir);
        rmtree $test_dir;
        mkpath $test_dir;
        # create our two test dirs
        mkpath(File::Spec->catdir($test_dir, 'plugg', 'extra'));
        mkpath(File::Spec->catdir($test_dir, 'pure'));
    }

    return $test_dir;
}

test_dir();

my $plugg_src = sub {
    my @cfg_base = @_;
    return File::Spec->catdir($test_dir, 'plugg', @cfg_base);
};

my $pure_src = sub {
    my @cfg_base = @_;
    0 == scalar(@cfg_base)
      or croak "pure_src(), not pure_src(" . join(",", ("\$") x scalar(@cfg_base)) . ")";
    return File::Spec->catdir($test_dir, 'pure');
};

ok(File::ConfigDir::_plug_dir_source($plugg_src), "registered extensible plugin");
ok(File::ConfigDir::_plug_dir_source($pure_src, "0E0"), "registered pure plugin");

ok(!File::ConfigDir::_plug_dir_source(),      "registered nothing");
ok(!File::ConfigDir::_plug_dir_source(undef), "registered undef");
ok(!File::ConfigDir::_plug_dir_source(42),    "registered 42");

my @dirs = config_dirs();
note("config_dirs: " . join(",", @dirs));
ok(scalar @dirs >= 3, "config_dirs");    # we expect system_cfg_dir + plugs
is($dirs[-1], File::Spec->catdir($test_dir, 'pure'),  'pure');
is($dirs[-2], File::Spec->catdir($test_dir, 'plugg'), 'plugg');

@dirs = config_dirs(qw(extra));
note("config_dirs: " . join(",", @dirs));
ok(scalar @dirs >= 2, "config_dirs");    # we expect our plugs
is($dirs[-1], File::Spec->catdir($test_dir, 'pure'), 'pure with extra');
is($dirs[-2], File::Spec->catdir($test_dir, 'plugg', 'extra'), 'plugg with extra');

done_testing();