@@ -88,6 +88,9 @@ Future<void> run(List<String> arguments) async {
8888 exitWithError (< String > ['The analyze.dart script must be run with --enable-asserts.' ]);
8989 }
9090
91+ print ('$clock All tool test files end in _test.dart...' );
92+ await verifyToolTestsEndInTestDart (flutterRoot);
93+
9194 print ('$clock No sync*/async*' );
9295 await verifyNoSyncAsyncStar (flutterPackages);
9396 await verifyNoSyncAsyncStar (flutterExamples, minimumMatches: 200 );
@@ -197,6 +200,53 @@ Future<void> run(List<String> arguments) async {
197200
198201// TESTS
199202
203+ /// Verify tool test files end in `_test.dart` .
204+ ///
205+ /// The test runner will only recognize files ending in `_test.dart` as tests to
206+ /// be run: https://github.com/dart-lang/test/tree/master/pkgs/test#running-tests
207+ Future <void > verifyToolTestsEndInTestDart (String workingDirectory) async {
208+ final String toolsTestPath = path.join (
209+ workingDirectory,
210+ 'packages' ,
211+ 'flutter_tools' ,
212+ 'test' ,
213+ );
214+ final List <String > violations = < String > [];
215+
216+ // detect files that contains calls to test(), testUsingContext(), and testWithoutContext()
217+ final RegExp callsTestFunctionPattern = RegExp (r'(test\(.*\)|testUsingContext\(.*\)|testWithoutContext\(.*\))' );
218+
219+ await for (final File file in _allFiles (toolsTestPath, 'dart' , minimumMatches: 300 )) {
220+ final bool isValidTestFile = file.path.endsWith ('_test.dart' );
221+ if (isValidTestFile) {
222+ continue ;
223+ }
224+
225+ final bool isTestData = file.path.contains (r'test_data' );
226+ if (isTestData) {
227+ continue ;
228+ }
229+
230+ final bool isInTestShard = file.path.contains (r'.shard/' );
231+ if (! isInTestShard) {
232+ continue ;
233+ }
234+
235+ final bool callsTestFunction = file.readAsStringSync ().contains (callsTestFunctionPattern);
236+ if (! callsTestFunction) {
237+ continue ;
238+ }
239+
240+ violations.add (file.path);
241+ }
242+ if (violations.isNotEmpty) {
243+ exitWithError (< String > [
244+ '${bold }Found flutter_tools tests that do not end in `_test.dart`; these will not be run by the test runner$reset ' ,
245+ ...violations,
246+ ]);
247+ }
248+ }
249+
200250Future <void > verifyNoSyncAsyncStar (String workingDirectory, {int minimumMatches = 2000 }) async {
201251 final RegExp syncPattern = RegExp (r'\s*?a?sync\*\s*?{' );
202252 final RegExp ignorePattern = RegExp (r'^\s*?// The following uses a?sync\* because:? ' );
0 commit comments