Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native_assets_cli] Make package:test dev dep #1799

Merged
merged 5 commits into from
Dec 10, 2024

Conversation

devoncarew
Copy link
Member

  • refactor the package:native_assets_cli dep on package:test; make the dep a dev_dependency instead of a regular dependency
  • rename testBuildHook to validateBuildHook and testCodeBuildHook to `validateCodeBuildHook
  • update the changelog

When doing an investigation into the deps of the dart cli tool, I found that this was bringing package:test all all its dependencies into the transitive closure of used packages. This refactors the package to still provide testing facilities but to no longer use package:test as a regular dep.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@coveralls
Copy link

coveralls commented Dec 10, 2024

Coverage Status

coverage: 88.679% (-0.02%) from 88.699%
when pulling e4f94f3 on refactor_native_assets_cli
into 00aae9e on main.

Copy link
Collaborator

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

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

Okay, so it's an antipattern to wrap package:test. We'd better add that to the documentation of package:test.

Is it also an antipattern to wrap package:matcher? It would feel natural to define matchers for our own classes.

I guess getting rid of the package:test dep is a good thing, It causes issues:

cc @mosuem

pkgs/native_assets_cli/lib/test.dart Outdated Show resolved Hide resolved
pkgs/native_assets_cli/lib/test.dart Show resolved Hide resolved
pkgs/native_assets_cli/lib/test.dart Show resolved Hide resolved
Future<void> testBuildHook({
required String description,
/// An exception thrown when validation fails.
class ValidationFailure implements Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto, Validate is a term we use for something else. Also, it's an exception so maybe TestException?

Copy link
Member Author

@devoncarew devoncarew Dec 10, 2024

Choose a reason for hiding this comment

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

I updated to VerificationException.

@dcharkes dcharkes changed the title refactor the package:native_assets_cli dep on package:test [native_assets_cli] Make package:test dev dep Dec 10, 2024
@devoncarew
Copy link
Member Author

Okay, so it's an antipattern to wrap package:test. We'd better add that to the documentation of package:test.

Is it also an antipattern to wrap package:matcher? It would feel natural to define matchers for our own classes.

Yes, mostly. matcher brings in many fewer transitive deps, so in practice its less of an issue (but still something to be avoided). It's fine if the purpose of your package is to ship matchers, or to build functionality on top of test, but mixing that w/ a package that's used for other things - dep'd into people's regular deps - causes issues.

I guess getting rid of the package:test dep is a good thing, It causes issues:

I'll update the PR as per the review feedback.

@dcharkes
Copy link
Collaborator

Okay, so it's an antipattern to wrap package:test. We'd better add that to the documentation of package:test.
Is it also an antipattern to wrap package:matcher? It would feel natural to define matchers for our own classes.

Yes, mostly. matcher brings in many fewer transitive deps, so in practice its less of an issue (but still something to be avoided). It's fine if the purpose of your package is to ship matchers, or to build functionality on top of test, but mixing that w/ a package that's used for other things - dep'd into people's regular deps - causes issues.

Ah right. We would make a separate package:native_toolchain_c_test then. We could consider that once we can change this repo to a pub workspace (#1223), before that it's too painful to have many packages.

Copy link
Member Author

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

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

Updated!

Future<void> testBuildHook({
required String description,
/// An exception thrown when validation fails.
class ValidationFailure implements Exception {
Copy link
Member Author

@devoncarew devoncarew Dec 10, 2024

Choose a reason for hiding this comment

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

I updated to VerificationException.

pkgs/native_assets_cli/lib/test.dart Show resolved Hide resolved
Copy link
Collaborator

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

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

One more comment 🤓

}

/// An exception thrown when build hook verification fails.
class VerificationException implements Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this class should be part of the public API. I don't believe users should catch it. So maybe it should an Error instead? Error itself has a message, so we could even throw Error instead of _VerificationError.

Or do you believe users should catch this?

Copy link
Member Author

@devoncarew devoncarew Dec 10, 2024

Choose a reason for hiding this comment

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

OK, I looked into this a bit more. Error itself doesn't have a message; its subclasses do. None of those look like great candidates to throw, and, it looks like expect throws an Exception, not an Error, so I think we should do the same.

I updated this to be a ValidationFailure, implementing an Exception and not an error. I also moved it to a place in the code where it won't be public API.

Copy link
Collaborator

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

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

lgtm! Please add auto-submit at your convenience (after rebase).

Thanks @devoncarew! 🙏

@auto-submit auto-submit bot merged commit cb47700 into main Dec 10, 2024
23 checks passed
@auto-submit auto-submit bot deleted the refactor_native_assets_cli branch December 10, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants