[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: warnings in unit tests
From: |
Bruno Haible |
Subject: |
Re: warnings in unit tests |
Date: |
Thu, 10 Jun 2021 21:39:32 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-210-generic; KDE/5.18.0; x86_64; ; ) |
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
- Re: new module 'sigsegv', (continued)
- Re: new module 'sigsegv', Jim Meyering, 2021/06/07
- warnings in unit tests, Bruno Haible, 2021/06/07
- Re: warnings in unit tests, Jim Meyering, 2021/06/08
- Re: warnings in unit tests, Bruno Haible, 2021/06/08
- Re: warnings in unit tests, Dmitry V. Levin, 2021/06/08
- Re: warnings in unit tests, Bruno Haible, 2021/06/10
- Message not available
- Re: warnings in unit tests, Bruno Haible, 2021/06/08
- Re: warnings in unit tests, Paul Eggert, 2021/06/08
- Re: warnings in unit tests, Dmitry V. Levin, 2021/06/09
- Re: warnings in unit tests, Bruno Haible, 2021/06/09
- Re: warnings in unit tests,
Bruno Haible <=
- Re: warnings in unit tests, Bernhard Voelker, 2021/06/09
- Re: warnings in unit tests, Bruno Haible, 2021/06/09
- Re: warnings in unit tests, Simon Josefsson, 2021/06/10
- Re: warnings in unit tests, Bruno Haible, 2021/06/10
- Re: warnings in unit tests, Simon Josefsson, 2021/06/10
- Re: warnings in unit tests, Eric Blake, 2021/06/11
- Re: warnings in unit tests, Bruno Haible, 2021/06/11
Re: new module 'sigsegv', Bruno Haible, 2021/06/19