onqtam | b43aa04 | 2017-03-13 19:04:08 +0200 | [diff] [blame] | 1 | #define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL |
| 2 | #include "doctest.h" |
| 3 | |
| 4 | #include <cstdio> |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 5 | |
| 6 | TEST_CASE("executable") { |
| 7 | printf("I am a test from the executable!\n"); |
onqtam | 05bcc37 | 2017-03-17 02:10:38 +0200 | [diff] [blame] | 8 | throw 'a'; |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 9 | } |
| 10 | |
onqtam | b43aa04 | 2017-03-13 19:04:08 +0200 | [diff] [blame] | 11 | #ifdef _WIN32 |
| 12 | #define WIN32_LEAN_AND_MEAN |
| 13 | #include <windows.h> |
| 14 | #ifdef _MSC_VER |
| 15 | #define LoadDynamicLib(lib) LoadLibrary(lib ".dll") |
| 16 | #else // _MSC_VER |
| 17 | #define LoadDynamicLib(lib) LoadLibrary("lib" lib ".dll") |
| 18 | #endif // _MSC_VER |
onqtam | b43aa04 | 2017-03-13 19:04:08 +0200 | [diff] [blame] | 19 | #else // _WIN32 |
| 20 | #include <dlfcn.h> |
| 21 | #ifdef __APPLE__ |
| 22 | #define LoadDynamicLib(lib) dlopen("lib" lib ".dylib", RTLD_NOW) |
| 23 | #else // __APPLE__ |
| 24 | #define LoadDynamicLib(lib) dlopen("lib" lib ".so", RTLD_NOW) |
| 25 | #endif // __APPLE__ |
onqtam | b43aa04 | 2017-03-13 19:04:08 +0200 | [diff] [blame] | 26 | #endif // _WIN32 |
| 27 | |
onqtam | 05bcc37 | 2017-03-17 02:10:38 +0200 | [diff] [blame] | 28 | // set an exception translator for double |
| 29 | REGISTER_EXCEPTION_TRANSLATOR(double& e) { |
| 30 | return doctest::String("double: ") + doctest::toString(e); |
| 31 | } |
| 32 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 33 | int main(int argc, char** argv) { |
onqtam | b43aa04 | 2017-03-13 19:04:08 +0200 | [diff] [blame] | 34 | // force the use of a symbol from the dll so tests from it get registered |
| 35 | DOCTEST_SYMBOL_IMPORT void from_dll(); from_dll(); |
| 36 | |
| 37 | LoadDynamicLib("plugin"); // load the plugin so tests from it get registered |
| 38 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 39 | doctest::Context context(argc, argv); |
| 40 | int res = context.run(); |
| 41 | |
onqtam | 96bdf71 | 2016-09-13 16:45:52 +0300 | [diff] [blame] | 42 | if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this |
| 43 | return res; // propagate the result of the tests |
| 44 | |
| 45 | return res; // the result from doctest is propagated here as well |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 46 | } |