blob: 930efc004c057fe116d678150ba438956d4ad7b2 [file] [log] [blame]
onqtamb43aa042017-03-13 19:04:08 +02001#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
ncihnegnc5458f22019-01-28 05:08:18 -08002#include <doctest/doctest.h>
onqtamb43aa042017-03-13 19:04:08 +02003
onqtamabf39d22017-10-28 21:30:45 +03004DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
onqtamb43aa042017-03-13 19:04:08 +02005#include <cstdio>
onqtamabf39d22017-10-28 21:30:45 +03006DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
onqtam4a655632016-05-26 14:20:52 +03007
onqtam036fa312017-03-17 11:44:30 +02008template<typename T>
onqtam4b68df32017-03-17 20:45:54 +02009static int conditional_throw(bool in, const T& ex) {
10 if(in)
11#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
12 throw ex;
13#else // DOCTEST_CONFIG_NO_EXCEPTIONS
14 ((void)ex);
15#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
16 return 42;
17}
onqtam8327c6c2017-03-17 11:18:45 +020018
onqtam4a655632016-05-26 14:20:52 +030019TEST_CASE("executable") {
20 printf("I am a test from the executable!\n");
onqtam8327c6c2017-03-17 11:18:45 +020021 conditional_throw(true, 'a');
onqtam4a655632016-05-26 14:20:52 +030022}
23
onqtamb43aa042017-03-13 19:04:08 +020024#ifdef _WIN32
25#define WIN32_LEAN_AND_MEAN
onqtamabf39d22017-10-28 21:30:45 +030026DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
Clare Macrae8df12f22020-02-19 14:27:14 +000027#include <Windows.h>
onqtamabf39d22017-10-28 21:30:45 +030028DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
onqtamb43aa042017-03-13 19:04:08 +020029#ifdef _MSC_VER
30#define LoadDynamicLib(lib) LoadLibrary(lib ".dll")
31#else // _MSC_VER
32#define LoadDynamicLib(lib) LoadLibrary("lib" lib ".dll")
33#endif // _MSC_VER
onqtamb43aa042017-03-13 19:04:08 +020034#else // _WIN32
35#include <dlfcn.h>
36#ifdef __APPLE__
37#define LoadDynamicLib(lib) dlopen("lib" lib ".dylib", RTLD_NOW)
38#else // __APPLE__
39#define LoadDynamicLib(lib) dlopen("lib" lib ".so", RTLD_NOW)
40#endif // __APPLE__
onqtamb43aa042017-03-13 19:04:08 +020041#endif // _WIN32
42
onqtam05bcc372017-03-17 02:10:38 +020043// set an exception translator for double
44REGISTER_EXCEPTION_TRANSLATOR(double& e) {
45 return doctest::String("double: ") + doctest::toString(e);
46}
47
onqtamdf8b6d42019-03-02 17:40:39 +020048DOCTEST_SYMBOL_IMPORT void from_dll();
49
onqtam4a655632016-05-26 14:20:52 +030050int main(int argc, char** argv) {
onqtamb43aa042017-03-13 19:04:08 +020051 // force the use of a symbol from the dll so tests from it get registered
onqtamdf8b6d42019-03-02 17:40:39 +020052 from_dll();
onqtamb43aa042017-03-13 19:04:08 +020053
54 LoadDynamicLib("plugin"); // load the plugin so tests from it get registered
55
onqtam4a655632016-05-26 14:20:52 +030056 doctest::Context context(argc, argv);
57 int res = context.run();
58
onqtam96bdf712016-09-13 16:45:52 +030059 if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
60 return res; // propagate the result of the tests
61
onqtam8a0a0232018-02-06 22:57:12 +020062 int client_stuff_return_code = 0;
63 // your program - if the testing framework is integrated in your production code
onqtamb29e6172018-02-06 22:24:18 +020064
65 return res + client_stuff_return_code; // the result from doctest is propagated here as well
onqtam4a655632016-05-26 14:20:52 +030066}