mirror of
https://github.com/flutter/packages.git
synced 2025-06-08 04:18:49 +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:
@ -7,6 +7,7 @@ import 'package:git/git.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||
|
||||
@ -77,11 +78,17 @@ class VersionCheckCommand extends PackageLoopingCommand {
|
||||
VersionCheckCommand(
|
||||
Directory packagesDir, {
|
||||
ProcessRunner processRunner = const ProcessRunner(),
|
||||
Platform platform = const LocalPlatform(),
|
||||
GitDir? gitDir,
|
||||
http.Client? httpClient,
|
||||
}) : _pubVersionFinder =
|
||||
PubVersionFinder(httpClient: httpClient ?? http.Client()),
|
||||
super(packagesDir, processRunner: processRunner, gitDir: gitDir) {
|
||||
super(
|
||||
packagesDir,
|
||||
processRunner: processRunner,
|
||||
platform: platform,
|
||||
gitDir: gitDir,
|
||||
) {
|
||||
argParser.addFlag(
|
||||
_againstPubFlag,
|
||||
help: 'Whether the version check should run against the version on pub.\n'
|
||||
@ -179,8 +186,13 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
|
||||
required GitVersionFinder gitVersionFinder,
|
||||
}) async {
|
||||
final File pubspecFile = package.childFile('pubspec.yaml');
|
||||
return await gitVersionFinder.getPackageVersion(
|
||||
p.relative(pubspecFile.absolute.path, from: (await gitDir).path));
|
||||
final String relativePath =
|
||||
path.relative(pubspecFile.absolute.path, from: (await gitDir).path);
|
||||
// Use Posix-style paths for git.
|
||||
final String gitPath = path.style == p.Style.windows
|
||||
? p.posix.joinAll(path.split(relativePath))
|
||||
: relativePath;
|
||||
return await gitVersionFinder.getPackageVersion(gitPath);
|
||||
}
|
||||
|
||||
/// Returns true if the version of [package] is either unchanged relative to
|
||||
|
Reference in New Issue
Block a user