]> git.ipfire.org Git - thirdparty/git.git/commitdiff
perl: check for perl warnings while running tests
authorJeff King <peff@peff.net>
Thu, 22 Oct 2020 03:24:00 +0000 (23:24 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Oct 2020 06:11:48 +0000 (23:11 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
22 files changed:
Makefile
config.mak.dev
git-svn.perl
perl/FromCPAN/Error.pm
perl/Git.pm
perl/Git/I18N.pm
perl/Git/IndexInfo.pm
perl/Git/LoadCPAN.pm
perl/Git/LoadCPAN/Error.pm
perl/Git/LoadCPAN/Mail/Address.pm
perl/Git/Packet.pm
perl/Git/SVN.pm
perl/Git/SVN/Editor.pm
perl/Git/SVN/Fetcher.pm
perl/Git/SVN/GlobSpec.pm
perl/Git/SVN/Log.pm
perl/Git/SVN/Memoize/YAML.pm
perl/Git/SVN/Migration.pm
perl/Git/SVN/Prompt.pm
perl/Git/SVN/Ra.pm
perl/Git/SVN/Utils.pm
t/test-lib.sh

index 95571ee3fcaf7969e62d850f4fe6712f959f6980..4d6f6dc16f6a50441601ba874ef2b54006372a5d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2767,6 +2767,9 @@ ifdef GIT_INTEROP_MAKE_OPTS
 endif
 ifdef GIT_TEST_INDEX_VERSION
        @echo GIT_TEST_INDEX_VERSION=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_INDEX_VERSION)))'\' >>$@+
+endif
+ifdef GIT_TEST_PERL_FATAL_WARNINGS
+       @echo GIT_TEST_PERL_FATAL_WARNINGS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_PERL_FATAL_WARNINGS)))'\' >>$@+
 endif
        @if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
 
index 89b218d11a5313f327492795964793bec8670160..89db5435343ad7c5a94a13bfec1d441e9ef1d0bb 100644 (file)
@@ -45,3 +45,5 @@ ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
 DEVELOPER_CFLAGS += -Wno-uninitialized
 endif
 endif
+
+GIT_TEST_PERL_FATAL_WARNINGS = YesPlease
index 58f5a7ac8f80ac609fe1b35a558f936c7af42b98..70cb5e2a83b5bec6e9f95ea0cb7feb112e2dfec5 100755 (executable)
@@ -2,7 +2,7 @@
 # Copyright (C) 2006, Eric Wong <normalperson@yhbt.net>
 # License: GPL v2 or later
 use 5.008;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use strict;
 use vars qw/   $AUTHOR $VERSION
                $oid $oid_short $oid_length
index 8b95e2d73d0f8f8d5b50eaaa360135f102b52b74..d82b71325c6bd492cd7eb0f703b00fa6634c627d 100644 (file)
@@ -12,7 +12,7 @@
 package Error;
 
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 
 use vars qw($VERSION);
 use 5.004;
index 10df990959e63938e1742d1cdaf0d009b61bee96..02eacef0c2a4a43058a74dda4cebe1ae16bdd2eb 100644 (file)
@@ -9,7 +9,7 @@ package Git;
 
 use 5.008;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 
 use File::Temp ();
 use File::Spec ();
index bfb4fb67a13f4530aae2d974e579b9ba45e20cdb..2037f387c89e8a8769910e164174085f1d2e645c 100644 (file)
@@ -1,7 +1,7 @@
 package Git::I18N;
 use 5.008;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 BEGIN {
        require Exporter;
        if ($] < 5.008003) {
index 2a7b4908f3e637d3e93462799c91cd75a8221354..9ee054f854e8682e16933ad0a770be5847bd33e5 100644 (file)
@@ -1,6 +1,6 @@
 package Git::IndexInfo;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use Git qw/command_input_pipe command_close_pipe/;
 
 sub new {
index e5585e75e809ef5763d3d4f19ebd185c6f7c0f51..0c360bc799860798ade6b2afce6e05b0a567d21f 100644 (file)
@@ -1,7 +1,7 @@
 package Git::LoadCPAN;
 use 5.008;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 
 =head1 NAME
 
index c6d2c45d808b2ec553f53f15ad5f495844199ac0..5d84c202884b7cb7cea576ea1a6f146b2e653ae2 100644 (file)
@@ -1,7 +1,7 @@
 package Git::LoadCPAN::Error;
 use 5.008;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use Git::LoadCPAN (
        module => 'Error',
        import => 1,
index f70a4f064c3c78a87be3f876ea3f325d6b6fa4de..340e88a7a56be37af8b1f437c92ecb52b1b29089 100644 (file)
@@ -1,7 +1,7 @@
 package Git::LoadCPAN::Mail::Address;
 use 5.008;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use Git::LoadCPAN (
        module => 'Mail::Address',
        import => 0,
index b75738bed4b52ac0085eb6a4919ba954d8fcfe98..d144f5168f37adaf54a2f9b768f04ad2a1c20196 100644 (file)
@@ -1,7 +1,7 @@
 package Git::Packet;
 use 5.008;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 BEGIN {
        require Exporter;
        if ($] < 5.008003) {
index d1c352f92b58392961b8e958c5539cba65458856..f6f1dc03c60861ca1fba1faf66617ad8b6c1b8b4 100644 (file)
@@ -1,6 +1,6 @@
 package Git::SVN;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use Fcntl qw/:DEFAULT :seek/;
 use constant rev_map_fmt => 'NH*';
 use vars qw/$_no_metadata
index c961444d4cbb622ea8045587c7294d50f2b655ef..47fd048bf2d14e3274ed0b6f7d3dbe957ac75b3c 100644 (file)
@@ -1,7 +1,7 @@
 package Git::SVN::Editor;
 use vars qw/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use SVN::Core;
 use SVN::Delta;
 use Carp qw/croak/;
index 729e5337df7accad3340f3a8f7411ba0ffd31085..968309e6d63b904c6ed76d78ee3f60bdfe64e271 100644 (file)
@@ -3,7 +3,7 @@ use vars qw/@ISA $_ignore_regex $_include_regex $_preserve_empty_dirs
             $_placeholder_filename @deleted_gpath %added_placeholder
             $repo_id/;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use SVN::Delta;
 use Carp qw/croak/;
 use File::Basename qw/dirname/;
index a0a8d1762150acd5b6a91116d4835fba1834d425..f2c1e1f6fbe8899cd3f871d4fefcee2c5939f2a5 100644 (file)
@@ -1,6 +1,6 @@
 package Git::SVN::GlobSpec;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 
 sub new {
        my ($class, $glob, $pattern_ok) = @_;
index 3858fcf27dee85c8d2b72ff96402d253c8ea1772..6cd4cdfcebfaffe4039006e02ba508cf0297c6a3 100644 (file)
@@ -1,6 +1,6 @@
 package Git::SVN::Log;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use Git::SVN::Utils qw(fatal);
 use Git qw(command
            command_oneline
index 9676b8f2f73520735b68f6ff13d03d52575afaae..8fcf6644a1c198ce7ea4d67d490f4a975251bf86 100644 (file)
@@ -1,5 +1,5 @@
 package Git::SVN::Memoize::YAML;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use strict;
 use YAML::Any ();
 
index dc90f6a6214281386c401235827a8fd268994eeb..ed96ac593e8098fcdf93a8a7b9639ae1a2734c73 100644 (file)
@@ -33,7 +33,7 @@ package Git::SVN::Migration;
 #              possible if noMetadata or useSvmProps are set; but should
 #              be no problem for users that use the (sensible) defaults.
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use Carp qw/croak/;
 use File::Path qw/mkpath/;
 use File::Basename qw/dirname basename/;
index e940b08505f1488efbe257201b3881b7e00a0a2a..de158e848fb0be0e3c7b8239cc774f695cf3ec7c 100644 (file)
@@ -1,6 +1,6 @@
 package Git::SVN::Prompt;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 require SVN::Core;
 use vars qw/$_no_auth_cache $_username/;
 
index 2cfe055a9a04305ab5b248a6de0bab2a8abfcec0..912e035040448858e0a53ecdd72deb4bf11206ab 100644 (file)
@@ -1,7 +1,7 @@
 package Git::SVN::Ra;
 use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 use Memoize;
 use Git::SVN::Utils qw(
        canonicalize_url
index 3d1a0933a2eb27dc123730c67470be503e91bf93..5ca09ab448328b7e29c1cc248191cd8abf2a82f3 100644 (file)
@@ -1,7 +1,7 @@
 package Git::SVN::Utils;
 
 use strict;
-use warnings;
+use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
 
 use SVN::Core;
 
index ef31f400374755015ccec300bdb450021aeccc17..dfad820dd40a79941a9b8eb77663bc50166115ea 100644 (file)
@@ -499,6 +499,12 @@ then
        export GIT_INDEX_VERSION
 fi
 
+if test -n "$GIT_TEST_PERL_FATAL_WARNINGS"
+then
+       GIT_PERL_FATAL_WARNINGS=1
+       export GIT_PERL_FATAL_WARNINGS
+fi
+
 # Add libc MALLOC and MALLOC_PERTURB test
 # only if we are not executing the test with valgrind
 if test -n "$valgrind" ||