tests: do not depend on config.h

Currently we face test suite failures in different environments,
because of a conflict between the definitions of isnan by gnulib, and
by the C++ library:

    262. headers.at:186: testing Sane headers: %locations %debug c++ ...
    ./headers.at:186: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -d -o input.cc input.y
    ./headers.at:186: $CXX $CXXFLAGS $CPPFLAGS  -c -o input.o input.cc
    stderr:
    In file included from /usr/include/c++/4.8.2/cmath:44:0,
                     from /usr/include/c++/4.8.2/random:38,
                     from /usr/include/c++/4.8.2/bits/stl_algo.h:65,
                     from /usr/include/c++/4.8.2/algorithm:62,
                     from location.hh:41,
                     from input.hh:90,
                     from input.cc:50:
    /u/cs/fac/eggert/src/gnu/bison/lib/math.h: In function 'bool isnan(double)':
    /u/cs/fac/eggert/src/gnu/bison/lib/math.h:2849:1: error: new declaration 'bool isnan(double)'
     _GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, isnan, bool)
     ^
    In file included from /usr/include/features.h:375:0,
                     from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/os_defines.h:39,
                     from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/c++config.h:2097,
                     from /usr/include/c++/4.8.2/cstdlib:41,
                     from input.hh:48,
                     from input.cc:50:
    /usr/include/bits/mathcalls.h:235:1: error: ambiguates old declaration 'int isnan(double)'
     __MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
     ^

There might be something to do in gnulib about this, but I believe
that gnulib should not be used in the test suite in the first place.

The test suite should work with other compilers than the one used to
compile the package.  For a start, Bison sources are more
demanding (C99) than the generated parsers.  Last time I tried, tcc
for example, was not able to compile Bison, yet our generated parsers
should compile cleanly with it.

Besides the problem at hand is with the C++ compiler, with is not the
one used to set up gnulib at configuration-time (config.h is mainly
built from probing the C compiler).

We should really not depend on gnulib in tests.

This was introduced in 2001 to check whether including
stdlib.h/string.h is safe thanks to STDC_HEADERS
(2ce1014469).  Today, we assume at least
a C90 compiler, it should be safe enough.

* tests/local.at, tests/testsuite.h: Do not include config.h.
* tests/atlocal.in (conftest.cc): Likewise.
(CPPFLAGS): Do not expose lib/, as because of this we might picked up
gnulib replacement headers for system headers.

* tests/input.at: Use int instead of ptrdiff_t, for easier portability
(some machine on the CI did not find ptrdiff_t).
* tests/c++.at: Add missing include for getchar.
This commit is contained in:
Akim Demaille
2019-10-09 09:10:57 +02:00
parent d6ce0521cf
commit f41e0cf73c
4 changed files with 5 additions and 11 deletions

View File

@@ -16,9 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# We need 'testsuite.h' (srcdir/test), 'config.h' (builddir/lib), and
# the gnulib headers (srcdir/lib).
CPPFLAGS="-I$abs_top_srcdir/tests -I$abs_top_srcdir/lib -I$abs_top_builddir/lib @CPPFLAGS@"
# We need 'testsuite.h' (srcdir/test).
CPPFLAGS="-I$abs_top_srcdir/tests @CPPFLAGS@"
# Don't just check if $POSIXLY_CORRECT is set, as Bash, when launched
# as /bin/sh, sets the shell variable POSIXLY_CORRECT to y, but not
@@ -73,11 +72,7 @@ fi
if $BISON_CXX_WORKS; then
# See AT_DATA_SOURCE_PROLOGUE.
cat >conftest.cc <<EOF
#include <config.h>
/* We don't need perfect functions for these tests. */
#undef malloc
#undef memcmp
#undef realloc
#include <testsuite.h>
#include <iostream>
int main ()

View File

@@ -1322,7 +1322,7 @@ yylex (void)
*/
enum { input_elts = sizeof input };
(void) input_elts;
static ptrdiff_t toknum;
static int toknum;
assert (0 <= toknum && toknum < input_elts);
yylval = value_as_yystype (input[toknum]);
return input[toknum++];

View File

@@ -388,7 +388,7 @@ m4_define([AT_LANG_DISPATCH],
# The prologue that should be included in any source code that is
# meant to be compiled. Keep atlocal.in sync (BISON_CXX_WORKS).
m4_define([AT_DATA_SOURCE_PROLOGUE],
[[/* Load config.h, and adjust to the compiler.
[[/* Adjust to the compiler.
We used to do it here, but each time we add a new line,
we have to adjust all the line numbers in error messages.
It's simpler to use a constant include to a varying file. */

View File

@@ -1,4 +1,3 @@
#include <config.h>
/* We don't need perfect functions for these tests. */
#undef malloc
#undef memcmp