based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit d1ec827045286c6d448fe375506e2b95b999e873
parent aa6555033365b5b0da0384f2a5e6329eeb2a062c
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Sun, 30 Mar 2025 21:52:01 +0200

Started testing with Catch2

Diffstat:
M test/CMakeLists.txt | ++++++++++++++ ------
D test/source/based_test.cpp | ---
A test/source/min_test.cpp | +++++++++++++++++++++++++++++++++++++++++++++++++++++
M vcpkg.json | ++++

4 files changed, 71 insertions(+), 9 deletions(-)


diff --git a/ test/CMakeLists.txt b/ test/CMakeLists.txt

@@ -12,14 +12,22 @@ if(PROJECT_IS_TOP_LEVEL)

enable_testing()
endif()

find_package(Catch2 REQUIRED)
include(Catch)

# ---- Tests ----

add_executable(based_test source/based_test.cpp)
target_link_libraries(
based_test PRIVATE
based::based
)
target_compile_features(based_test PRIVATE cxx_std_20)
function(add_test NAME)
add_executable("${NAME}" "source/${NAME}.cpp")
target_link_libraries("${NAME}" PRIVATE based::based)
target_link_libraries("${NAME}" PRIVATE Catch2::Catch2WithMain)
target_compile_features("${NAME}" PRIVATE cxx_std_20)
catch_discover_tests("${NAME}")
endfunction()

# ---- Algorithm ----

add_test(min_test)

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

diff --git a/ test/source/based_test.cpp b/ test/source/based_test.cpp

@@ -1,3 +0,0 @@

int main() {
return 0;
}

diff --git a/ test/source/min_test.cpp b/ test/source/min_test.cpp

@@ -0,0 +1,53 @@

#include <catch2/catch_test_macros.hpp>

#include "based/algorithm.hpp"

TEST_CASE("min(literal, literal)", "[based/algorithm/min]")
{
REQUIRE(std::same_as<int, decltype(based::min(3, 4))>);
REQUIRE(based::min(3, 4) == 3);
}

TEST_CASE("min(value, literal)", "[based/algorithm/min]")
{
int a = 3; // NOLINT misc-const-correctness
REQUIRE(std::same_as<int, decltype(based::min(a, 4))>);
REQUIRE(based::min(a, 4) == 3);
}

TEST_CASE("min(literal, value)", "[based/algorithm/min]")
{
int b = 4; // NOLINT misc-const-correctness
REQUIRE(std::same_as<int, decltype(based::min(3, b))>);
REQUIRE(based::min(3, b) == 3);
}

TEST_CASE("min(value, value)", "[based/algorithm/min]")
{
int a = 3; // NOLINT misc-const-correctness
int b = 4; // NOLINT misc-const-correctness
REQUIRE(std::same_as<const int&, decltype(based::min(a, b))>);
REQUIRE(based::min(a, b) == 3);
}

TEST_CASE("min(const value, literal)", "[based/algorithm/min]")
{
const int a = 3;
REQUIRE(std::same_as<int, decltype(based::min(a, 4))>);
REQUIRE(based::min(a, 4) == 3);
}

TEST_CASE("min(literal, const value)", "[based/algorithm/min]")
{
const int b = 4;
REQUIRE(std::same_as<int, decltype(based::min(3, b))>);
REQUIRE(based::min(3, b) == 3);
}

TEST_CASE("min(const value, const value)", "[based/algorithm/min]")
{
const int a = 3;
const int b = 4;
REQUIRE(std::same_as<const int&, decltype(based::min(a, b))>);
REQUIRE(based::min(a, b) == 3);
}

diff --git a/ vcpkg.json b/ vcpkg.json

@@ -8,6 +8,10 @@

"test": {
"description": "Dependencies for testing",
"dependencies": [
{
"name": "catch2",
"version>=": "3.7.1"
}
]
}
},