Skip to content

Commit

Permalink
Do not enforce POSIX if __STRICT_ANSI__ is defined
Browse files Browse the repository at this point in the history
On b4c1548 I proposed defining _POSIX_C_SOURCE in
order to enable the macros to use POSIX under unix-like
systems, as POSIX was used anyway.

Here I propose to follow whatever the user wants. This means:

- If the user explicitly defines a strict standard C compliance
  (e.g. compiling using `--std=c99`) then we do not use
  any POSIX feature. This is detected through the definition
  of the __STRICT_ANSI__ macro.

- If the user does not enforce any C standard, we assume POSIX
  is available as before if the system is unix-like.

I believe this approach is better than the previous one because if
any cutest user does not want to rely on POSIX features we do not
force it. However by default we use them if they are available.
  • Loading branch information
zeehio committed Feb 24, 2017
1 parent 944d3ff commit d4c21e8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions include/cutest.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@
**********************/

/* The unit test files should not rely on anything below. */

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

#if defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__)
#if (defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__)) && !defined(__STRICT_ANSI__)
#define CUTEST_UNIX__ 1
#include <errno.h>
#include <unistd.h>
Expand All @@ -102,12 +101,16 @@
#include <signal.h>
#endif

#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
#if (defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)) && !defined(__STRICT_ANSI__)
#define CUTEST_WIN__ 1
#include <windows.h>
#include <io.h>
#endif

#if defined(__STRICT_ANSI__)
#define CUTEST_ANSI__ 1
#endif

#ifdef __cplusplus
#include <exception>
#endif
Expand Down Expand Up @@ -352,9 +355,10 @@ test_do_run__(const struct test__* test)
return (test_current_failures__ == 0) ? 0 : -1;
}

#if !defined(CUTEST_ANSI__)
/* Called if anything goes bad in cutest, or if the unit test ends in other
* way then by normal returning from its function (e.g. exception or some
* abnormal child process termination). */
* abnormal child process termination). On CUTEST_ANSI__ this is not used so we don't define it*/
static void
test_error__(const char* fmt, ...)
{
Expand All @@ -377,6 +381,7 @@ test_error__(const char* fmt, ...)
printf("\n");
}
}
#endif

/* Trigger the unit test. If possible (and not suppressed) it starts a child
* process who calls test_do_run__(), otherwise it calls test_do_run__()
Expand Down Expand Up @@ -458,7 +463,7 @@ test_run__(const struct test__* test)
failed = 1;
}

#else
#else /* CUTEST_ANSI__ */

/* A platform where we don't know how to run child process. */
failed = (test_do_run__(test) != 0);
Expand Down

0 comments on commit d4c21e8

Please sign in to comment.