tests: fix tests in travis-ci.orgtags/json-c-0.13-20171207
@@ -16,16 +16,17 @@ os: | |||||
before_install: | before_install: | ||||
- echo $LANG | - echo $LANG | ||||
- echo $LC_ALL | - echo $LC_ALL | ||||
- set -e | |||||
install: | install: | ||||
- sh autogen.sh | - sh autogen.sh | ||||
before_script: | before_script: | ||||
- ./configure | |||||
- ./configure --enable-strerror-override | |||||
script: | script: | ||||
- make | - make | ||||
after_success: | after_success: | ||||
- make check | - make check | ||||
- cppcheck --quiet *.h *.c tests/ | |||||
- if type cppcheck &> /dev/null ; then cppcheck --error-exitcode=1 --quiet *.h *.c tests/ ; fi |
@@ -53,6 +53,12 @@ libjson_c_la_SOURCES = \ | |||||
printbuf.c \ | printbuf.c \ | ||||
random_seed.c | random_seed.c | ||||
if ENABLE_STRERROR_OVERRIDE | |||||
libjson_cinclude_HEADERS+= \ | |||||
strerror_override.h | |||||
libjson_c_la_SOURCES+= \ | |||||
strerror_override.c | |||||
endif | |||||
distclean-local: | distclean-local: | ||||
-rm -rf $(testsubdir) | -rm -rf $(testsubdir) | ||||
@@ -7,6 +7,8 @@ AM_INIT_AUTOMAKE | |||||
AC_PROG_MAKE_SET | AC_PROG_MAKE_SET | ||||
AC_CANONICAL_HOST | |||||
AC_ARG_ENABLE(rdrand, | AC_ARG_ENABLE(rdrand, | ||||
AS_HELP_STRING([--enable-rdrand], | AS_HELP_STRING([--enable-rdrand], | ||||
[Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms.]), | [Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms.]), | ||||
@@ -21,6 +23,22 @@ else | |||||
AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable]) | AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable]) | ||||
fi | fi | ||||
AC_ARG_ENABLE(strerror-override, | |||||
AS_HELP_STRING([--enable-strerror-override], | |||||
[Override strerror() function with internal version.]), | |||||
[if test x$enableval = xyes; then | |||||
enable_strerror_override=yes | |||||
AC_DEFINE(ENABLE_STRERROR_OVERRIDE, 1, [Override strerror() with internal version]) | |||||
fi]) | |||||
AM_CONDITIONAL([ENABLE_STRERROR_OVERRIDE], [test "x$enable_strerror_override" = "xyes"]) | |||||
if test "x$enable_strerror_override" = "xyes"; then | |||||
AC_MSG_RESULT([Overriding `strerror()` function with internal version]) | |||||
else | |||||
AC_MSG_RESULT([Using libc's `strerror()` function]) | |||||
fi | |||||
# enable silent build by default | # enable silent build by default | ||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) | ||||
@@ -57,7 +75,7 @@ AS_IF([test "x$ac_cv___thread" != xno], | |||||
AC_FUNC_VPRINTF | AC_FUNC_VPRINTF | ||||
AC_FUNC_MEMCMP | AC_FUNC_MEMCMP | ||||
AC_CHECK_FUNCS([realloc]) | AC_CHECK_FUNCS([realloc]) | ||||
AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale uselocale) | |||||
AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale) | |||||
AC_CHECK_DECLS([INFINITY], [], [], [[#include <math.h>]]) | AC_CHECK_DECLS([INFINITY], [], [], [[#include <math.h>]]) | ||||
AC_CHECK_DECLS([nan], [], [], [[#include <math.h>]]) | AC_CHECK_DECLS([nan], [], [], [[#include <math.h>]]) | ||||
AC_CHECK_DECLS([isnan], [], [], [[#include <math.h>]]) | AC_CHECK_DECLS([isnan], [], [], [[#include <math.h>]]) | ||||
@@ -65,6 +83,14 @@ AC_CHECK_DECLS([isinf], [], [], [[#include <math.h>]]) | |||||
AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]]) | AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]]) | ||||
AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]]) | AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]]) | ||||
case "${host_os}" in | |||||
linux*) | |||||
AC_CHECK_FUNCS([uselocale]) | |||||
;; | |||||
*) # Nothing | |||||
;; | |||||
esac | |||||
if test "$ac_cv_have_decl_isnan" = "yes" ; then | if test "$ac_cv_have_decl_isnan" = "yes" ; then | ||||
AC_TRY_LINK([#include <math.h>], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"]) | AC_TRY_LINK([#include <math.h>], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"]) | ||||
fi | fi | ||||
@@ -12,13 +12,14 @@ | |||||
#include "config.h" | #include "config.h" | ||||
#include "strerror_override.h" | |||||
#include <assert.h> | #include <assert.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stddef.h> | #include <stddef.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <math.h> | #include <math.h> | ||||
#include <errno.h> | |||||
#include "debug.h" | #include "debug.h" | ||||
#include "printbuf.h" | #include "printbuf.h" | ||||
@@ -8,10 +8,11 @@ | |||||
#include "config.h" | #include "config.h" | ||||
#include "strerror_override.h" | |||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <errno.h> | |||||
#include <string.h> | #include <string.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
@@ -12,13 +12,14 @@ | |||||
#include "config.h" | #include "config.h" | ||||
#undef realloc | #undef realloc | ||||
#include "strerror_override.h" | |||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stddef.h> | #include <stddef.h> | ||||
#include <limits.h> | #include <limits.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <errno.h> | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#ifdef HAVE_SYS_TYPES_H | #ifdef HAVE_SYS_TYPES_H | ||||
@@ -9,6 +9,7 @@ | |||||
* | * | ||||
*/ | */ | ||||
#include "strerror_override.h" | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include "config.h" | #include "config.h" | ||||
#include "random_seed.h" | #include "random_seed.h" | ||||
@@ -128,7 +129,6 @@ retry: | |||||
#include <string.h> | #include <string.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <errno.h> | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
@@ -1,4 +1,4 @@ | |||||
#include <errno.h> | |||||
#include "strerror_override.h" | |||||
/* | /* | ||||
* Override strerror() to get consistent output across platforms. | * Override strerror() to get consistent output across platforms. | ||||
@@ -54,7 +54,7 @@ static struct { | |||||
#define PREFIX "ERRNO=" | #define PREFIX "ERRNO=" | ||||
static char errno_buf[128] = PREFIX; | static char errno_buf[128] = PREFIX; | ||||
char *strerror(int errno_in) | |||||
char *_json_c_strerror(int errno_in) | |||||
{ | { | ||||
int start_idx; | int start_idx; | ||||
char digbuf[20]; | char digbuf[20]; |
@@ -0,0 +1,12 @@ | |||||
#ifndef __STRERROR_OVERRIDE_H__ | |||||
#define __STRERROR_OVERRIDE_H__ | |||||
#include "config.h" | |||||
#include <errno.h> | |||||
#if ENABLE_STRERROR_OVERRIDE | |||||
char *_json_c_strerror(int errno_in); | |||||
#define strerror _json_c_strerror | |||||
#endif | |||||
#endif /* __STRERROR_OVERRIDE_H__ */ |
@@ -52,7 +52,7 @@ EXTRA_DIST+= test2Formatted_plain.expected | |||||
EXTRA_DIST+= test2Formatted_pretty.expected | EXTRA_DIST+= test2Formatted_pretty.expected | ||||
EXTRA_DIST+= test2Formatted_spaced.expected | EXTRA_DIST+= test2Formatted_spaced.expected | ||||
test_util_file_SOURCES = test_util_file.c strerror_override.c | |||||
test_util_file_SOURCES = test_util_file.c | |||||
testsubdir=testSubDir | testsubdir=testSubDir | ||||
TESTS_ENVIRONMENT = top_builddir=$(top_builddir) | TESTS_ENVIRONMENT = top_builddir=$(top_builddir) | ||||
@@ -11,5 +11,9 @@ fi | |||||
filename=$(basename "$0") | filename=$(basename "$0") | ||||
filename="${filename%.*}" | filename="${filename%.*}" | ||||
run_output_test $filename | |||||
# This is only for the test_util_file.test ; | |||||
# more stuff could be extended | |||||
cp -f "$srcdir/valid.json" . | |||||
run_output_test $filename "$srcdir" | |||||
exit $? | exit $? |
@@ -1,4 +1,4 @@ | |||||
#include <errno.h> | |||||
#include "strerror_override.h" | |||||
#include <assert.h> | #include <assert.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
@@ -1,4 +1,4 @@ | |||||
#include <errno.h> | |||||
#include "strerror_override.h" | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stddef.h> | #include <stddef.h> | ||||
@@ -106,6 +106,7 @@ static void stat_and_cat(const char *file) | |||||
buf[sb.st_size] = '\0'; | buf[sb.st_size] = '\0'; | ||||
printf("file[%s], size=%d, contents=%s\n", file, (int)sb.st_size, buf); | printf("file[%s], size=%d, contents=%s\n", file, (int)sb.st_size, buf); | ||||
free(buf); | free(buf); | ||||
close(d); | |||||
} | } | ||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
@@ -1,15 +0,0 @@ | |||||
#!/bin/sh | |||||
# Common definitions | |||||
if test -z "$srcdir"; then | |||||
srcdir="${0%/*}" | |||||
test "$srcdir" = "$0" && srcdir=. | |||||
test -z "$srcdir" && srcdir=. | |||||
fi | |||||
. "$srcdir/test-defs.sh" | |||||
cp -f "$srcdir/valid.json" . | |||||
run_output_test test_util_file "$srcdir" | |||||
_err=$? | |||||
exit $_err |
@@ -0,0 +1 @@ | |||||
test_basic.test |