testRun method

  1. @visibleForTesting
Future<List<AnalysisError>> testRun(
  1. ResolvedUnitResult result, {
  2. Pubspec? pubspec,
})
inherited

Runs this assist in test mode.

The result will contain all the changes that would have been applied by run.

The parameter pubspec can be used to simulate a pubspec file which will be passed to CustomLintContext.pubspec. By default, an empty pubspec with the name test_project will be used.

Implementation

@visibleForTesting
Future<List<AnalysisError>> testRun(
  ResolvedUnitResult result, {
  Pubspec? pubspec,
}) async {
  final registry = LintRuleNodeRegistry(
    NodeLintRegistry(LintRegistry(), enableTiming: false),
    'unknown',
  );
  final postRunCallbacks = <void Function()>[];
  final context = CustomLintContext(
    registry,
    postRunCallbacks.add,
    {},
    pubspec,
  );
  final resolver = CustomLintResolverImpl(
    () => Future.value(result),
    lineInfo: result.lineInfo,
    path: result.path,
    source: result.libraryElement.source,
  );

  final listener = RecordingErrorListener();
  final reporter = ErrorReporter(
    listener,
    result.libraryElement.source,
    isNonNullableByDefault: false,
  );

  await startUp(resolver, context);

  run(resolver, reporter, context);
  runPostRunCallbacks(postRunCallbacks);

  return listener.errors;
}