Graphle 1.0.0
A C++20 header-only graph library
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Functions
test_framework.hpp File Reference
#include <vector>
#include <string_view>
#include <iostream>
#include <source_location>
#include <format>
#include <functional>

Go to the source code of this file.

Classes

struct  graphle::test::assertion_failure
 
class  graphle::test::test_registry
 
struct  graphle::test::subtest_scope_handler
 

Namespaces

namespace  graphle
 
namespace  graphle::test
 

Macros

#define GRAPHLE_CAT_1(A, B)   A##B
 
#define GRAPHLE_CAT(A, B)   GRAPHLE_CAT_1(A, B)
 
#define GRAPHLE_TEST_DONT_CATCH_ERRORS   "Not Defined"
 
#define TEST(Suite, Name)
 
#define SUBTEST_SCOPE(Name)   if (auto impl_scope_object = graphle::test::subtest_scope_handler { Name }; true)
 
#define FAIL(...)   throw graphle::test::assertion_failure { __VA_ARGS__ }
 
#define ASSERT_TRUE(...)   if (!bool(__VA_ARGS__)) FAIL(#__VA_ARGS__)
 
#define ASSERT_FALSE(...)   if (bool(__VA_ARGS__)) FAIL(#__VA_ARGS__)
 

Typedefs

template<typename R , typename... A>
using graphle::test::fn = R(*)(A...)
 

Functions

void graphle::test::emit_test_success (std::string_view name)
 
void graphle::test::emit_test_failure (std::string_view name, const auto &failure)
 
int main (void)
 

Macro Definition Documentation

◆ ASSERT_FALSE

#define ASSERT_FALSE (   ...)    if (bool(__VA_ARGS__)) FAIL(#__VA_ARGS__)

Fails the current test if the given condition is true.

Definition at line 74 of file test_framework.hpp.

◆ ASSERT_TRUE

#define ASSERT_TRUE (   ...)    if (!bool(__VA_ARGS__)) FAIL(#__VA_ARGS__)

Fails the current test if the given condition is not true.

Definition at line 67 of file test_framework.hpp.

◆ FAIL

#define FAIL (   ...)    throw graphle::test::assertion_failure { __VA_ARGS__ }

Fails the current test with the given message.

Definition at line 60 of file test_framework.hpp.

◆ GRAPHLE_CAT

#define GRAPHLE_CAT (   A,
  B 
)    GRAPHLE_CAT_1(A, B)

Definition at line 12 of file test_framework.hpp.

◆ GRAPHLE_CAT_1

#define GRAPHLE_CAT_1 (   A,
  B 
)    A##B

Definition at line 11 of file test_framework.hpp.

◆ SUBTEST_SCOPE

#define SUBTEST_SCOPE (   Name)    if (auto impl_scope_object = graphle::test::subtest_scope_handler { Name }; true)

Defines a subscope of the current test which will have a separate success or error message logged.

Definition at line 51 of file test_framework.hpp.

◆ TEST

#define TEST (   Suite,
  Name 
)
Value:
struct test_##Suite_##Name { \
static void main(void); \
\
static inline auto autoregister = [] { \
graphle::test::test_registry::instance() \
.register_test( \
#Suite, \
#Name, \
&test_##Suite_##Name::main); \
\
return 0; \
} (); \
}; \
\
void test_##Suite_##Name::main(void)
int main(void)

Defines a new test with the given suite and name which will be invoked when tests are run.

Definition at line 29 of file test_framework.hpp.

Function Documentation

◆ main()

int main ( void  )

Test framework entry point. Runs all registered tests.

Definition at line 224 of file test_framework.hpp.