blob: d405525dea074d501350816fceff31628141bf73 [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
Viktor Kirilovba32eb42021-02-02 16:27:47 +020027DOCTEST_CLANG_SUPPRESS_WARNING("-Wnonportable-system-include-path")
Jan Niklas Hassea702cab2021-02-02 15:26:47 +010028#include <windows.h>
onqtamabf39d22017-10-28 21:30:45 +030029DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
onqtamb43aa042017-03-13 19:04:08 +020030#ifdef _MSC_VER
31#define LoadDynamicLib(lib) LoadLibrary(lib ".dll")
32#else // _MSC_VER
33#define LoadDynamicLib(lib) LoadLibrary("lib" lib ".dll")
34#endif // _MSC_VER
onqtamb43aa042017-03-13 19:04:08 +020035#else // _WIN32
36#include <dlfcn.h>
37#ifdef __APPLE__
38#define LoadDynamicLib(lib) dlopen("lib" lib ".dylib", RTLD_NOW)
39#else // __APPLE__
40#define LoadDynamicLib(lib) dlopen("lib" lib ".so", RTLD_NOW)
41#endif // __APPLE__
onqtamb43aa042017-03-13 19:04:08 +020042#endif // _WIN32
43
onqtam05bcc372017-03-17 02:10:38 +020044// set an exception translator for double
45REGISTER_EXCEPTION_TRANSLATOR(double& e) {
46 return doctest::String("double: ") + doctest::toString(e);
47}
48
onqtamdf8b6d42019-03-02 17:40:39 +020049DOCTEST_SYMBOL_IMPORT void from_dll();
50
onqtam4a655632016-05-26 14:20:52 +030051int main(int argc, char** argv) {
onqtamb43aa042017-03-13 19:04:08 +020052 // force the use of a symbol from the dll so tests from it get registered
onqtamdf8b6d42019-03-02 17:40:39 +020053 from_dll();
onqtamb43aa042017-03-13 19:04:08 +020054
55 LoadDynamicLib("plugin"); // load the plugin so tests from it get registered
56
onqtam4a655632016-05-26 14:20:52 +030057 doctest::Context context(argc, argv);
58 int res = context.run();
59
onqtam96bdf712016-09-13 16:45:52 +030060 if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
61 return res; // propagate the result of the tests
62
onqtam8a0a0232018-02-06 22:57:12 +020063 int client_stuff_return_code = 0;
64 // your program - if the testing framework is integrated in your production code
onqtamb29e6172018-02-06 22:24:18 +020065
66 return res + client_stuff_return_code; // the result from doctest is propagated here as well
onqtam4a655632016-05-26 14:20:52 +030067}