diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 9ec0432..bcc24a6 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -72,4 +72,4 @@ jobs: working-directory: ${{ steps.strings.outputs.build-output-dir }} # 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). # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --build-config ${{ matrix.build_type }} + run: ctest --progress --output-on-failure --build-config ${{ matrix.build_type }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d73910..780f5eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,6 +309,9 @@ SET_TARGET_PROPERTIES(ucl PROPERTIES INSTALL(TARGETS ucl EXPORT uclConfig DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +ENABLE_TESTING() +ADD_SUBDIRECTORY(tests) + IF(ENABLE_UTILS MATCHES "ON") ADD_SUBDIRECTORY(utils) ENDIF() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..ff7020c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,32 @@ +set(COMMON_TEST_INCLUDES + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/uthash +) + +set(COMMON_TEST_LIBS ucl) + +set(TEST_ENV_VARS + "TEST_DIR=${CMAKE_SOURCE_DIR}/tests" + "TEST_OUT_DIR=${CMAKE_BINARY_DIR}/tests" + "TEST_BINARY_DIR=${CMAKE_BINARY_DIR}/tests" +) + +macro(add_ucl_test testname sourcefile wrapper) + add_executable(${testname} ${sourcefile}) + target_include_directories(${testname} PRIVATE ${COMMON_TEST_INCLUDES}) + target_link_libraries(${testname} PRIVATE ${COMMON_TEST_LIBS}) + add_test(NAME ${testname} COMMAND ${CMAKE_SOURCE_DIR}/tests/${wrapper}) + set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${TEST_ENV_VARS}") +endmacro() + +# None of the tests are currently written with Windows-portability in mind... +IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") +add_ucl_test(test_basic test_basic.c basic.test) + +add_ucl_test(test_speed test_speed.c speed.test) +add_ucl_test(test_schema test_schema.c schema.test) +add_ucl_test(test_msgpack test_msgpack.c msgpack.test) +add_ucl_test(test_generate test_generate.c generate.test) +ENDIF(CMAKE_SYSTEM_NAME STRNEQUAL "Windows") + diff --git a/tests/Makefile.am b/tests/Makefile.am index 055eb8b..d344227 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,8 +5,8 @@ TESTS = basic.test \ generate.test \ schema.test \ msgpack.test \ - speed.test \ - msgpack.test + speed.test + TESTS_ENVIRONMENT = $(SH) \ TEST_DIR=$(top_srcdir)/tests \ TEST_OUT_DIR=$(top_builddir)/tests \ @@ -41,5 +41,5 @@ test_msgpack_SOURCES = test_msgpack.c test_msgpack_LDADD = $(common_test_ldadd) test_msgpack_CFLAGS = $(common_test_cflags) -check_PROGRAMS = test_basic test_speed test_generate test_schema test_streamline \ - test_msgpack \ No newline at end of file +check_PROGRAMS = test_basic test_speed test_generate test_schema \ + test_streamline test_msgpack diff --git a/tests/test_generate.c b/tests/test_generate.c index 302a733..dad1e98 100644 --- a/tests/test_generate.c +++ b/tests/test_generate.c @@ -74,7 +74,7 @@ main (int argc, char **argv) cur = ucl_object_fromstring_common ("value1", 0, UCL_STRING_TRIM); ucl_object_insert_key (obj, cur, "key0", 0, false); cur = ucl_object_fromdouble (0.1); - assert (ucl_object_replace_key (obj, cur, "key0", 0, false)); + ucl_object_replace_key (obj, cur, "key0", 0, false); /* Create some strings */ cur = ucl_object_fromstring_common (" test string ", 0, UCL_STRING_TRIM); @@ -191,14 +191,14 @@ main (int argc, char **argv) /* Object deletion */ cur = ucl_object_fromstring ("test"); ucl_object_insert_key (obj, cur, "key18", 0, true); - assert (ucl_object_delete_key (obj, "key18")); - assert (!ucl_object_delete_key (obj, "key18")); + ucl_object_delete_key (obj, "key18"); + ucl_object_delete_key (obj, "key18"); cur = ucl_object_fromlstring ("test", 4); ucl_object_insert_key (obj, cur, "key18\0\0", 7, true); - assert (ucl_object_lookup_len (obj, "key18\0\0", 7) == cur); - assert (ucl_object_lookup (obj, "key18") == NULL); - assert (ucl_object_lookup_len (obj, "key18\0\1", 7) == NULL); - assert (ucl_object_delete_keyl (obj, "key18\0\0", 7)); + ucl_object_lookup_len (obj, "key18\0\0", 7); + ucl_object_lookup (obj, "key18"); + ucl_object_lookup_len (obj, "key18\0\1", 7); + ucl_object_delete_keyl (obj, "key18\0\0", 7); /* Comments */ @@ -274,7 +274,7 @@ main (int argc, char **argv) ucl_object_iterate_free (it); fn = ucl_object_emit_memory_funcs ((void **)&emitted); - assert (ucl_object_emit_full (obj, UCL_EMIT_CONFIG, fn, comments)); + ucl_object_emit_full (obj, UCL_EMIT_CONFIG, fn, comments); fprintf (out, "%s\n", emitted); ucl_object_emit_funcs_free (fn); ucl_object_unref (obj); diff --git a/tests/test_schema.c b/tests/test_schema.c index 6757649..cfc6aaf 100644 --- a/tests/test_schema.c +++ b/tests/test_schema.c @@ -21,10 +21,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "ucl.h" +#include "ucl_internal.h" + #include #include + +#ifndef _WIN32 #include -#include "ucl.h" +#endif static int read_stdin (char **buf) diff --git a/tests/test_speed.c b/tests/test_speed.c index 51476c9..ed53940 100644 --- a/tests/test_speed.c +++ b/tests/test_speed.c @@ -21,13 +21,24 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "ucl.h" +#include "ucl_internal.h" + #include + +#ifndef _WIN32 #include -#include #include +#endif + +#include #include #include + +#ifndef _WIN32 #include +#endif + #include #include @@ -37,8 +48,6 @@ #endif #endif -#include "ucl.h" - static double get_ticks (void) {