From 791742d8855cbf384a13cb31d9e21d7b21354095 Mon Sep 17 00:00:00 2001 From: Gwendolyn Date: Mon, 3 Jan 2022 16:17:25 +0100 Subject: [PATCH] move xassert.h to assert/assert.h so it can be included as by prepending the assert/ dir to the include search path and use include_next to facilitate that. Removed -pedantic from C flags of examples because include_next is an extension. --- CMakeLists.txt | 4 +++- xassert.h => assert/assert.h | 9 +++++---- examples/source.c | 2 +- xtest.c | 5 +---- xtest.h | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) rename xassert.h => assert/assert.h (51%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a769ac..764cb75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,12 @@ project(xtest C) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED TRUE) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -pedantic") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") add_compile_definitions(XTEST) +include_directories(BEFORE ${CMAKE_SOURCE_DIR}/assert) + add_executable(example-all xtest.c examples/all.c examples/parameterized.c examples/assertions.c examples/expect_assertions.c examples/fail.c examples/groups.c examples/float.c examples/source.c examples/source.h examples/skip.c) target_compile_definitions(example-all PRIVATE XTEST_ALL_EXAMPLES) diff --git a/xassert.h b/assert/assert.h similarity index 51% rename from xassert.h rename to assert/assert.h index 0fb532d..f694dad 100644 --- a/xassert.h +++ b/assert/assert.h @@ -1,12 +1,13 @@ +#if defined(__GNUC__) || defined(__clang__) || defined(XTEST_USE_INCLUDE_NEXT) +#include_next +#else #include +#endif #define XTEST_XASSERT -#if defined(XTEST_XTEST_H) && !defined(XTEST_SOURCE) -#error "do not include xtest.h and xassert.h at the same time. xassert.h should only be included from your source files and xtest.h should only be included from your test files." -#endif -#if defined(XTEST) && (!defined(XTEST_XTEST_H) || defined(XTEST_SOURCE)) +#if defined(XTEST) && !defined(XTEST_XTEST_H) void xtest_internal_assert(const char* file, int line, const char* func, const char* expr); diff --git a/examples/source.c b/examples/source.c index 7df04f9..3fe006d 100644 --- a/examples/source.c +++ b/examples/source.c @@ -1,6 +1,6 @@ #include #include "source.h" -#include "../xassert.h" +#include int ret_1() { return 1; diff --git a/xtest.c b/xtest.c index 274b344..f185648 100644 --- a/xtest.c +++ b/xtest.c @@ -1,9 +1,6 @@ #include - -#define XTEST_SOURCE - #include "xtest.h" -#include "xassert.h" +#include struct xtest_assert_info { const char *file; diff --git a/xtest.h b/xtest.h index b9a37df..14d7635 100644 --- a/xtest.h +++ b/xtest.h @@ -1,8 +1,8 @@ #ifndef XTEST_XTEST_H #define XTEST_XTEST_H -#if defined(XTEST_XASSERT) && !defined(XTEST_SOURCE) -#error "do not include xtest.h and xassert.h at the same time. xassert.h should only be included from your source files and xtest.h should only be included from your test files." +#if defined(XTEST_XASSERT) +#error "do not include xtest.h before assert.h. If your tests make use of standard library assertions, include first xtest.h and then assert.h" #endif