Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Nov 18, 2025

This PR adds a lint rule to catch imports between Material, Cupertino, and Widgets in tests. Spun out of #177029 and the Decoupling Tests design doc.

For now, Material will be the place to put tests that need to import both Material and Cupertino. See #178693 (comment).

I used #130523 as a reference to create this PR.

Still some cleanup to do. Need to error when a test in the "known" list
is not found anymore.
@justinmc justinmc self-assigned this Nov 18, 2025
filesByLibrary[Library.cupertino]!,
Library.material,
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Material importing Cupertino?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Material importing Cupertino is allowed, at least for now. Material will continue to contain platform adaptive code (like Switch.adaptive), and it will also be responsible for testing interactions that involve both Material and Cupertino.

@justinmc justinmc marked this pull request as ready for review December 2, 2025 22:12
///
/// The Material library should contain tests that verify behaviors involving
/// multiple libraries, such as platform adaptivity. Otherwise, these libraries
/// should not import each other in tests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the bullet point rules in the "Overview" section of your flutter.dev/go/decoupling-framework-tests doc:

  • The Cupertino library/tests should never import Material. It should test its widgets under a full-Cupertino scenario.
  • The Material library should test its widgets in a full-Material scenario.
  • Design languages are responsible for testing their interoperability with Widgets.
  • Tests that cover interoperability between Material and Cupertino should go in Material. See the next section for when and how interoperability should be tested.
  • The Widgets library/tests should never import Cupertino or Material.

What do you think of copying the bullet point rules here? I don't feel strongly about this, feel free to skip.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, I hope we can properly communicate the ideas in that design doc. This also reminded me to create an issue (#179429) about explaining this sort of thing in the test README files.

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

/// Returns the Set of paths in `knownPaths` that are not in `files`.
static Set<String> _differencePaths(Set<String> knownPaths, Set<File> files) {
final Set<String> testPaths = files.map((File file) {
final prefix = RegExp('packages.flutter.test');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work?

Suggested change
final prefix = RegExp('packages.flutter.test');
final prefix = RegExp('packages[\/\\]flutter[\/\\]test');

I'm OK with the current solution though 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you update this, don't forget to also update _getUnknowns too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, more strict!

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 30, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Dec 30, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Dec 30, 2025

autosubmit label was removed for flutter/flutter/178693, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 30, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Dec 30, 2025
Merged via the queue into flutter:master with commit d37058b Dec 30, 2025
149 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Dec 30, 2025
@justinmc justinmc deleted the cross-import-lint branch December 30, 2025 20:40
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 1, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants