testRun method

  1. @visibleForTesting
Future<List<PrioritizedSourceChange>> testRun(
  1. ResolvedUnitResult result,
  2. SourceRange target, {
  3. Pubspec? pubspec,
})

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<PrioritizedSourceChange>> testRun(
  ResolvedUnitResult result,
  SourceRange target, {
  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 reporter = ChangeReporterImpl(result.session, resolver);

  await startUp(
    resolver,
    context,
    target,
  );

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

  return reporter.waitForCompletion();
}