fixed inconsistent file names for *_chip.dart files and added a test (#111364)

This commit is contained in:
Viren Khatri
2022-09-17 08:47:06 +05:30
committed by GitHub
parent f13737ce6a
commit e2ab3e581e
9 changed files with 67 additions and 13 deletions

View File

@@ -201,6 +201,10 @@ Future<void> run(List<String> arguments) async {
} finally {
outDir.deleteSync(recursive: true);
}
// Ensure gen_default links the correct files
printProgress('Correct file names in gen_defaults.dart...');
await verifyTokenTemplatesUpdateCorrectFiles(flutterRoot);
}
@@ -278,6 +282,56 @@ Future<void> verifyNoDoubleClamp(String workingDirectory) async {
}
}
/// Verify Token Templates are mapped to correct file names while generating
/// M3 defaults in /dev/tools/gen_defaults/bin/gen_defaults.dart.
Future<void> verifyTokenTemplatesUpdateCorrectFiles(String workingDirectory) async {
final List<String> errors = <String>[];
String getMaterialDirPath(List<String> lines) {
final String line = lines.firstWhere((String line) => line.contains('String materialLib'));
final String relativePath = line.substring(line.indexOf("'") + 1, line.lastIndexOf("'"));
return path.join(workingDirectory, relativePath);
}
String getFileName(String line) {
const String materialLibString = r"'$materialLib/";
final String leftClamp = line.substring(line.indexOf(materialLibString) + materialLibString.length);
return leftClamp.substring(0, leftClamp.indexOf("'"));
}
final String genDefaultsBinDir = '$workingDirectory/dev/tools/gen_defaults/bin';
final File file = File(path.join(genDefaultsBinDir, 'gen_defaults.dart'));
final List<String> lines = file.readAsLinesSync();
final String materialDirPath = getMaterialDirPath(lines);
bool atLeastOneTargetLineExists = false;
for (final String line in lines) {
if (line.contains('updateFile();')) {
atLeastOneTargetLineExists = true;
final String fileName = getFileName(line);
final String filePath = path.join(materialDirPath, fileName);
final File file = File(filePath);
if (!file.existsSync()) {
errors.add('file $filePath does not exist.');
}
}
}
assert(atLeastOneTargetLineExists, 'No lines exist that this test expects to '
'verify. Check if the target file is correct or remove this test');
// Fail if any errors
if (errors.isNotEmpty) {
final String s = errors.length > 1 ? 's' : '';
final String itThem = errors.length > 1 ? 'them' : 'it';
foundError(<String>[
...errors,
'${bold}Please correct the file name$s or remove $itThem from /dev/tools/gen_defaults/bin/gen_defaults.dart$reset',
]);
}
}
/// Verify tool test files end in `_test.dart`.
///
/// The test runner will only recognize files ending in `_test.dart` as tests to