-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libtest json output option (#1086)
Add support for machine-readable outputs for nextest's test runs.
- Loading branch information
1 parent
26168d8
commit 2728de2
Showing
6 changed files
with
687 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//! Functionality for emitting structured, machine readable output in different | ||
//! formats | ||
mod libtest; | ||
|
||
use super::*; | ||
pub use libtest::{EmitNextestObject, LibtestReporter}; | ||
|
||
/// Error returned when a user-supplied format version fails to be parsed to a | ||
/// valid and supported version | ||
#[derive(Clone, Debug, thiserror::Error)] | ||
#[error("invalid format version: {input}")] | ||
pub struct FormatVersionError { | ||
/// The input that failed to parse. | ||
pub input: String, | ||
/// The underlying error | ||
#[source] | ||
pub err: FormatVersionErrorInner, | ||
} | ||
|
||
/// The different errors that can occur when parsing and validating a format version | ||
#[derive(Clone, Debug, thiserror::Error)] | ||
pub enum FormatVersionErrorInner { | ||
/// The input did not have a valid syntax | ||
#[error("expected format version in form of `{expected}`")] | ||
InvalidFormat { | ||
/// The expected pseudo format | ||
expected: &'static str, | ||
}, | ||
/// A decimal integer was expected but could not be parsed | ||
#[error("version component `{which}` could not be parsed as an integer")] | ||
InvalidInteger { | ||
/// Which component was invalid | ||
which: &'static str, | ||
/// The parse failure | ||
#[source] | ||
err: std::num::ParseIntError, | ||
}, | ||
/// The version component was not within th expected range | ||
#[error("version component `{which}` value {value} is out of range {range:?}")] | ||
InvalidValue { | ||
/// The component which was out of range | ||
which: &'static str, | ||
/// The value that was parsed | ||
value: u8, | ||
/// The range of valid values for the component | ||
range: std::ops::Range<u8>, | ||
}, | ||
} | ||
|
||
/// A reporter for structured, machine readable, output based on the user's | ||
/// preference | ||
pub enum StructuredReporter<'a> { | ||
/// Libtest compatible output | ||
Libtest(LibtestReporter<'a>), | ||
// TODO: make a custom format that is easier to consume than libtest's | ||
//Json(json::JsonReporter<'a>), | ||
/// Variant that doesn't actually emit anything | ||
Disabled, | ||
} | ||
|
||
impl<'a> StructuredReporter<'a> { | ||
#[inline] | ||
pub(super) fn write_event(&mut self, event: &TestEvent<'a>) -> Result<(), WriteEventError> { | ||
match self { | ||
Self::Disabled => Ok(()), | ||
Self::Libtest(ltr) => ltr.write_event(event), | ||
} | ||
} | ||
} |
Oops, something went wrong.