libshit

Just some random shit
git clone https://git.neptards.moe/neptards/libshit.git
Log | Files | Refs | Submodules | README | LICENSE

test_helper.cpp (1913B)


      1 #include "libshit/except.hpp"
      2 #include "libshit/function.hpp"
      3 #include "libshit/options.hpp"
      4 #include "libshit/platform.hpp"
      5 
      6 #include <string>
      7 #include <vector>
      8 
      9 #if LIBSHIT_OS_IS_WINDOWS
     10 #  include <libshit/windows_version.hpp>
     11 
     12 #  define WIN32_LEAN_AND_MEAN
     13 #  define NOMINMAX
     14 #  include <windows.h>
     15 
     16 // inline contents of crtdbg.h, as it conflicts with _LIBCPP_NO_VCRUNTIME
     17 using _HFILE = void*;
     18 // these two functions can be a macro or a normal function, and they only exist
     19 // in the debug version of crt which we don't use.
     20 #ifndef _CrtSetReportMode
     21 #define _CrtSetReportMode(a, b) 0
     22 #endif
     23 #ifndef _CrtSetReportFile
     24 #define _CrtSetReportFile(a, b) static_cast<_HFILE>(nullptr)
     25 #endif
     26 
     27 #  if !LIBSHIT_WINVER_VISTA
     28 #    include "libshit/dynamic_lib.hpp"
     29 inline BOOL SetThreadStackGuarantee_wrap(PULONG size)
     30 {
     31   if (auto dyn = LIBSHIT_GLOBAL_SYM2(
     32         BOOL WINAPI (*)(PULONG), "kernel32", "SetThreadStackGuarantee"))
     33     return dyn(size);
     34   return 0;
     35 }
     36 #    define SetThreadStackGuarantee SetThreadStackGuarantee_wrap
     37 #  endif
     38 #endif
     39 #define DOCTEST_CONFIG_IMPLEMENT
     40 #include "libshit/doctest_fwd.hpp"
     41 
     42 using namespace std::string_literals;
     43 
     44 namespace Libshit
     45 {
     46 
     47   REGISTER_EXCEPTION_TRANSLATOR(const Libshit::Exception& e)
     48   { return Libshit::ExceptionToString(e, false).c_str(); }
     49 
     50   static void Fun(OptionParser& parser, std::vector<const char*>&& args)
     51   {
     52     parser.CommandTriggered();
     53     doctest::Context ctx;
     54 
     55     ctx.setOption("exit", true);
     56     args.insert(args.begin(), parser.GetArgv0());
     57     ctx.applyCommandLine(args.size(), args.data());
     58     auto ret = ctx.run();
     59     if (ctx.shouldExit()) throw Exit{!ret};
     60   }
     61 
     62   static Option opt{
     63     OptionGroup::GetCommands(), "test", Option::ALL_ARGS, "ARGS...",
     64     "Run doctest tests\n\t"
     65     "Remaining arguments will be passed to doctest. You must pass any doctest "
     66     "option AFTER \"--test\" and every other option BEFORE!", FUNC<Fun>};
     67 }