Skip to content

Commit 455e6ac

Browse files
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: Loïc Sharma <[email protected]> * 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 <[email protected]> * Indentation Co-authored-by: Loïc Sharma <[email protected]>
1 parent 50ed8a3 commit 455e6ac

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

dev/bots/analyze.dart

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ Future<void> run(List<String> arguments) async {
208208
// Ensure gen_default links the correct files
209209
printProgress('Correct file names in gen_defaults.dart...');
210210
await verifyTokenTemplatesUpdateCorrectFiles(flutterRoot);
211+
212+
// Ensure integration test files are up-to-date with the app template.
213+
printProgress('Up to date integration test template files...');
214+
await verifyIntegrationTestTemplateFiles(flutterRoot);
211215
}
212216

213217

@@ -1861,6 +1865,81 @@ Future<void> verifyTabooDocumentation(String workingDirectory, { int minimumMatc
18611865
}
18621866
}
18631867

1868+
const List<String> _kIgnoreList = <String>[
1869+
'Runner.rc.tmpl',
1870+
'flutter_window.cpp',
1871+
];
1872+
final String _kIntegrationTestsRelativePath = path.join('dev', 'integration_tests');
1873+
final String _kTemplateRelativePath = path.join('packages', 'flutter_tools', 'templates', 'app_shared', 'windows.tmpl', 'runner');
1874+
final String _kWindowsRunnerSubPath = path.join('windows', 'runner');
1875+
const String _kProjectNameKey = '{{projectName}}';
1876+
const String _kTmplExt = '.tmpl';
1877+
final String _kLicensePath = path.join('dev', 'conductor', 'core', 'lib', 'src', 'proto', 'license_header.txt');
1878+
1879+
String _getFlutterLicense(String flutterRoot) {
1880+
return '${File(path.join(flutterRoot, _kLicensePath)).readAsLinesSync().join("\n")}\n\n';
1881+
}
1882+
1883+
String _removeLicenseIfPresent(String fileContents, String license) {
1884+
if (fileContents.startsWith(license)) {
1885+
return fileContents.substring(license.length);
1886+
}
1887+
return fileContents;
1888+
}
1889+
1890+
Future<void> verifyIntegrationTestTemplateFiles(String flutterRoot) async {
1891+
final List<String> errors = <String>[];
1892+
final String license = _getFlutterLicense(flutterRoot);
1893+
final String integrationTestsPath = path.join(flutterRoot, _kIntegrationTestsRelativePath);
1894+
final String templatePath = path.join(flutterRoot, _kTemplateRelativePath);
1895+
final Iterable<Directory>subDirs = Directory(integrationTestsPath).listSync().toList().whereType<Directory>();
1896+
for (final Directory testPath in subDirs) {
1897+
final String projectName = path.basename(testPath.path);
1898+
final String runnerPath = path.join(testPath.path, _kWindowsRunnerSubPath);
1899+
final Directory runner = Directory(runnerPath);
1900+
if (!runner.existsSync()) {
1901+
continue;
1902+
}
1903+
final Iterable<File> files = Directory(templatePath).listSync().toList().whereType<File>();
1904+
for (final File templateFile in files) {
1905+
final String fileName = path.basename(templateFile.path);
1906+
if (_kIgnoreList.contains(fileName)) {
1907+
continue;
1908+
}
1909+
String templateFileContents = templateFile.readAsLinesSync().join('\n');
1910+
String appFilePath = path.join(runnerPath, fileName);
1911+
if (fileName.endsWith(_kTmplExt)) {
1912+
appFilePath = appFilePath.substring(0, appFilePath.length - _kTmplExt.length); // Remove '.tmpl' from app file path
1913+
templateFileContents = templateFileContents.replaceAll(_kProjectNameKey, projectName); // Substitute template project name
1914+
}
1915+
String appFileContents = File(appFilePath).readAsLinesSync().join('\n');
1916+
appFileContents = _removeLicenseIfPresent(appFileContents, license);
1917+
if (appFileContents != templateFileContents) {
1918+
int indexOfDifference;
1919+
for (indexOfDifference = 0; indexOfDifference < appFileContents.length; indexOfDifference++) {
1920+
if (indexOfDifference >= templateFileContents.length || templateFileContents.codeUnitAt(indexOfDifference) != appFileContents.codeUnitAt(indexOfDifference)) {
1921+
break;
1922+
}
1923+
}
1924+
final String error = '''
1925+
Error: file $fileName mismatched for integration test $testPath
1926+
Verify the integration test has been migrated to the latest app template.
1927+
=====$appFilePath======
1928+
$appFileContents
1929+
=====${templateFile.path}======
1930+
$templateFileContents
1931+
==========
1932+
Diff at character #$indexOfDifference
1933+
''';
1934+
errors.add(error);
1935+
}
1936+
}
1937+
}
1938+
if (errors.isNotEmpty) {
1939+
foundError(errors);
1940+
}
1941+
}
1942+
18641943
Future<CommandResult> _runFlutterAnalyze(String workingDirectory, {
18651944
List<String> options = const <String>[],
18661945
}) async {

dev/integration_tests/windows_startup_test/windows/runner/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <flutter/dart_project.h>
66
#include <flutter/flutter_view_controller.h>
77
#include <windows.h>
8-
#include <windef.h>
98

109
#include "flutter_window.h"
1110
#include "utils.h"

0 commit comments

Comments
 (0)