-
Notifications
You must be signed in to change notification settings - Fork 40
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
Allow customising number of lines shown before <n lines omitted> #180
Comments
I've been hesitant to include env variables for controlling things, so far. Unsure if I'm more open to that or a feature flag. |
A feature flag that disables truncating would be great for me if that works for you. |
I'm also not a big fan of feature flags, so that was a bit of "which evil do I prefer?" |
Fair enough. I keep hitting issues where truncated output hides the key details of what went wrong in CI, so I'm also weighing up using a git fork (not ideal) vs not using the crate, vs waiting for this to be an option. I guess this could also be a set of options on the Command struct, so I could do something like: let mut cmd = Command::cargo_bin("mycli")?;
cmd.truncate(false);
// ... |
An alternative would be an option to print the full stdout and stderr to a temp file somewhere, so when the output is small one could just see it inline, but when it is large one could go find it if needed. |
to be able to configure in this way would be very convenient -- also encountered the need to see the full output |
I also like to see a way to disable truncation. I just pulled that from our CI logs, which is evidence of a problem that we have never seen before, so it must be quite rare:
Sadly, the intermediate value has been truncated, so we cannot reproduce the problem locally. |
@teythoon , alternatively as a workaround, you can use this fork (https://github.com/kamu-data/assert_cmd): [patch.crates-io]
assert_cmd = { git = 'https://github.com/kamu-data/assert_cmd', branch = "deactivate-output-truncation" } (c) https://github.com/kamu-data/kamu-cli/blob/176a781910530d9e73c23415692ebae927c9a3e8/Cargo.toml#L274 We use it on a large volume of tests and large outputs, long time. |
What I did was add this method to my test utils file: /// Extensions to `assert_cmd` functions.
pub trait AssertCmdExt {
/**
`assert_cmd`'s assert functions truncate the stdout and stderr.
This is painful in CI, so add a function to always print them in CI.
Refs: <https://github.com/assert-rs/assert_cmd/issues/180>
*/
fn eprint_stdout_stderr(self) -> Self;
}
impl AssertCmdExt for assert_cmd::assert::Assert {
/**
`assert_cmd`'s assert functions truncate the stdout and stderr.
This is painful in CI, so add a function to always print them in CI.
In general instead of `.success()?` and `.stderr()` we use `.try_success()?` and
`.try_stderr()?`. This is mostly to remind the author to use this method before
asserting.
Refs: <https://github.com/assert-rs/assert_cmd/issues/180>
*/
fn eprint_stdout_stderr(self) -> Self {
let output = self.get_output();
eprintln!(
"COMMAND STDOUT:\n-------------------\n<<<<\n{stdout}\n>>>>\n\COMMAND \
STDERR:\n-------------------\n<<<<\n{stderr}\n>>>>",
stdout = String::from_utf8_lossy(&output.stdout),
stderr = String::from_utf8_lossy(&output.stderr),
);
self
}
} Then I use this crate like: Command::cargo_bin("my-crate")?
.arg("run")
.assert()
.eprint_stdout_stderr()
.try_success()?
.try_stdout(expected_value)?; Downside is it prints the full and then the truncated output (but also prints the full output with proper colour codes). Upside is I don't need to fork the crate, and then have to maintain said fork. |
Often in CI I find the important details are lost behind:
this makes it hard to debug issues. It would be great to have an environment variable or similar to customise how much is printed.
The text was updated successfully, but these errors were encountered: