File: 41ppi_imports.t

package info (click to toggle)
liblog-report-lexicon-perl 1.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 452 kB
  • sloc: perl: 2,676; makefile: 9
file content (66 lines) | stat: -rw-r--r-- 1,835 bytes parent folder | download
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
#!/usr/bin/env perl
# Test that we can cope with all of the ways of specifying a text domain.

use warnings;
use strict;

use Cwd;
use File::Temp qw/tempdir/;
use Test::More;

BEGIN
{   eval "require PPI";
    plan skip_all => 'PPI not installed'
        if $@;

    use_ok('Log::Report::Extract::PerlPPI');
}

_test_import(
    subtest_name => 'Preceded by a version number',
    source       => 'use Log::Report 1.00 "not-a-version-number";',
    text_domain  => 'not-a-version-number',
);
_test_import(
    subtest_name => 'Using a quotelike operator',
    source       => 'use Log::Report qw(wossname)',
    text_domain  => 'wossname',
);
_test_import(
    subtest_name => 'The Dancer plugin works as well',
    source       => q{use Dancer2::Plugin::LogReport 'dance-monkey-dance';},
    text_domain  => 'dance-monkey-dance',
);
_test_import(
    subtest_name => 'With no arguments at all',
    source       => 'use Log::Report',
    text_domain  => undef,
);
done_testing();

sub _test_import {
    my (%args) = @_;

    subtest $args{subtest_name} => sub {
        my $source_dir = tempdir CLEANUP => 1;
        my $lexicon    = tempdir CLEANUP => 1;
        my $ppi = Log::Report::Extract::PerlPPI->new(lexicon => $lexicon);
        my $previous_cwd = Cwd::cwd();
        chdir($source_dir);
        open (my $fh, '>', 'perl-source.pl');
        print $fh $args{source};
        close $fh;
        $ppi->process('perl-source.pl');
        $ppi->write;

        my @leafnames = keys %{ $ppi->index->index };
        if (defined $args{text_domain}) {
            is @leafnames, 1, 'We added a file';
            like $leafnames[0], qr/^$args{text_domain}/, '...matching the expected text domain';
        } else {
            is @leafnames, 0, 'No text domain = no files added';
        }

        chdir($previous_cwd);
    };
}