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
32 changes: 0 additions & 32 deletions cli/src/error_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,35 +249,3 @@ fn adds_settings_if_domain_present() {
"Hint: You can find it under the settings page at https://app.fake-trunk.io/fake-org-slug/settings"
)
}

#[test]
fn prints_a_client_error_explanation_beneath_the_base_message() {
let error = anyhow::anyhow!("HTTP status client error (400 Bad Request)")
.context(ClientErrorExplanation {
code: Some(String::from("SOME_CODE")),
message: Some(String::from("Pass --test-collection-id.")),
})
.context("Error in create bundle upload endpoint");
let report = ErrorReport::new(
error,
String::from("fake-org-slug"),
Some(String::from("There was an unexpected error")),
);

let text = report
.output()
.unwrap()
.iter()
.map(|line| line.to_unstyled())
.collect::<Vec<_>>();

assert_eq!(
text[..4],
[
"Error Encountered",
"There was an unexpected error",
"",
"Pass --test-collection-id.",
]
);
}
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod context;
pub mod context_quarantine;
pub mod error_report;
pub mod print;
mod report_limiting;
pub mod report_limiting;
pub mod test_command;
pub mod upload_command;
pub mod validate_command;
164 changes: 83 additions & 81 deletions cli/src/upload_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,94 +1080,96 @@ impl EndOutput for UploadRunResult {
}
}
// Helper to render a group
let mut render_group =
|header: &str, color: Color, group: &Vec<&Test>| -> anyhow::Result<()> {
output.push(Line::from_iter([Span::new_styled(
style(header.to_string())
.with(color)
.attribute(Attribute::Bold),
)?]));
for test in group.iter().take(3) {
let output_name = format!(
"{}{}{}",
test.parent_name,
if test.parent_name.is_empty() { "" } else { "/" },
test.name
);
let mut test_line = Line::from_iter([Span::new_styled_lossy(
style(output_name.to_string()).attribute(Attribute::Bold),
)]);
test_line.pad_left(2);
output.push(test_line);
let link = url_for_test_case(
&self.api_address,
&self.quarantine_context.org_url_slug,
&self.quarantine_context.repo,
test,
test_collection_short_id,
guid_scope,
)?;
let mut link_output = Line::from_iter([
Span::new_unstyled("⤷ ")?,
hyperlink_span(link, Attribute::Underlined)?,
]);
link_output.pad_left(4);
output.push(link_output);
// Display failure message if present and enabled
// TODO: show_failure_messages is a temporary flag to show failure messages
// in the output. It should be removed once we are confident in this flow
// and we should use the validation report flag instead.
if self.show_failure_messages && test.failure_message.is_some() {
let failure_message = test.failure_message.as_ref().unwrap();
let lines: Vec<&str> = failure_message.split('\n').collect();
let max_lines = 20;
let shown_lines = lines.iter().take(max_lines);
let mut failure_header = Line::from_iter([Span::new_styled(
style("Failure: ".to_string()).with(Color::DarkGrey),
)?]);
failure_header.pad_left(4);
output.push(failure_header);
for (j, line) in shown_lines.enumerate() {
let sanitized_line = line.replace('\t', " ").replace('\r', "");
if !sanitized_line.trim().is_empty() || j == 0 {
let mut failure_output = Line::from_iter([
Span::new_unstyled(" ")?,
Span::new_styled_lossy(
style(sanitized_line.to_string())
.with(Color::Grey)
.attribute(Attribute::Italic),
),
]);
failure_output.pad_left(4);
output.push(failure_output);
}
}
if lines.len() > max_lines {
let omitted = lines.len() - max_lines;
let mut more_output = Line::from_iter([
let mut render_group = |header: &str,
color: Color,
group: &Vec<&Test>|
-> anyhow::Result<()> {
output.push(Line::from_iter([Span::new_styled(
style(header.to_string())
.with(color)
.attribute(Attribute::Bold),
)?]));
for test in group.iter().take(3) {
let output_name = format!(
"{}{}{}",
test.parent_name,
if test.parent_name.is_empty() { "" } else { "/" },
test.name
);
let mut test_line = Line::from_iter([Span::new_styled_lossy(
style(output_name.to_string()).attribute(Attribute::Bold),
)]);
test_line.pad_left(2);
output.push(test_line);
let link = url_for_test_case(
&self.api_address,
&self.quarantine_context.org_url_slug,
&self.quarantine_context.repo,
test,
test_collection_short_id,
guid_scope,
)?;
let mut link_output = Line::from_iter([
Span::new_unstyled("⤷ ")?,
hyperlink_span(link, Attribute::Underlined)?,
]);
link_output.pad_left(4);
output.push(link_output);
// Display failure message if present and enabled
// TODO: show_failure_messages is a temporary flag to show failure messages
// in the output. It should be removed once we are confident in this flow
// and we should use the validation report flag instead.
if self.show_failure_messages && test.failure_message.is_some() {
let failure_message = test.failure_message.as_ref().unwrap();
let lines: Vec<&str> = failure_message.split('\n').collect();
let max_lines = 20;
let shown_lines = lines.iter().take(max_lines);
let mut failure_header = Line::from_iter([Span::new_styled(
style("Failure: ".to_string()).with(Color::DarkGrey),
)?]);
failure_header.pad_left(4);
output.push(failure_header);
for (j, line) in shown_lines.enumerate() {
let sanitized_line = line.replace('\t', " ").replace('\r', "");
if !sanitized_line.trim().is_empty() || j == 0 {
let mut failure_output = Line::from_iter([
Span::new_unstyled(" ")?,
Span::new_styled(
style(format!("…and {omitted} more lines not shown"))
Span::new_styled_lossy(
style(sanitized_line.to_string())
.with(Color::Grey)
.attribute(Attribute::Italic),
)?,
),
]);
more_output.pad_left(4);
output.push(more_output);
failure_output.pad_left(4);
output.push(failure_output);
}
}
if lines.len() > max_lines {
let omitted = lines.len() - max_lines;
let mut more_output = Line::from_iter([
Span::new_unstyled(" ")?,
Span::new_styled(
style(format!("…and {omitted} more lines not shown"))
.with(Color::Grey)
.attribute(Attribute::Italic),
)?,
]);
more_output.pad_left(4);
output.push(more_output);
}
}
if group.len() > 3 {
let mut more_failures = Line::from_iter([Span::new_unstyled(format!(
"…and {} more failures in this group",
group.len() - 3
))?]);
more_failures.pad_left(2);
output.push(more_failures);
}
output.push(Line::default());
Ok(())
};
}
if group.len() > 3 {
let mut more_failures = Line::from_iter([Span::new_unstyled(format!(
"…and {} more failures in this group",
group.len() - 3
))?]);
more_failures.pad_left(2);
output.push(more_failures);
}
output.push(Line::default());
Ok(())
};
// Render file path groups (cyan)
for (file, group) in &groups {
render_group(&format!("📁 {}", file), Color::Cyan, group)?;
Expand Down
2 changes: 2 additions & 0 deletions cli/test_fixtures/summary/bep/bep_with_parse_error
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"id":{"testResult":{"label":"//app:unit_test","run":1,"shard":1,"attempt":1}},"testResult":{"testActionOutput":[{"name":"test.xml","uri":"file://test_fixtures/summary/bep/test.xml"}],"status":"PASSED"}}
{"id":{"testResult":
6 changes: 6 additions & 0 deletions cli/test_fixtures/summary/bep/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="unit_test">
<testsuite name="MathTests">
<testcase name="adds" classname="MathTests" file="app/math_test.cc" time="0.1"/>
</testsuite>
</testsuites>
1 change: 1 addition & 0 deletions cli/test_fixtures/summary/validate/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @example-org/example-team
4 changes: 4 additions & 0 deletions cli/test_fixtures/summary/validate/broken.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="broken">
<testsuite name="MathTests">
</testsuites>
Empty file.
11 changes: 11 additions & 0 deletions cli/test_fixtures/summary/validate/multiple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="first">
<testsuite name="MathTests">
<testcase name="adds" classname="MathTests" file="src/math.rs" time="0.1"/>
</testsuite>
</testsuites>
<testsuites name="second">
<testsuite name="MathTests">
<testcase name="subtracts" classname="MathTests" file="src/math.rs" time="0.1"/>
</testsuite>
</testsuites>
8 changes: 8 additions & 0 deletions cli/test_fixtures/summary/validate/unit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="unit">
<testsuite name="MathTests">
<testcase name="adds" classname="MathTests" file="src/math.rs" time="0.1"/>
<testcase name="subtracts" classname="MathTests" time="0.1"/>
<testcase name="" classname="MathTests" file="src/math.rs"/>
</testsuite>
</testsuites>
Loading
Loading