Skip to content

Commit

Permalink
[test] add testcmake
Browse files Browse the repository at this point in the history
  • Loading branch information
lvntky committed Aug 11, 2024
1 parent e63f4bd commit ede710c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.21)

project(ccontainerTests LANGUAGES C CXX)

include(../cmake/folders.cmake)

# ---- Dependencies ----

if(PROJECT_IS_TOP_LEVEL)
find_package(ccontainer REQUIRED)
enable_testing()
endif()

find_package(Catch2 REQUIRED)
include(Catch)

# ---- Tests ----

add_executable(
ccontainer_test
source/ccontainer_test.cpp
source/header_impl.c
)
target_link_libraries(
ccontainer_test PRIVATE
ccontainer::ccontainer
Catch2::Catch2WithMain
)
target_compile_features(ccontainer_test PRIVATE c_std_99 cxx_std_11)

catch_discover_tests(ccontainer_test)

# ---- End-of-file commands ----

add_folders(Test)
27 changes: 27 additions & 0 deletions test/source/ccontainer_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <cstdlib>
#include <memory>
#include <string>
#include <type_traits>

#include <catch2/catch.hpp>

#include "ccontainer/ccontainer.h"

namespace {

template<typename T>
void c_free(T* ptr)
{
using U = typename std::remove_cv<T>::type;
std::free(static_cast<void*>(const_cast<U*>(ptr)));
}

}

TEST_CASE("Name is ccontainer", "[library]")
{
using c_string_ptr = std::unique_ptr<char const, void(*)(char const*)>;
auto name_ptr = c_string_ptr(header_only_name(), &c_free<char const>);

REQUIRE(std::string("ccontainer") == name_ptr.get());
}
2 changes: 2 additions & 0 deletions test/source/header_impl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define CCONTAINER_IMPLEMENTATION
#include "ccontainer/ccontainer.h"
Empty file removed test/test_main.c
Empty file.

0 comments on commit ede710c

Please sign in to comment.