forked from doctest/doctest
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the example code from issue doctest#436
- Loading branch information
Showing
10 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ples/combining_the_same_tests_built_differently_in_multiple_shared_objects/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# for more information about this example refer to the GitHub issue: https://github.com/onqtam/doctest/issues/436 | ||
|
||
add_library(default SHARED default.cpp) | ||
target_link_libraries(default PUBLIC doctest) | ||
set_target_properties(default PROPERTIES CXX_VISIBILITY_PRESET hidden) | ||
|
||
add_library(return42 SHARED return42.cpp) | ||
target_link_libraries(return42 PUBLIC doctest) | ||
set_target_properties(return42 PROPERTIES CXX_VISIBILITY_PRESET hidden) | ||
|
||
add_executable(same_tests_multiple_configurations main.cpp) | ||
target_link_libraries(same_tests_multiple_configurations PUBLIC default return42 doctest) | ||
|
||
|
||
# create the test runner, to which all other targets will link to | ||
add_library(test_runner SHARED test_runner.cpp) | ||
target_link_libraries(test_runner PUBLIC doctest) | ||
|
||
# link all targets to the test runner | ||
target_link_libraries(same_tests_multiple_configurations PUBLIC test_runner) | ||
target_link_libraries(default PUBLIC test_runner) | ||
target_link_libraries(return42 PUBLIC test_runner) | ||
|
||
doctest_add_test(NAME same_tests_multiple_configurations COMMAND $<TARGET_FILE:same_tests_multiple_configurations> --no-version) |
6 changes: 6 additions & 0 deletions
6
examples/combining_the_same_tests_built_differently_in_multiple_shared_objects/default.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL | ||
#include "doctest/doctest.h" | ||
|
||
#include "foo.h" | ||
|
||
DOCTEST_SYMBOL_EXPORT void default_cpp_force_link() {} |
42 changes: 42 additions & 0 deletions
42
examples/combining_the_same_tests_built_differently_in_multiple_shared_objects/foo.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
#include "doctest/doctest.h" | ||
#include <type_traits> | ||
|
||
DOCTEST_GCC_SUPPRESS_WARNING("-Wmissing-declarations") | ||
|
||
#ifdef RETURN_42 | ||
#define TEST_LABEL "[return42] " | ||
#else | ||
#define TEST_LABEL "[default] " | ||
#endif | ||
|
||
int bar() { | ||
#ifdef RETURN_42 | ||
return 42; | ||
#else | ||
return 11; | ||
#endif | ||
} | ||
|
||
#ifdef DOCTEST_LIBRARY_INCLUDED | ||
|
||
#ifdef RETURN_42 | ||
TEST_CASE(TEST_LABEL "bartest"){ | ||
INFO("Running " TEST_LABEL "bartest"); MESSAGE(""); | ||
CHECK_EQ(42, bar()); | ||
} | ||
#endif | ||
|
||
#ifndef RETURN_42 | ||
TEST_CASE(TEST_LABEL "bartest"){ | ||
INFO("Running " TEST_LABEL "bartest"); MESSAGE(""); | ||
CHECK_EQ(11, bar()); | ||
} | ||
#endif | ||
|
||
TEST_CASE(TEST_LABEL "commontest"){ | ||
INFO("Running " TEST_LABEL "commontest"); MESSAGE(""); | ||
auto x = bar(); | ||
CHECK(std::is_same<decltype(x), int>::value); | ||
} | ||
#endif // DOCTEST_LIBRARY_INCLUDED |
25 changes: 25 additions & 0 deletions
25
examples/combining_the_same_tests_built_differently_in_multiple_shared_objects/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL | ||
#define DOCTEST_CONFIG_IMPLEMENT | ||
#include "doctest/doctest.h" | ||
|
||
DOCTEST_SYMBOL_IMPORT void default_cpp_force_link(); | ||
DOCTEST_SYMBOL_IMPORT void return42_cpp_force_link(); | ||
|
||
TEST_CASE("main") { MESSAGE("hello from <main.cpp>"); } | ||
|
||
int main(int argc, char** argv) { | ||
|
||
default_cpp_force_link(); | ||
return42_cpp_force_link(); | ||
|
||
doctest::Context context(argc, argv); | ||
int res = context.run(); | ||
|
||
if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this | ||
return res; // propagate the result of the tests | ||
|
||
int client_stuff_return_code = 0; | ||
// your program - if the testing framework is integrated in your production code | ||
|
||
return res + client_stuff_return_code; // the result from doctest is propagated here as well | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/combining_the_same_tests_built_differently_in_multiple_shared_objects/return42.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL | ||
#include "doctest/doctest.h" | ||
|
||
#define RETURN_42 | ||
#include "foo.h" | ||
|
||
DOCTEST_SYMBOL_EXPORT void return42_cpp_force_link() {} |
45 changes: 45 additions & 0 deletions
45
...differently_in_multiple_shared_objects/test_output/same_tests_multiple_configurations.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
[doctest] run with "--help" for options | ||
=============================================================================== | ||
foo.h(0): | ||
TEST CASE: [return42] bartest | ||
|
||
foo.h(0): MESSAGE: | ||
logged: Running [return42] bartest | ||
|
||
=============================================================================== | ||
foo.h(0): | ||
TEST CASE: [default] bartest | ||
|
||
foo.h(0): MESSAGE: | ||
logged: Running [default] bartest | ||
|
||
=============================================================================== | ||
foo.h(0): | ||
TEST CASE: [default] commontest | ||
|
||
foo.h(0): MESSAGE: | ||
logged: Running [default] commontest | ||
|
||
=============================================================================== | ||
foo.h(0): | ||
TEST CASE: [return42] commontest | ||
|
||
foo.h(0): MESSAGE: | ||
logged: Running [return42] commontest | ||
|
||
=============================================================================== | ||
main.cpp(0): | ||
TEST CASE: main | ||
|
||
main.cpp(0): MESSAGE: hello from <main.cpp> | ||
|
||
=============================================================================== | ||
test_runner.cpp(0): | ||
TEST CASE: test_runner | ||
|
||
test_runner.cpp(0): MESSAGE: hello from <test_runner.cpp> | ||
|
||
=============================================================================== | ||
[doctest] test cases: 6 | 6 passed | 0 failed | 0 skipped | ||
[doctest] assertions: 4 | 4 passed | 0 failed | | ||
[doctest] Status: SUCCESS! |
11 changes: 11 additions & 0 deletions
11
...ently_in_multiple_shared_objects/test_output/same_tests_multiple_configurations_junit.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites> | ||
<testsuite name="same_tests_multiple_configurations" errors="0" failures="0" tests="4"> | ||
<testcase classname="foo.h" name="[return42] bartest" status="run"/> | ||
<testcase classname="foo.h" name="[default] bartest" status="run"/> | ||
<testcase classname="foo.h" name="[default] commontest" status="run"/> | ||
<testcase classname="foo.h" name="[return42] commontest" status="run"/> | ||
<testcase classname="main.cpp" name="main" status="run"/> | ||
<testcase classname="test_runner.cpp" name="test_runner" status="run"/> | ||
</testsuite> | ||
</testsuites> |
60 changes: 60 additions & 0 deletions
60
...erently_in_multiple_shared_objects/test_output/same_tests_multiple_configurations_xml.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctest binary="same_tests_multiple_configurations"> | ||
<Options order_by="file" rand_seed="0" first="0" last="4294967295" abort_after="0" subcase_filter_levels="2147483647" case_sensitive="false" no_throw="false" no_skip="false"/> | ||
<TestSuite> | ||
<TestCase name="[return42] bartest" filename="foo.h" line="0"> | ||
<Message type="WARNING" filename="foo.h" line="0"> | ||
<Text/> | ||
<Info> | ||
Running [return42] bartest | ||
</Info> | ||
</Message> | ||
<OverallResultsAsserts successes="1" failures="0"/> | ||
</TestCase> | ||
<TestCase name="[default] bartest" filename="foo.h" line="0"> | ||
<Message type="WARNING" filename="foo.h" line="0"> | ||
<Text/> | ||
<Info> | ||
Running [default] bartest | ||
</Info> | ||
</Message> | ||
<OverallResultsAsserts successes="1" failures="0"/> | ||
</TestCase> | ||
<TestCase name="[default] commontest" filename="foo.h" line="0"> | ||
<Message type="WARNING" filename="foo.h" line="0"> | ||
<Text/> | ||
<Info> | ||
Running [default] commontest | ||
</Info> | ||
</Message> | ||
<OverallResultsAsserts successes="1" failures="0"/> | ||
</TestCase> | ||
<TestCase name="[return42] commontest" filename="foo.h" line="0"> | ||
<Message type="WARNING" filename="foo.h" line="0"> | ||
<Text/> | ||
<Info> | ||
Running [return42] commontest | ||
</Info> | ||
</Message> | ||
<OverallResultsAsserts successes="1" failures="0"/> | ||
</TestCase> | ||
<TestCase name="main" filename="main.cpp" line="0"> | ||
<Message type="WARNING" filename="main.cpp" line="0"> | ||
<Text> | ||
hello from <main.cpp> | ||
</Text> | ||
</Message> | ||
<OverallResultsAsserts successes="0" failures="0"/> | ||
</TestCase> | ||
<TestCase name="test_runner" filename="test_runner.cpp" line="0"> | ||
<Message type="WARNING" filename="test_runner.cpp" line="0"> | ||
<Text> | ||
hello from <test_runner.cpp> | ||
</Text> | ||
</Message> | ||
<OverallResultsAsserts successes="0" failures="0"/> | ||
</TestCase> | ||
</TestSuite> | ||
<OverallResultsAsserts successes="4" failures="0"/> | ||
<OverallResultsTestCases successes="6" failures="0" skipped="0"/> | ||
</doctest> |
5 changes: 5 additions & 0 deletions
5
...les/combining_the_same_tests_built_differently_in_multiple_shared_objects/test_runner.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL | ||
#define DOCTEST_CONFIG_IMPLEMENT | ||
#include "doctest/doctest.h" | ||
|
||
TEST_CASE("test_runner") { MESSAGE("hello from <test_runner.cpp>"); } |