This commit is contained in:
parent
dd93dab0a6
commit
cf19753de0
|
@ -26,10 +26,12 @@ steps:
|
|||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- apt-get update -q
|
||||
- apt-get install -qq build-essential cmake
|
||||
- apt-get install -qq catch
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake -G "Unix Makefiles" ..
|
||||
- cmake -G "Unix Makefiles" -DWITH_TESTS=YES ..
|
||||
- make VERBOSE=1
|
||||
- make install DESTDIR=install
|
||||
- cd tests && ctest -V
|
||||
volumes:
|
||||
- name: debian-package-cache
|
||||
path: /var/cache/apt/archives
|
||||
|
@ -47,10 +49,12 @@ steps:
|
|||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- apt-get update -q
|
||||
- apt-get install -qq build-essential cmake
|
||||
- apt-get install -qq catch
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake -G "Unix Makefiles" ..
|
||||
- cmake -G "Unix Makefiles" -DWITH_TESTS=YES ..
|
||||
- make VERBOSE=1
|
||||
- make install DESTDIR=install
|
||||
- cd tests && ctest -V
|
||||
volumes:
|
||||
- name: debian-package-cache
|
||||
path: /var/cache/apt/archives
|
||||
|
|
|
@ -18,7 +18,7 @@ project(mastodonpp
|
|||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
||||
|
||||
# Project build options.
|
||||
# option(WITH_TESTS "Compile tests." NO)
|
||||
option(WITH_TESTS "Compile tests." NO)
|
||||
# option(WITH_DOC "Generate HTML documentation." YES)
|
||||
# option(WITH_EXAMPLES "Compile examples." NO)
|
||||
# option(WITH_DEB "Prepare for the building of .deb packages." NO)
|
||||
|
@ -32,8 +32,8 @@ include(debug_flags)
|
|||
|
||||
add_subdirectory(src)
|
||||
|
||||
# if(WITH_TESTS)
|
||||
# add_subdirectory(tests)
|
||||
# endif()
|
||||
if(WITH_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
# include(cmake/packages.cmake)
|
||||
|
|
27
tests/CMakeLists.txt
Normal file
27
tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
include(CTest)
|
||||
|
||||
file(GLOB sources_tests test_*.cpp)
|
||||
|
||||
find_package(Catch2 CONFIG)
|
||||
if(Catch2_FOUND) # Catch 2.x
|
||||
include(Catch)
|
||||
add_executable(all_tests main.cpp ${sources_tests})
|
||||
target_link_libraries(all_tests
|
||||
PRIVATE Catch2::Catch2 ${PROJECT_NAME})
|
||||
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
|
||||
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
|
||||
else() # Catch 1.x
|
||||
if(EXISTS "/usr/include/catch.hpp")
|
||||
message(STATUS "Catch 1.x found.")
|
||||
foreach(src ${sources_tests})
|
||||
get_filename_component(bin ${src} NAME_WE)
|
||||
add_executable(${bin} main.cpp ${src})
|
||||
target_link_libraries(${bin}
|
||||
PRIVATE ${PROJECT_NAME})
|
||||
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
|
||||
endforeach()
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"Neither Catch 2.x nor Catch 1.x could be found.")
|
||||
endif()
|
||||
endif()
|
19
tests/main.cpp
Normal file
19
tests/main.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* This file is part of mastodonpp.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include <catch.hpp>
|
51
tests/test_instanciation.cpp
Normal file
51
tests/test_instanciation.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* This file is part of mastodonpp.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mastodonpp.hpp"
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace mastodonpp
|
||||
{
|
||||
|
||||
using std::string;
|
||||
|
||||
SCENARIO ("API can be instantiated.")
|
||||
{
|
||||
bool exception = false;
|
||||
|
||||
GIVEN ("One instanciation.")
|
||||
{
|
||||
try
|
||||
{
|
||||
API masto("example.com", "");
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
THEN ("No exception is thrown")
|
||||
{
|
||||
REQUIRE_FALSE(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mastodonpp
|
Loading…
Reference in New Issue
Block a user