Even though perl_5 should be valid in 1.4, CPANTS barfs
[dbsrgits/DBIx-Class.git] / xt / authors.t
CommitLineData
3440100b 1use warnings;
2use strict;
3
4use Test::More;
5use Config;
6use File::Spec;
7
8my @known_authors = do {
9 # according to #p5p this is how one safely reads random unicode
10 # this set of boilerplate is insane... wasn't perl unicode-king...?
11 no warnings 'once';
12 require Encode;
13 require PerlIO::encoding;
14 local $PerlIO::encoding::fallback = Encode::FB_CROAK();
15
16 open (my $fh, '<:encoding(UTF-8)', 'AUTHORS') or die "Unable to open AUTHORS - can't happen: $!\n";
17 map { chomp; ( ( ! $_ or $_ =~ /^\s*\#/ ) ? () : $_ ) } <$fh>;
18
19} or die "Known AUTHORS file seems empty... can't happen...";
20
21is_deeply (
22 [ grep { /^\s/ } @known_authors ],
23 [],
24 "No entries with leading space",
25);
26
27is_deeply (
28 \@known_authors,
29 [ sort { lc $a cmp lc $b } @known_authors ],
30 'Author list is case-insensitively sorted'
31);
32
33my $email_re = qr/( \< [^\<\>]+ \> ) $/x;
34
35my (%known_authors, $count);
36for (@known_authors) {
37 my ($name_email) = m/ ^ (?: [^\:]+ \: \s )? (.+) /x;
38 my ($email) = $name_email =~ $email_re;
39
40 if (
41 $known_authors{$name_email}++
42 or
43 ( $email and $known_authors{$email}++ )
44 ) {
45 fail "Duplicate found: $name_email";
46 }
47 else {
48 $count++;
49 }
50}
51
52# do not announce anything under travis - we are watching for STDERR silence
53diag "\n\n$count contributors made this library what it is today\n\n"
54 unless ($ENV{TRAVIS}||'') eq 'true';
55
56# augh taint mode
57if (length $ENV{PATH}) {
58 ( $ENV{PATH} ) = join ( $Config{path_sep},
59 map { length($_) ? File::Spec->rel2abs($_) : () }
60 split /\Q$Config{path_sep}/, $ENV{PATH}
61 ) =~ /\A(.+)\z/;
62}
63
64# this may fail - not every system has git
65if (my @git_authors = map
66 { my ($gitname) = m/^ \s* \d+ \s* (.+?) \s* $/mx; utf8::decode($gitname); $gitname }
67 qx( git shortlog -e -s )
68) {
69 for (@git_authors) {
70 my ($eml) = $_ =~ $email_re;
71
72 fail "Commit author '$_' (from git) not reflected in AUTHORS, perhaps a missing .mailmap entry?"
73 unless $known_authors{$eml};
74 }
75}
76
77done_testing;