- Compile everything in src/ except main.cpp into a static library - Link the static library into tests - Add test for zip::list()
This commit is contained in:
parent
8c8a19b86b
commit
6c040fa951
|
@ -66,6 +66,7 @@ git clone https://schlomp.space/tastytea/epubgrep.git
|
|||
mkdir -p build && cd build
|
||||
cmake ..
|
||||
cmake --build . -- --jobs=$(nproc --ignore=1)
|
||||
# cd tests && ctest
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
.CMake options:
|
||||
|
|
|
@ -3,21 +3,34 @@ include(GNUInstallDirs)
|
|||
configure_file("version.hpp.in" "version.hpp" @ONLY)
|
||||
configure_file("fs-compat.hpp.in" "fs-compat.hpp" @ONLY)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
# The library is only here for the tests.
|
||||
add_library(${PROJECT_NAME}_lib STATIC)
|
||||
|
||||
file(GLOB_RECURSE sources_src *.cpp)
|
||||
file(GLOB_RECURSE headers_src *.hpp)
|
||||
target_sources(${PROJECT_NAME}
|
||||
PRIVATE "${sources_src}" "${headers_src}")
|
||||
list(REMOVE_ITEM sources_src "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
|
||||
|
||||
target_sources(${PROJECT_NAME}_lib
|
||||
PUBLIC "${sources_src}" "${headers_src}")
|
||||
unset(sources_src)
|
||||
unset(headers_src)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
Boost::program_options Boost::locale
|
||||
std::filesystem LibArchive::LibArchive fmt::fmt)
|
||||
target_link_libraries(${PROJECT_NAME}_lib
|
||||
PUBLIC
|
||||
Boost::program_options
|
||||
Boost::locale
|
||||
std::filesystem
|
||||
LibArchive::LibArchive
|
||||
fmt::fmt)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
|
||||
target_include_directories(${PROJECT_NAME}_lib
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
|
||||
|
||||
add_executable(${PROJECT_NAME} "main.cpp")
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${PROJECT_NAME}_lib)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
include(CTest)
|
||||
|
||||
file(GLOB sources_tests test_*.cpp)
|
||||
file(COPY "test.zip" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
find_package(Catch2 CONFIG)
|
||||
|
||||
|
@ -8,7 +9,7 @@ if(Catch2_FOUND) # Catch 2.x
|
|||
include(Catch)
|
||||
add_executable(all_tests main.cpp ${sources_tests})
|
||||
target_link_libraries(all_tests
|
||||
PRIVATE Catch2::Catch2)
|
||||
PRIVATE Catch2::Catch2 ${PROJECT_NAME}_lib)
|
||||
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
|
||||
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
|
||||
else() # Catch 1.x
|
||||
|
@ -17,6 +18,7 @@ else() # Catch 1.x
|
|||
foreach(src ${sources_tests})
|
||||
get_filename_component(bin ${src} NAME_WE)
|
||||
add_executable(${bin} main.cpp ${src})
|
||||
target_link_libraries(${bin} ${PROJECT_NAME}_lib)
|
||||
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
|
||||
endforeach()
|
||||
else()
|
||||
|
|
BIN
tests/test.zip
Normal file
BIN
tests/test.zip
Normal file
Binary file not shown.
42
tests/test_zip_list.cpp
Normal file
42
tests/test_zip_list.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "fs-compat.hpp"
|
||||
#include "zip.hpp"
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
SCENARIO("epubgrep::zip::list() doesn't fail and returns the right file list")
|
||||
{
|
||||
bool exception{false};
|
||||
std::vector<std::string> filelist;
|
||||
|
||||
GIVEN("Our test zip file")
|
||||
{
|
||||
fs::path zipfile{"test.zip"};
|
||||
|
||||
REQUIRE(fs::exists(zipfile));
|
||||
|
||||
WHEN("We list the file contents")
|
||||
{
|
||||
try
|
||||
{
|
||||
filelist = epubgrep::zip::list(zipfile);
|
||||
}
|
||||
catch (const std::exception &)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
THEN("No exception is thrown")
|
||||
AND_THEN("It returns the file contents correctly")
|
||||
{
|
||||
REQUIRE_FALSE(exception);
|
||||
REQUIRE(filelist.at(0) == "test folder/");
|
||||
REQUIRE(filelist.at(1) == "test folder/test file");
|
||||
REQUIRE(filelist.at(2) == "test folder/😊");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user