compiles top-level property

_CompileMatcher compiles
final

Analyze a Code instance and verify that it has no error.

If the code contains comments under the form of // expect-error: ERROR_CODE, compiles will expect that the very next line of code has an error with the matching code.

If an // expect-error is added, but the next line doesn't have an error with the matching code, the expectation will fail. If the code has an error without a matching // expect-error on the previous line, the expectation will also fail. Otherwise, the expectation will pass.

A common usage would be:

import 'package:expect_error/src/expect_error.dart';
import 'package:test/test.dart';

Future<void> main() async {
  final library = await Library.parseFromStacktrace();

  test('String is not assignable to int', () async {
    await expectLater(library.withCode('''
class Counter {
  int count = 0;
}

void main() {
  final counter = Counter();
  // expect-error: INVALID_ASSIGNMENT
  counter.count = 'string';
}
'''), compiles);
  });
}

Implementation

final compiles = _CompileMatcher();