-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from rodneylab/test__add_catch2_skeleton
test: add Catch2 skeleton
- Loading branch information
Showing
8 changed files
with
115 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
find_package(Catch2 3) | ||
if(NOT Catch2_FOUND) | ||
cpmaddpackage("gh:catchorg/Catch2#8ac8190e494a381072c89f5e161b92a08d98b37b" | ||
)# v3.5.3 | ||
endif() | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) | ||
|
||
add_executable(Catch_tests_run test.cpp) | ||
|
||
target_link_libraries(Catch_tests_run PRIVATE jolt_raylib_hello_world_compiler_flags) | ||
target_link_libraries(Catch_tests_run PRIVATE Catch2::Catch2WithMain) | ||
target_include_directories(Catch_tests_run PUBLIC "${PROJECT_SOURCE_DIR}/src") | ||
|
||
include(Catch) | ||
catch_discover_tests(Catch_tests_run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/matchers/catch_matchers_floating_point.hpp> | ||
|
||
#include <cstdint> | ||
|
||
uint32_t factorial(uint32_t number) | ||
{ | ||
return number <= 1 ? number : factorial(number - 1) * number; | ||
} | ||
|
||
TEST_CASE("Factorials are computed", "[factorial]") | ||
{ | ||
REQUIRE(factorial(1) == 1); | ||
REQUIRE(factorial(2) == 2); | ||
REQUIRE(factorial(3) == 6); | ||
REQUIRE(factorial(10) == 3'628'800); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Source: https://github.com/cmake-modules/lcov | ||
# | ||
# MIT License | ||
# | ||
# Copyright (c) 2020 cmake-modules | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
function(add_coverage_target exclude) | ||
|
||
find_program(GCOV gcov) | ||
if (NOT GCOV) | ||
message(WARNING "program gcov not found") | ||
endif() | ||
|
||
find_program(LCOV lcov) | ||
if (NOT LCOV) | ||
message(WARNING "program lcov not found") | ||
endif() | ||
|
||
find_program(GENHTML genhtml) | ||
if (NOT GENHTML) | ||
message(WARNING "program genhtml not found") | ||
endif() | ||
|
||
if (LCOV AND GCOV AND GENHTML) | ||
#set(covname cov.info) | ||
set(covname lcov.txt) | ||
add_compile_options(-fprofile-arcs -ftest-coverage) | ||
add_link_options(--coverage) | ||
add_custom_target(cov DEPENDS ${covname}) | ||
add_custom_command( | ||
OUTPUT ${covname} | ||
COMMAND ${LCOV} -c -o ${covname} -d . -b . --gcov-tool ${GCOV} | ||
COMMAND ${LCOV} -r ${covname} -o ${covname} ${exclude} --exclude "*/SFML/System" --exclude "*/catch2/*" --exclude "v1/*" | ||
COMMAND ${LCOV} -l ${covname} | ||
COMMAND ${GENHTML} ${covname} -output coverage | ||
COMMAND ${LCOV} -l ${covname} 2>/dev/null | grep Total | sed 's/|//g' | sed 's/Total://g' | awk '{print $1}' | sed s/%//g > coverage/total | ||
) | ||
set_directory_properties(PROPERTIES | ||
ADDITIONAL_CLEAN_FILES ${covname} | ||
) | ||
else() | ||
message(WARNING "unable to add target `cov`: missing coverage tools") | ||
endif() | ||
|
||
endfunction() |