Unverified Commit 455e6aca authored by yaakovschectman's avatar yaakovschectman Committed by GitHub

Test integration test apps' runner files against current template app (#118646)

* Create template file test

* Add to .ci.yaml

* Add to TESTOWNERS

* Organize test script

* Push license to top of file

* Equals sign

* Utilize path.join

* Expand error message
Co-authored-by: 's avatarLoïc Sharma <737941+loic-sharma@users.noreply.github.com>

* Fix missing newline string

* Move template file test to analyze.dart

* Fix newline

* Var name

* Fix extension length

* Use ignore-list for filenames

* Update dev/bots/analyze.dart
Co-authored-by: 's avatarLoïc Sharma <737941+loic-sharma@users.noreply.github.com>

* Indentation
Co-authored-by: 's avatarLoïc Sharma <737941+loic-sharma@users.noreply.github.com>
parent 50ed8a34
...@@ -208,6 +208,10 @@ Future<void> run(List<String> arguments) async { ...@@ -208,6 +208,10 @@ Future<void> run(List<String> arguments) async {
// Ensure gen_default links the correct files // Ensure gen_default links the correct files
printProgress('Correct file names in gen_defaults.dart...'); printProgress('Correct file names in gen_defaults.dart...');
await verifyTokenTemplatesUpdateCorrectFiles(flutterRoot); await verifyTokenTemplatesUpdateCorrectFiles(flutterRoot);
// Ensure integration test files are up-to-date with the app template.
printProgress('Up to date integration test template files...');
await verifyIntegrationTestTemplateFiles(flutterRoot);
} }
...@@ -1861,6 +1865,81 @@ Future<void> verifyTabooDocumentation(String workingDirectory, { int minimumMatc ...@@ -1861,6 +1865,81 @@ Future<void> verifyTabooDocumentation(String workingDirectory, { int minimumMatc
} }
} }
const List<String> _kIgnoreList = <String>[
'Runner.rc.tmpl',
'flutter_window.cpp',
];
final String _kIntegrationTestsRelativePath = path.join('dev', 'integration_tests');
final String _kTemplateRelativePath = path.join('packages', 'flutter_tools', 'templates', 'app_shared', 'windows.tmpl', 'runner');
final String _kWindowsRunnerSubPath = path.join('windows', 'runner');
const String _kProjectNameKey = '{{projectName}}';
const String _kTmplExt = '.tmpl';
final String _kLicensePath = path.join('dev', 'conductor', 'core', 'lib', 'src', 'proto', 'license_header.txt');
String _getFlutterLicense(String flutterRoot) {
return '${File(path.join(flutterRoot, _kLicensePath)).readAsLinesSync().join("\n")}\n\n';
}
String _removeLicenseIfPresent(String fileContents, String license) {
if (fileContents.startsWith(license)) {
return fileContents.substring(license.length);
}
return fileContents;
}
Future<void> verifyIntegrationTestTemplateFiles(String flutterRoot) async {
final List<String> errors = <String>[];
final String license = _getFlutterLicense(flutterRoot);
final String integrationTestsPath = path.join(flutterRoot, _kIntegrationTestsRelativePath);
final String templatePath = path.join(flutterRoot, _kTemplateRelativePath);
final Iterable<Directory>subDirs = Directory(integrationTestsPath).listSync().toList().whereType<Directory>();
for (final Directory testPath in subDirs) {
final String projectName = path.basename(testPath.path);
final String runnerPath = path.join(testPath.path, _kWindowsRunnerSubPath);
final Directory runner = Directory(runnerPath);
if (!runner.existsSync()) {
continue;
}
final Iterable<File> files = Directory(templatePath).listSync().toList().whereType<File>();
for (final File templateFile in files) {
final String fileName = path.basename(templateFile.path);
if (_kIgnoreList.contains(fileName)) {
continue;
}
String templateFileContents = templateFile.readAsLinesSync().join('\n');
String appFilePath = path.join(runnerPath, fileName);
if (fileName.endsWith(_kTmplExt)) {
appFilePath = appFilePath.substring(0, appFilePath.length - _kTmplExt.length); // Remove '.tmpl' from app file path
templateFileContents = templateFileContents.replaceAll(_kProjectNameKey, projectName); // Substitute template project name
}
String appFileContents = File(appFilePath).readAsLinesSync().join('\n');
appFileContents = _removeLicenseIfPresent(appFileContents, license);
if (appFileContents != templateFileContents) {
int indexOfDifference;
for (indexOfDifference = 0; indexOfDifference < appFileContents.length; indexOfDifference++) {
if (indexOfDifference >= templateFileContents.length || templateFileContents.codeUnitAt(indexOfDifference) != appFileContents.codeUnitAt(indexOfDifference)) {
break;
}
}
final String error = '''
Error: file $fileName mismatched for integration test $testPath
Verify the integration test has been migrated to the latest app template.
=====$appFilePath======
$appFileContents
=====${templateFile.path}======
$templateFileContents
==========
Diff at character #$indexOfDifference
''';
errors.add(error);
}
}
}
if (errors.isNotEmpty) {
foundError(errors);
}
}
Future<CommandResult> _runFlutterAnalyze(String workingDirectory, { Future<CommandResult> _runFlutterAnalyze(String workingDirectory, {
List<String> options = const <String>[], List<String> options = const <String>[],
}) async { }) async {
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <flutter/dart_project.h> #include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h> #include <flutter/flutter_view_controller.h>
#include <windows.h> #include <windows.h>
#include <windef.h>
#include "flutter_window.h" #include "flutter_window.h"
#include "utils.h" #include "utils.h"
......
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