Skip to content

Check cross imports test subfolders#185493

Merged
auto-submit[bot] merged 40 commits into
flutter:masterfrom
navaronbracke:check_cross_imports_test_subfolders
Apr 30, 2026
Merged

Check cross imports test subfolders#185493
auto-submit[bot] merged 40 commits into
flutter:masterfrom
navaronbracke:check_cross_imports_test_subfolders

Conversation

@navaronbracke

@navaronbracke navaronbracke commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

This PR extends the tests cross imports check to also verify cross imports in flutter/test itself and its subdirectories. It now also validates .dart files, such as flutter/test/gesture_utils.dart, instead of only _test.dart files.

The underlying test was rewritten a bit to accomodate this.
The known cross imports have been rebaselined, to account for the new checks.

Currently the cross imports check does not validate subdirectories of flutter/test/xyz (for example flutter/test/gestures/utils), because at this time there are no such subdirectories, beyond directories inside flutter/test itself.

Fixes #185464

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@navaronbracke navaronbracke requested a review from justinmc April 23, 2026 19:27
@google-cla

google-cla Bot commented Apr 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.


void main() {
late TestsCrossImportChecker checker;
late Directory testWidgetsDirectory;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

testWidget/testCupertino have moved and are now grouped with related directories to check

}
}

File getFile(String filepath, Directory directory) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is moved from the function above

/// Writes [importString] into the given [filePaths] in [inDirectory].
///
/// The default [importString] is `import 'package:flutter/material.dart';`.
void writeImportInFiles(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a refactor of the original for-loop, so that we can specify the directory / import string


// A utility that keeps track of the directories under test,
// to avoid having to late initialize them individually in `setUp()`.
class _CrossImportsTestDirectories {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since we now have a bunch more dirs to check, I opted to group this here

// - a shortened directory name of the test folder for the library, without the `flutter/` prefix
// - the name of the known cross imports list variable in `check_tests_cross_imports.dart` for that library
// - the actual known cross imports list for that library
// dart format off

@navaronbracke navaronbracke Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The max line length is 100, but this goes over that a little bit :/

I do like it formatted like this, though, but I can remove the dart format comment if requested

}
}

for (final filepath in extraWidgetsImportingMaterial) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was moved out of this function and is now done by the tests themselves

expect(success, isTrue);
});

test('when not all widgets knowns have cross imports', () async {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test and when not all cupertino knowns have cross imports are now the same test

});
final String excludedSample = knownCrossImports.first;

test('unknown Widgets cross import of Material', () async {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test and unknown Widgets cross import of Cupertino/ unknown Cupertino cross importing Material are now the same test, but with support for the other directories, and the test cases switch between "Material" and "Cupertino"

@navaronbracke navaronbracke force-pushed the check_cross_imports_test_subfolders branch from 1c30f10 to 9e908d4 Compare April 23, 2026 20:08
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Apr 29, 2026
@navaronbracke navaronbracke force-pushed the check_cross_imports_test_subfolders branch from e822137 to a54ac41 Compare April 29, 2026 10:33
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 29, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Apr 29, 2026
@navaronbracke navaronbracke marked this pull request as ready for review April 29, 2026 10:51

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the cross-import checker to support all subdirectories within packages/flutter/test, replacing the previous hardcoded focus on the widgets and cupertino libraries. It introduces a sealed class hierarchy for libraries and expands the sets of known cross-imports to cover the entire test suite. Review feedback identifies a duplicate entry in the painting cross-imports list and suggests updating an assertion message to align with the expanded scope of the tool.

Comment thread dev/bots/check_tests_cross_imports.dart
Comment thread dev/bots/check_tests_cross_imports.dart Outdated
@navaronbracke navaronbracke requested a review from Piinks April 29, 2026 10:54
expect(success, isFalse);
});

test('multiple unknown $libraryName cross imports of Material', () async {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We didn't actually validate the error messages for N+1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch!

expect(success, isFalse);
});

test('unknown $libraryName cross import of Material in non-test file', () async {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a regression test for the updated file regex

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 29, 2026
Piinks
Piinks previously approved these changes Apr 29, 2026

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This LGTM - G recommended adding these additional regression tests:

Regression tests
test('TestsCrossImportChecker ignores non-Dart files even if path contains .dart', () async {
    final fs = MemoryFileSystem();

    // Create a mock Flutter root and test directory
    final Directory flutterRoot = fs.directory('/flutter')..createSync();
    final Directory testsDir =
        flutterRoot.childDirectory('packages').childDirectory('flutter').childDirectory('test')
          ..createSync(recursive: true);

    // Create a directory that has '.dart' in its name
    final Directory specialDir = testsDir.childDirectory('widgets.dart_utils')..createSync();

    // Create a non-Dart file in that directory with a disallowed import
    // If the checker incorrectly matches this file, it will fail the check.
    final File nonDartFile = specialDir.childFile('README.txt')..createSync();
    nonDartFile.writeAsStringSync("import 'package:flutter/material.dart';");

    final checker = TestsCrossImportChecker(
      testsDirectory: testsDir,
      flutterRoot: flutterRoot,
      filesystem: fs,
    );

    // We don't need to 'capture' output here since we expect success (no errors printed)
    final bool success = checker.check();

    expect(
      success,
      isTrue,
      reason: 'The checker should have ignored README.txt despite the disallowed import.',
    );
  });

  test('TestsCrossImportChecker still catches disallowed imports in actual .dart files', () async {
    final fs = MemoryFileSystem();
    final Directory flutterRoot = fs.directory('/flutter')..createSync();
    final Directory testsDir =
        flutterRoot.childDirectory('packages').childDirectory('flutter').childDirectory('test')
          ..createSync(recursive: true);

    final Directory widgetsDir = testsDir.childDirectory('widgets')..createSync();
    final File testFile = widgetsDir.childFile('foo_test.dart')..createSync();
    testFile.writeAsStringSync("import 'package:flutter/material.dart';");

    final checker = TestsCrossImportChecker(
      testsDirectory: testsDir,
      flutterRoot: flutterRoot,
      filesystem: fs,
    );

    final bool success = checker.check();
    expect(
      success,
      isFalse,
      reason: 'The checker should have caught the disallowed import in a .dart file.',
    );
  });

Comment thread dev/bots/check_tests_cross_imports.dart
expect(success, isFalse);
});

test('multiple unknown $libraryName cross imports of Material', () async {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch!

@navaronbracke

Copy link
Copy Markdown
Contributor Author

The test TestsCrossImportChecker still catches disallowed imports in actual .dart files seems a bit redundant to me though, since the existing tests that verify the error output already cover that.

But I do agree about the other suggestions!

@navaronbracke

Copy link
Copy Markdown
Contributor Author

Added the tests!

@navaronbracke navaronbracke requested a review from Piinks April 29, 2026 17:46
Piinks
Piinks previously approved these changes Apr 29, 2026

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

AbdeMohlbi
AbdeMohlbi previously approved these changes Apr 29, 2026
@navaronbracke

Copy link
Copy Markdown
Contributor Author

Ahhh, Windows path separators!

@navaronbracke navaronbracke force-pushed the check_cross_imports_test_subfolders branch from 13aab6f to 8f8b0bf Compare April 30, 2026 09:38
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 30, 2026
@navaronbracke navaronbracke added the CICD Run CI/CD label Apr 30, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 30, 2026
@navaronbracke

Copy link
Copy Markdown
Contributor Author

There was a small mistake around the test expectation still. I'll do a dry run of the tests on my Windows machine, before stamping this with the CICD label again.

@navaronbracke navaronbracke added the CICD Run CI/CD label Apr 30, 2026
@navaronbracke

Copy link
Copy Markdown
Contributor Author

Passes locally on my Windows machine now, so we can try this again.

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@AbdeMohlbi AbdeMohlbi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mask LGTM

@navaronbracke navaronbracke added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 30, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Apr 30, 2026
Merged via the queue into flutter:master with commit 2e1cbe2 Apr 30, 2026
170 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 30, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request May 1, 2026
Roll Flutter from 81bc3d69535f to 707dbc0420a3 (85 revisions)

flutter/flutter@81bc3d6...707dbc0

2026-05-01 [email protected] Removing TODOs from the WebParagraph code and addressing technical debts. (flutter/flutter#185168)
2026-05-01 [email protected] Ensure that vulkan_interface.h gets included before vk_mem_alloc.h (flutter/flutter#185777)
2026-05-01 [email protected] [flutter_tools] Bump dwds dependency to v27.1.1 (flutter/flutter#185357)
2026-05-01 [email protected] Roll Dart SDK from 6d4a319cbdac to 9aa7097f2e3e (3 revisions) (flutter/flutter#185888)
2026-05-01 [email protected] Roll Skia from fa1dcb289709 to 7ac6d42f2fd0 (1 revision) (flutter/flutter#185887)
2026-05-01 [email protected] Roll Skia from 54cc00adde38 to fa1dcb289709 (3 revisions) (flutter/flutter#185880)
2026-05-01 [email protected] [iOS] Migrate to FlutterFMLTaskRunner(s) (flutter/flutter#185815)
2026-05-01 [email protected] Remove material imports from navigator_on_did_remove_page_test and scrollable_in_overlay_test (flutter/flutter#182546)
2026-05-01 [email protected] Roll Skia from 2e279266f06a to 54cc00adde38 (3 revisions) (flutter/flutter#185872)
2026-05-01 [email protected] dev: Remove unused parameters (flutter/flutter#185345)
2026-05-01 [email protected] Roll Fuchsia Linux SDK from HN5VYzftnf_B8T-n9... to VnzuUefDQR0UhQ1L1... (flutter/flutter#185870)
2026-05-01 [email protected] Use g_free when using glib memory allocation (flutter/flutter#185519)
2026-05-01 [email protected] Roll Dart SDK from d30df3428f2e to 6d4a319cbdac (2 revisions) (flutter/flutter#185862)
2026-05-01 [email protected] Remove trivial test utility cross-imports from material and cupertino… (flutter/flutter#184295)
2026-05-01 [email protected] Inline test callback painter in tab scaffold test (flutter/flutter#184851)
2026-05-01 [email protected] [a11y] Add support for high contrast themes in the a11y assessments app  (flutter/flutter#185801)
2026-05-01 [email protected] [a11y assessment app] Use default color for banner (flutter/flutter#185804)
2026-04-30 [email protected] Added name to AUTHORS (flutter/flutter#185586)
2026-04-30 [email protected] Remove semantics_tester import from raw_material_button_test.dart (flutter/flutter#184806)
2026-04-30 [email protected] Remove semantics_tester import from user_accounts_drawer_header_test.dart (flutter/flutter#184809)
2026-04-30 [email protected] Roll Skia from 7b88c5c281e5 to 2e279266f06a (5 revisions) (flutter/flutter#185854)
2026-04-30 [email protected] Handle symmetric rectangular and elliptical round super ellipses in the uber SDF renderer  (flutter/flutter#185695)
2026-04-30 [email protected] Match on process name before killing for SwiftPM (flutter/flutter#185774)
2026-04-30 [email protected] Sync CHANGELOG.md from stable (flutter/flutter#185838)
2026-04-30 [email protected] Roll Dart SDK from 25910e31a6d2 to d30df3428f2e (5 revisions) (flutter/flutter#185839)
2026-04-30 [email protected] Check cross imports test subfolders (flutter/flutter#185493)
2026-04-30 [email protected] test: inline TestCallbackPainter in cupertino/picker_test.dart (flutter/flutter#185398)
2026-04-30 [email protected] Update customer testing version (flutter/flutter#185830)
2026-04-30 [email protected] Adapt the Metal shader library output list for debug versus release mode (flutter/flutter#185798)
2026-04-30 [email protected] [Impeller] Port a recent Vulkan swapchain fence waiting fix to the AHB version of the swapchain (flutter/flutter#185763)
2026-04-30 [email protected] Roll Skia from 26a59aa71eff to 7b88c5c281e5 (1 revision) (flutter/flutter#185821)
2026-04-30 [email protected] Roll Skia from 6b4167b4e204 to 26a59aa71eff (4 revisions) (flutter/flutter#185808)
2026-04-30 [email protected] [a11y] Mark SemanticsNode dirty when customSemanticsActions change  (flutter/flutter#185707)
2026-04-30 [email protected] Roll Skia from 1bd2f1cc2746 to 6b4167b4e204 (8 revisions) (flutter/flutter#185799)
2026-04-30 [email protected] [iOS] Extract FlutterVSyncClient from vsync_waiter_ios (flutter/flutter#185737)
2026-04-30 [email protected] Roll Fuchsia Linux SDK from nnv8-SSam6yE8dw4z... to HN5VYzftnf_B8T-n9... (flutter/flutter#185782)
2026-04-29 [email protected] [iOS] Soften TaskRunner.postTask(delay:task:) delay check (flutter/flutter#185729)
2026-04-29 [email protected] Add reportErrors to ImageStreamListener (flutter/flutter#180327)
2026-04-29 [email protected] Roll Skia from f5c781c083c7 to 1bd2f1cc2746 (5 revisions) (flutter/flutter#185761)
2026-04-29 [email protected] Update merge semantics logic to merge sibling nodes (flutter/flutter#183745)
2026-04-29 [email protected] Roll Packages from ba80f8f to cde5b36 (12 revisions) (flutter/flutter#185748)
2026-04-29 [email protected] examples: Remove unused parameters (flutter/flutter#185346)
2026-04-29 [email protected] Update TickerMode.getValuesNotifier to handle initialization during State.dispose (flutter/flutter#185248)
2026-04-29 [email protected] Update triage links (flutter/flutter#185714)
2026-04-29 [email protected] Add support for high contrast and color inversion on Android (flutter/flutter#182263)
2026-04-29 [email protected] Roll Skia from 05251260fda6 to f5c781c083c7 (2 revisions) (flutter/flutter#185743)
...
@navaronbracke navaronbracke deleted the check_cross_imports_test_subfolders branch May 6, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(Test cross-imports) The cross imports checker does not verify cross imports in flutter/xyz directories

3 participants