Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix tests in travis-ci.org #336

Merged
merged 7 commits into from Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -16,16 +16,17 @@ os:
before_install:
- echo $LANG
- echo $LC_ALL
- set -e

install:
- sh autogen.sh

before_script:
- ./configure
- ./configure --enable-strerror-override

script:
- make

after_success:
- make check
- cppcheck --quiet *.h *.c tests/
- if type cppcheck &> /dev/null ; then cppcheck --error-exitcode=1 --quiet *.h *.c tests/ ; fi
6 changes: 6 additions & 0 deletions Makefile.am
Expand Up @@ -53,6 +53,12 @@ libjson_c_la_SOURCES = \
printbuf.c \
random_seed.c

if ENABLE_STRERROR_OVERRIDE
libjson_cinclude_HEADERS+= \
strerror_override.h
libjson_c_la_SOURCES+= \
strerror_override.c
endif

distclean-local:
-rm -rf $(testsubdir)
Expand Down
28 changes: 27 additions & 1 deletion configure.ac
Expand Up @@ -7,6 +7,8 @@ AM_INIT_AUTOMAKE

AC_PROG_MAKE_SET

AC_CANONICAL_HOST

AC_ARG_ENABLE(rdrand,
AS_HELP_STRING([--enable-rdrand],
[Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms.]),
Expand All @@ -21,6 +23,22 @@ else
AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable])
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
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

Expand Down Expand Up @@ -57,14 +75,22 @@ AS_IF([test "x$ac_cv___thread" != xno],
AC_FUNC_VPRINTF
AC_FUNC_MEMCMP
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([nan], [], [], [[#include <math.h>]])
AC_CHECK_DECLS([isnan], [], [], [[#include <math.h>]])
AC_CHECK_DECLS([isinf], [], [], [[#include <math.h>]])
AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]])
AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]])

case "${host_os}" in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should linux be the only OS allowed to use uselocale? When I said that the configure test needs to be adjusted I mean that it needs to actually check whether uselocale works. This is effectively just an obfuscated #ifdef APPLE.
I'm going to merge this PR since all the other changes look fine, but then I'm going to revert this piece and we'll need to approach it a different way.

linux*)
AC_CHECK_FUNCS([uselocale])
;;
*) # Nothing
;;
esac

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"])
fi
Expand Down
3 changes: 2 additions & 1 deletion json_object.c
Expand Up @@ -12,13 +12,14 @@

#include "config.h"

#include "strerror_override.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <math.h>
#include <errno.h>

#include "debug.h"
#include "printbuf.h"
Expand Down
3 changes: 2 additions & 1 deletion json_pointer.c
Expand Up @@ -8,10 +8,11 @@

#include "config.h"

#include "strerror_override.h"

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>

Expand Down
3 changes: 2 additions & 1 deletion json_util.c
Expand Up @@ -12,13 +12,14 @@
#include "config.h"
#undef realloc

#include "strerror_override.h"

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>

#ifdef HAVE_SYS_TYPES_H
Expand Down
2 changes: 1 addition & 1 deletion random_seed.c
Expand Up @@ -9,6 +9,7 @@
*
*/

#include "strerror_override.h"
#include <stdio.h>
#include "config.h"
#include "random_seed.h"
Expand Down Expand Up @@ -128,7 +129,6 @@ static int get_rdrand_seed()
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>

Expand Down
4 changes: 2 additions & 2 deletions tests/strerror_override.c → strerror_override.c
@@ -1,4 +1,4 @@
#include <errno.h>
#include "strerror_override.h"

/*
* Override strerror() to get consistent output across platforms.
Expand Down Expand Up @@ -54,7 +54,7 @@ static struct {

#define PREFIX "ERRNO="
static char errno_buf[128] = PREFIX;
char *strerror(int errno_in)
char *_json_c_strerror(int errno_in)
{
int start_idx;
char digbuf[20];
Expand Down
12 changes: 12 additions & 0 deletions strerror_override.h
@@ -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__ */
2 changes: 1 addition & 1 deletion tests/Makefile.am
Expand Up @@ -52,7 +52,7 @@ EXTRA_DIST+= test2Formatted_plain.expected
EXTRA_DIST+= test2Formatted_pretty.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
TESTS_ENVIRONMENT = top_builddir=$(top_builddir)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_basic.test
Expand Up @@ -11,5 +11,9 @@ fi
filename=$(basename "$0")
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 $?
2 changes: 1 addition & 1 deletion tests/test_json_pointer.c
@@ -1,4 +1,4 @@
#include <errno.h>
#include "strerror_override.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
Expand Down
3 changes: 2 additions & 1 deletion tests/test_util_file.c
@@ -1,4 +1,4 @@
#include <errno.h>
#include "strerror_override.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
Expand Down Expand Up @@ -106,6 +106,7 @@ static void stat_and_cat(const char *file)
buf[sb.st_size] = '\0';
printf("file[%s], size=%d, contents=%s\n", file, (int)sb.st_size, buf);
free(buf);
close(d);
}

int main(int argc, char **argv)
Expand Down
15 changes: 0 additions & 15 deletions tests/test_util_file.test

This file was deleted.

1 change: 1 addition & 0 deletions tests/test_util_file.test