import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; /// Window content takes input only inside its window (see `WindowNavigator`), /// so a menu panel, which may extend past the window, must be in the root /// overlay. Any content can end up in a window, so the app's menus are all /// `AppMenuAnchor`, the one place a `MenuAnchor` is built. void main() { test('MenuAnchor is used only through AppMenuAnchor', () { final offenders = []; for (final file in Directory('lib').listSync(recursive: true)) { if (file is! File || !file.path.endsWith('.dart')) continue; if (file.path.endsWith('ui/adaptive/app_menu_anchor.dart')) continue; final source = file.readAsStringSync(); for (final match in RegExp(r'\bMenuAnchor\(').allMatches(source)) { if (match.start > 0 && source[match.start - 1] == 'p') continue; final line = '\n'.allMatches(source.substring(0, match.start)).length; offenders.add('${file.path}:${line + 1}'); } } expect(offenders, isEmpty); }); }