assertExceptionFields function
Asserts M7A exception fields on a MontyException against fixture expectations.
Checks these fixture keys (all optional — missing keys are no-ops):
expectedExcType— expectedexcTypestringexpectedTracebackMinFrames— minimum traceback frame countexpectedTracebackFrameHasFilename— first frame has non-empty filenameexpectedErrorFilename— expectedfilenameon the exceptionexpectedTracebackFilename— 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"',
);
}
}