testlib for tests.

This commit is contained in:
tastytea 2019-04-21 10:51:14 +02:00
parent 79dab8bd17
commit 8c21e93791
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
5 changed files with 25 additions and 6 deletions

View File

@ -20,6 +20,7 @@ set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -ftrapv \
-fsanitize=undefined -g -Og -fno-omit-frame-pointer")
include_directories(${PROJECT_SOURCE_DIR}/src)
Include_directories(${PROJECT_BINARY_DIR})
include_directories(${CURLPP_INCLUDE_DIRS})
@ -53,5 +54,8 @@ if (WITH_MAN)
endif()
if(WITH_TESTS)
add_library(${PROJECT_NAME}_testlib SHARED ${sources})
target_link_libraries(${PROJECT_NAME}_testlib
${CURLPP_LIBRARIES} ${JSONCPP_LIBRARIES})
include(tests.CMakeLists.txt)
endif()

19
src/gitea2rss.cpp Normal file
View File

@ -0,0 +1,19 @@
/* This file is part of gitea2rss.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gitea2rss.hpp"
bool cgi = false;

View File

@ -27,8 +27,6 @@ using std::endl;
using std::string;
using std::chrono::system_clock;
bool cgi = false;
int main(int argc, char *argv[])
{
const char *envquery = std::getenv("QUERY_STRING");

View File

@ -1,12 +1,11 @@
include(CTest)
file(GLOB sources_tests tests/test_*.cpp)
include_directories(${PROJECT_SOURCE_DIR}/src)
find_package(Catch2)
if(Catch2_FOUND) # Catch 2.x
include(Catch)
add_executable(all_tests tests/main.cpp ${sources_tests})
target_link_libraries(all_tests Catch2::Catch2)
target_link_libraries(all_tests Catch2::Catch2 ${PROJECT_NAME}_testlib)
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
else() # Catch 1.x
@ -15,6 +14,7 @@ else() # Catch 1.x
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} tests/main.cpp ${src})
target_link_libraries(${bin} ${PROJECT_NAME}_testlib)
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
endforeach()
else()

View File

@ -17,5 +17,3 @@
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include "strings.cpp"
#include "time.cpp"