From: Bruno Haible <bruno@clisp.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: noloader@gmail.com, bug-gnulib@gnu.org
Subject: Re: warnings in unit tests
Date: Thu, 10 Jun 2021 21:39:32 +0200 [thread overview]
Message-ID: <2531743.PxXWdyhe4H@omega> (raw)
In-Reply-To: <948c6b04-883b-0385-0cd1-77be21b3becd@cs.ucla.edu>
Paul Eggert wrote:
> For what it's worth I'm more with Bruno on this. For the tests, the cost
> of these warnings outweighs the benefit.
>
> It'd be OK with me to disable the troublesome warnings globally for the
> tests subdirectory, using -Wno-missing-prototypes or whatever.
Thanks for your backing, Paul.
It's not the actual warnings that I want to disable. It's more the
expectation that the Gnulib tests "should be warning-free" that is
to be corrected. Implemented through this:
1) Add a '-Wno-error' option that disables the '-Werror' from [1]
that has no raison d'être.
2) A message that indicates that warnings can be ignored in this
directory.
[1] https://git.savannah.gnu.org/gitweb/?p=grep.git;a=blob;f=gnulib-tests/Makefile.am;h=3085f6357b7ece8e68c93650bf409a7609079d19;hb=HEAD
2021-06-10 Bruno Haible <bruno@clisp.org>
Clarify that compiler warnings in the Gnulib tests can be ignored.
* gnulib-tool (func_emit_tests_Makefile_am): Emit overrides for CFLAGS
and CXXFLAGS. Emit a dependency of 'all' on 'all-notice' that prints a
notice.
(func_emit_initmacro_start): Add a second argument. If it is true, emit
code to require gl_CC_ALLOW_WARNINGS and gl_CXX_ALLOW_WARNINGS.
(func_import, func_create_testdir): All callers updated.
* m4/gnulib-common.m4 (gl_CC_ALLOW_WARNINGS, gl_CXX_ALLOW_WARNINGS): New
macros.
diff --git a/gnulib-tool b/gnulib-tool
index 237693a..d41d58c 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -4201,6 +4201,25 @@ func_emit_tests_Makefile_am ()
fi
done
echo
+ # Insert a '-Wno-error' option in the compilation commands emitted by
+ # Automake, between $(AM_CPPFLAGS) and before the reference to @CFLAGS@.
+ # Why?
+ # 1) Because parts of the Gnulib tests exercise corner cases (invalid
+ # arguments, endless recursions, etc.) that a compiler may warn about,
+ # even with just the normal '-Wall' option.
+ # 2) Because every package maintainer has their preferred set of warnings
+ # that they may want to enforce in the main source code of their package.
+ # But Gnulib tests are maintained in Gnulib and don't end up in binaries
+ # that that package installs; therefore it does not make sense for
+ # package maintainers to enforce the absence of warnings on these tests.
+ # Why before @CFLAGS@?
+ # - Because "the user is always right": If a user adds '-Werror' to their
+ # CFLAGS, they have asked for errors, they will get errors. But they have
+ # no right to complain about these errors, because Gnulib does not support
+ # '-Werror'.
+ echo "CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@ @CFLAGS@"
+ echo "CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@"
+ echo
echo "AM_CPPFLAGS = \\"
if $for_test; then
echo " -DGNULIB_STRICT_CHECKING=1 \\"
@@ -4248,6 +4267,14 @@ func_emit_tests_Makefile_am ()
echo
cat "$tmp"/main_snippets "$tmp"/longrunning_snippets \
| sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
+ # Arrange to print a message before compiling the files in this directory.
+ echo "all: all-notice"
+ echo "all-notice:"
+ echo " @echo '## ---------------------------------------------------- ##'"
+ echo " @echo '## ------------------- Gnulib tests ------------------- ##'"
+ echo " @echo '## You can ignore compiler warnings in this directory. ##'"
+ echo " @echo '## ---------------------------------------------------- ##'"
+ echo
echo "# Clean up after Solaris cc."
echo "clean-local:"
echo " rm -rf SunWS_cache"
@@ -4262,9 +4289,11 @@ func_emit_tests_Makefile_am ()
rm -f "$tmp"/main_snippets "$tmp"/longrunning_snippets
}
-# func_emit_initmacro_start macro_prefix
+# func_emit_initmacro_start macro_prefix gentests
# emits the first few statements of the gl_INIT macro to standard output.
# - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
+# - gentests true if a tests Makefile.am is being generated,
+# false otherwise
# - module_indicator_prefix prefix of GNULIB_<modulename> variables to use
func_emit_initmacro_start ()
{
@@ -4298,6 +4327,10 @@ func_emit_initmacro_start ()
# Scope the GNULIB_<modulename> variables.
echo " m4_pushdef([GL_MODULE_INDICATOR_PREFIX], [${module_indicator_prefix}])"
echo " gl_COMMON"
+ if "$2"; then
+ echo " AC_REQUIRE([gl_CC_ALLOW_WARNINGS])"
+ echo " AC_REQUIRE([gl_CXX_ALLOW_WARNINGS])"
+ fi
}
# func_emit_initmacro_end macro_prefix
@@ -5778,7 +5811,7 @@ s,//*$,/,'
sed_replace_build_aux="$sed_noop"
fi
echo " gl_m4_base='$m4base'"
- func_emit_initmacro_start $macro_prefix
+ func_emit_initmacro_start $macro_prefix false
echo " gl_source_base='$sourcebase'"
if test -n "$witness_c_macro"; then
echo " m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$witness_c_macro])"
@@ -5791,7 +5824,7 @@ s,//*$,/,'
func_emit_initmacro_end $macro_prefix
echo " gltests_libdeps="
echo " gltests_ltlibdeps="
- func_emit_initmacro_start ${macro_prefix}tests
+ func_emit_initmacro_start ${macro_prefix}tests $gentests
echo " gl_source_base='$testsbase'"
# Define a tests witness macro that depends on the package.
# PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by AC_INIT.
@@ -6436,7 +6469,7 @@ func_create_testdir ()
ba
}'
echo "gl_m4_base='../$m4base'"
- func_emit_initmacro_start $macro_prefix
+ func_emit_initmacro_start $macro_prefix true
# We don't have explicit ordering constraints between the various
# autoconf snippets. It's cleanest to put those of the library before
# those of the tests.
@@ -6552,7 +6585,7 @@ func_create_testdir ()
sed_replace_build_aux="$sed_noop"
fi
echo "gl_m4_base='$m4base'"
- func_emit_initmacro_start $macro_prefix
+ func_emit_initmacro_start $macro_prefix false
echo "gl_source_base='$sourcebase'"
if $single_configure; then
func_emit_autoconf_snippets "$main_modules" "$main_modules" func_verify_module true false false
@@ -6563,7 +6596,7 @@ func_create_testdir ()
if $single_configure; then
echo " gltests_libdeps="
echo " gltests_ltlibdeps="
- func_emit_initmacro_start ${macro_prefix}tests
+ func_emit_initmacro_start ${macro_prefix}tests true
echo " gl_source_base='$testsbase'"
# Define a tests witness macro.
echo " ${macro_prefix}tests_WITNESS=IN_GNULIB_TESTS"
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 7db4be1..bfa1645 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 65
+# gnulib-common.m4 serial 66
dnl Copyright (C) 2007-2021 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -666,6 +666,72 @@ AC_DEFUN([gl_CACHE_VAL_SILENT],
])
])
+# gl_CC_ALLOW_WARNINGS
+# sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
+# that reverts a preceding '-Werror' option, if available.
+# This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
+# and empty otherwise.
+AC_DEFUN([gl_CC_ALLOW_WARNINGS],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_CACHE_CHECK([for C compiler option to allow warnings],
+ [gl_cv_cc_wallow],
+ [rm -f conftest*
+ echo 'int dummy;' > conftest.c
+ AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
+ AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
+ dnl Test the number of error output lines, because AIX xlc accepts the
+ dnl option '-Wno-error', just to produce a warning
+ dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
+ dnl afterwards.
+ if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
+ gl_cv_cc_wallow='-Wno-error'
+ else
+ gl_cv_cc_wallow=none
+ fi
+ rm -f conftest*
+ ])
+ case "$gl_cv_cc_wallow" in
+ none) GL_CFLAG_ALLOW_WARNINGS='' ;;
+ *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
+ esac
+ AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
+])
+
+# gl_CXX_ALLOW_WARNINGS
+# sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
+# that reverts a preceding '-Werror' option, if available.
+AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
+[
+ dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
+ if test -n "$CXX" && test "$CXX" != no; then
+ AC_CACHE_CHECK([for C++ compiler option to allow warnings],
+ [gl_cv_cxx_wallow],
+ [rm -f conftest*
+ echo 'int dummy;' > conftest.cc
+ AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
+ AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
+ dnl Test the number of error output lines, because AIX xlC accepts the
+ dnl option '-Wno-error', just to produce a warning
+ dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
+ dnl afterwards.
+ if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
+ gl_cv_cxx_wallow='-Wno-error'
+ else
+ gl_cv_cxx_wallow=none
+ fi
+ rm -f conftest*
+ ])
+ case "$gl_cv_cxx_wallow" in
+ none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
+ *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
+ esac
+ else
+ GL_CXXFLAG_ALLOW_WARNINGS=''
+ fi
+ AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
+])
+
dnl Expands to some code for use in .c programs that, on native Windows, defines
dnl the Microsoft deprecated alias function names to the underscore-prefixed
dnl actual function names. With this macro, these function names are available
next prev parent reply other threads:[~2021-06-10 19:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-16 17:01 new module 'sigsegv' Bruno Haible
2021-06-06 23:27 ` Dmitry V. Levin
2021-06-07 0:49 ` Bruno Haible
2021-06-07 10:29 ` Dmitry V. Levin
2021-06-08 1:45 ` Jim Meyering
2021-06-08 2:40 ` warnings in unit tests Bruno Haible
2021-06-08 5:55 ` Jim Meyering
2021-06-08 8:56 ` Bruno Haible
2021-06-09 0:41 ` Dmitry V. Levin
2021-06-10 20:05 ` Bruno Haible
[not found] ` <CAH8yC8kHTq5J9onJj+2jwy_DwzXrwujqFs9TEBxGh5k_KCu=kg@mail.gmail.com>
2021-06-08 10:57 ` Bruno Haible
2021-06-08 16:42 ` Paul Eggert
2021-06-09 13:35 ` Dmitry V. Levin
2021-06-09 19:38 ` Bruno Haible
2021-06-10 19:39 ` Bruno Haible [this message]
2021-06-09 7:23 ` Bernhard Voelker
2021-06-09 14:17 ` Bruno Haible
2021-06-10 8:13 ` Simon Josefsson via Gnulib discussion list
2021-06-10 19:51 ` Bruno Haible
2021-06-10 21:49 ` Simon Josefsson via Gnulib discussion list
2021-06-11 12:21 ` Eric Blake
2021-06-11 13:57 ` Bruno Haible
2021-06-19 12:02 ` new module 'sigsegv' Bruno Haible
2021-06-21 18:22 ` [PATCH] sigsegv, sigsegv-tests: Assign my contributions to the FSF Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2531743.PxXWdyhe4H@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=eggert@cs.ucla.edu \
--cc=noloader@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).