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