Class Failure

Inheritance Relationships

Derived Types

Class Documentation

class Failure
[source]

Holds location and message information for a single test failure.

Subclass Failure to provide richer diagnostic messages. The assertion macros construct the appropriate concrete subclass and pass it to Shell::add_failure().

Subclassed by mu::tiny::mock::Failure, mu::tiny::test::ApproxEqualFailure< T >, mu::tiny::test::BinaryEqualFailure, mu::tiny::test::CheckEqualFailure, mu::tiny::test::CheckFailure, mu::tiny::test::ComparisonFailure, mu::tiny::test::ContainsFailure, mu::tiny::test::EqualsFailure, mu::tiny::test::FailFailure, mu::tiny::test::FeatureUnsupportedFailure, mu::tiny::test::IntMaxEqualFailure, mu::tiny::test::StringEqualFailure, mu::tiny::test::StringEqualNoCaseFailure, mu::tiny::test::UintMaxEqualFailure, mu::tiny::test::UnexpectedExceptionFailure

Public Functions

Failure(Shell *test, const char *file_name, int_least32_t line_number, const String &the_message)

Construct with full location information and a message.

Parameters:
  • test – The test shell in which the failure occurred.

  • file_name – Source file of the failing assertion.

  • line_number – Line number of the failing assertion.

  • the_message – Human-readable failure description.

Failure(Shell *test, const String &the_message)

Construct with a message but no assertion location (test-level error).

Parameters:
  • test – The test shell in which the failure occurred.

  • the_message – Human-readable failure description.

Failure(Shell *test, const char *file_name, int_least32_t line_number)

Construct with a location but no message (location-only failure).

Parameters:
  • test – The test shell in which the failure occurred.

  • file_name – Source file of the failing assertion.

  • line_number – Line number of the failing assertion.

Failure(const Failure&) = default
Failure(Failure &&other) noexcept
virtual ~Failure() = default
[source]
virtual const String &get_file_name() const
Returns:

Source file of the failing assertion.

virtual const String &get_test_name() const
Returns:

Fully-qualified test name (group.case).

virtual const String &get_test_name_only() const
Returns:

Test case name without the group prefix.

virtual int_least32_t get_failure_line_number() const
Returns:

Line number of the failing assertion.

virtual const String &get_message() const
Returns:

Human-readable failure description.

virtual const String &get_test_file_name() const
Returns:

Source file in which the test is defined.

virtual int_least32_t get_test_line_number() const
Returns:

Line number of the TEST() macro for the failing test.

inline virtual bool is_error() const
Returns:

true if this failure represents an error (e.g. unexpected exception) rather than a normal assertion failure.

bool is_outside_test_file() const
Returns:

true if the failure originated outside the test’s source file.

bool is_in_helper_function() const
Returns:

true if the failure originated in a helper function.

Protected Functions

Failure &operator=(const Failure&)

Protected Attributes

String test_name_
String test_name_only_
String file_name_
int_least32_t line_number_
String test_file_name_
int_least32_t test_line_number_
String message_

Protected Static Functions

static String create_but_was_string(const String &expected, const String &actual)

Format a expected <X> but was <Y> string.

Parameters:
  • expected – Expected value as a string.

  • actual – Actual value as a string.

Returns:

Formatted comparison string.

static String create_difference_at_pos_string(const String &actual, size_t offset, size_t reported_position)

Format a difference starts at position N string.

Parameters:
  • actual – Actual string value.

  • offset – Byte offset where the difference starts.

  • reported_position – 1-based position to report to the user.

Returns:

Formatted difference-position string.

static String create_user_text(const String &text)

Wrap a user-supplied text string for inclusion in a failure message.

Parameters:

text – User text from the _TEXT variant of an assertion.

Returns:

Formatted user-text string, or empty if text is empty.