Skip to content

Commit

Permalink
Add Catch2 to ystdlib-cpp and use Catch2 as main
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-hbrhbr committed Feb 11, 2025
1 parent 1cb2278 commit 2780b90
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
FORCE
)

find_package(Catch2 3.8.0 REQUIRED)
if (Catch2_FOUND)
message(STATUS "Found Catch2 ${Catch2_VERSION}.")
else()
message(FATAL_ERROR "Could not find libraries for Catch2.")
endif()

# Import CMake helper functions
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
include(ystdlib-cpp-helpers)

add_subdirectory(src/ystdlib)

# Test dummy project
add_executable(dummy)
target_sources(dummy PRIVATE src/main.cpp)
target_link_libraries(dummy PRIVATE ystdlib::testlib)
target_compile_features(dummy PRIVATE cxx_std_20)
add_executable(unitTest)
target_sources(unitTest PRIVATE src/main.cpp)
target_link_libraries(unitTest PRIVATE ystdlib::testlib Catch2::Catch2WithMain)
target_compile_features(unitTest PRIVATE cxx_std_20)
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#define CATCH_CONFIG_MAIN

#include <concepts>
#include <iostream>

#include <catch2/catch_all.hpp>
#include <ystdlib/testlib/hello.hpp>

namespace {
Expand All @@ -10,7 +14,6 @@ requires std::integral<T>
}
}; // namespace

[[nodiscard]] auto main() -> int {
std::cout << square(ystdlib::testlib::hello().size()) << '\n';
return 0;
TEST_CASE("dummy") {
REQUIRE((169 == square(ystdlib::testlib::hello().size())));
}
13 changes: 0 additions & 13 deletions taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ tasks:
cmds:
- "rm -rf '{{.G_BUILD_DIR}}'"

config-cmake-project:
internal: true
deps:
- "deps:install-all"
sources:
- "CMakeLists.txt"
- "{{.TASKFILE}}"
generates:
- "{{.G_CMAKE_CACHE}}"
- "{{.G_COMPILE_COMMANDS_DB}}"
cmds:
- "cmake -S '{{.ROOT_DIR}}' -B '{{.G_BUILD_DIR}}'"

init:
internal: true
silent: true
Expand Down
19 changes: 7 additions & 12 deletions taskfiles/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ version: "3"
tasks:
target:
desc: "Builds ystdlib-cpp."
vars:
TARGETS:
ref: "default (list \"all\") .TARGETS"
deps:
- ":config-cmake-project"
cmds:
- >-
cmake
--build "{{.G_BUILD_DIR}}"
--parallel {{numCPU}}
--target {{range .TARGETS}}{{.}} {{end}}
- task: ":utils:cmake-config-and-build"
vars:
BUILD_DIR: "{{.G_BUILD_DIR}}"
SOURCE_DIR: "{{.ROOT_DIR}}"
CONF_ARGS: >-
-DCatch2_ROOT="{{.G_DEPS_DIR}}/Catch2-install"
JOBS: "{{numCPU}}"

clean:
desc: "Removes all built artifacts."
deps:
- ":config-cmake-project"
cmds:
- >-
cmake
Expand Down

0 comments on commit 2780b90

Please sign in to comment.