You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libshit/test/test_helper.cpp

68 lines
1.9 KiB
C++

#include "libshit/except.hpp"
#include "libshit/function.hpp"
#include "libshit/options.hpp"
#include "libshit/platform.hpp"
#include <string>
#include <vector>
#if LIBSHIT_OS_IS_WINDOWS
# include <libshit/windows_version.hpp>
# define WIN32_LEAN_AND_MEAN
# define NOMINMAX
# include <windows.h>
// inline contents of crtdbg.h, as it conflicts with _LIBCPP_NO_VCRUNTIME
using _HFILE = void*;
// these two functions can be a macro or a normal function, and they only exist
// in the debug version of crt which we don't use.
#ifndef _CrtSetReportMode
#define _CrtSetReportMode(a, b) 0
#endif
#ifndef _CrtSetReportFile
#define _CrtSetReportFile(a, b) static_cast<_HFILE>(nullptr)
#endif
# if !LIBSHIT_WINVER_VISTA
# include "libshit/dynamic_lib.hpp"
inline BOOL SetThreadStackGuarantee_wrap(PULONG size)
{
if (auto dyn = LIBSHIT_GLOBAL_SYM2(
BOOL WINAPI (*)(PULONG), "kernel32", "SetThreadStackGuarantee"))
return dyn(size);
return 0;
}
# define SetThreadStackGuarantee SetThreadStackGuarantee_wrap
# endif
#endif
#define DOCTEST_CONFIG_IMPLEMENT
#include "libshit/doctest_fwd.hpp"
using namespace std::string_literals;
namespace Libshit
{
REGISTER_EXCEPTION_TRANSLATOR(const Libshit::Exception& e)
{ return Libshit::ExceptionToString(e, false).c_str(); }
static void Fun(OptionParser& parser, std::vector<const char*>&& args)
{
parser.CommandTriggered();
doctest::Context ctx;
ctx.setOption("exit", true);
args.insert(args.begin(), parser.GetArgv0());
ctx.applyCommandLine(args.size(), args.data());
auto ret = ctx.run();
if (ctx.shouldExit()) throw Exit{!ret};
}
static Option opt{
OptionGroup::GetCommands(), "test", Option::ALL_ARGS, "ARGS...",
"Run doctest tests\n\t"
"Remaining arguments will be passed to doctest. You must pass any doctest "
"option AFTER \"--test\" and every other option BEFORE!", FUNC<Fun>};
}