From 455e6aca5086ff2c9e67bff90ee2892580dc1474 Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Tue, 24 Jan 2023 17:00:22 -0500 Subject: [PATCH] Test integration test apps' runner files against current template app (#118646) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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> --- dev/bots/analyze.dart | 79 +++++++++++++++++++ .../windows/runner/main.cpp | 1 - 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 055da52b1ef1..9c707d45b9ac 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -208,6 +208,10 @@ Future run(List 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); } @@ -1861,6 +1865,81 @@ Future verifyTabooDocumentation(String workingDirectory, { int minimumMatc } } +const List _kIgnoreList = [ + '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 verifyIntegrationTestTemplateFiles(String flutterRoot) async { + final List errors = []; + final String license = _getFlutterLicense(flutterRoot); + final String integrationTestsPath = path.join(flutterRoot, _kIntegrationTestsRelativePath); + final String templatePath = path.join(flutterRoot, _kTemplateRelativePath); + final IterablesubDirs = Directory(integrationTestsPath).listSync().toList().whereType(); + 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 files = Directory(templatePath).listSync().toList().whereType(); + 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 _runFlutterAnalyze(String workingDirectory, { List options = const [], }) async { diff --git a/dev/integration_tests/windows_startup_test/windows/runner/main.cpp b/dev/integration_tests/windows_startup_test/windows/runner/main.cpp index 2bf0983c0079..141f6360587e 100644 --- a/dev/integration_tests/windows_startup_test/windows/runner/main.cpp +++ b/dev/integration_tests/windows_startup_test/windows/runner/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "flutter_window.h" #include "utils.h"