tests: Build version test with CTest
This begins the conversion to CTest and the GLib unit test framework. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
0e171012ce
commit
2f559b2fb3
|
@ -18,3 +18,5 @@ CMakeFiles
|
||||||
Makefile
|
Makefile
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
install_manifest.txt
|
install_manifest.txt
|
||||||
|
CTestTestfile.cmake
|
||||||
|
Testing/
|
||||||
|
|
|
@ -3,6 +3,7 @@ project(Ocarina)
|
||||||
|
|
||||||
# Various options for users
|
# Various options for users
|
||||||
option(CONFIG_DEBUG "Compile with debugging symbols" OFF)
|
option(CONFIG_DEBUG "Compile with debugging symbols" OFF)
|
||||||
|
option(CONFIG_TESTING_VERBOSE "Enable verbose output when running tests" OFF)
|
||||||
|
|
||||||
# Configure settings
|
# Configure settings
|
||||||
set(CONFIG_MAJOR 6)
|
set(CONFIG_MAJOR 6)
|
||||||
|
@ -16,8 +17,9 @@ if (CONFIG_RC)
|
||||||
set(CONFIG_VERSION "${CONFIG_VERSION}-rc")
|
set(CONFIG_VERSION "${CONFIG_VERSION}-rc")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(DEBUG_OPTIONS -Wall -Werror -g -DCONFIG_DEBUG)
|
||||||
if (CONFIG_DEBUG)
|
if (CONFIG_DEBUG)
|
||||||
add_definitions(-Wall -Werror -g -DCONFIG_DEBUG)
|
add_definitions(${DEBUG_OPTIONS})
|
||||||
set(CONFIG_VERSION "${CONFIG_VERSION}-debug")
|
set(CONFIG_VERSION "${CONFIG_VERSION}-debug")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -65,3 +67,14 @@ install(DIRECTORY share/ DESTINATION /usr/share/)
|
||||||
# Configure release target
|
# Configure release target
|
||||||
set(CONFIG_RELEASE ocarina-${CONFIG_VERSION})
|
set(CONFIG_RELEASE ocarina-${CONFIG_VERSION})
|
||||||
add_custom_target(release COMMAND git archive -v --prefix=${CONFIG_RELEASE}/ -o ${CONFIG_RELEASE}.tar.gz HEAD)
|
add_custom_target(release COMMAND git archive -v --prefix=${CONFIG_RELEASE}/ -o ${CONFIG_RELEASE}.tar.gz HEAD)
|
||||||
|
|
||||||
|
# Set up unit tests
|
||||||
|
set(CMAKE_TEST_COMMAND ctest --output-on-failure)
|
||||||
|
if (CONFIG_TESTING_VERBOSE)
|
||||||
|
set(CMAKE_TEST_COMMAND ctest -V)
|
||||||
|
endif()
|
||||||
|
if (IS_DIRECTORY tests/)
|
||||||
|
enable_testing()
|
||||||
|
add_custom_target(tests COMMAND ${CMAKE_TEST_COMMAND})
|
||||||
|
add_subdirectory(tests/)
|
||||||
|
endif()
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#define OCARINA_CORE_VERSION_H
|
#define OCARINA_CORE_VERSION_H
|
||||||
|
|
||||||
#ifdef CONFIG_TESTING
|
#ifdef CONFIG_TESTING
|
||||||
#define OCARINA_NAME "ocarina-test"
|
#define OCARINA_NAME "ocarina-test/"CONFIG_TESTING_DIR
|
||||||
#elif CONFIG_DEBUG
|
#elif CONFIG_DEBUG
|
||||||
#define OCARINA_NAME "ocarina-debug"
|
#define OCARINA_NAME "ocarina-debug"
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
add_definitions(${DEBUG_OPTIONS} -DCONFIG_TESTING)
|
||||||
|
|
||||||
|
# Handle files that depend on CONFIG_TESTING_DIR
|
||||||
|
list(REMOVE_ITEM core ${PROJECT_SOURCE_DIR}/core/file.c)
|
||||||
|
list(REMOVE_ITEM core ${PROJECT_SOURCE_DIR}/core/tags/album.c)
|
||||||
|
list(APPEND corefiles ${PROJECT_SOURCE_DIR}/core/file.c)
|
||||||
|
list(APPEND corefiles ${PROJECT_SOURCE_DIR}/core/tags/album.c)
|
||||||
|
|
||||||
|
add_library(corelib OBJECT EXCLUDE_FROM_ALL ${core})
|
||||||
|
add_subdirectory(core/)
|
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY .)
|
||||||
|
|
||||||
|
file(REMOVE .gitignore)
|
||||||
|
function(unit_test dir name lib sources)
|
||||||
|
string(TOLOWER ${name} lower)
|
||||||
|
string(TOLOWER ${dir}/${name} testname)
|
||||||
|
string(REPLACE "/" "_" targetname ${testname})
|
||||||
|
|
||||||
|
add_executable(${targetname} EXCLUDE_FROM_ALL ${lower}.c ${sources} $<TARGET_OBJECTS:${lib}>)
|
||||||
|
target_compile_definitions(${targetname} PUBLIC -DCONFIG_TESTING_DIR=\"${testname}\")
|
||||||
|
set_target_properties(${targetname} PROPERTIES OUTPUT_NAME ${lower})
|
||||||
|
add_dependencies(tests ${targetname})
|
||||||
|
|
||||||
|
add_test(NAME ${dir}/${name} COMMAND tests/${testname} --verbose WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||||
|
file(APPEND .gitignore "${lower}\n")
|
||||||
|
endfunction()
|
|
@ -0,0 +1,7 @@
|
||||||
|
Include(../UnitTest.cmake)
|
||||||
|
|
||||||
|
function(core_unit_test name)
|
||||||
|
unit_test(Core ${name} corelib "${corefiles}")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
core_unit_test(Version)
|
|
@ -24,7 +24,6 @@ def CoreTest(name):
|
||||||
Export("core_objs", "CoreTest")
|
Export("core_objs", "CoreTest")
|
||||||
|
|
||||||
|
|
||||||
res += [ CoreTest("version") ]
|
|
||||||
res += [ CoreTest("string") ]
|
res += [ CoreTest("string") ]
|
||||||
res += [ CoreTest("file") ]
|
res += [ CoreTest("file") ]
|
||||||
res += [ CoreTest("date") ]
|
res += [ CoreTest("date") ]
|
||||||
|
|
|
@ -2,14 +2,17 @@
|
||||||
* Copyright 2013 (c) Anna Schumaker.
|
* Copyright 2013 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
#include <core/version.h>
|
#include <core/version.h>
|
||||||
#include <tests/test.h>
|
#include <glib.h>
|
||||||
|
|
||||||
static void test_version()
|
static void test_version()
|
||||||
{
|
{
|
||||||
test_equal(get_version(), CONFIG_VERSION);
|
g_assert_cmpstr(get_version(), ==, CONFIG_VERSION);
|
||||||
test_equal(OCARINA_NAME, "ocarina-test");
|
g_assert_cmpstr(OCARINA_NAME, ==, "ocarina-test/core/version");
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_UNIT_TESTS(
|
int main(int argc, char **argv)
|
||||||
UNIT_TEST("Version", test_version),
|
{
|
||||||
);
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
g_test_add_func("/Core/Version", test_version);
|
||||||
|
return g_test_run();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue