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

Fails to build with -DWITH_TESTS=on and without custom allocator #128

Closed
panlinux opened this issue Mar 20, 2020 · 2 comments · Fixed by #129
Closed

Fails to build with -DWITH_TESTS=on and without custom allocator #128

panlinux opened this issue Mar 20, 2020 · 2 comments · Fixed by #129

Comments

@panlinux
Copy link

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.

@panlinux
Copy link
Author

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)
 

@PJK
Copy link
Owner

PJK commented Mar 20, 2020

LGTM, thanks @panlinux !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants