ScopedDiagnosticChecker#

Fully qualified name: usdex::test::ScopedDiagnosticChecker

class ScopedDiagnosticChecker#

A scoped class to capture and assert expected TfDiagnostics and TfErrorMarks for use in a doctest suite.

Construct a ScopedDiagnosticChecker and a list of expected diagnostic messages.

Each DiagnosticPattern must contain:

  • One TfDiagnosticType (e.g TF_DIAGNOSTIC_STATUS_TYPE)

  • A regex pattern matching the expected diagnostic commentary (message)

On context exit, the ScopedDiagnosticChecker will assert that all expected TfDiagnostics and TfErrorMarks were emmitted.

Example:

#include <usdex/test/ScopedDiagnosticChecker.h>
#include <pxr/base/tf/diagnostic.h>

#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#include <doctest/doctest.h>

using namespace pxr;

TEST_CASE("My Test Case")
{
    {
        usdex::test::ScopedDiagnosticChecker check({ { TF_DIAGNOSTIC_WARNING_TYPE, ".*foo" } });
        TF_WARN("This message ends in foo");
    }
}

Note

TfErrorMarks will be diagnosed before any general TfDiagnostics. The supplied list of expected values should account for this.

Public Types

using DiagnosticPatterns = std::vector<std::pair<pxr::TfEnum, std::string>>#

A vector of expected TfDiagnosticTypes and std::regex compliant match patterns.

Public Functions

ScopedDiagnosticChecker() = default#

Construct a default ScopedDiagnosticChecker to assert that no TfDiagnostics or TfErrorMarks are emitted.

inline ScopedDiagnosticChecker(DiagnosticPatterns expected)#

Construct a ScopedDiagnosticChecker with a vector of expected DiagnosticPattern pairs.

inline ~ScopedDiagnosticChecker()#

On destruction the ScopedDiagnosticChecker will assert the expected TfDiagnostics and TfErrorMarks were emitted using doctest CHECK