From b8471c6d767109691af94e40b873d83a5f799cca Mon Sep 17 00:00:00 2001 From: fef Date: Wed, 14 Jul 2021 21:30:10 +0200 Subject: [PATCH] set up Catch2 for testing Looks like there isn't really a way around C++ smh --- CMakeLists.txt | 13 +++++++++---- include/neo/_error.h | 3 ++- test/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ test/neo_test.cpp | 17 +++++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 test/CMakeLists.txt create mode 100644 test/neo_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index dd53f99..51db36f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,13 @@ # See the end of this file for copyright and license terms. -cmake_minimum_required(VERSION 3.0.0) -project(neo VERSION 0.1.0 LANGUAGES C ASM) +cmake_minimum_required(VERSION 3.14.0) +project(neo VERSION 0.1.0 LANGUAGES C) set(CMAKE_C_STANDARD 11) +set(CMAKE_C_EXTENSIONS ON) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set_property(GLOBAL PROPERTY USE_FOLDERS ON) option(DEBUG "Enable debug features" ON) - include(CTest) - enable_testing() endif() find_package(Git QUIET) @@ -29,6 +28,12 @@ add_subdirectory(src) add_subdirectory(demo) +option(BUILD_TESTING "Build tests" ON) +if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR NEO_BUILD_TESTING) AND BUILD_TESTING) + enable_testing() + add_subdirectory(test) +endif() + set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) include(CPack) diff --git a/include/neo/_error.h b/include/neo/_error.h index b469bb6..fa82702 100644 --- a/include/neo/_error.h +++ b/include/neo/_error.h @@ -6,6 +6,7 @@ extern "C" { #endif +#include "neo/_toolchain.h" #include "neo/_types.h" /** @@ -21,7 +22,7 @@ extern "C" { * the values to insert which will become the error message. */ __attribute__(( __format__(printf, 3, 4) )) -void yeet(error *err, u32 number, const char *restrict fmt, ...); +void yeet(error *err, u32 number, const char *__restrict fmt, ...); /** * Indicate an operation has completed successfully. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..608b55f --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,31 @@ +# See the end of this file for copyright and license terms. + +enable_language(CXX) +set(CMAKE_CXX_STANDARD 17) + +include(CTest) +include(FetchContent) +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v2.13.6 +) +FetchContent_MakeAvailable(Catch2) + +add_executable(neo_test neo_test.cpp) + +target_compile_features(neo_test PRIVATE cxx_std_17) +target_link_libraries(neo_test PRIVATE neo Catch2::Catch2) + +add_test(NAME neo COMMAND neo_test) + +# This file is part of libneo. +# Copyright (c) 2021 Fefie . +# +# libneo is non-violent software: you may only use, redistribute, +# and/or modify it under the terms of the CNPLv6+ as found in +# the LICENSE file in the source code root directory or at +# . +# +# libneo comes with ABSOLUTELY NO WARRANTY, to the extent +# permitted by applicable law. See the CNPLv6+ for details. diff --git a/test/neo_test.cpp b/test/neo_test.cpp new file mode 100644 index 0000000..80035ca --- /dev/null +++ b/test/neo_test.cpp @@ -0,0 +1,17 @@ +/** See the end of this file for copyright and license terms. */ + +#define CATCH_CONFIG_MAIN +#include + +/* + * This file is part of libneo. + * Copyright (c) 2021 Fefie . + * + * libneo is non-violent software: you may only use, redistribute, + * and/or modify it under the terms of the CNPLv6+ as found in + * the LICENSE file in the source code root directory or at + * . + * + * libneo comes with ABSOLUTELY NO WARRANTY, to the extent + * permitted by applicable law. See the CNPLv6+ for details. + */