From 1c9b7cb3f4df1ac2168fca1231ab8038aa0479c5 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 18 Oct 2023 19:49:49 +0200 Subject: [PATCH] feat: extract test code --- CMakeLists.txt | 2 +- src/main.cpp | 24 ++---------------------- src/null.cpp | 29 +++++++++++++++++++++++++++++ src/null.h | 5 +++++ 4 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 src/null.cpp create mode 100644 src/null.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e50fdb9..c543d70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ include(ExportCompileCommands) configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in" "${PROJECT_BINARY_DIR}/include/version.h") -add_executable(hello src/main.cpp) +add_executable(hello src/main.cpp src/null.cpp) target_compile_features(hello PUBLIC cxx_std_20) target_include_directories(hello PRIVATE "${PROJECT_BINARY_DIR}/include") diff --git a/src/main.cpp b/src/main.cpp index 3298d6a..fbea74c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,36 +1,16 @@ #include #include -#include #include "version.h" -void call_test(char *) { std::cout << "call_test(char *) called" << std::endl; } - -void call_test(int) { std::cout << "call_test(int) called" << std::endl; } +#include "null.h" int main(int argc, char **argv) { std::cout << "Running " << PROJECT_NAME << ", version " << VERSION << "\n" << std::endl; - if (std::is_same::value) { - std::cout << "NULL == 0" << std::endl; - } - - if (std::is_same::value) { - std::cout << "NULL == (void *)0" << std::endl; - } - - if (std::is_same::value) { - std::cout << "NULL == __null" << std::endl; - } - - if (std::is_same::value) { - std::cout << "NULL == nullptr" << std::endl; - } - - call_test(0); - call_test(nullptr); + null::test(); std::cout << "\nExiting" << std::endl; diff --git a/src/null.cpp b/src/null.cpp new file mode 100644 index 0000000..066e95f --- /dev/null +++ b/src/null.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include "null.h" + +void call_test(char *) { std::cout << "call_test(char *) called" << std::endl; } + +void call_test(int) { std::cout << "call_test(int) called" << std::endl; } + +void null::test() { + if (std::is_same::value) { + std::cout << "NULL == 0" << std::endl; + } + + if (std::is_same::value) { + std::cout << "NULL == (void *)0" << std::endl; + } + + if (std::is_same::value) { + std::cout << "NULL == __null" << std::endl; + } + + if (std::is_same::value) { + std::cout << "NULL == nullptr" << std::endl; + } + + call_test(0); + call_test(nullptr); +} diff --git a/src/null.h b/src/null.h new file mode 100644 index 0000000..e8434f7 --- /dev/null +++ b/src/null.h @@ -0,0 +1,5 @@ +#pragma once + +namespace null { +void test(); +};