assertExceptionFields function

void assertExceptionFields(
  1. MontyException exception,
  2. Map<String, dynamic> fixture
)

Asserts M7A exception fields on a MontyException against fixture expectations.

Checks these fixture keys (all optional — missing keys are no-ops):

  • expectedExcType — expected excType string
  • expectedTracebackMinFrames — minimum traceback frame count
  • expectedTracebackFrameHasFilename — first frame has non-empty filename
  • expectedErrorFilename — expected filename on the exception
  • expectedTracebackFilename — some frame has this filename

Implementation

void assertExceptionFields(
  MontyException exception,
  Map<String, dynamic> fixture,
) {
  final expectedExcType = fixture['expectedExcType'] as String?;
  if (expectedExcType != null) {
    expect(
      exception.excType,
      expectedExcType,
      reason: 'Fixture #${fixture['id']}: expected excType '
          '"$expectedExcType", got: "${exception.excType}"',
    );
  }

  final expectedMinFrames = fixture['expectedTracebackMinFrames'] as int?;
  if (expectedMinFrames != null) {
    final traceback = exception.traceback;
    expect(
      traceback.length,
      greaterThanOrEqualTo(expectedMinFrames),
      reason: 'Fixture #${fixture['id']}: expected >= $expectedMinFrames '
          'traceback frames, got: ${traceback.length}',
    );
  }

  if (fixture['expectedTracebackFrameHasFilename'] == true &&
      exception.traceback.isNotEmpty) {
    expect(
      exception.traceback.first.filename,
      isNotEmpty,
      reason: 'Fixture #${fixture['id']}: expected traceback frame '
          'to have non-empty filename',
    );
  }

  final expectedErrorFilename = fixture['expectedErrorFilename'] as String?;
  if (expectedErrorFilename != null) {
    expect(
      exception.filename,
      expectedErrorFilename,
      reason: 'Fixture #${fixture['id']}: expected error filename '
          '"$expectedErrorFilename", got: "${exception.filename}"',
    );
  }

  final expectedTracebackFilename =
      fixture['expectedTracebackFilename'] as String?;
  final tracebackFrames = exception.traceback;
  if (expectedTracebackFilename != null && tracebackFrames.isNotEmpty) {
    final hasFilename = tracebackFrames.any(
      (f) => f.filename == expectedTracebackFilename,
    );
    expect(
      hasFilename,
      isTrue,
      reason: 'Fixture #${fixture['id']}: expected traceback to contain '
          'frame with filename "$expectedTracebackFilename"',
    );
  }
}