This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add t/porting/pending-author.t, fixing a limitation of t/porting/authors.t
[perl5.git] / t / porting / pending-author.t
CommitLineData
f0bcc49a
NC
1#!./perl -w
2
3# What does this test?
4# This uses Porting/checkAUTHORS.pl to check that any pending commit isn't
5# about to break t/porting/authors.t
6#
7# Why do we test this?
8# t/porting/authors.t checks that the AUTHORS file is up to date, accounting
9# for the "Author:" of every commit. However, any pending changes can't be
10# tested, which leaves a gotcha - "make test" can pass, one then commits
11# the passing code, pushes it uptream, and tests fail. So this test attempts
12# to spot that problem before it happens, where it can.
13#
14# It's broken - how do I fix it?
15# It will fail if you're in a git checkout, have uncommitted changes, and the
16# e-mail address that your commit will default to is in AUTHORS, or the list
17# of author aliases in Porting/checkAUTHORS.pl. So one of
18# a) reset your pending changes
19# b) change your git config user.email to the previously-known e-mail address
20# c) add yourself to AUTHORS
21# d) add an alias to Porting/checkAUTHORS.pl
22
23BEGIN {
24 @INC = '..' if -f '../TestInit.pm';
25}
26use TestInit qw(T A); # T is chdir to the top level, A makes paths absolute
27use strict;
28
29require 't/test.pl';
30find_git_or_skip('all');
31
32my $changes;
33foreach (`git status --porcelain 2>/dev/null`) {
34 next if /^\?\?/;
35 ++$changes;
36 last;
37}
38
39skip_all("No pending changes (or git status --porcelain doesn't work here)")
40 unless $changes;
41
42sub get {
43 my $key = shift;
44 my $value = `git config --get user.$key`;
45 unless (defined $value && $value =~ /\S/) {
46 plan(1);
47 like($value, qr/\S/, "git config --get user.$key returned a value");
48 exit 1;
49 }
50 chomp $value;
51 return $value;
52}
53
54my $email = get('email');
55my $name = get('name');
56
57open my $fh, '|-', "$^X Porting/checkAUTHORS.pl --tap -"
58 or die $!;
59print $fh "Author: $name <$email>\n";
60close $fh or die $!;