Trying tests

This commit is contained in:
zv0n 2022-09-28 23:40:21 +02:00
parent b782dc1292
commit 701b091833
2 changed files with 56 additions and 0 deletions

View File

@ -6,6 +6,12 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories(/usr/local/include) include_directories(/usr/local/include)
link_directories(/usr/local/lib) link_directories(/usr/local/lib)
if(APPLE)
include_directories(/opt/homebrew/include)
link_directories(/opt/homebrew/lib)
endif()
find_package(Catch2 3 REQUIRED)
project(RenameServer) project(RenameServer)
@ -47,3 +53,16 @@ add_library(moviedb SHARED
network/unix/network.cpp) network/unix/network.cpp)
target_link_libraries(moviedb curl) target_link_libraries(moviedb curl)
add_executable(tests
tests/tests.cpp
rename_object.cpp
functions.cpp
config/config.cpp
filesystem/unix/filesystem.cpp
jwt.cpp
)
set_source_files_properties(tests/tests.cpp PROPERTIES COMPILE_OPTIONS "--coverage;-g;-fsanitize=address,undefined")
target_compile_options(tests PUBLIC -Wall -fprofile-arcs -ftest-coverage --coverage -g)
target_link_options(tests PUBLIC --coverage -Wall -fprofile-arcs -ftest-coverage -fsanitize=address,undefined)
target_link_libraries(tests PRIVATE restbed config++ jwt Catch2::Catch2WithMain)

37
tests/tests.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <catch2/catch_all.hpp>
#include "../functions.hpp"
#include <iostream>
bool runBash( const std::string &command ) {
std::string cmd = "/bin/bash -c \"" + command + "\"";
return system( cmd.c_str() ) == 0;
}
TEST_CASE( "iterateFS" ) {
const std::string directory = "test_dir";
runBash(
"mkdir " + directory + " ; cd test_dir ; for f in {01..10} ; do "
"mkdir \\\"Season \\${f}\\\" ; cd \\\"Season \\${f}\\\" ; for g in "
"{01..30} ; do touch \\\"S\\${f}E\\${g}.mkv\\\" ; done ; cd .. ; "
"done" );
auto files = getFilesInSource("test_dir");
REQUIRE( files.size() == 310 );
REQUIRE(files[0].getFileType() == FileType::TYPE_DIRECTORY);
REQUIRE(files[0].getDepth() == 0);
REQUIRE_THAT(files[0].getPath(), Catch::Matchers::Equals("Season 01") || Catch::Matchers::Equals("Season 1"));
REQUIRE(files[1].getFileType() == FileType::TYPE_FILE);
REQUIRE(files[1].getDepth() == 1);
REQUIRE_THAT(files[1].getPath(), Catch::Matchers::EndsWith(".mkv"));
REQUIRE_THROWS_WITH( getFilesInSource( "nonexistendir" ),
Catch::Matchers::ContainsSubstring( "Directory" ) &&
Catch::Matchers::ContainsSubstring( "doesn't exist" ) );
REQUIRE_THROWS_WITH(
getFilesInSource( directory + "/Season 01/S01E01.mkv" ),
Catch::Matchers::ContainsSubstring( "Directory" ) &&
Catch::Matchers::ContainsSubstring( "isn't a directory" ) );
runBash("rm -Rf " + directory );
}