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

test(cli): Verify terminal styling #13461

Merged
merged 1 commit into from
Feb 23, 2024
Merged

test(cli): Verify terminal styling #13461

merged 1 commit into from
Feb 23, 2024

Conversation

epage
Copy link
Contributor

@epage epage commented Feb 19, 2024

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

Additional information

@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 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 A-testing-cargo-itself Area: cargo's tests S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 19, 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.

image

This is wild 🤯, but pretty neat!

Do you have an example of side-by-side image diff for this new feature?

@epage
Copy link
Contributor Author

epage commented Feb 19, 2024

Do you have an example of side-by-side image diff for this new feature?

See rust-cli/anstyle@d5111b0

@weihanglo
Copy link
Member

One pretty minor concern is that GitHub Mobile renders SVG as text. (Who else review PRs on mobile? 🤷🏾‍♂️)

@epage
Copy link
Contributor Author

epage commented Feb 19, 2024

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).

@weihanglo
Copy link
Member

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).

At the point that I won't review them on mobile. Keeping the size down is good, and I don't think we will go back to text diff too often. Even we do, git word diff should be sufficient to help review.

Specific to this PR, the "Files changed" tab is janky for loading images that I cannot even review them, and some of them stop rendering.

image

@@ -0,0 +1,30 @@
<svg width="831.6px" height="72px" xmlns="http://www.w3.org/2000/svg">
Copy link
Contributor Author

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

Copy link
Contributor Author

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

@epage
Copy link
Contributor Author

epage commented Feb 19, 2024

 ---- cargo_add::target::case stdout ----
thread 'cargo_add::target::case' panicked at tests/testsuite/cargo_add/target/mod.rs:34:10:
tests/testsuite/cargo_add/target/stdout.term.svg (expected):
Failed to read /Users/runner/work/cargo/cargo/tests/testsuite/cargo_add/target/stdout.term.svg: No such file or directory (os error 2)

A very generic test name combined with a very broad .gitignore entry caused me to not add these files.

Unsure if we should rename the test or rename the ignore to /target

@Rustin170506
Copy link
Member

👍 wow, I never thought we could test CLI like this 🤯

@epage
Copy link
Contributor Author

epage commented Feb 20, 2024

We should instead not generate snapshots for empty content

bors added a commit that referenced this pull request Feb 20, 2024
test: Remove empty snapshots

Inspired by #13461
@bors
Copy link
Contributor

bors commented Feb 20, 2024

☔ 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).
@epage
Copy link
Contributor Author

epage commented Feb 22, 2024

We need to rename the target tests so they don't run into issues with our gitignore file.

epage added a commit to epage/cargo that referenced this pull request Feb 22, 2024
@epage epage force-pushed the snapbox branch 3 times, most recently from f80b8cf to eafda07 Compare February 22, 2024 16:42
epage added a commit to epage/cargo that referenced this pull request Feb 22, 2024
@epage epage force-pushed the snapbox branch 2 times, most recently from a2c117e to 306d69b Compare February 22, 2024 17:25
bors added a commit that referenced this pull request Feb 22, 2024
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.
@epage
Copy link
Contributor Author

epage commented Feb 23, 2024

@rustbot ready

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.

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.

@weihanglo
Copy link
Member

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+

@bors
Copy link
Contributor

bors commented Feb 23, 2024

📌 Commit b14a70f 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 Feb 23, 2024
@bors
Copy link
Contributor

bors commented Feb 23, 2024

⌛ Testing commit b14a70f with merge 2b302a5...

@bors
Copy link
Contributor

bors commented Feb 23, 2024

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 2b302a5 to master...

@bors bors merged commit 2b302a5 into rust-lang:master Feb 23, 2024
23 checks passed
<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>
Copy link
Member

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

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 28, 2024
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-&gt;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)
stupendoussuperpowers pushed a commit to stupendoussuperpowers/cargo that referenced this pull request Feb 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 28, 2024
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-&gt;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)
@ehuss ehuss added this to the 1.78.0 milestone Mar 2, 2024
bors added a commit that referenced this pull request Mar 2, 2024
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.
charmitro pushed a commit to charmitro/cargo that referenced this pull request Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testing-cargo-itself Area: cargo's tests 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.

6 participants