Skip to content

Commit f91ea2e

Browse files
epagerami3l
authored andcommitted
test(list): Add UI test
1 parent 16fcef2 commit f91ea2e

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

src/test/clitools.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ pub struct Config {
115115
pub struct Assert {
116116
pub output: SanitizedOutput,
117117
redactions: Redactions,
118+
sort_stdout: bool,
119+
sort_stderr: bool,
118120
}
119121

120122
impl Assert {
@@ -133,7 +135,12 @@ impl Assert {
133135
("[MULTI_ARCH_I]", Cow::Borrowed(MULTI_ARCH1)),
134136
])
135137
.expect("invalid redactions detected");
136-
Self { output, redactions }
138+
Self {
139+
output,
140+
redactions,
141+
sort_stdout: false,
142+
sort_stderr: false,
143+
}
137144
}
138145

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

167+
/// Sort stdout lines to gloss over platform-specific sort orders
168+
pub fn sort_stdout(&mut self, yes: bool) -> &mut Self {
169+
self.sort_stdout = yes;
170+
self
171+
}
172+
173+
/// Sort stderr lines to gloss over platform-specific sort orders
174+
pub fn sort_stderr(&mut self, yes: bool) -> &mut Self {
175+
self.sort_stderr = yes;
176+
self
177+
}
178+
160179
/// Performs the redaction based on the existing rules.
161180
pub fn redact(&self, input: &str) -> String {
162181
self.redactions.redact(input)
@@ -176,7 +195,12 @@ impl Assert {
176195

177196
/// Asserts that the command exited with the given `expected` stdout pattern.
178197
pub fn with_stdout(&self, expected: impl IntoData) -> &Self {
179-
let stdout = self.redact(&self.output.stdout);
198+
let mut stdout = self.redact(&self.output.stdout);
199+
if self.sort_stdout {
200+
let mut lines = stdout.lines().collect::<Vec<_>>();
201+
lines.sort();
202+
stdout = lines.join("\n");
203+
}
180204
assert_data_eq!(&stdout, expected);
181205
self
182206
}
@@ -192,7 +216,12 @@ impl Assert {
192216

193217
/// Asserts that the command exited with the given `expected` stderr pattern.
194218
pub fn with_stderr(&self, expected: impl IntoData) -> &Self {
195-
let stderr = self.redact(&self.output.stderr);
219+
let mut stderr = self.redact(&self.output.stderr);
220+
if self.sort_stderr {
221+
let mut lines = stderr.lines().collect::<Vec<_>>();
222+
lines.sort();
223+
stderr = lines.join("\n");
224+
}
196225
assert_data_eq!(&stderr, expected);
197226
self
198227
}

tests/suite/cli_rustup_ui.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,29 @@ fn rustup_component_cmd_add_cmd_help_flag() {
137137
);
138138
}
139139

140+
#[tokio::test]
141+
async fn rustup_component_list() {
142+
let name = "rustup_component_list";
143+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
144+
cx.config
145+
.expect(["rustup", "default", "nightly"])
146+
.await
147+
.is_ok();
148+
cx.config
149+
.expect_with_env(
150+
["rustup", "component", "list"],
151+
[("RUSTUP_TERM_COLOR", "always")],
152+
)
153+
.await
154+
.sort_stdout(true)
155+
.with_stdout(Data::read_from(
156+
Path::new(&format!("tests/suite/cli_rustup_ui/{name}.stdout.term.svg")),
157+
None,
158+
))
159+
.with_stderr("")
160+
.is_ok();
161+
}
162+
140163
#[test]
141164
fn rustup_component_cmd_list_cmd_help_flag() {
142165
test_help(
Lines changed: 40 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)