diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index 9b6ff03b..80711326 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -63,4 +63,4 @@ jobs: # TODO: Change the task to run all unittests once any unittest is added. Until then we check # that building the project succeeds. - - run: "task build:target" + - run: "task build:all" diff --git a/CMakeLists.txt b/CMakeLists.txt index fbffc4e0..770c71f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,14 +11,25 @@ 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) diff --git a/README.md b/README.md index 7dc05193..44fce89e 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ git submodule update --init --recursive ## Building To build all targets in `ystdlib-cpp`: ```shell -task build:target +task build:all ``` ## Linting diff --git a/src/.clang-format b/src/.clang-format new file mode 100644 index 00000000..9914624a --- /dev/null +++ b/src/.clang-format @@ -0,0 +1,19 @@ +BasedOnStyle: "InheritParentConfig" + +IncludeCategories: + # NOTE: A header is grouped by first matching regex library headers. Update when adding new + # libraries. + # NOTE: clang-format retains leading white-space on a line in violation of the YAML spec. + - Regex: "<(ystdlib)" + Priority: 3 + - Regex: "<(catch2)" + Priority: 4 + # C system headers + - Regex: "^<.+\\.h>" + Priority: 1 + # C++ standard libraries + - Regex: "^<.+>" + Priority: 2 + # Project headers + - Regex: "^\".+\"" + Priority: 5 diff --git a/src/main.cpp b/src/main.cpp index c65d5a8c..85f56a99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,18 @@ #include -#include + #include +#include + namespace { template requires std::integral + [[nodiscard]] auto square(T x) -> T { return x * x; } }; // 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()))); } diff --git a/taskfile.yaml b/taskfile.yaml index ada6689c..92a24e2e 100644 --- a/taskfile.yaml +++ b/taskfile.yaml @@ -2,14 +2,14 @@ version: "3" includes: build: "./taskfiles/build.yaml" + deps: "./taskfiles/deps.yaml" lint: "./taskfiles/lint.yaml" - utils: "tools/yscope-dev-utils/taskfiles/utils.yml" + utils: "tools/yscope-dev-utils/taskfiles/utils.yaml" vars: G_BUILD_DIR: "{{.ROOT_DIR}}/build" - G_CMAKE_CACHE: "{{.G_BUILD_DIR}}/CMakeCache.txt" - G_COMPILE_COMMANDS_DB: "{{.G_BUILD_DIR}}/compile_commands.json" G_CPP_SRC_DIR: "{{.ROOT_DIR}}/src" + G_DEPS_DIR: "{{.G_BUILD_DIR}}/deps" tasks: clean: @@ -17,17 +17,6 @@ tasks: cmds: - "rm -rf '{{.G_BUILD_DIR}}'" - config-cmake-project: - internal: true - 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 diff --git a/taskfiles/build.yaml b/taskfiles/build.yaml index 83123a48..1a6accd7 100644 --- a/taskfiles/build.yaml +++ b/taskfiles/build.yaml @@ -1,27 +1,37 @@ version: "3" +vars: + G_CMAKE_CACHE: "{{.G_BUILD_DIR}}/CMakeCache.txt" + G_CMAKE_CONF_ARGS: + - "-DCatch2_ROOT={{.G_DEPS_DIR}}/Catch2/Catch2-install" + G_COMPILE_COMMANDS_DB: "{{.G_BUILD_DIR}}/compile_commands.json" + tasks: - target: + all: desc: "Builds ystdlib-cpp." - vars: - TARGETS: - ref: "default (list \"all\") .TARGETS" deps: - - ":config-cmake-project" + - "init" cmds: - - >- - cmake - --build "{{.G_BUILD_DIR}}" - --parallel {{numCPU}} - --target {{range .TARGETS}}{{.}} {{end}} + - task: ":utils:cmake-build" + vars: + BUILD_DIR: "{{.G_BUILD_DIR}}" clean: desc: "Removes all built artifacts." deps: - - ":config-cmake-project" + - task: ":utils:cmake-clean" + vars: + BUILD_DIR: "{{.G_BUILD_DIR}}" + + init: + internal: true + deps: + - ":deps:install-all" + run: "once" cmds: - - >- - cmake - --build "{{.G_BUILD_DIR}}" - --parallel {{numCPU}} - --target clean + - task: ":utils:cmake-generate" + vars: + BUILD_DIR: "{{.G_BUILD_DIR}}" + EXTRA_ARGS: + ref: ".G_CMAKE_CONF_ARGS" + SOURCE_DIR: "{{.ROOT_DIR}}" diff --git a/taskfiles/deps.yaml b/taskfiles/deps.yaml new file mode 100644 index 00000000..c41201fd --- /dev/null +++ b/taskfiles/deps.yaml @@ -0,0 +1,21 @@ +version: "3" + +tasks: + install-all: + desc: "Install all dependencies required by ystdlib-cpp." + deps: + - "install-Catch2" + + install-Catch2: + internal: true + vars: + NAME: "Catch2" + WORK_DIR: "{{.G_DEPS_DIR}}/{{.NAME}}" + run: "once" + cmds: + - task: ":utils:cmake-install-remote-tar" + vars: + NAME: "{{.NAME}}" + WORK_DIR: "{{.WORK_DIR}}" + FILE_SHA256: "1ab2de20460d4641553addfdfe6acd4109d871d5531f8f519a52ea4926303087" + URL: "https://github.com/catchorg/Catch2/archive/refs/tags/v3.8.0.tar.gz" diff --git a/taskfiles/lint-cpp.yaml b/taskfiles/lint-cpp.yaml index 5683ad98..1ac21e1d 100644 --- a/taskfiles/lint-cpp.yaml +++ b/taskfiles/lint-cpp.yaml @@ -65,7 +65,7 @@ tasks: - "{{.ROOT_DIR}}/.clang-tidy" - "{{.TASKFILE}}" deps: - - ":config-cmake-project" + - ":build:init" - "cpp-configs" - "venv" cmds: diff --git a/taskfiles/lint-venv.yaml b/taskfiles/lint-venv.yaml index 9305b8f0..4e082de0 100644 --- a/taskfiles/lint-venv.yaml +++ b/taskfiles/lint-venv.yaml @@ -18,7 +18,7 @@ tasks: - task: ":utils:validate-checksum" vars: CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" - DATA_DIR: "{{.OUTPUT_DIR}}" + INCLUDE_PATTERNS: ["{{.OUTPUT_DIR}}"] cmds: - task: ":utils:create-venv" vars: @@ -28,5 +28,5 @@ tasks: # This command must be last - task: ":utils:compute-checksum" vars: - DATA_DIR: "{{.OUTPUT_DIR}}" - OUTPUT_FILE: "{{.CHECKSUM_FILE}}" + CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" + INCLUDE_PATTERNS: ["{{.OUTPUT_DIR}}"] diff --git a/taskfiles/lint-yaml.yaml b/taskfiles/lint-yaml.yaml index 0a7f494f..ed2f3736 100644 --- a/taskfiles/lint-yaml.yaml +++ b/taskfiles/lint-yaml.yaml @@ -12,7 +12,6 @@ tasks: - "{{.ROOT_DIR}}/**/*.yml" - "{{.TASKFILE}}" - exclude: "{{.ROOT_DIR}}/**/build/*" - - exclude: "{{.ROOT_DIR}}/**/submodules/*" - exclude: "{{.ROOT_DIR}}/**/tools/*" dir: "{{.ROOT_DIR}}" deps: @@ -21,7 +20,7 @@ tasks: - |- . "{{.G_LINT_VENV_DIR}}/bin/activate" find . \ - \( -path '**/build' -o -path '**/submodules' -o -path '**/tools' \) -prune -o \ + \( -path '**/build' -o -path '**/tools' \) -prune -o \ \( -iname "*.yaml" -o -iname "*.yml" \) \ -print0 | \ xargs -0 yamllint \ diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index c1593f74..3c0e7d92 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit c1593f7414112f2b6e0bf46595126c8edeffe106 +Subproject commit 3c0e7d92e928dd9874849c0be4f0a44801d08678