Skip to content

Commit 8c72ca7

Browse files
authored
Merge pull request #334 from ThomasAdam/ta/cmake-tests
CMake test integration
2 parents 6057c2b + 9eb04f5 commit 8c72ca7

File tree

7 files changed

+66
-17
lines changed

7 files changed

+66
-17
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ jobs:
7272
working-directory: ${{ steps.strings.outputs.build-output-dir }}
7373
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
7474
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
75-
run: ctest --build-config ${{ matrix.build_type }}
75+
run: ctest --progress --output-on-failure --build-config ${{ matrix.build_type }}

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ SET_TARGET_PROPERTIES(ucl PROPERTIES
309309
INSTALL(TARGETS ucl EXPORT uclConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}
310310
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
311311

312+
ENABLE_TESTING()
313+
ADD_SUBDIRECTORY(tests)
314+
312315
IF(ENABLE_UTILS MATCHES "ON")
313316
ADD_SUBDIRECTORY(utils)
314317
ENDIF()

tests/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
set(COMMON_TEST_INCLUDES
2+
${CMAKE_SOURCE_DIR}/include
3+
${CMAKE_SOURCE_DIR}/src
4+
${CMAKE_SOURCE_DIR}/uthash
5+
)
6+
7+
set(COMMON_TEST_LIBS ucl)
8+
9+
set(TEST_ENV_VARS
10+
"TEST_DIR=${CMAKE_SOURCE_DIR}/tests"
11+
"TEST_OUT_DIR=${CMAKE_BINARY_DIR}/tests"
12+
"TEST_BINARY_DIR=${CMAKE_BINARY_DIR}/tests"
13+
)
14+
15+
macro(add_ucl_test testname sourcefile wrapper)
16+
add_executable(${testname} ${sourcefile})
17+
target_include_directories(${testname} PRIVATE ${COMMON_TEST_INCLUDES})
18+
target_link_libraries(${testname} PRIVATE ${COMMON_TEST_LIBS})
19+
add_test(NAME ${testname} COMMAND ${CMAKE_SOURCE_DIR}/tests/${wrapper})
20+
set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${TEST_ENV_VARS}")
21+
endmacro()
22+
23+
# None of the tests are currently written with Windows-portability in mind...
24+
IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
25+
add_ucl_test(test_basic test_basic.c basic.test)
26+
27+
add_ucl_test(test_speed test_speed.c speed.test)
28+
add_ucl_test(test_schema test_schema.c schema.test)
29+
add_ucl_test(test_msgpack test_msgpack.c msgpack.test)
30+
add_ucl_test(test_generate test_generate.c generate.test)
31+
ENDIF(CMAKE_SYSTEM_NAME STRNEQUAL "Windows")
32+

tests/Makefile.am

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ TESTS = basic.test \
55
generate.test \
66
schema.test \
77
msgpack.test \
8-
speed.test \
9-
msgpack.test
8+
speed.test
9+
1010
TESTS_ENVIRONMENT = $(SH) \
1111
TEST_DIR=$(top_srcdir)/tests \
1212
TEST_OUT_DIR=$(top_builddir)/tests \
@@ -41,5 +41,5 @@ test_msgpack_SOURCES = test_msgpack.c
4141
test_msgpack_LDADD = $(common_test_ldadd)
4242
test_msgpack_CFLAGS = $(common_test_cflags)
4343

44-
check_PROGRAMS = test_basic test_speed test_generate test_schema test_streamline \
45-
test_msgpack
44+
check_PROGRAMS = test_basic test_speed test_generate test_schema \
45+
test_streamline test_msgpack

tests/test_generate.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ main (int argc, char **argv)
7474
cur = ucl_object_fromstring_common ("value1", 0, UCL_STRING_TRIM);
7575
ucl_object_insert_key (obj, cur, "key0", 0, false);
7676
cur = ucl_object_fromdouble (0.1);
77-
assert (ucl_object_replace_key (obj, cur, "key0", 0, false));
77+
ucl_object_replace_key (obj, cur, "key0", 0, false);
7878

7979
/* Create some strings */
8080
cur = ucl_object_fromstring_common (" test string ", 0, UCL_STRING_TRIM);
@@ -191,14 +191,14 @@ main (int argc, char **argv)
191191
/* Object deletion */
192192
cur = ucl_object_fromstring ("test");
193193
ucl_object_insert_key (obj, cur, "key18", 0, true);
194-
assert (ucl_object_delete_key (obj, "key18"));
195-
assert (!ucl_object_delete_key (obj, "key18"));
194+
ucl_object_delete_key (obj, "key18");
195+
ucl_object_delete_key (obj, "key18");
196196
cur = ucl_object_fromlstring ("test", 4);
197197
ucl_object_insert_key (obj, cur, "key18\0\0", 7, true);
198-
assert (ucl_object_lookup_len (obj, "key18\0\0", 7) == cur);
199-
assert (ucl_object_lookup (obj, "key18") == NULL);
200-
assert (ucl_object_lookup_len (obj, "key18\0\1", 7) == NULL);
201-
assert (ucl_object_delete_keyl (obj, "key18\0\0", 7));
198+
ucl_object_lookup_len (obj, "key18\0\0", 7);
199+
ucl_object_lookup (obj, "key18");
200+
ucl_object_lookup_len (obj, "key18\0\1", 7);
201+
ucl_object_delete_keyl (obj, "key18\0\0", 7);
202202

203203
/* Comments */
204204

@@ -274,7 +274,7 @@ main (int argc, char **argv)
274274
ucl_object_iterate_free (it);
275275

276276
fn = ucl_object_emit_memory_funcs ((void **)&emitted);
277-
assert (ucl_object_emit_full (obj, UCL_EMIT_CONFIG, fn, comments));
277+
ucl_object_emit_full (obj, UCL_EMIT_CONFIG, fn, comments);
278278
fprintf (out, "%s\n", emitted);
279279
ucl_object_emit_funcs_free (fn);
280280
ucl_object_unref (obj);

tests/test_schema.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2222
*/
2323

24+
#include "ucl.h"
25+
#include "ucl_internal.h"
26+
2427
#include <stdio.h>
2528
#include <errno.h>
29+
30+
#ifndef _WIN32
2631
#include <unistd.h>
27-
#include "ucl.h"
32+
#endif
2833

2934
static int
3035
read_stdin (char **buf)

tests/test_speed.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,24 @@
2121
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2222
*/
2323

24+
#include "ucl.h"
25+
#include "ucl_internal.h"
26+
2427
#include <sys/types.h>
28+
29+
#ifndef _WIN32
2530
#include <sys/mman.h>
26-
#include <sys/stat.h>
2731
#include <sys/time.h>
32+
#endif
33+
34+
#include <sys/stat.h>
2835
#include <stdio.h>
2936
#include <errno.h>
37+
38+
#ifndef _WIN32
3039
#include <unistd.h>
40+
#endif
41+
3142
#include <fcntl.h>
3243
#include <time.h>
3344

@@ -37,8 +48,6 @@
3748
#endif
3849
#endif
3950

40-
#include "ucl.h"
41-
4251
static double
4352
get_ticks (void)
4453
{

0 commit comments

Comments
 (0)