-
-
Notifications
You must be signed in to change notification settings - Fork 120
Add support for silencing only one of the outputs of a test (cont.) #2517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ArhanChaudhary
wants to merge
2
commits into
nextest-rs:main
Choose a base branch
from
ArhanChaudhary-forks:stdout-stderr-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -37,6 +37,7 @@ use nextest_runner::{ | |
redact::Redactor, | ||
reporter::{ | ||
FinalStatusLevel, ReporterBuilder, StatusLevel, TestOutputDisplay, TestOutputErrorSlice, | ||
displayer::TestOutputDisplayStreams, | ||
events::{FinalRunStats, RunStatsFailureKind}, | ||
highlight_end, structured, | ||
}, | ||
|
@@ -57,6 +58,7 @@ use std::{ | |
env::VarError, | ||
fmt, | ||
io::{Cursor, Write}, | ||
str::FromStr, | ||
sync::{Arc, OnceLock}, | ||
time::Duration, | ||
}; | ||
|
@@ -1027,13 +1029,19 @@ fn non_zero_duration(input: &str) -> Result<Duration, String> { | |
#[derive(Debug, Default, Args)] | ||
#[command(next_help_heading = "Reporter options")] | ||
struct ReporterOpts { | ||
/// Output stdout and stderr on failure | ||
/// Output stdout and/or stderr on failure | ||
/// | ||
/// Takes the form of: '{value}' or 'stdout={value}' or 'stdout={value},stderr={value}' | ||
/// where {value} is one of: 'immediate', 'immediate-final', 'final', 'never' | ||
#[arg(long, value_enum, value_name = "WHEN", env = "NEXTEST_FAILURE_OUTPUT")] | ||
failure_output: Option<TestOutputDisplayOpt>, | ||
failure_output: Option<TestOutputDisplayStreamsOpt>, | ||
|
||
/// Output stdout and stderr on success | ||
/// Output stdout and/or stderr on success | ||
/// | ||
/// Takes the form of: '{value}' or 'stdout={value}' or 'stdout={value},stderr={value}' | ||
/// where {value} is one of: 'immediate', 'immediate-final', 'final', 'never' | ||
#[arg(long, value_enum, value_name = "WHEN", env = "NEXTEST_SUCCESS_OUTPUT")] | ||
success_output: Option<TestOutputDisplayOpt>, | ||
success_output: Option<TestOutputDisplayStreamsOpt>, | ||
|
||
// status_level does not conflict with --no-capture because pass vs skip still makes sense. | ||
/// Test statuses to output | ||
|
@@ -1152,6 +1160,68 @@ impl ReporterOpts { | |
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
struct TestOutputDisplayStreamsOpt { | ||
stdout: Option<TestOutputDisplayOpt>, | ||
stderr: Option<TestOutputDisplayOpt>, | ||
} | ||
|
||
impl FromStr for TestOutputDisplayStreamsOpt { | ||
type Err = String; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
// expected input has three forms | ||
// - "{value}": where value is one of [immediate, immediate-final, final, never] | ||
// - "{stream}={value}": where {stream} is one of [stdout, stderr] | ||
// - "{stream}={value},{stream=value}": where the two {stream} keys cannot be the same | ||
let (stdout, stderr) = if let Some((left, right)) = s.split_once(',') { | ||
// the "{stream}={value},{stream=value}" case | ||
let left = left | ||
.split_once('=') | ||
.map(|l| (l.0, TestOutputDisplayOpt::from_str(l.1, false))); | ||
let right = right | ||
.split_once('=') | ||
.map(|r| (r.0, TestOutputDisplayOpt::from_str(r.1, false))); | ||
match (left, right) { | ||
(Some(("stderr", Ok(stderr))), Some(("stdout", Ok(stdout)))) => (Some(stdout), Some(stderr)), | ||
(Some(("stdout", Ok(stdout))), Some(("stderr", Ok(stderr)))) => (Some(stdout), Some(stderr)), | ||
(Some((stream @ "stdout" | stream @ "stderr", Err(_))), _) => return Err(format!("\n unrecognized setting for {stream}: [possible values: immediate, immediate-final, final, never]")), | ||
(_, Some((stream @ "stdout" | stream @ "stderr", Err(_)))) => return Err(format!("\n unrecognized setting for {stream}: [possible values: immediate, immediate-final, final, never]")), | ||
Comment on lines
+1188
to
+1189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should return a structured error ( |
||
(Some(("stdout", _)), Some(("stdout", _))) => return Err("\n stdout specified twice".to_string()), | ||
(Some(("stderr", _)), Some(("stderr", _))) => return Err("\n stderr specified twice".to_string()), | ||
(Some((stream, _)), Some(("stdout" | "stderr", _))) => return Err(format!("\n unrecognized output stream '{stream}': [possible values: stdout, stderr]")), | ||
(Some(("stdout" | "stderr", _)), Some((stream, _))) => return Err(format!("\n unrecognized output stream '{stream}': [possible values: stdout, stderr]")), | ||
(_, _) => return Err("\n [possible values: immediate, immediate-final, final, never], or specify one or both output streams: stdout={}, stderr={}, stdout={},stderr={}".to_string()), | ||
} | ||
} else if let Some((stream, right)) = s.split_once('=') { | ||
// the "{stream}={value}" case | ||
let value = TestOutputDisplayOpt::from_str(right, false); | ||
match (stream, value) { | ||
("stderr", Ok(stderr)) => (None, Some(stderr)), | ||
("stdout", Ok(stdout)) => (Some(stdout), None), | ||
("stdout" | "stderr", Err(_)) => return Err(format!("\n unrecognized setting for {stream}: [possible values: immediate, immediate-final, final, never]")), | ||
(_, _) => return Err("\n unrecognized output stream, possible values: [stdout={}, stderr={}, stdout={},stderr={}]".to_string()) | ||
} | ||
} else if let Ok(value) = TestOutputDisplayOpt::from_str(s, false) { | ||
// the "{value}" case | ||
(Some(value), Some(value)) | ||
} else { | ||
// did not recognize one of the three cases | ||
return Err("\n [possible values: immediate, immediate-final, final, never], or specify one or both output streams: stdout={}, stderr={}, stdout={},stderr={}".to_string()); | ||
}; | ||
Ok(Self { stdout, stderr }) | ||
} | ||
} | ||
|
||
impl From<TestOutputDisplayStreamsOpt> for TestOutputDisplayStreams { | ||
fn from(value: TestOutputDisplayStreamsOpt) -> Self { | ||
Self { | ||
stdout: value.stdout.map(TestOutputDisplay::from), | ||
stderr: value.stderr.map(TestOutputDisplay::from), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, ValueEnum)] | ||
enum TestOutputDisplayOpt { | ||
Immediate, | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's got to be a much better way to write this. One way would be to write a small left-to-right parser using winnow for this, reading characters until you reach a comma or equals sign. Another would be to first decompose the string into components, and then match on them.
This also needs tests.