Skip to content

Commit

Permalink
Refactor flutter_plugins (#145870)
Browse files Browse the repository at this point in the history
Refactor flutter_plugins suite in order to reduce testing logic in test.dart and allow for later implementing package:test onto the existing flutter_plugins tests

Also update the test_test invocation of getFlutterPackagesVersion

Part of flutter/flutter#145482
  • Loading branch information
sealesj authored Mar 29, 2024
1 parent 0984a7f commit 93b071e
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 88 deletions.
101 changes: 101 additions & 0 deletions dev/bots/suite_runners/run_flutter_packages_tests.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io' show Directory, File;

import 'package:file/file.dart' as fs;
import 'package:file/local.dart';
import 'package:path/path.dart' as path;

import '../run_command.dart';
import '../test.dart';
import '../utils.dart';

/// Executes the test suite for the flutter/packages repo.
Future<void> flutterPackagesRunner(String flutterRoot) async {

Future<void> runAnalyze() async {
printProgress('${green}Running analysis for flutter/packages$reset');
final Directory checkout = Directory.systemTemp.createTempSync('flutter_packages.');
await runCommand(
'git',
const <String>[
'-c',
'core.longPaths=true',
'clone',
'https://github.com/flutter/packages.git',
'.',
],
workingDirectory: checkout.path,
);
final String packagesCommit = await getFlutterPackagesVersion(flutterRoot: flutterRoot);
await runCommand(
'git',
<String>[
'-c',
'core.longPaths=true',
'checkout',
packagesCommit,
],
workingDirectory: checkout.path,
);
// Prep the repository tooling.
// This test does not use tool_runner.sh because in this context the test
// should always run on the entire packages repo, while tool_runner.sh
// is designed for flutter/packages CI and only analyzes changed repository
// files when run for anything but master.
final String toolDir = path.join(checkout.path, 'script', 'tool');
await runCommand(
'dart',
const <String>[
'pub',
'get',
],
workingDirectory: toolDir,
);
final String toolScript = path.join(toolDir, 'bin', 'flutter_plugin_tools.dart');
await runCommand(
'dart',
<String>[
'run',
toolScript,
'analyze',
// Fetch the oldest possible dependencies, rather than the newest, to
// insulate flutter/flutter from out-of-band failures when new versions
// of dependencies are published. This compensates for the fact that
// flutter/packages doesn't use pinned dependencies, and for the
// purposes of this test using old dependencies is fine. See
// https://github.com/flutter/flutter/issues/129633
'--downgrade',
'--custom-analysis=script/configs/custom_analysis.yaml',
],
workingDirectory: checkout.path,
);
}
await selectSubshard(<String, ShardRunner>{
'analyze': runAnalyze,
});
}

/// Returns the commit hash of the flutter/packages repository that's rolled in.
///
/// The flutter/packages repository is a downstream dependency, it is only used
/// by flutter/flutter for testing purposes, to assure stable tests for a given
/// flutter commit the flutter/packages commit hash to test against is coded in
/// the bin/internal/flutter_packages.version file.
///
/// The `filesystem` parameter specified filesystem to read the packages version file from.
/// The `packagesVersionFile` parameter allows specifying an alternative path for the
/// packages version file, when null [flutterPackagesVersionFile] is used.
Future<String> getFlutterPackagesVersion({
fs.FileSystem fileSystem = const LocalFileSystem(),
String? packagesVersionFile,
required String flutterRoot,
}) async {
final String flutterPackagesVersionFile = path.join(flutterRoot, 'bin', 'internal', 'flutter_packages.version');

final File versionFile = fileSystem.file(packagesVersionFile ?? flutterPackagesVersionFile);
final String versionFileContents = await versionFile.readAsString();
return versionFileContents.trim();
}
88 changes: 2 additions & 86 deletions dev/bots/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import 'package:process/process.dart';

import 'run_command.dart';
import 'suite_runners/run_add_to_app_life_cycle_tests.dart';
import 'suite_runners/run_flutter_packages_tests.dart';
import 'suite_runners/run_skp_generator_tests.dart';
import 'suite_runners/run_web_long_running_tests.dart';
import 'tool_subsharding.dart';
Expand All @@ -88,7 +89,6 @@ final String dart = path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'd
final String pubCache = path.join(flutterRoot, '.pub-cache');
final String engineVersionFile = path.join(flutterRoot, 'bin', 'internal', 'engine.version');
final String engineRealmFile = path.join(flutterRoot, 'bin', 'internal', 'engine.realm');
final String flutterPackagesVersionFile = path.join(flutterRoot, 'bin', 'internal', 'flutter_packages.version');

String get platformFolderName {
if (Platform.isWindows) {
Expand Down Expand Up @@ -248,7 +248,7 @@ Future<void> main(List<String> args) async {
'web_skwasm_tests': _runWebSkwasmUnitTests,
// All web integration tests
'web_long_running_tests': () => webLongRunningTestsRunner(flutterRoot),
'flutter_plugins': _runFlutterPackagesTests,
'flutter_plugins': () => flutterPackagesRunner(flutterRoot),
'skp_generator': skpGeneratorTestsRunner,
'realm_checker': _runRealmCheckerTest,
'customer_testing': _runCustomerTesting,
Expand Down Expand Up @@ -1196,90 +1196,6 @@ Future<void> _runWebUnitTests(String webRenderer, bool useWasm) async {
await selectSubshard(subshards);
}

/// Returns the commit hash of the flutter/packages repository that's rolled in.
///
/// The flutter/packages repository is a downstream dependency, it is only used
/// by flutter/flutter for testing purposes, to assure stable tests for a given
/// flutter commit the flutter/packages commit hash to test against is coded in
/// the bin/internal/flutter_packages.version file.
///
/// The `filesystem` parameter specified filesystem to read the packages version file from.
/// The `packagesVersionFile` parameter allows specifying an alternative path for the
/// packages version file, when null [flutterPackagesVersionFile] is used.
Future<String> getFlutterPackagesVersion({
fs.FileSystem fileSystem = const LocalFileSystem(),
String? packagesVersionFile,
}) async {
final File versionFile = fileSystem.file(packagesVersionFile ?? flutterPackagesVersionFile);
final String versionFileContents = await versionFile.readAsString();
return versionFileContents.trim();
}

/// Executes the test suite for the flutter/packages repo.
Future<void> _runFlutterPackagesTests() async {
Future<void> runAnalyze() async {
printProgress('${green}Running analysis for flutter/packages$reset');
final Directory checkout = Directory.systemTemp.createTempSync('flutter_packages.');
await runCommand(
'git',
<String>[
'-c',
'core.longPaths=true',
'clone',
'https://github.com/flutter/packages.git',
'.',
],
workingDirectory: checkout.path,
);
final String packagesCommit = await getFlutterPackagesVersion();
await runCommand(
'git',
<String>[
'-c',
'core.longPaths=true',
'checkout',
packagesCommit,
],
workingDirectory: checkout.path,
);
// Prep the repository tooling.
// This test does not use tool_runner.sh because in this context the test
// should always run on the entire packages repo, while tool_runner.sh
// is designed for flutter/packages CI and only analyzes changed repository
// files when run for anything but master.
final String toolDir = path.join(checkout.path, 'script', 'tool');
await runCommand(
'dart',
<String>[
'pub',
'get',
],
workingDirectory: toolDir,
);
final String toolScript = path.join(toolDir, 'bin', 'flutter_plugin_tools.dart');
await runCommand(
'dart',
<String>[
'run',
toolScript,
'analyze',
// Fetch the oldest possible dependencies, rather than the newest, to
// insulate flutter/flutter from out-of-band failures when new versions
// of dependencies are published. This compensates for the fact that
// flutter/packages doesn't use pinned dependencies, and for the
// purposes of this test using old dependencies is fine. See
// https://github.com/flutter/flutter/issues/129633
'--downgrade',
'--custom-analysis=script/configs/custom_analysis.yaml',
],
workingDirectory: checkout.path,
);
}
await selectSubshard(<String, ShardRunner>{
'analyze': runAnalyze,
});
}

// Runs customer_testing.
Future<void> _runCustomerTesting() async {
printProgress('${green}Running customer testing$reset');
Expand Down
5 changes: 3 additions & 2 deletions dev/bots/test/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:file/memory.dart';
import 'package:path/path.dart' as path;
import 'package:process/process.dart';

import '../suite_runners/run_flutter_packages_tests.dart';
import '../test.dart';
import 'common.dart';

Expand Down Expand Up @@ -92,13 +93,13 @@ void main() {

test('commit hash', () async {
packagesVersionFile.writeAsStringSync(kSampleHash);
final String actualHash = await getFlutterPackagesVersion(fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path);
final String actualHash = await getFlutterPackagesVersion(flutterRoot: flutterRoot, fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path);
expect(actualHash, kSampleHash);
});

test('commit hash with newlines', () async {
packagesVersionFile.writeAsStringSync('\n$kSampleHash\n');
final String actualHash = await getFlutterPackagesVersion(fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path);
final String actualHash = await getFlutterPackagesVersion(flutterRoot: flutterRoot, fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path);
expect(actualHash, kSampleHash);
});
});
Expand Down

0 comments on commit 93b071e

Please sign in to comment.