Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@stuartmorgan-g
Copy link
Contributor

Converts the test utils for creating fake packages and associated files
to use the newer RepositoryPackage instead of Directory, to improve
the typing of common objects.

As part of this, converts various test-local support utilities to take
RepositoryPackages to keep the consistent type, and adds several more
package path utility methods for common subpaths to reduce duplication
of directory.child{File,Directory}('some-hard-coded-value').

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

Converts the test utils for creating fake packages and associated files
to use the newer `RepositoryPackage` instead of `Directory`, to improve
the typing of common objects.

As part of this, converts various test-local support utilities to take
`RepositoryPackage`s to keep the consistent type, and adds several more
package path utility methods for common subpaths to reduce duplication
of `directory.child{File,Directory}('some-hard-coded-value')`.
@stuartmorgan-g stuartmorgan-g requested a review from gaaclarke May 3, 2022 18:16

/// Target platforms supported by Flutter.
// ignore: public_member_api_docs
enum FlutterPlatform { android, ios, linux, macos, web, windows }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this since I was adding a utility method to RepositoryPackage to get the platform directories of a package. Currently we use string constants everywhere for platforms which I've been wanting to move to enums, and this was a good opportunity to introduce it. (I didn't convert anything else to it yet.)


/// Returns whether the specified entity is a directory containing a
/// `pubspec.yaml` file.
bool _isDartPackage(FileSystemEntity entity) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a duplicate of the recently-added isPackage that I noticed while looking for uses of .childFile('pubspec.yaml').

});
});

group('runXcodeBuild', () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was opportunistic copypasta fixing.

const String _endColor = '\x1B[0m';

// The filename within a package containing warnings to log during runForPackage.
enum _ResultFileType {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the utils below was opportunistic improvement of a bunch of places that would have needed to become package.directory.childFile..., with string constants, and I was trying to minimize that construction in the new RepositoryPackage world.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a couple nits. I was reading through closely to look for clerical errors, but the scope of this PR is so large I'm not confident I didn't miss something. Ultimately the tests will be better at finding clerical errors, the change sounds good to me.

case FlutterPlatform.windows:
directoryName = 'windows';
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a default which throws an exception. I'm pretty sure incomplete switch statements are not an error in Dart, but our linter flags might catch it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the lint for that enabled in the repo, so if a new platform is added to the enum CI will fail unless this is updated.

unorderedEquals(<String>[
included.path,
included.childDirectory('example').path,
getExampleDir(included).path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come getExampleDir is a function when getting the platform directories is a method? That seems a bit odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is addressed in the getExampleDir comment:

/// This is deliberately not a method on [RepositoryPackage] since actual tool
/// code should essentially never need this, and instead be using
/// [RepositoryPackage.getExamples] to avoid assuming there's a single example
/// directory. However, needing to construct paths with the example directory
/// is very common in test code.

I considered making it a visable-for-testing method instead, but that seemed even more bizarre since it's not for testing RepositoryPackage. Making it a free function that's only defined in the test utilities means it'll never even show up as a possibility when people are writing non-test code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal. It just looked weird compared to the other methods. Could you have used extension methods in the test utilities?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also considered that, but it violates Flutter style.

@stuartmorgan-g stuartmorgan-g added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label May 3, 2022
@fluttergithubbot fluttergithubbot merged commit 92333f7 into flutter:main May 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 4, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants