Minetest  5.4.0
test.h File Reference
#include <exception>
#include <vector>
#include "irrlichttypes_extrabloated.h"
#include "porting.h"
#include "filesys.h"
#include "mapnode.h"
+ Include dependency graph for test.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  TestFailedException
 
class  TestBase
 
class  TestManager
 

Macros

#define TEST(fxn, ...)
 
#define UASSERT(x)
 
#define UTEST(x, fmt, ...)
 
#define UASSERTCMP(T, CMP, actual, expected)
 
#define UASSERTEQ(T, actual, expected)   UASSERTCMP(T, ==, actual, expected)
 
#define EXCEPTION_CHECK(EType, code)
 

Functions

bool run_tests ()
 

Variables

content_t t_CONTENT_STONE
 
content_t t_CONTENT_GRASS
 
content_t t_CONTENT_TORCH
 
content_t t_CONTENT_WATER
 
content_t t_CONTENT_LAVA
 
content_t t_CONTENT_BRICK
 

Macro Definition Documentation

◆ EXCEPTION_CHECK

#define EXCEPTION_CHECK (   EType,
  code 
)
Value:
{ \
bool exception_thrown = false; \
try { \
code; \
} catch (EType &e) { \
exception_thrown = true; \
} \
UASSERT(exception_thrown); \
}

◆ TEST

#define TEST (   fxn,
  ... 
)
Value:
{ \
u64 t1 = porting::getTimeMs(); \
try { \
fxn(__VA_ARGS__); \
rawstream << "[PASS] "; \
} catch (TestFailedException &e) { \
rawstream << "[FAIL] "; \
num_tests_failed++; \
} catch (std::exception &e) { \
rawstream << "Caught unhandled exception: " << e.what() << std::endl; \
rawstream << "[FAIL] "; \
num_tests_failed++; \
} \
num_tests_run++; \
u64 tdiff = porting::getTimeMs() - t1; \
rawstream << #fxn << " - " << tdiff << "ms" << std::endl; \
}
Definition: test.h:30
u64 getTimeMs()
Definition: porting.h:233

◆ UASSERT

#define UASSERT (   x)
Value:
if (!(x)) { \
rawstream << "Test assertion failed: " #x << std::endl \
<< " at " << fs::GetFilenameFromPath(__FILE__) \
<< ":" << __LINE__ << std::endl; \
}
const char * GetFilenameFromPath(const char *path)
Definition: filesys.cpp:668

◆ UASSERTCMP

#define UASSERTCMP (   T,
  CMP,
  actual,
  expected 
)
Value:
{ \
T a = (actual); \
T e = (expected); \
if (!(a CMP e)) { \
rawstream \
<< "Test assertion failed: " << #actual << " " << #CMP << " " \
<< #expected << std::endl \
<< " at " << fs::GetFilenameFromPath(__FILE__) << ":" \
<< __LINE__ << std::endl \
<< " actual: " << a << std::endl << " expected: " \
<< e << std::endl; \
} \
}

◆ UASSERTEQ

#define UASSERTEQ (   T,
  actual,
  expected 
)    UASSERTCMP(T, ==, actual, expected)

◆ UTEST

#define UTEST (   x,
  fmt,
  ... 
)
Value:
if (!(x)) { \
char utest_buf[1024]; \
snprintf(utest_buf, sizeof(utest_buf), fmt, __VA_ARGS__); \
rawstream << "Test assertion failed: " << utest_buf << std::endl \
<< " at " << fs::GetFilenameFromPath(__FILE__) \
<< ":" << __LINE__ << std::endl; \
}

Function Documentation

◆ run_tests()

bool run_tests ( )

References g_logger, TestManager::getTestModules(), porting::getTimeMs(), LL_ERROR, rawstream, and Logger::setLevelSilenced().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ t_CONTENT_BRICK

◆ t_CONTENT_GRASS

◆ t_CONTENT_LAVA

◆ t_CONTENT_STONE

◆ t_CONTENT_TORCH

◆ t_CONTENT_WATER