Drake
Drake C++ Documentation
expect_no_throw.h File Reference
#include <exception>
#include <gtest/gtest.h>
#include "drake/common/nice_type_name.h"
Include dependency graph for expect_no_throw.h:
This graph shows which files directly or indirectly include this file:

Macros

#define _DRAKE_TEST_NO_THROW(statement, fail_macro)
 
#define DRAKE_EXPECT_NO_THROW(statement)   _DRAKE_TEST_NO_THROW(statement, ADD_FAILURE)
 Unittest helper to explicitly indicate that a statement should not throw an exception. More...
 
#define DRAKE_ASSERT_NO_THROW(statement)   _DRAKE_TEST_NO_THROW(statement, GTEST_FAIL)
 Same as DRAKE_EXPECT_NO_THROW, but halts the execution of the given test case on failure. More...
 

Macro Definition Documentation

◆ _DRAKE_TEST_NO_THROW

#define _DRAKE_TEST_NO_THROW (   statement,
  fail_macro 
)
Value:
try { \
statement; \
} catch (const std::exception& e) { \
fail_macro() \
<< "Expected: Does not throw:\n " << #statement << std::endl \
<< "Actual: Throws " << ::drake::NiceTypeName::Get(e) << std::endl \
<< " " << e.what(); \
} catch (...) { \
fail_macro() \
<< "Expected: Does not throw:\n " << #statement << std::endl \
<< "Actual: Throws type which does not inherit from std::exception"; \
}
static std::string Get()
Returns a nicely demangled and canonicalized type name that is the same on all platforms,...
Definition: nice_type_name.h:51

◆ DRAKE_ASSERT_NO_THROW

#define DRAKE_ASSERT_NO_THROW (   statement)    _DRAKE_TEST_NO_THROW(statement, GTEST_FAIL)

Same as DRAKE_EXPECT_NO_THROW, but halts the execution of the given test case on failure.

◆ DRAKE_EXPECT_NO_THROW

#define DRAKE_EXPECT_NO_THROW (   statement)    _DRAKE_TEST_NO_THROW(statement, ADD_FAILURE)

Unittest helper to explicitly indicate that a statement should not throw an exception.

This should be used in place of EXPECT_NO_THROW because it will have useful information when a failure indeed happens.