Skip to content

Commit

Permalink
[nextest-runner] add TestInstanceId
Browse files Browse the repository at this point in the history
This identifier is used as a sort key as well.
  • Loading branch information
sunshowers committed Nov 28, 2024
1 parent cfc664d commit ea576d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions nextest-runner/src/list/test_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,14 @@ impl<'a> TestInstance<'a> {
}
}

/// Return a reasonable key for sorting. This is (binary ID, test name).
/// Return an identifier for test instances, including being able to sort
/// them.
#[inline]
pub(crate) fn sort_key(&self) -> (&'a str, &'a str) {
((self.suite_info.binary_id.as_str()), self.name)
pub(crate) fn id(&self) -> TestInstanceId<'a> {
TestInstanceId {
binary_id: &self.suite_info.binary_id,
test_name: self.name,
}
}

/// Returns the corresponding [`TestQuery`] for this `TestInstance`.
Expand Down Expand Up @@ -1052,6 +1056,18 @@ impl<'a> TestInstance<'a> {
}
}

/// A key for identifying and sorting test instances.
///
/// Returned by [`TestInstance::id`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub(crate) struct TestInstanceId<'a> {
/// The binary ID.
pub binary_id: &'a RustBinaryId,

/// The name of the test.
pub test_name: &'a str,
}

/// Context required for test execution.
#[derive(Clone, Debug)]
pub struct TestExecuteContext<'a> {
Expand Down
5 changes: 3 additions & 2 deletions nextest-runner/src/reporter/displayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,11 @@ impl<'a> TestReporterImpl<'a> {
// Sort the final outputs for a friendlier experience.
self.final_outputs
.sort_by_key(|(test_instance, final_output)| {
// Use the final status level, reversed (i.e. failing tests are printed at the very end).
// Use the final status level, reversed (i.e.
// failing tests are printed at the very end).
(
Reverse(final_output.final_status_level()),
test_instance.sort_key(),
test_instance.id(),
)
});

Expand Down

0 comments on commit ea576d6

Please sign in to comment.