👷 move tests to separate folder

This commit is contained in:
Vladislav Nepogodin 2022-08-08 00:55:17 +04:00
parent 0e58d539ab
commit 1be8a1fd73
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
8 changed files with 81 additions and 43 deletions

View File

@ -99,34 +99,6 @@ add_executable(${PROJECT_NAME}
src/main.cpp 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 # Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE) add_library(project_warnings INTERFACE)
set_project_warnings(project_warnings) set_project_warnings(project_warnings)
@ -139,9 +111,11 @@ enable_sanitizers(project_options)
include_directories(${CMAKE_SOURCE_DIR}/src) 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(${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) option(ENABLE_UNITY "Enable Unity builds of projects" OFF)
if(ENABLE_UNITY) if(ENABLE_UNITY)

View File

@ -73,3 +73,6 @@ option(ENABLE_DEVENV "Enable dev environment" ON)
if(NOT ENABLE_DEVENV) if(NOT ENABLE_DEVENV)
add_definitions(-DNDEVENV) add_definitions(-DNDEVENV)
endif() endif()
# Enables tests.
option(COS_INSTALLER_BUILD_TESTS "Enable dev environment" ON)

View File

@ -10,6 +10,7 @@ project('cachyos-installer', 'cpp',
is_debug_build = get_option('buildtype').startswith('debug') is_debug_build = get_option('buildtype').startswith('debug')
is_dev_environment = get_option('devenv') is_dev_environment = get_option('devenv')
is_tests_build = get_option('build_tests')
cc = meson.get_compiler('cpp') cc = meson.get_compiler('cpp')
if cc.get_id() == 'clang' if cc.get_id() == 'clang'
specific_cc_flags = [ specific_cc_flags = [
@ -132,19 +133,9 @@ executable(
include_directories: [include_directories('src')], include_directories: [include_directories('src')],
install: true) install: true)
executable( if is_tests_build
'test-exec-interactive', subdir('tests')
files('src/config.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/main_test.cpp'), endif
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)
summary( summary(
{ {

View File

@ -1 +1,2 @@
option('devenv', type: 'boolean', value: true, description: 'enable dev environment') option('devenv', type: 'boolean', value: true, description: 'enable dev environment')
option('build_tests', type: 'boolean', value: false, description: 'enable tests')

35
tests/CMakeLists.txt Normal file
View File

@ -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
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU>:-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()

34
tests/meson.build Normal file
View File

@ -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)