Skip to content

DAS plugins - rule testing - simpler setup for stubbing a package #61079

@srawlins

Description

@srawlins

Right now a (lint) rule test can stub out a package in the setUp method like so:

  void setUp() {
    super.setUp();

    var matcherPath = '/packages/matcher';
    newFile('$matcherPath/lib/matcher.dart', '''
void expect(dynamic actual, dynamic matcher) {}

const isNotNull = 0;
const isNull = 0;
''');
    writeTestPackageConfig(
      PackageConfigFileBuilder()
        ..add(name: 'matcher', rootPath: convertPath(matcherPath)),
    );
  }

This could be made simpler, without much complexity. But it might be nice to discuss design for a moment.

The basic idea is that certain lint rules might check things like "Is this SimpleIdentifier spelled 'expect'? And is this SimpleIdentifier from the 'matcher' package?". And those checks should work on mock/stub packages (in a test) or on real ones. And test code needs to be able to refer to 'expect' from the 'matcher' package.

So you want to be able to write one or more files in a separate package, such that those files can be imported with a package: syntax. And those files should be written to file system, and also the package should be added to the test package config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestanalyzer-apiIssues that impact the public API of the analyzer packagearea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions