-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor: Transition direct assertions from cargo-test-support to snapbox #13980
Conversation
This comes with improved redacting on mismatches which will provide more focused assertions and there will be less need for intervention on snapshot updates. This also gives more flexibility with placeholders
This leaves off `validate_crate_contents` as that would be an effort on its own
e450cbd
to
010c112
Compare
@rustbot ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding it.
str![[r#" | ||
[ROOT]/foo/target/debug/deps/artifact/bar-baz-[..]/bin | ||
[ROOT]/foo/target/debug/deps/artifact/bar-baz-[..]/bin/baz_suffix-[..] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snapshotting always adds a newline over whats already there so the closing "#]]
is on its own line. Rather than error if the newline isn't there, its just ignored.
(iirc cargo-test-support was also sloppy with newlines but it wasn't as obvious because it doesn't have snapshot updating)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
@@ -1492,8 +1494,10 @@ dependencies = [ | |||
[[package]] | |||
name = "foo" | |||
version = "0.1.0" | |||
source = "sparse+http://[..]/" | |||
checksum = "458c1addb23fde7dfbca0410afdbcc0086f96197281ec304d9e0e10def3cb899""#, | |||
source = "sparse+http://127.0.0.1:[..]/index/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that source = "source = "sparse+http://[..]/index/"
also passes the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I had snapshot updating process all of these and re-added the globbing. I tried to be more limited in where I added globs. I also tried to find where we could replace globs with something else (e.g. the [BROKEN_PIPE]
) so snapshot updating can be more automatic.
I could possibly detect localhost with a port and redact the port (127.0.0.1:[PORT]
). The main risk with redactions is we'd redact something that another test explicitly checks (e.g. most of the time we don't care about the .crate
size reported by cargo publish
but some tests specifically do)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Make sense. Thanks!
982eadf
to
995746b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks! 👍
I guess you need to rerun the tests. |
@bors try |
refactor: Transition direct assertions from cargo-test-support to snapbox ### What does this PR try to resolve? Cargo has a bespoke testing framework for functional tests - Extra stuff for us to maintain - Don't leverage benefits from contributions related to other projects - Less incentive to be thoroughly documented UI tests are written using snapbox. The latest release of snapbox (#13963) was geared at supporting cargo's needs in the hope that we can consolidate on testing frameworks. Besides having a single set of semantics, benefits we'd gain include - Updating of test snapshots - Fancier redacting of test output (e.g. #13973) This is the first incremental step in this direction. This replaces direct assertions with snapbox assertions. This still leaves all of the CLI output assertions. These will be done incrementally. ### How should we test and review this PR? ### Additional information
☀️ Try build successful - checks-actions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you all for working on and reviewing this!
/// | ||
/// # Patterns | ||
/// | ||
/// - `[..]` is a character wildcard, stopping at line breaks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess we might want to add [CWD]
in the future. Nevertheless it is not a blocker.
@bors r=hi-rustin |
☀️ Test successful - checks-actions |
Update cargo 9 commits in 7a6fad0984d28c8330974636972aa296b67c4513..34a6a87d8a2330d8c9d578f927489689328a652d 2024-05-31 22:26:03 +0000 to 2024-06-04 15:31:01 +0000 - Silence the warning about forgetting the vendoring (rust-lang/cargo#13886) - fix(vendor): Ensure sort happens for vendor (rust-lang/cargo#14004) - fix(add): Avoid escaping double-quotes by using string literals (rust-lang/cargo#14006) - refactor(source): Split `RecursivePathSource` out of `PathSource` (rust-lang/cargo#13993) - doc: Add README for resolver-tests (rust-lang/cargo#13977) - Allows the default git/gitoxide configuration to be obtained from the ENV and config (rust-lang/cargo#13687) - refactor: Transition direct assertions from cargo-test-support to snapbox (rust-lang/cargo#13980) - Fix: Skip deserialization of unrelated fields with overlapping name (rust-lang/cargo#14000) - chore(deps): update alpine docker tag to v3.20 (rust-lang/cargo#13996) r? ghost
tests: Migrate alt_registry to snapbox ### What does this PR try to resolve? The overall goal is to enable the use of snapshot testing on as many cargo tests as possible to reduce the burden when having to touch a lot of tests. Towards that aim, this PR - Adds snapshot testing to `cargo_test_support::Execs` - Migrates `alt_registry` tests over as an example (and to vet it) I've taken the approach of deprecating all other output assertions on `Execs` with `#[allow(deprecated)]` in every test file. This let's us easily identity what files haven't been migrated, what in a file needs migration, and helps prevent a file from regressing. This should make it easier to do a gradual migration that (as many people as they want) can chip in. It comes at the cost of losing visibility into deprecated items we use. Hopefully we won't be in this intermediate state for too long. To reduce manual touch ups of snapshots, I've added some regex redactions. My main concern with the `FILE_SIZE` redaction was when we test for specific sizes. That shouldn't be a problem because we don't use `Execs::with_stderr` to test those but we capture the output and have a custom asserter for it. ### How should we test and review this PR? Yes, this puts us in an intermediate state which isn't ideal but much better than one person trying to do all of this in a single branch / PR. The main risk is that we'll hit a snag with snapbox being able to support our needs. We got away with a lot because everything was custom, down to the diffing algorithm. This is why I at least started with `alt_registry` to get a feel for what problems we might have. There will likely be some we uncover. I'm fairly confident that we can resolve them in some way, ### Additional information This is a continuation of the work done in #13980.
Update cargo 9 commits in 7a6fad0984d28c8330974636972aa296b67c4513..34a6a87d8a2330d8c9d578f927489689328a652d 2024-05-31 22:26:03 +0000 to 2024-06-04 15:31:01 +0000 - Silence the warning about forgetting the vendoring (rust-lang/cargo#13886) - fix(vendor): Ensure sort happens for vendor (rust-lang/cargo#14004) - fix(add): Avoid escaping double-quotes by using string literals (rust-lang/cargo#14006) - refactor(source): Split `RecursivePathSource` out of `PathSource` (rust-lang/cargo#13993) - doc: Add README for resolver-tests (rust-lang/cargo#13977) - Allows the default git/gitoxide configuration to be obtained from the ENV and config (rust-lang/cargo#13687) - refactor: Transition direct assertions from cargo-test-support to snapbox (rust-lang/cargo#13980) - Fix: Skip deserialization of unrelated fields with overlapping name (rust-lang/cargo#14000) - chore(deps): update alpine docker tag to v3.20 (rust-lang/cargo#13996) r? ghost
What does this PR try to resolve?
Cargo has a bespoke testing framework for functional tests
UI tests are written using snapbox. The latest release of snapbox (#13963) was geared at supporting cargo's needs in the hope that we can consolidate on testing frameworks.
Besides having a single set of semantics, benefits we'd gain include
This is the first incremental step in this direction. This replaces direct assertions with snapbox assertions. This still leaves all of the CLI output assertions. These will be done incrementally.
How should we test and review this PR?
Additional information