From 10c7f5cc1cbf1da54aa61993be9f9aa630e6f3b9 Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Fri, 15 Sep 2023 17:12:51 -0500 Subject: [PATCH] Added test structure and Unity usage --- .gitignore | 2 ++ CMakeLists.txt | 16 ++++++++++++++++ src/main.cpp | 6 ++++++ test/CMakeLists.txt | 7 +++++++ test/test.cpp | 21 +++++++++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/main.cpp create mode 100644 test/CMakeLists.txt create mode 100644 test/test.cpp diff --git a/.gitignore b/.gitignore index e257658..129f2a6 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ *.out *.app +# CMake +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0834132 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.10) + +project( + search-algorithms + LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard to use") +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) + +add_subdirectory(src) + +if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + add_subdirectory(test) +endif() diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..29b2fa0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(void) { + std::cout << "Hello world" << std::endl; + return 0; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..8a65233 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,7 @@ +find_package(unity REQUIRED) +include_directories(${CMAKE_SOURCE_DIR}/src) +add_executable(testing + test.cpp +) +set_target_properties(testing PROPERTIES LINKER_LANGUAGE CXX) +target_link_libraries(testing unity) diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..6668b68 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,21 @@ +#include +#include + +void setUp() { ; } +void tearDown() { ; } + +int Math(void) { + return 2+2; +} + +void test_Math(void) { + TEST_ASSERT_EQUAL_INT(4, Math()); +} + + +int main(void) { + UNITY_BEGIN(); + RUN_TEST(test_Math); + return UNITY_END(); +} +