Skip to content

Conversation

@0xPoe
Copy link
Member

@0xPoe 0xPoe commented Nov 13, 2023

  • Added debug assert test for the admin CLI.

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
@0xPoe 0xPoe changed the title Add debug assert to crates-admin cli WIP: Add debug assert to crates-admin cli Nov 13, 2023
Cargo.toml Outdated
hyper-tls = "=0.5.0"
insta = { version = "=1.34.0", features = ["json", "redactions"] }
tokio = "=1.34.0"
trycmd = "0.14.19"
Copy link
Member

Choose a reason for hiding this comment

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

would it be possible to use insta for this instead? seems unfortunate to add that many new dev dependencies just for asserting the help output of an internal CLI tool 😅

Copy link
Member Author

@0xPoe 0xPoe Nov 14, 2023

Choose a reason for hiding this comment

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

would it be possible to use insta for this instead?

Maybe we can do that. But then we would need to handle how to obtain the binary and get the stdout and stderr outputs ourselves. Because insta is just text output, not an emulation for the terminal. So, I think it will be more difficult.

seems unfortunate to add that many new dev dependencies just for asserting the help output of an internal CLI tool

This would help us avoid breaking anything during the big version upgrade. It's not only for one help output, but it also helps with other subcommands(TODO). These tests ensure that we can easily identify changes to the arguments and subcommands.

Copy link
Member Author

Choose a reason for hiding this comment

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

seems unfortunate to add that many new dev dependencies

Can you tell me about your concert? Are you concerned about the compilation time?

Copy link
Member

Choose a reason for hiding this comment

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

But then we would need to handle how to obtain the binary and get the stdout and stderr outputs ourselves.

does clap have an API to get the help output as a String instead?

This would help us avoid breaking anything during the big version upgrade.

what big version upgrade are we talking about? 😅

are there breaking changes on the horizon that would cause behavior changes without compilation errors?

Are you concerned about the compilation time?

yeah, exactly.

I'm not sure yet whether the tradeoff is worth it. If this was a public application where people expect a stable CLI interface then it's definitely worth it, but since this application is an internal tool I'm not sure we need to care that much about interface stability. One notable exception are the subcommands that are configured as cronjobs at Heroku, but those subcommands are very simple and I would be surprised if a clap upgrade broke those without causing compilation errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

what big version upgrade are we talking about? 😅

The major version change. Sorry for my bad English. In Chinese, we call the BIG version upgrade.

yeah, exactly.

It increased the building time by about 10s. Anyway, I will drop it.

Copy link
Member Author

Choose a reason for hiding this comment

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

does clap have an API to get the help output as a String instead?

It has a render_help API. It will return a StyledStr. I will try it in the future. (If you think it is worth to give a try 😅)

Copy link
Member

Choose a reason for hiding this comment

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

it looks like https://docs.rs/clap_builder/4.4.8/clap_builder/builder/struct.StyledStr.html implements Display and then produces a string without ANSI escape codes. seems perfect for using it with insta::assert_display_snapshot!(...) :)

@0xPoe 0xPoe closed this Nov 14, 2023
@0xPoe 0xPoe reopened this Nov 14, 2023
@0xPoe 0xPoe force-pushed the rustin-patch-amdin-cli branch from d794158 to c7b32e3 Compare November 14, 2023 14:38
@0xPoe 0xPoe changed the title WIP: Add debug assert to crates-admin cli Add debug assert to crates-admin cli Nov 14, 2023
@0xPoe 0xPoe requested a review from Turbo87 November 14, 2023 14:42
@0xPoe 0xPoe marked this pull request as ready for review November 14, 2023 14:43
@0xPoe 0xPoe added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Nov 14, 2023
#[test]
fn verify_cli() {
use clap::CommandFactory;
Command::command().debug_assert();
Copy link
Member

Choose a reason for hiding this comment

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

I was curious what debug_assert() is doing. It looks like it runs all of https://docs.rs/clap_builder/4.4.8/src/clap_builder/builder/debug_asserts.rs.html, but only when debug_assertions is enabled, which should be the case when running the test suite. In other words, debug_assert() apparently enables some additional checks that won't even be caught when running the binary from a release build.

tl;dr LGTM 👍

@Turbo87 Turbo87 merged commit cd51b7b into rust-lang:main Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants