@@ -208,6 +208,10 @@ Future<void> run(List<String> arguments) async {
208
208
// Ensure gen_default links the correct files
209
209
printProgress ('Correct file names in gen_defaults.dart...' );
210
210
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);
211
215
}
212
216
213
217
@@ -1861,6 +1865,81 @@ Future<void> verifyTabooDocumentation(String workingDirectory, { int minimumMatc
1861
1865
}
1862
1866
}
1863
1867
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
+
1864
1943
Future <CommandResult > _runFlutterAnalyze (String workingDirectory, {
1865
1944
List <String > options = const < String > [],
1866
1945
}) async {
0 commit comments