This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t write beyond the stack with scalar \()
[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}
ac976f88 26use TestInit qw(T); # T is chdir to the top level
f0bcc49a 27use strict;
8d85448a 28use File::Spec;
f0bcc49a
NC
29
30require 't/test.pl';
31find_git_or_skip('all');
32
8d85448a 33my $devnull = File::Spec->devnull;
f0bcc49a 34my $changes;
8d85448a 35foreach (`git status --porcelain 2>$devnull`) {
f0bcc49a
NC
36 next if /^\?\?/;
37 ++$changes;
38 last;
39}
40
41skip_all("No pending changes (or git status --porcelain doesn't work here)")
42 unless $changes;
43
44sub get {
45 my $key = shift;
46 my $value = `git config --get user.$key`;
47 unless (defined $value && $value =~ /\S/) {
ce2dc92a 48 skip_all("git config --get user.$key returned nought");
f0bcc49a
NC
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 $!;