mirror of
https://github.com/flutter/packages.git
synced 2025-08-24 03:18:54 +08:00
[tools] Check integration tests for test
(#5936)
This commit is contained in:
@ -182,7 +182,16 @@ class DriveExamplesCommand extends PackageLoopingCommand {
|
||||
if (legacyTestFile != null) {
|
||||
testTargets.add(legacyTestFile);
|
||||
} else {
|
||||
(await _getIntegrationTests(example)).forEach(testTargets.add);
|
||||
for (final File testFile in await _getIntegrationTests(example)) {
|
||||
// Check files for known problematic patterns.
|
||||
final bool passesValidation = _validateIntegrationTest(testFile);
|
||||
if (!passesValidation) {
|
||||
// Report the issue, but continue with the test as the validation
|
||||
// errors don't prevent running.
|
||||
errors.add('${testFile.basename} failed validation');
|
||||
}
|
||||
testTargets.add(testFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (testTargets.isEmpty) {
|
||||
@ -310,6 +319,25 @@ class DriveExamplesCommand extends PackageLoopingCommand {
|
||||
return tests;
|
||||
}
|
||||
|
||||
/// Checks [testFile] for known bad patterns in integration tests, logging
|
||||
/// any issues.
|
||||
///
|
||||
/// Returns true if the file passes validation without issues.
|
||||
bool _validateIntegrationTest(File testFile) {
|
||||
final List<String> lines = testFile.readAsLinesSync();
|
||||
|
||||
final RegExp badTestPattern = RegExp(r'\s*test\(');
|
||||
if (lines.any((String line) => line.startsWith(badTestPattern))) {
|
||||
final String filename = testFile.basename;
|
||||
printError(
|
||||
'$filename uses "test", which will not report failures correctly. '
|
||||
'Use testWidgets instead.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// For each file in [targets], uses
|
||||
/// `flutter drive --driver [driver] --target <target>`
|
||||
/// to drive [example], returning a list of any failing test targets.
|
||||
|
Reference in New Issue
Block a user