Skip to content

Conversation

eth3lbert
Copy link
Contributor

@eth3lbert eth3lbert commented Jun 25, 2024

What does this PR try to resolve?

Part of #14039.

Migrate following to snapbox:

  • tests/testsuite/registry.rs
  • tests/testsuite/registry_auth.rs

Additional information

Parameterize shared logic over inline snapshots to prevent the content from being appended multiple times in str![] when it's called multiple times within a reusable function.

Big thanks to @weihanglo for helping me out!

@rustbot
Copy link
Collaborator

rustbot commented Jun 25, 2024

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 25, 2024
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Apart from those two comments, LGTM

@@ -85,7 +84,7 @@ fn simple() {
.build();

let p = make_project();
cargo(&p, "build").with_stderr(SUCCESS_OUTPUT).run();
cargo(&p, "build").with_stderr_data(SUCCESS_OUTPUT).run();
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to make SUCCESS_OUTPUT snapshot aware?

Copy link
Member

Choose a reason for hiding this comment

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

I feel that this comment contradict to #14149 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to make SUCCESS_OUTPUT snapshot aware?

Is this referring to using its own str![] instead of the same SUCCESS_OUTPUT?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. The goal is making assertions auto-updatable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks!

}

fn simple() {
fn simple(is_http: bool) {
Copy link
Member

Choose a reason for hiding this comment

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

I feel it a bit confusing. By just looking at code, I don't know why this is_http is needed. Apparently there is not different between each branch. Is there a way to document it, or this should be fixed in snapbox or go the other way round?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, if a function contains str![] and is called twice, the content will become something like str![[...] [...]].

This PR introduces an argument is_http to handle str![] separately, allowing it to be filled with the correct content (even though the current testsuite doesn't show the difference).

If appending multiple times is not the expected behavior, I think this should be fixed in snapbox.

Alternatively, it's possible to eliminate the need for the is_http argument by avoiding str![] altogether.

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 think tests/testsuite/list_availables.rs is also worth mentioning here. It reuses a function for assertions with distinct commands multiple times.

Copy link
Member

@weihanglo weihanglo Jun 27, 2024

Choose a reason for hiding this comment

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

Thanks for the reply!

I still found it cumbersome to understand. Maybe we should parameterize over inline snapshot itself. That may look like

fn simple_git() {
    simple(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
[CHECKING] bar v0.0.1
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]], str[[r#"
[CHECKING] bar v0.0.1
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]);
}

(Note that we have two shared assertions hence two arguments)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this also make sense to me! Thanks!

@eth3lbert
Copy link
Contributor Author

All feedback addressed!

@weihanglo
Copy link
Member

Filed assert-rs/snapbox#345 though I don't think this is blocked on it.

I appreciate the effort you put on this back-and-forth snapshot changes. Thanks a lot!

@bors r+

@bors
Copy link
Contributor

bors commented Jun 27, 2024

📌 Commit b7c0054 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 27, 2024
@bors
Copy link
Contributor

bors commented Jun 27, 2024

⌛ Testing commit b7c0054 with merge 6ed64a7...

@bors
Copy link
Contributor

bors commented Jun 27, 2024

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 6ed64a7 to master...

@bors bors merged commit 6ed64a7 into rust-lang:master Jun 27, 2024
@eth3lbert eth3lbert deleted the snapbox-registry branch June 27, 2024 18:55
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2024
Update cargo

23 commits in 4ed7bee47f7dd4416b36fada1909e9a62c546246..a515d463427b3912ec0365d106791f88c1c14e1b
2024-06-25 16:28:22 +0000 to 2024-07-02 20:53:36 +0000
- test: migrate rust_version and rustc* to snapbox (rust-lang/cargo#14177)
- test: mirgate fix* and future_incompat_report to snapbox (rust-lang/cargo#14173)
- test:migrate `edition/error` to snapbox (rust-lang/cargo#14175)
- chore(deps): update compatible (rust-lang/cargo#14174)
- refactor(source): Clean up after PathSource/RecursivePathSource split (rust-lang/cargo#14169)
- test: Migrate some files to snapbox (rust-lang/cargo#14132)
- test:  fix several assertions (rust-lang/cargo#14167)
- test: replace glob with explicit unordered calls (rust-lang/cargo#14166)
- Make it clear that `CARGO_CFG_TARGET_FAMILY` is multi-valued (rust-lang/cargo#14165)
- Document `CARGO_CFG_TARGET_ABI` (rust-lang/cargo#14164)
- test: Migrate git to snapbox (rust-lang/cargo#14159)
- test: migrate some files to snapbox (rust-lang/cargo#14158)
- test: migrate registry and registry_auth to snapbox (rust-lang/cargo#14149)
- gix: remove `revision` feature from cargo (rust-lang/cargo#14160)
- test: migrate package* and publish* to snapbox (rust-lang/cargo#14130)
- More `update --breaking` tests (rust-lang/cargo#14049)
- test: migrate clean to snapbox (rust-lang/cargo#14096)
- Allow `unexpected_builtin_cfgs` lint in `user_specific_cfgs` test (rust-lang/cargo#14153)
- test: migrate search, source_replacement and standard_lib to snapbox (rust-lang/cargo#14151)
- Docs: Update config summary to include missing keys. (rust-lang/cargo#14145)
- test: migrate `dep_info/diagnostics/direct_minimal_versions` to snapbox (rust-lang/cargo#14143)
- Docs: Remove duplicate `strip` section. (rust-lang/cargo#14146)
- Docs: Fix curly quotes in config docs. (rust-lang/cargo#14144)
@rustbot rustbot added this to the 1.81.0 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants