diff --git a/CMakeLists.txt b/CMakeLists.txt index bf08f9a..31d8a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,34 +99,6 @@ add_executable(${PROJECT_NAME} src/main.cpp ) -add_executable(test-exec-interactive - src/config.cpp src/config.hpp - src/utils.cpp src/utils.hpp - src/disk.cpp src/disk.hpp - src/drivers.cpp src/drivers.hpp - src/widgets.cpp src/widgets.hpp - src/follow_process_log.hpp src/follow_process_log.cpp - src/crypto.cpp src/crypto.hpp - src/misc.cpp src/misc.hpp - src/simple_tui.cpp src/simple_tui.hpp - src/tui.cpp src/tui.hpp - src/main_test.cpp - ) - -add_executable(test-process-tailing - src/config.cpp src/config.hpp - src/utils.cpp src/utils.hpp - src/disk.cpp src/disk.hpp - src/drivers.cpp src/drivers.hpp - src/widgets.cpp src/widgets.hpp - src/follow_process_log.hpp src/follow_process_log.cpp - src/crypto.cpp src/crypto.hpp - src/misc.cpp src/misc.hpp - src/simple_tui.cpp src/simple_tui.hpp - src/tui.cpp src/tui.hpp - src/test_proccess_tailing.cpp - ) - # Link this 'library' to use the warnings specified in CompilerWarnings.cmake add_library(project_warnings INTERFACE) set_project_warnings(project_warnings) @@ -139,9 +111,11 @@ enable_sanitizers(project_options) include_directories(${CMAKE_SOURCE_DIR}/src) +if(COS_INSTALLER_BUILD_TESTS) + add_subdirectory(tests) +endif() + target_link_libraries(${PROJECT_NAME} PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::screen ftxui::dom ftxui::component cpr::cpr range-v3::range-v3) -target_link_libraries(test-exec-interactive PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component cpr::cpr range-v3::range-v3) -target_link_libraries(test-process-tailing PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component cpr::cpr) option(ENABLE_UNITY "Enable Unity builds of projects" OFF) if(ENABLE_UNITY) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 243b526..ef87531 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -73,3 +73,6 @@ option(ENABLE_DEVENV "Enable dev environment" ON) if(NOT ENABLE_DEVENV) add_definitions(-DNDEVENV) endif() + +# Enables tests. +option(COS_INSTALLER_BUILD_TESTS "Enable dev environment" ON) diff --git a/meson.build b/meson.build index 802a336..115c07c 100644 --- a/meson.build +++ b/meson.build @@ -10,6 +10,7 @@ project('cachyos-installer', 'cpp', is_debug_build = get_option('buildtype').startswith('debug') is_dev_environment = get_option('devenv') +is_tests_build = get_option('build_tests') cc = meson.get_compiler('cpp') if cc.get_id() == 'clang' specific_cc_flags = [ @@ -132,19 +133,9 @@ executable( include_directories: [include_directories('src')], install: true) -executable( - 'test-exec-interactive', - files('src/config.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/main_test.cpp'), - dependencies: deps, - include_directories: [include_directories('src')], - install: false) - -executable( - 'test-process-tailing', - files('src/config.cpp', 'src/widgets.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/follow_process_log.cpp','src/test_proccess_tailing.cpp'), - dependencies: deps, - include_directories: [include_directories('src')], - install: false) +if is_tests_build + subdir('tests') +endif summary( { diff --git a/meson_options.txt b/meson_options.txt index 5591e2e..7654afb 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ option('devenv', type: 'boolean', value: true, description: 'enable dev environment') +option('build_tests', type: 'boolean', value: false, description: 'enable tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..8b4105a --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,35 @@ +list(APPEND test_SOURCES + ${CMAKE_SOURCE_DIR}/src/config.cpp + ${CMAKE_SOURCE_DIR}/src/utils.cpp + ${CMAKE_SOURCE_DIR}/src/disk.cpp + ${CMAKE_SOURCE_DIR}/src/drivers.cpp + ${CMAKE_SOURCE_DIR}/src/widgets.cpp + ${CMAKE_SOURCE_DIR}/src/follow_process_log.cpp + ${CMAKE_SOURCE_DIR}/src/crypto.cpp + ${CMAKE_SOURCE_DIR}/src/misc.cpp + ${CMAKE_SOURCE_DIR}/src/simple_tui.cpp + ${CMAKE_SOURCE_DIR}/src/tui.cpp +) + +add_library(test_libreq STATIC ${test_SOURCES}) +target_include_directories(test_libreq PRIVATE ${CMAKE_BINARY_DIR}/include ${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_DIR}) +target_link_libraries(test_libreq PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component cpr::cpr range-v3::range-v3) + +############################################################################# +# one executable for each unit test file +############################################################################# + +file(GLOB files unit-*.cpp) + +foreach(file ${files}) + get_filename_component(file_basename ${file} NAME_WE) + string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename}) + + add_executable(${testcase} ${file}) + target_compile_options(${testcase} PRIVATE + $<$>:-Wno-deprecated;-Wno-float-equal> + $<$:-Wno-deprecated-declarations> + ) + target_include_directories(${testcase} PRIVATE ${CMAKE_BINARY_DIR}/include ${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_DIR}) + target_link_libraries(${testcase} PRIVATE project_warnings project_options test_libreq spdlog::spdlog fmt::fmt ftxui::component cpr::cpr range-v3::range-v3) +endforeach() diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..d35c5cc --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,34 @@ +source_path = '../src/' + +test_libreq = shared_library('test_libreq', + sources : [ + source_path + 'config.cpp', + source_path + 'utils.cpp', + source_path + 'disk.cpp', + source_path + 'drivers.cpp', + source_path + 'widgets.cpp', + source_path + 'follow_process_log.cpp', + source_path + 'crypto.cpp', + source_path + 'misc.cpp', + source_path + 'simple_tui.cpp', + source_path + 'tui.cpp', + ], + include_directories : [include_directories(source_path)], + dependencies: deps +) + +executable( + 'test-exec-interactive', + files('unit-exec-interactive.cpp'), + dependencies: deps, + link_with: [test_libreq], + include_directories: [include_directories(source_path)], + install: false) + +executable( + 'test-process-tailing', + files('unit-proccess-tailing.cpp'), + dependencies: deps, + link_with: [test_libreq], + include_directories: [include_directories(source_path)], + install: false) diff --git a/src/main_test.cpp b/tests/unit-exec-interactive.cpp similarity index 100% rename from src/main_test.cpp rename to tests/unit-exec-interactive.cpp diff --git a/src/test_proccess_tailing.cpp b/tests/unit-proccess-tailing.cpp similarity index 100% rename from src/test_proccess_tailing.cpp rename to tests/unit-proccess-tailing.cpp