Skip to content

Commit 5338ed2

Browse files
peffgitster
authored andcommitted
perl: check for perl warnings while running tests
We set "use warnings" in most of our perl code to catch problems. But as the name implies, warnings just emit a message to stderr and don't otherwise affect the program. So our tests are quite likely to miss that warnings are being spewed, as most of them do not look at stderr. We could ask perl to make all warnings fatal, but this is likely annoying for non-developers, who would rather have a running program with a warning than something that refuses to work at all. So instead, let's teach the perl code to respect an environment variable (GIT_PERL_FATAL_WARNINGS) to increase the severity of the warnings. This can be set for day-to-day running if people want to be really pedantic, but the primary use is to trigger it within the test suite. We could also trigger that for every test run, but likewise even the tests failing may be annoying to distro builders, etc (just as -Werror would be for compiling C code). So we'll tie it to a special test-mode variable (GIT_TEST_PERL_FATAL_WARNINGS) that can be set in the environment or as a Makefile knob, and we'll automatically turn the knob when DEVELOPER=1 is set. That should give developers and CI the more careful view without disrupting normal users or packagers. Note that the mapping from the GIT_TEST_* form to the GIT_* form in test-lib.sh is necessary even if they had the same name: the perl scripts need it to be normalized to a perl truth value, and we also have to make sure it's exported (we might have gotten it from the environment, but we might also have gotten it from GIT-BUILD-OPTIONS directly). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69986e1 commit 5338ed2

22 files changed

+30
-19
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,9 @@ ifdef GIT_INTEROP_MAKE_OPTS
27672767
endif
27682768
ifdef GIT_TEST_INDEX_VERSION
27692769
@echo GIT_TEST_INDEX_VERSION=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_INDEX_VERSION)))'\' >>$@+
2770+
endif
2771+
ifdef GIT_TEST_PERL_FATAL_WARNINGS
2772+
@echo GIT_TEST_PERL_FATAL_WARNINGS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_PERL_FATAL_WARNINGS)))'\' >>$@+
27702773
endif
27712774
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
27722775

config.mak.dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
4545
DEVELOPER_CFLAGS += -Wno-uninitialized
4646
endif
4747
endif
48+
49+
GIT_TEST_PERL_FATAL_WARNINGS = YesPlease

git-svn.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (C) 2006, Eric Wong <[email protected]>
33
# License: GPL v2 or later
44
use 5.008;
5-
use warnings;
5+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
66
use strict;
77
use vars qw/ $AUTHOR $VERSION
88
$oid $oid_short $oid_length

perl/FromCPAN/Error.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
package Error;
1313

1414
use strict;
15-
use warnings;
15+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
1616

1717
use vars qw($VERSION);
1818
use 5.004;

perl/Git.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package Git;
99

1010
use 5.008;
1111
use strict;
12-
use warnings;
12+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
1313

1414
use File::Temp ();
1515
use File::Spec ();

perl/Git/I18N.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package Git::I18N;
22
use 5.008;
33
use strict;
4-
use warnings;
4+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
55
BEGIN {
66
require Exporter;
77
if ($] < 5.008003) {

perl/Git/IndexInfo.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Git::IndexInfo;
22
use strict;
3-
use warnings;
3+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
44
use Git qw/command_input_pipe command_close_pipe/;
55

66
sub new {

perl/Git/LoadCPAN.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package Git::LoadCPAN;
22
use 5.008;
33
use strict;
4-
use warnings;
4+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
55

66
=head1 NAME
77

perl/Git/LoadCPAN/Error.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package Git::LoadCPAN::Error;
22
use 5.008;
33
use strict;
4-
use warnings;
4+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
55
use Git::LoadCPAN (
66
module => 'Error',
77
import => 1,

perl/Git/LoadCPAN/Mail/Address.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package Git::LoadCPAN::Mail::Address;
22
use 5.008;
33
use strict;
4-
use warnings;
4+
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
55
use Git::LoadCPAN (
66
module => 'Mail::Address',
77
import => 0,

0 commit comments

Comments
 (0)