File: load-from-relative-inc-path.t

package info (click to toggle)
libdatetime-locale-perl 1%3A1.41-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,068 kB
  • sloc: perl: 286,446; sh: 23; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,335 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
use strict;
use warnings;

use Test2::V0;
use Test::File::ShareDir::Dist { 'DateTime-Locale' => 'share' };

use DateTime::Locale;
use File::ShareDir qw( dist_dir );
use Path::Tiny     qw( path );

{
    # This is kind of gross since we are assuming that File::ShareDir always
    # constructs a path ending in "auto/share/dist/DateTime-Locale". If
    # File::ShareDir were ever to change how it constructs paths this would
    # break, but that seems very unlikely.
    my $dist_dir  = path( dist_dir('DateTime-Locale') );
    my $share_dir = $dist_dir;

    # This removes the auto/share/dist/DateTime-Locale part of the path.
    for ( 1 .. 4 ) {
        $share_dir = $share_dir->parent;
    }

    # This is the top-level dir that contains "auto/share/...". This will be a
    # temp dir of some sort.
    my $share_dir_name = $share_dir->basename;

    # And this is the directory that contains $share_dir_name. On Linux this
    # will be $ENV{TMPDIR} or /tmp.
    my $containing_dir = $share_dir->parent;

    chdir $containing_dir
        or die "could not chdir to $containing_dir: $!";

    my $l = do {
        local @INC = ($share_dir_name);
        DateTime::Locale->load('de-DE');
    };

    ok( $l, 'was able to load de-DE locale from relative dir' );
    isa_ok( $l, 'DateTime::Locale::FromData' );
}

done_testing();