File: msg_scan.t

package info (click to toggle)
libdist-zilla-localetextdomain-perl 0.90-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 248 kB
  • ctags: 45
  • sloc: perl: 1,109; makefile: 2
file content (106 lines) | stat: -rw-r--r-- 3,821 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
#!/usr/bin/perl -w

use strict;
use warnings;
use Test::More 0.90;
use Test::DZil;
use IPC::Cmd 'can_run';
use Path::Class;
use Test::File;
use Test::File::Contents;
use Dist::Zilla::App::Tester;
use App::Cmd::Tester::CaptureExternal;

BEGIN {
    # Make Tester to inherit CaptureExternal to prevent "Bad file descriptor".
    package Dist::Zilla::App::Tester;
    for (@Dist::Zilla::App::Tester::ISA) {
        $_ = 'App::Cmd::Tester::CaptureExternal' if $_ eq 'App::Cmd::Tester';
    }
}

$ENV{DZIL_GLOBAL_CONFIG_ROOT} = 't';

plan skip_all => 'xgettext not found' unless can_run 'xgettext';

require_ok 'Dist::Zilla::App::Command::msg_scan';

my $result = test_dzil('t/dist', [qw(msg-scan)]);
is $result->exit_code, 0, "dzil would have exited 0" or diag @{ $result->log_messages };

ok((grep {
    /extracting gettext strings into po.DZT-Sample[.]pot/
} @{ $result->log_messages }),  'Should have logged the POT file creation');

my $pot = file $result->tempdir, qw(source po DZT-Sample.pot);
file_exists_ok $pot, 'po/DZT-Sample.pot should exist';
file_contents_like $pot, qr/\QCopyright (C) YEAR David E. Wheeler/m,
    'po/DZT-Sample.pot should have copyright holder';
file_contents_like $pot, qr/^\Q"Project-Id-Version: DZT-Sample 1.2\n"\E$/m,
    'po/DZT-Sample.pot should exist should have project ID and version';
file_contents_like $pot,
    qr/^\Q"Report-Msgid-Bugs-To: david\E[@]\Qjustatheory.com\n"\E$/m,
    'po/DZT-Sample.pot should exist should have bugs email';
file_contents_like $pot,
    qr/^\Qmsgid "Hi"\E$/m,
    'po/DZT-Sample.pot should exist should have "Hi" msgid';
file_contents_like $pot,
    qr/^\Qmsgid "Bye"\E$/m,
    'po/DZT-Sample.pot should exist should have "Bye" msgid';
file_contents_like $pot,
    qr/^\Qmsgid "Foo"\E$/m,
    'po/DZT-Sample.pot should exist should have "Foo" msgid';

# Try setting some stuff.
$result = test_dzil('t/dist', [qw(
    msg-scan
    --pot-file my.pot
    --bugs-email homer@example.com
    --copyright-holder
), 'Homer Simpson']);
is $result->exit_code, 0, "dzil would have exited 0 again" or diag @{ $result->log_messages };

ok((grep {
    /extracting gettext strings into my[.]pot/
} @{ $result->log_messages }),  'Should have logged the mo.pot creation');

$pot = file $result->tempdir, qw(source my.pot);
file_exists_ok $pot, 'my.pot should exist';
file_contents_like $pot, qr/\QCopyright (C) YEAR Homer Simpson/m,
    'my.pot should have copyright holder';
file_contents_like $pot, qr/^\Q"Project-Id-Version: DZT-Sample 1.2\n"\E$/m,
    'my.pot should exist should have project ID and version';
file_contents_like $pot,
    qr/^\Q"Report-Msgid-Bugs-To: homer\E[@]\Qexample.com\n"\E$/m,
    'my.pot should exist should have custom bugs email';
file_contents_like $pot,
    qr/^\Qmsgid "Hi"\E$/m,
    'my.pot should exist should have "Hi" msgid';
file_contents_like $pot,
    qr/^\Qmsgid "Bye"\E$/m,
    'my.pot should exist should have "Bye" msgid';

# Use finder attribute
$result = test_dzil('t/dist2', [qw(msg-scan)]);
is $result->exit_code, 0, "dzil would have exited 0" or diag @{ $result->log_messages };

ok((grep {
    /extracting gettext strings into po.DZT-Sample2[.]pot/
} @{ $result->log_messages }),  'Should have logged the POT file creation');

$pot = file $result->tempdir, qw(source po DZT-Sample2.pot);
file_exists_ok $pot, 'po/DZT-Sample2.pot should exist';
file_contents_like $pot,
    qr/bar[.]pl:6$/m,
    'po/DZT-Sample2.pot should have entry for "bar.pl" file';
file_contents_like $pot,
    qr/^\Qmsgid "Bar"\E$/m,
    'po/DZT-Sample2.pot should exist should have "Bar" msgid';
file_contents_like $pot,
    qr/Config[.]pm:6$/m,
    'po/DZT-Sample2.pot should have entry for "Config.pm" file';
file_contents_like $pot,
    qr/^\Qmsgid "Foo"\E$/m,
    'po/DZT-Sample2.pot should exist should have "Foo" msgid';

done_testing;