testautomation: avoid format related warnings by using a few pragma's

ci: enable -Werror to a few platforms
main
Anonymous Maarten 2022-10-06 00:31:00 +02:00 committed by Anonymous Maarten
parent d04fa0ef76
commit 274ec02581
5 changed files with 177 additions and 2 deletions

View File

@ -160,6 +160,25 @@ add_executable(controllermap controllermap.c testutils.c)
add_executable(testvulkan testvulkan.c)
add_executable(testoffscreen testoffscreen.c)
cmake_push_check_state(RESET)
check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
if(HAVE_WFORMAT_OVERFLOW)
target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
endif()
check_c_compiler_flag(-Wformat HAVE_WFORMAT)
if(HAVE_WFORMAT)
target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
endif()
check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
if(HAVE_WFORMAT_EXTRA_ARGS)
target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
endif()
cmake_pop_check_state()
SET(ALL_TESTS
checkkeys
checkkeysthreads

84
test/configure vendored
View File

@ -4664,6 +4664,90 @@ if test x$have_opengl = xyes; then
OPENGL_TARGETS="TARGETS"
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat" >&5
printf %s "checking for GCC -Wformat... " >&6; }
have_wformat=no
save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Wformat"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int x = 0;
int
main (void)
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
have_wformat=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat" >&5
printf "%s\n" "$have_wformat" >&6; }
CFLAGS="$save_CFLAGS"
if test x$have_wformat = xyes; then
CFLAGS="$CFLAGS -DHAVE_WFORMAT"
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat-overflow" >&5
printf %s "checking for GCC -Wformat-overflow... " >&6; }
have_wformat_overflow=no
save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Wformat-overflow"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int x = 0;
int
main (void)
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
have_wformat_overflow=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat_overflow" >&5
printf "%s\n" "$have_wformat_overflow" >&6; }
CFLAGS="$save_CFLAGS"
if test x$have_wformat_overflow = xyes; then
CFLAGS="$CFLAGS -DHAVE_WFORMAT_OVERFLOW"
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat-extra-args" >&5
printf %s "checking for GCC -Wformat-extra-args... " >&6; }
have_wformat_extra_args=no
save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Wformat-extra-args"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int x = 0;
int
main (void)
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
have_wformat_extra_args=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat_extra_args" >&5
printf "%s\n" "$have_wformat_extra_args" >&6; }
CFLAGS="$save_CFLAGS"
if test x$have_wformat_extra_args = xyes; then
CFLAGS="$CFLAGS -DHAVE_WFORMAT_EXTRA_ARGS"
fi
# Check whether --enable-werror was given.
if test ${enable_werror+y}
then :

View File

@ -184,6 +184,42 @@ if test x$have_opengl = xyes; then
OPENGL_TARGETS="TARGETS"
fi
AC_MSG_CHECKING(for GCC -Wformat)
have_wformat=no
save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Wformat"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
[have_wformat=yes], [])
AC_MSG_RESULT($have_wformat)
CFLAGS="$save_CFLAGS"
if test x$have_wformat = xyes; then
CFLAGS="$CFLAGS -DHAVE_WFORMAT"
fi
AC_MSG_CHECKING(for GCC -Wformat-overflow)
have_wformat_overflow=no
save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Wformat-overflow"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
[have_wformat_overflow=yes], [])
AC_MSG_RESULT($have_wformat_overflow)
CFLAGS="$save_CFLAGS"
if test x$have_wformat_overflow = xyes; then
CFLAGS="$CFLAGS -DHAVE_WFORMAT_OVERFLOW"
fi
AC_MSG_CHECKING(for GCC -Wformat-extra-args)
have_wformat_extra_args=no
save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Wformat-extra-args"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
[have_wformat_extra_args=yes], [])
AC_MSG_RESULT($have_wformat_extra_args)
CFLAGS="$save_CFLAGS"
if test x$have_wformat_extra_args = xyes; then
CFLAGS="$CFLAGS -DHAVE_WFORMAT_EXTRA_ARGS"
fi
AC_ARG_ENABLE(werror,
[AS_HELP_STRING([--enable-werror], [treat warnings as errors [default=no]])],
enable_werror=$enableval, enable_werror=no)

View File

@ -376,6 +376,11 @@ int platform_testSetErrorEmptyInput(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT_OVERFLOW)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-overflow"
#endif
/* !
* \brief Tests SDL_SetError with invalid input
* \sa
@ -451,7 +456,7 @@ int platform_testSetErrorInvalidInput(void *arg)
probeError,
lastError);
}
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
@ -459,6 +464,10 @@ int platform_testSetErrorInvalidInput(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT_OVERFLOW)
#pragma GCC diagnostic pop
#endif
/* !
* \brief Tests SDL_GetPowerInfo
* \sa

View File

@ -7,7 +7,6 @@
#include "SDL.h"
#include "SDL_test.h"
/* Test case functions */
/**
@ -36,6 +35,16 @@ stdlib_strlcpy(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic push
#if defined(HAVE_WFORMAT)
#pragma GCC diagnostic ignored "-Wformat"
#endif
#if defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic ignored "-Wformat-extra-args"
#endif
#endif
/**
* @brief Call to SDL_snprintf
*/
@ -159,6 +168,10 @@ stdlib_snprintf(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic pop
#endif
/**
* @brief Call to SDL_getenv and SDL_setenv
*/
@ -293,6 +306,16 @@ stdlib_getsetenv(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic push
#if defined(HAVE_WFORMAT)
#pragma GCC diagnostic ignored "-Wformat"
#endif
#if defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic ignored "-Wformat-extra-args"
#endif
#endif
/**
* @brief Call to SDL_sscanf
*/
@ -375,6 +398,10 @@ stdlib_sscanf(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic pop
#endif
#if defined(_WIN64)
# define SIZE_FORMAT "I64u"
#elif defined(__WIN32__)