Files
nvbench/testing/test_asserts.cuh
Allison Vacanti ad44463d6e Replace params class with nvbench::named_values.
Refactor nvbench::state to use this for axis parameters.

These will also be useful for summaries and measurements.

Also adds a new ASSERT_THROWS_ANY macro to test some of the new API.
2020-12-30 14:45:46 -05:00

54 lines
3.6 KiB
Plaintext

#pragma once
#include <fmt/format.h>
#define ASSERT(cond) \
do \
{ \
if (cond) \
{} \
else \
{ \
fmt::print("{}:{}: Assertion failed ({}).\n", __FILE__, __LINE__, #cond); \
exit(EXIT_FAILURE); \
} \
} while (false)
#define ASSERT_MSG(cond, fmtstr, ...) \
do \
{ \
if (cond) \
{} \
else \
{ \
fmt::print("{}:{}: Test assertion failed ({}) {}\n", \
__FILE__, \
__LINE__, \
#cond, \
fmt::format(fmtstr, __VA_ARGS__)); \
exit(EXIT_FAILURE); \
} \
} while (false)
#define ASSERT_THROWS_ANY(expr) \
do \
{ \
bool threw = false; \
try \
{ \
expr; \
} \
catch (...) \
{ \
threw = true; \
} \
if (!threw) \
{ \
fmt::print("{}:{}: Expression expected exception: '{}'.", \
__FILE__, \
__LINE__, \
#expr); \
exit(EXIT_FAILURE); \
} \
} while (false)