Unverified Commit 41ff30c8 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Added a check to the analyzer script to detect skipped tests. (#88003)

Added a check to the analyzer script to detect skipped tests that aren't commented.

The comment following the `skip` parameter should include either a link to a
github issue tracking the reenabling of the test, or a '[intended]' tag with
a brief description of why the test should never be enabled for the given
condition.
parent b08366ce
......@@ -60,6 +60,9 @@ Future<void> run(List<String> arguments) async {
print('$clock Deprecations...');
await verifyDeprecations(flutterRoot);
print('$clock Skip test comments...');
await verifySkipTestComments(flutterRoot);
print('$clock Licenses...');
await verifyNoMissingLicense(flutterRoot);
......@@ -280,6 +283,38 @@ Future<void> _verifyNoMissingLicenseForExtension(String workingDirectory, String
}
}
final RegExp _skipTestCommentPattern = RegExp(r'\bskip:.*?//(.*)');
const Pattern _skipTestIntentionalPattern = '[intended]';
final Pattern _skipTestTrackingBugPattern = RegExp(r'https+?://github.com/.*/issues/[0-9]+');
Future<void> verifySkipTestComments(String workingDirectory) async {
final List<String> errors = <String>[];
final Stream<File> testFiles = _allFiles(workingDirectory, 'dart', minimumMatches: 1500)
.where((File f) => f.path.endsWith('_test.dart'));
await for (final File file in testFiles) {
final List<String> lines = file.readAsLinesSync();
for (int index = 0; index < lines.length; index++) {
final Match? match = _skipTestCommentPattern.firstMatch(lines[index]);
final String? skipComment = match?.group(1);
if (skipComment != null
&& !skipComment.contains(_skipTestIntentionalPattern)
&& !skipComment.contains(_skipTestTrackingBugPattern)) {
final int sourceLine = index + 1;
errors.add('${file.path}:$sourceLine}: skip test without a justification comment.');
}
}
}
// Fail if any errors
if (errors.isNotEmpty) {
exitWithError(<String>[
...errors,
'\n${bold}See: https://github.com/flutter/flutter/wiki/Tree-hygiene#skipped-tests$reset',
]);
}
}
final RegExp _testImportPattern = RegExp(r'''import (['"])([^'"]+_test\.dart)\1''');
const Set<String> _exemptTestImports = <String>{
'package:flutter_test/flutter_test.dart',
......
......@@ -58,7 +58,7 @@ Future<double> findCostsForFile(File file) async {
total += deprecationCost;
if (line.contains(legacyDeprecationPattern))
total += legacyDeprecationCost;
if (isTest && line.contains('skip:'))
if (isTest && line.contains('skip:') && !line.contains('[intended]'))
total += skipCost;
if (isDart && isOptingOutOfNullSafety(line))
total += fileNullSafetyMigrationCost;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment