Fails to build with -DWITH_TESTS=on and without custom allocator
panlinux opened this issue · comments
When building with tests enabled and without the custom allocator, the build fails. There are two classes of failure:
a)
[ 61%] Building C object test/CMakeFiles/memory_allocation_test.dir/memory_allocation_test.c.o
/home/ubuntu/git/packages/libcbor/libcbor/test/memory_allocation_test.c: In function ‘main’:
/home/ubuntu/git/packages/libcbor/libcbor/test/memory_allocation_test.c:278:37: warning: ISO C forbids empty initializer braces [-Wpedantic]
278 | const struct CMUnitTest tests[] = {};
| ^
/home/ubuntu/git/packages/libcbor/libcbor/test/memory_allocation_test.c:278:27: error: zero or negative size array ‘tests’
278 | const struct CMUnitTest tests[] = {};
| ^~~~~
and
b)
/home/ubuntu/git/packages/libcbor/libcbor/test/memory_allocation_test.c:238:13: warning: ‘test_map_add’ defined but not used [-Wunused-function]
238 | static void test_map_add(void **state) {
| ^~~~~~~~~~~~
The memory_allocation_test.c
code tries to cope with CBOR_CUSTOM_ALLOC
being unset, but the gcc warnings (treated as errors) trip it.
I think this test file should be removed from the list when CBOR_CUSTOM_ALLOC is false or undefined.
How about this to skip that test entirely if CBOR_CUSTOM_ALLOC
is not defined?
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index b4cea8c..70ba2e0 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,4 +1,7 @@
file(GLOB TESTS "*_test.c")
+if(NOT CBOR_CUSTOM_ALLOC)
+ list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/memory_allocation_test.c)
+endif(NOT CBOR_CUSTOM_ALLOC)
find_package(CMocka REQUIRED)
LGTM, thanks @panlinux !