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