1
0
mirror of https://github.com/lefticus/6502-cpp.git synced 2026-04-19 20:16:32 +00:00

change name to 6502-c++ and merge in files from cpp_starter_project

This commit is contained in:
Jason Turner
2021-05-06 14:04:59 -06:00
parent 21d23dfcb9
commit 4ffae19177
19 changed files with 1064 additions and 61 deletions
+64
View File
@@ -0,0 +1,64 @@
# Automatically enable catch2 to generate ctest targets
if(CONAN_CATCH2_ROOT_DEBUG)
include(${CONAN_CATCH2_ROOT_DEBUG}/lib/cmake/Catch2/Catch.cmake)
else()
include(${CONAN_CATCH2_ROOT}/lib/cmake/Catch2/Catch.cmake)
endif()
add_library(catch_main STATIC catch_main.cpp)
target_link_libraries(catch_main PUBLIC CONAN_PKG::catch2)
target_link_libraries(catch_main PRIVATE project_options)
add_executable(tests tests.cpp)
target_link_libraries(tests PRIVATE project_warnings project_options catch_main)
# automatically discover tests that are defined in catch based test files you can modify the unittests. Set TEST_PREFIX
# to whatever you want, or use different for different binaries
catch_discover_tests(
tests
TEST_PREFIX
"unittests."
REPORTER
xml
OUTPUT_DIR
.
OUTPUT_PREFIX
"unittests."
OUTPUT_SUFFIX
.xml)
# Add a file containing a set of constexpr tests
add_executable(constexpr_tests constexpr_tests.cpp)
target_link_libraries(constexpr_tests PRIVATE project_options project_warnings catch_main)
catch_discover_tests(
constexpr_tests
TEST_PREFIX
"constexpr."
REPORTER
xml
OUTPUT_DIR
.
OUTPUT_PREFIX
"constexpr."
OUTPUT_SUFFIX
.xml)
# Disable the constexpr portion of the test, and build again this allows us to have an executable that we can debug when
# things go wrong with the constexpr testing
add_executable(relaxed_constexpr_tests constexpr_tests.cpp)
target_link_libraries(relaxed_constexpr_tests PRIVATE project_options project_warnings catch_main)
target_compile_definitions(relaxed_constexpr_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
catch_discover_tests(
relaxed_constexpr_tests
TEST_PREFIX
"relaxed_constexpr."
REPORTER
xml
OUTPUT_DIR
.
OUTPUT_PREFIX
"relaxed_constexpr."
OUTPUT_SUFFIX
.xml)
+5
View File
@@ -0,0 +1,5 @@
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
#include <catch2/catch.hpp>
+14
View File
@@ -0,0 +1,14 @@
#include <catch2/catch.hpp>
constexpr unsigned int Factorial(unsigned int number)
{
return number <= 1 ? number : Factorial(number - 1) * number;
}
TEST_CASE("Factorials are computed with constexpr", "[factorial]")
{
STATIC_REQUIRE(Factorial(1) == 1);
STATIC_REQUIRE(Factorial(2) == 2);
STATIC_REQUIRE(Factorial(3) == 6);
STATIC_REQUIRE(Factorial(10) == 3628800);
}
+14
View File
@@ -0,0 +1,14 @@
#include <catch2/catch.hpp>
unsigned int Factorial(unsigned int 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) == 3628800);
}