-
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
test(cli): Verify terminal styling #13461
Conversation
r? @weihanglo rustbot has assigned @weihanglo. Use r? to explicitly pick a reviewer |
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.
|
One pretty minor concern is that GitHub Mobile renders SVG as text. (Who else review PRs on mobile? 🤷🏾♂️) |
How viewable do you feel that is to look at the raw SVG? I tried to keep the overhead down to make comparing them in text form easier (and to keep the file sizes down). |
@@ -0,0 +1,30 @@ | |||
<svg width="831.6px" height="72px" xmlns="http://www.w3.org/2000/svg"> |
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.
---- expected: tests/testsuite/cargo_remove/invalid_package/stderr.term.svg
++++ actual: stderr
1 - <svg width="890.4000000000001px" height="36px" xmlns="http://www.w3.org/2000/svg">
1 + <svg width="882px" height="36px" xmlns="http://www.w3.org/2000/svg">
The presence of variable substitution is throwing off the width
calculations
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.
Tracking in assert-rs/snapbox#258
A very generic test name combined with a very broad Unsure if we should rename the test or rename the ignore to |
term.svg
files get the wrong width
calculated when using variable substitution
assert-rs/snapbox#258
👍 wow, I never thought we could test CLI like this 🤯 |
We should instead not generate snapshots for empty content |
test: Remove empty snapshots Inspired by #13461
☔ The latest upstream changes (presumably #13465) made this pull request unmergeable. Please resolve the merge conflicts. |
This uses a new feature from snapbox that let's us render terminal styling in SVG files. This let's us see / visualize ANSI escape codes, including in github's UI (will render images, including side-by-side images for diffs).
7a73315
to
216a22a
Compare
We need to rename the |
Found this with the test for `-Zhelp` in rust-lang#13461.
f80b8cf
to
eafda07
Compare
Found this with the test for `-Zhelp` in rust-lang#13461.
a2c117e
to
306d69b
Compare
fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' ### What does this PR try to resolve? Similar to #9012, we aren't respecting `CARGO_TERM_COLOR` for `-Zhelp` and other places. This corrects that. ### How should we test and review this PR? #9012 was about initialization order to get the value. Here, the problem is that we don't update `Shell` with `CARGO_TERM_COLOR`. In doing this, I was concerned about keeping track of where it is safe to call `config_configure` without running it twice. To this end, I refactored `main` to make it clear that each call to `config_configure` is in a mutually exclusive path that exists immediately. ### Additional information Found this with the test for `-Zhelp` in #13461.
@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.
File size: du -ch tests reported 13MB before and after
This is 8.4 to 8.6MB on my machine, which seems pretty acceptable.
BTW, we should update contributor guide https://doc.crates.io/contrib/tests/writing.html after this change.
I only reviewed 70 of all files changes, but assuming most of the changes are generated, I am going to check my box. If people disagree on it later, we can always revert. @bors r+ |
☀️ Test successful - checks-actions |
<text xml:space="preserve" class="container fg"> | ||
<tspan x="10px" y="28px"><tspan class="fg-bright-red bold">error</tspan><tspan>: </tspan><tspan class="[..]">invalid string</tspan> | ||
</tspan> | ||
<tspan x="10px" y="46px"><tspan class="[..]">expected `"`, `'`</tspan> |
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.
Glob ([..]
) is used here because annotate-snippets print platform-specific colors. This is a thing worth keeping in mind or writing down in contributor guide
Update cargo 16 commits in 194a60b2952bd5d12ba15dd2577a97eed7d3c587..8964c8ccff6e420e2a38b8696d178d69fab84d9d 2024-02-21 01:53:45 +0000 to 2024-02-27 19:22:46 +0000 - feat: Add "-Zpublic-dependency" for public-dependency feature. (rust-lang/cargo#13340) - Stabilize global cache data tracking. (rust-lang/cargo#13492) - chore: bump baseline version requirement of sub crates (rust-lang/cargo#13494) - fix(doctest): search native libs in build script outputs (rust-lang/cargo#13490) - chore: fixed a typo(two->too) (rust-lang/cargo#13489) - test: relax help text assertion (rust-lang/cargo#13488) - refactor: clean up for `GlobalContext` rename (rust-lang/cargo#13486) - test(cli): Verify terminal styling (rust-lang/cargo#13461) - fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' (rust-lang/cargo#13479) - Error messages when collecting workspace members now mention the workspace root location (rust-lang/cargo#13480) - fix(add): Improve error when adding registry packages while vendored (rust-lang/cargo#13281) - [docs]:Add missing jump links (rust-lang/cargo#13478) - Add global_cache_tracker stability tests. (rust-lang/cargo#13467) - fix(cli): Control clap colors through config (rust-lang/cargo#13463) - chore: remove the unused function (rust-lang/cargo#13472) - Fix missing brackets (rust-lang/cargo#13470)
Found this with the test for `-Zhelp` in rust-lang#13461.
Update cargo 16 commits in 194a60b2952bd5d12ba15dd2577a97eed7d3c587..8964c8ccff6e420e2a38b8696d178d69fab84d9d 2024-02-21 01:53:45 +0000 to 2024-02-27 19:22:46 +0000 - feat: Add "-Zpublic-dependency" for public-dependency feature. (rust-lang/cargo#13340) - Stabilize global cache data tracking. (rust-lang/cargo#13492) - chore: bump baseline version requirement of sub crates (rust-lang/cargo#13494) - fix(doctest): search native libs in build script outputs (rust-lang/cargo#13490) - chore: fixed a typo(two->too) (rust-lang/cargo#13489) - test: relax help text assertion (rust-lang/cargo#13488) - refactor: clean up for `GlobalContext` rename (rust-lang/cargo#13486) - test(cli): Verify terminal styling (rust-lang/cargo#13461) - fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' (rust-lang/cargo#13479) - Error messages when collecting workspace members now mention the workspace root location (rust-lang/cargo#13480) - fix(add): Improve error when adding registry packages while vendored (rust-lang/cargo#13281) - [docs]:Add missing jump links (rust-lang/cargo#13478) - Add global_cache_tracker stability tests. (rust-lang/cargo#13467) - fix(cli): Control clap colors through config (rust-lang/cargo#13463) - chore: remove the unused function (rust-lang/cargo#13472) - Fix missing brackets (rust-lang/cargo#13470)
feat: Use consistent colors when testing In cargo#13461, it was [noted that `annotate-snippets`](#13461 (comment)) made testing hard as it outputs platform specific colors. To fix this I created [annotate-snippets-rs#82](rust-lang/annotate-snippets-rs#82), which added a feature to make the output platform agnostic when enabled. This makes it so glob syntax does not need to be used when matching colored output.
Found this with the test for `-Zhelp` in rust-lang#13461.
What does this PR try to resolve?
This uses a new feature from snapbox that let's us render terminal styling in SVG files. This let's us see / visualize ANSI escape codes, including in github's UI (will render images, including side-by-side images for diffs).
How should we test and review this PR?
Potential concerns
term.svg
files require twoSNAPSHOTS=overwrite
runs to be rendered properly assert-rs/snapbox#257: If the snapshot file doesn't exist, you need toSNAPSHOTS=overwrite
twice--color
orCARGO_TERM_COLOR
for help text and errors from clap #9012: because we narrow the enabling of colors to cargo viaCARGO_TERM_COLOR
, clap doesn't know about it and those are rendered without colordu -ch tests
reported 13MB before and afterAdditional information