[go: nahoru, domu]

Skip to content

Commit

Permalink
Test integration test apps' runner files against current template app…
Browse files Browse the repository at this point in the history
… (#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: Loï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: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>

* Indentation

Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
  • Loading branch information
yaakovschectman and loic-sharma committed Jan 24, 2023
1 parent 50ed8a3 commit 455e6ac
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
79 changes: 79 additions & 0 deletions dev/bots/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ Future<void> run(List<String> arguments) async {
// Ensure gen_default links the correct files
printProgress('Correct file names in gen_defaults.dart...');
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);
}


Expand Down Expand Up @@ -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, {
List<String> options = const <String>[],
}) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <windows.h>
#include <windef.h>

#include "flutter_window.h"
#include "utils.h"
Expand Down

0 comments on commit 455e6ac

Please sign in to comment.