391#include "test_case.h"
393#include "generators/builds.h"
394#include "generators/collections.h"
395#include "generators/combinators.h"
396#include "generators/default.h"
397#include "generators/formats.h"
398#include "generators/numeric.h"
399#include "generators/primitives.h"
400#include "generators/random.h"
401#include "generators/stateful.h"
402#include "generators/strings.h"
403#include "generators/temporal.h"
408#if defined(__GNUC__) || defined(__clang__) || \
409 (defined(_MSC_VER) && _MSC_VER >= 1927)
410#define HEGEL_CALLER_FILE __builtin_FILE()
411#define HEGEL_CALLER_FUNCTION __builtin_FUNCTION()
412#define HEGEL_CALLER_LINE __builtin_LINE()
414#define HEGEL_CALLER_FILE ""
415#define HEGEL_CALLER_FUNCTION ""
416#define HEGEL_CALLER_LINE 0
450 class FailureOrigin {
452 FailureOrigin() =
default;
453 virtual ~FailureOrigin() =
default;
458 FailureOrigin&
operator=(
const FailureOrigin&) =
default;
546 const std::vector<std::string>& failure_blobs = {},
547 const std::vector<ExplicitTestCase>& explicit_cases = {},
548 const char* caller_file = HEGEL_CALLER_FILE,
549 const char* caller_function = HEGEL_CALLER_FUNCTION,
550 int caller_line = HEGEL_CALLER_LINE);
578 const std::vector<std::string>& failure_blobs = {},
579 const std::vector<ExplicitTestCase>& explicit_cases = {});
584 struct FrameworkHooks {
586 std::string (*current_test_name)() =
nullptr;
589 void (*run_case)(
const std::function<void()>&) =
nullptr;
592 bool (*is_assertion_failure)(
const std::exception&) =
nullptr;
598 bool install_framework_hooks(
const FrameworkHooks& hooks);
601 bool register_blob(
const char* name, std::vector<const char*> blobs);
603 std::vector<std::string> reproduce_blobs_for(
const char* name);
606 bool register_explicit_case(
const char* name,
607 ExplicitTestCase test_case);
609 std::vector<ExplicitTestCase> explicit_cases_for(
const char* name);
613 test_from_macro(
const std::function<
void(TestCase&)>& test_fn,
614 const TestLocation& location,
const Settings& settings,
615 const std::vector<std::string>& failure_blobs,
616 const std::vector<ExplicitTestCase>& explicit_cases);
622 main_from_macro(
int argc,
char** argv,
623 const std::function<
void(TestCase&)>& test_fn,
624 const TestLocation& location,
625 const std::function<Settings()>& make_settings,
626 const std::vector<std::string>& failure_blobs,
627 const std::vector<ExplicitTestCase>& explicit_cases);
674#define HEGEL_TEST(name, ...) \
675 static void hegel_test_body_##name(::hegel::TestCase&); \
676 static void name(const ::hegel::Settings& settings = \
677 ::hegel::Settings(__VA_ARGS__)) { \
678 ::hegel::internal::test_from_macro( \
679 hegel_test_body_##name, \
680 ::hegel::TestLocation{#name, __FILE__, __LINE__}, settings, \
681 ::hegel::internal::reproduce_blobs_for(__FILE__ "::" #name), \
682 ::hegel::internal::explicit_cases_for(__FILE__ "::" #name)); \
684 static void hegel_test_body_##name
722#define HEGEL_MAIN(name, ...) \
723 static void hegel_test_body_##name(::hegel::TestCase&); \
724 int main(int argc, char** argv) { \
725 return ::hegel::internal::main_from_macro( \
726 argc, argv, hegel_test_body_##name, \
727 ::hegel::TestLocation{#name, __FILE__, __LINE__}, \
728 [] { return ::hegel::Settings(__VA_ARGS__); }, \
729 ::hegel::internal::reproduce_blobs_for(__FILE__ "::" #name), \
730 ::hegel::internal::explicit_cases_for(__FILE__ "::" #name)); \
732 static void hegel_test_body_##name
760#define HEGEL_REPRODUCE_FAILURE(name, blob, ...) \
761 [[maybe_unused]] static const bool hegel_reproduce_registered_##name = \
762 ::hegel::internal::register_blob(__FILE__ "::" #name, \
763 {blob, __VA_ARGS__});
766#define HEGEL_CONCAT_IMPL(a, b) a##b
767#define HEGEL_CONCAT(a, b) HEGEL_CONCAT_IMPL(a, b)
791#define HEGEL_EXPLICIT_TEST_CASE(name, ...) \
792 [[maybe_unused]] static const bool HEGEL_CONCAT( \
793 hegel_explicit_registered_##name##_, __LINE__) = \
794 ::hegel::internal::register_explicit_case( \
795 __FILE__ "::" #name, ::hegel::ExplicitTestCase(__VA_ARGS__));
800#if defined(GTEST_TEST)
FailureOrigin(const FailureOrigin &)=default
Copy-constructs. An origin holds no state of its own.
virtual std::string failure_origin() const =0
The origin grouping this failure.
FailureOrigin & operator=(const FailureOrigin &)=default
Handle to the currently-executing test case.
Definition test_case.h:46
Main namespace.
Definition config.h:29
void test(const std::function< void(TestCase &)> &test_fn, const Settings &settings={}, const std::vector< std::string > &failure_blobs={}, const std::vector< ExplicitTestCase > &explicit_cases={}, const char *caller_file=HEGEL_CALLER_FILE, const char *caller_function=HEGEL_CALLER_FUNCTION, int caller_line=HEGEL_CALLER_LINE)
Run a Hegel test.
Configuration options for hegel::test().
Definition settings.h:180
Where a test is defined.
Definition hegel.h:476
int line
Line the test is defined on.
Definition hegel.h:482
std::string name
Test name.
Definition hegel.h:478
std::string file
Source file the test is defined in.
Definition hegel.h:480