diff options
author | onqtam <vik.kirilov@gmail.com> | 2019-03-24 10:55:28 +0200 |
---|---|---|
committer | onqtam <vik.kirilov@gmail.com> | 2019-03-24 10:55:28 +0200 |
commit | a3ae95865eb78a2303e0028822ebac01082d9be3 (patch) | |
tree | ae534718c8f22108b7094e5c31c355d816d7ec85 /examples/installed_doctest_cmake | |
parent | c1f3e01ee10eeb6cfc9ddc175da7915ac5ed35c1 (diff) |
version 2.3.1 - mainly a fix for #210 - nothing in the doctest header has changed. Also renamed a bit the recently merged examples using doctest as installed
Diffstat (limited to 'examples/installed_doctest_cmake')
-rw-r--r-- | examples/installed_doctest_cmake/dll/CMakeLists.txt | 14 | ||||
-rw-r--r-- | examples/installed_doctest_cmake/dll/dll.cpp | 22 | ||||
-rw-r--r-- | examples/installed_doctest_cmake/dll/dll.h | 7 | ||||
-rw-r--r-- | examples/installed_doctest_cmake/dll/exporting.h | 15 | ||||
-rw-r--r-- | examples/installed_doctest_cmake/dll/main.cpp | 34 | ||||
-rw-r--r-- | examples/installed_doctest_cmake/executable/CMakeLists.txt | 9 | ||||
-rw-r--r-- | examples/installed_doctest_cmake/executable/main.cpp | 35 |
7 files changed, 136 insertions, 0 deletions
diff --git a/examples/installed_doctest_cmake/dll/CMakeLists.txt b/examples/installed_doctest_cmake/dll/CMakeLists.txt new file mode 100644 index 0000000..3fd9325 --- /dev/null +++ b/examples/installed_doctest_cmake/dll/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.0) + +project(example_dll VERSION 0.0.1 LANGUAGES CXX) + +find_package(doctest REQUIRED) + +add_library("dll" SHARED dll.cpp) +target_compile_features("dll" PRIVATE cxx_std_17) +target_compile_definitions("dll" PUBLIC -D_EXPORT) +target_link_libraries("dll" doctest::doctest) + +add_executable(${PROJECT_NAME} main.cpp) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) +target_link_libraries(${PROJECT_NAME} dll)
\ No newline at end of file diff --git a/examples/installed_doctest_cmake/dll/dll.cpp b/examples/installed_doctest_cmake/dll/dll.cpp new file mode 100644 index 0000000..83b79a0 --- /dev/null +++ b/examples/installed_doctest_cmake/dll/dll.cpp @@ -0,0 +1,22 @@ +#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL +#define DOCTEST_CONFIG_IMPLEMENT +#include <doctest/doctest.h> + +#include "dll.h" +#include <stdio.h> + +extern "C" { + void say_hello_dll() { printf("%s", "Hello, World!\n"); } +} + +int factorial(int number) { + return number < 1 ? 1 : number <= 1 ? number : factorial(number - 1) * number; +} + +TEST_CASE("testing the factorial function") { + CHECK(factorial(0) == 1); + CHECK(factorial(1) == 1); + CHECK(factorial(2) == 2); + CHECK(factorial(3) == 6); + CHECK(factorial(10) == 3628800); +}
\ No newline at end of file diff --git a/examples/installed_doctest_cmake/dll/dll.h b/examples/installed_doctest_cmake/dll/dll.h new file mode 100644 index 0000000..4d08985 --- /dev/null +++ b/examples/installed_doctest_cmake/dll/dll.h @@ -0,0 +1,7 @@ +#pragma once + +#include "exporting.h" + +extern "C" { + DLL_API void say_hello_dll(); +}
\ No newline at end of file diff --git a/examples/installed_doctest_cmake/dll/exporting.h b/examples/installed_doctest_cmake/dll/exporting.h new file mode 100644 index 0000000..a0f624b --- /dev/null +++ b/examples/installed_doctest_cmake/dll/exporting.h @@ -0,0 +1,15 @@ +#pragma once + +#ifdef _EXPORT +#ifdef _MSC_VER +#define DLL_API __declspec(dllexport) +#elif defined __GNUC__ +#define DLL_API __attribute__((visibility("default"))) +#endif +#else +#ifdef _MSC_VER +#define DLL_API __declspec(dllimport) +#elif defined __GNUC__ +#define DLL_API __attribute__((visibility("hidden"))) +#endif +#endif
\ No newline at end of file diff --git a/examples/installed_doctest_cmake/dll/main.cpp b/examples/installed_doctest_cmake/dll/main.cpp new file mode 100644 index 0000000..7c6d0f9 --- /dev/null +++ b/examples/installed_doctest_cmake/dll/main.cpp @@ -0,0 +1,34 @@ +#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL +#include <doctest/doctest.h> + +#include "dll.h" + +int main(int argc, char **argv) { + doctest::Context context; + context.applyCommandLine(argc, argv); + + int res = context.run(); // run doctest + + // important - query flags (and --exit) rely on the user doing this + if (context.shouldExit()) { + // propagate the result of the tests + return res; + } + + say_hello_dll(); // test dll func +} + +int square(const int number) { return number * number; } + +TEST_CASE("testing the square function") { + CHECK(square(2) == 4); + CHECK(square(4) == 16); + CHECK(square(5) == 25); + CHECK(square(8) == 64); +} + +// running notes +// ./example_dll --no-run (run normal program) +// ./example_dll --exit (run tests then exit) +// ./example_dll (run tests then run program) +// ./example_dll --success (print successful test casts)
\ No newline at end of file diff --git a/examples/installed_doctest_cmake/executable/CMakeLists.txt b/examples/installed_doctest_cmake/executable/CMakeLists.txt new file mode 100644 index 0000000..6182a8a --- /dev/null +++ b/examples/installed_doctest_cmake/executable/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.0) + +project(example_exe VERSION 0.0.1 LANGUAGES CXX) + +find_package(doctest REQUIRED) + +add_executable(${PROJECT_NAME} main.cpp) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) +target_link_libraries(${PROJECT_NAME} doctest::doctest)
\ No newline at end of file diff --git a/examples/installed_doctest_cmake/executable/main.cpp b/examples/installed_doctest_cmake/executable/main.cpp new file mode 100644 index 0000000..88f57b0 --- /dev/null +++ b/examples/installed_doctest_cmake/executable/main.cpp @@ -0,0 +1,35 @@ +#define DOCTEST_CONFIG_IMPLEMENT +#include <doctest/doctest.h> + +int main(int argc, char **argv) { + doctest::Context context; + context.applyCommandLine(argc, argv); + + int res = context.run(); // run doctest + + // important - query flags (and --exit) rely on the user doing this + if (context.shouldExit()) { + // propagate the result of the tests + return res; + } + + printf("%s", "Hello, World!"); +} + +int factorial(const int number) { + return number < 1 ? 1 : number <= 1 ? number : factorial(number - 1) * number; +} + +TEST_CASE("testing the factorial function") { + CHECK(factorial(0) == 1); + CHECK(factorial(1) == 1); + CHECK(factorial(2) == 2); + CHECK(factorial(3) == 6); + CHECK(factorial(10) == 3628800); +} + +// running notes +// ./example_exe --no-run (run normal program) +// ./example_exe --exit (run tests then exit) +// ./example_exe (run tests then run program) +// ./example_exe --success (print successful test casts)
\ No newline at end of file |