blob: 10421402a27f3216683e29c8590302b14c7c9024 [file] [log] [blame]
onqtamb43aa042017-03-13 19:04:08 +02001#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
2#include "doctest.h"
3
4#include <cstdio>
onqtam4a655632016-05-26 14:20:52 +03005
onqtam036fa312017-03-17 11:44:30 +02006template<typename T>
7static int conditional_throw(bool in, const T& ex) { if(in) throw ex; return 42; }
onqtam8327c6c2017-03-17 11:18:45 +02008
onqtam4a655632016-05-26 14:20:52 +03009TEST_CASE("executable") {
10 printf("I am a test from the executable!\n");
onqtam8327c6c2017-03-17 11:18:45 +020011 conditional_throw(true, 'a');
onqtam4a655632016-05-26 14:20:52 +030012}
13
onqtamb43aa042017-03-13 19:04:08 +020014#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
onqtamb43aa042017-03-13 19:04:08 +020022#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__
onqtamb43aa042017-03-13 19:04:08 +020029#endif // _WIN32
30
onqtam05bcc372017-03-17 02:10:38 +020031// set an exception translator for double
32REGISTER_EXCEPTION_TRANSLATOR(double& e) {
33 return doctest::String("double: ") + doctest::toString(e);
34}
35
onqtam4a655632016-05-26 14:20:52 +030036int main(int argc, char** argv) {
onqtamb43aa042017-03-13 19:04:08 +020037 // 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
onqtam4a655632016-05-26 14:20:52 +030042 doctest::Context context(argc, argv);
43 int res = context.run();
44
onqtam96bdf712016-09-13 16:45:52 +030045 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
onqtam4a655632016-05-26 14:20:52 +030049}