runErrorFixture function

Future<void> runErrorFixture(
  1. MontyPlatform platform,
  2. String code,
  3. Map<String, dynamic> fixture
)

Runs an error fixture through platform, expecting MontyException.

Implementation

Future<void> runErrorFixture(
  MontyPlatform platform,
  String code,
  Map<String, dynamic> fixture,
) async {
  final scriptName = fixture['scriptName'] as String?;
  try {
    await platform.run(code, scriptName: scriptName);
    fail('Expected MontyException but run() succeeded');
  } on MontyException catch (e) {
    final errorContains = fixture['errorContains'] as String?;
    if (errorContains != null) {
      final fullError = e.toString();
      expect(
        fullError.contains(errorContains),
        isTrue,
        reason: 'Expected error to contain "$errorContains", '
            'got: "$fullError"',
      );
    }

    assertExceptionFields(e, fixture);
  }
}