blob: ad3b429daa4449514468d1dba6a741981fd32d2d [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>
onqtam4b68df32017-03-17 20:45:54 +02007static 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}
onqtam8327c6c2017-03-17 11:18:45 +020016
onqtam4a655632016-05-26 14:20:52 +030017TEST_CASE("executable") {
18 printf("I am a test from the executable!\n");
onqtam8327c6c2017-03-17 11:18:45 +020019 conditional_throw(true, 'a');
onqtam4a655632016-05-26 14:20:52 +030020}
21
onqtamb43aa042017-03-13 19:04:08 +020022#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
onqtamb43aa042017-03-13 19:04:08 +020030#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__
onqtamb43aa042017-03-13 19:04:08 +020037#endif // _WIN32
38
onqtam05bcc372017-03-17 02:10:38 +020039// set an exception translator for double
40REGISTER_EXCEPTION_TRANSLATOR(double& e) {
41 return doctest::String("double: ") + doctest::toString(e);
42}
43
onqtam4a655632016-05-26 14:20:52 +030044int main(int argc, char** argv) {
onqtamb43aa042017-03-13 19:04:08 +020045 // 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
onqtam4a655632016-05-26 14:20:52 +030050 doctest::Context context(argc, argv);
51 int res = context.run();
52
onqtam96bdf712016-09-13 16:45:52 +030053 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
onqtam4a655632016-05-26 14:20:52 +030057}