Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub(super) fn list_items(
let bold = Style::new().bold();
for (name, installed) in items {
if installed && !installed_only && !quiet {
writeln!(t, "{bold}{name} (installed){bold:#}")?;
writeln!(t, "{bold}{name}{bold:#} {CONTEXT}(installed){CONTEXT:#}")?;
} else if installed || !installed_only {
writeln!(t, "{name}")?;
}
Expand Down
35 changes: 32 additions & 3 deletions src/test/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pub struct Config {
pub struct Assert {
pub output: SanitizedOutput,
redactions: Redactions,
sort_stdout: bool,
sort_stderr: bool,
}

impl Assert {
Expand All @@ -133,7 +135,12 @@ impl Assert {
("[MULTI_ARCH_I]", Cow::Borrowed(MULTI_ARCH1)),
])
.expect("invalid redactions detected");
Self { output, redactions }
Self {
output,
redactions,
sort_stdout: false,
sort_stderr: false,
}
}

/// Extends the redaction rules used in the current assertion with new values.
Expand All @@ -157,6 +164,18 @@ impl Assert {
self
}

/// Sort stdout lines to gloss over platform-specific sort orders
pub fn sort_stdout(&mut self, yes: bool) -> &mut Self {
self.sort_stdout = yes;
self
}

/// Sort stderr lines to gloss over platform-specific sort orders
pub fn sort_stderr(&mut self, yes: bool) -> &mut Self {
self.sort_stderr = yes;
self
}

/// Performs the redaction based on the existing rules.
pub fn redact(&self, input: &str) -> String {
self.redactions.redact(input)
Expand All @@ -176,7 +195,12 @@ impl Assert {

/// Asserts that the command exited with the given `expected` stdout pattern.
pub fn with_stdout(&self, expected: impl IntoData) -> &Self {
let stdout = self.redact(&self.output.stdout);
let mut stdout = self.redact(&self.output.stdout);
if self.sort_stdout {
let mut lines = stdout.lines().collect::<Vec<_>>();
lines.sort();
stdout = lines.join("\n");
}
assert_data_eq!(&stdout, expected);
self
}
Expand All @@ -192,7 +216,12 @@ impl Assert {

/// Asserts that the command exited with the given `expected` stderr pattern.
pub fn with_stderr(&self, expected: impl IntoData) -> &Self {
let stderr = self.redact(&self.output.stderr);
let mut stderr = self.redact(&self.output.stderr);
if self.sort_stderr {
let mut lines = stderr.lines().collect::<Vec<_>>();
lines.sort();
stderr = lines.join("\n");
}
assert_data_eq!(&stderr, expected);
self
}
Expand Down
23 changes: 23 additions & 0 deletions tests/suite/cli_rustup_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,29 @@ fn rustup_component_cmd_add_cmd_help_flag() {
);
}

#[tokio::test]
async fn rustup_component_list() {
let name = "rustup_component_list";
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect_with_env(
["rustup", "component", "list"],
[("RUSTUP_TERM_COLOR", "always")],
)
.await
.sort_stdout(true)
.with_stdout(Data::read_from(
Path::new(&format!("tests/suite/cli_rustup_ui/{name}.stdout.term.svg")),
None,
))
.with_stderr("")
.is_ok();
}

#[test]
fn rustup_component_cmd_list_cmd_help_flag() {
test_help(
Expand Down
41 changes: 41 additions & 0 deletions tests/suite/cli_rustup_ui/rustup_component_list.stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading