mirror of
https://github.com/flutter/packages.git
synced 2025-06-09 05:59:45 +08:00
[flutter_plugin_tools] Make unit tests pass on Windows (#4149)
The purpose of this PR is to make running all unit tests on Windows pass (vs failing a large portion of the tests as currently happens). This does not mean that the commands actually work when run on Windows, or that Windows support is tested, only that it's possible to actually run the tests themselves. This is prep for actually supporting parts of the tool on Windows in future PRs. Major changes: - Make the tests significantly more hermetic: - Make almost all tools take a `Platform` constructor argument that can be used to inject a mock platform to control what OS the command acts like it is running on under test. - Add a path `Context` object to the base command, whose style matches the `Platform`, and use that almost everywhere instead of the top-level `path` functions. - In cases where Posix behavior is always required (such as parsing `git` output), explicitly use the `posix` context object for `path` functions. - Start laying the groundwork for actual Windows support: - Replace all uses of `flutter` as a command with a getter that returns `flutter` or `flutter.bat` as appropriate. - For user messages that include relative paths, use a helper that always uses Posix-style relative paths for consistent output. This bumps the version since quite a few changes have built up, and having a cut point before starting to make more changes to the commands to support Windows seems like a good idea. Part of https://github.com/flutter/flutter/issues/86113
This commit is contained in:
@ -21,6 +21,7 @@ abstract class PluginCommand extends Command<void> {
|
||||
PluginCommand(
|
||||
this.packagesDir, {
|
||||
this.processRunner = const ProcessRunner(),
|
||||
this.platform = const LocalPlatform(),
|
||||
GitDir? gitDir,
|
||||
}) : _gitDir = gitDir {
|
||||
argParser.addMultiOption(
|
||||
@ -79,6 +80,11 @@ abstract class PluginCommand extends Command<void> {
|
||||
/// This can be overridden for testing.
|
||||
final ProcessRunner processRunner;
|
||||
|
||||
/// The current platform.
|
||||
///
|
||||
/// This can be overridden for testing.
|
||||
final Platform platform;
|
||||
|
||||
/// The git directory to use. If unset, [gitDir] populates it from the
|
||||
/// packages directory's enclosing repository.
|
||||
///
|
||||
@ -88,9 +94,11 @@ abstract class PluginCommand extends Command<void> {
|
||||
int? _shardIndex;
|
||||
int? _shardCount;
|
||||
|
||||
/// A context that matches the default for [platform].
|
||||
p.Context get path => platform.isWindows ? p.windows : p.posix;
|
||||
|
||||
/// The command to use when running `flutter`.
|
||||
String get flutterCommand =>
|
||||
const LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';
|
||||
String get flutterCommand => platform.isWindows ? 'flutter.bat' : 'flutter';
|
||||
|
||||
/// The shard of the overall command execution that this instance should run.
|
||||
int get shardIndex {
|
||||
@ -240,9 +248,9 @@ abstract class PluginCommand extends Command<void> {
|
||||
// plugins under 'my_plugin'. Also match if the exact plugin is
|
||||
// passed.
|
||||
final String relativePath =
|
||||
p.relative(subdir.path, from: dir.path);
|
||||
final String packageName = p.basename(subdir.path);
|
||||
final String basenamePath = p.basename(entity.path);
|
||||
path.relative(subdir.path, from: dir.path);
|
||||
final String packageName = path.basename(subdir.path);
|
||||
final String basenamePath = path.basename(entity.path);
|
||||
if (!excludedPlugins.contains(basenamePath) &&
|
||||
!excludedPlugins.contains(packageName) &&
|
||||
!excludedPlugins.contains(relativePath) &&
|
||||
|
Reference in New Issue
Block a user