Skip to content
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

Open
gibfahn opened this issue Aug 14, 2023 · 9 comments
Open

Allow customising number of lines shown before <n lines omitted> #180

gibfahn opened this issue Aug 14, 2023 · 9 comments

Comments

@gibfahn
Copy link

gibfahn commented Aug 14, 2023

Often in CI I find the important details are lost behind:

```
<72 lines omitted>
```

this makes it hard to debug issues. It would be great to have an environment variable or similar to customise how much is printed.

@epage
Copy link
Contributor

epage commented Aug 16, 2023

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.

@gibfahn
Copy link
Author

gibfahn commented Aug 31, 2023

A feature flag that disables truncating would be great for me if that works for you.

@epage
Copy link
Contributor

epage commented Aug 31, 2023

I'm also not a big fan of feature flags, so that was a bit of "which evil do I prefer?"

@gibfahn
Copy link
Author

gibfahn commented Sep 5, 2023

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);
// ...

@gibfahn
Copy link
Author

gibfahn commented Sep 25, 2023

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.

@s373r
Copy link

s373r commented Aug 13, 2024

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);
// ...

to be able to configure in this way would be very convenient -- also encountered the need to see the full output

@teythoon
Copy link

teythoon commented Dec 3, 2024

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:

thread 'integration::sq_cert_lint::sha1_authentication_subkey' panicked at /usr/src/rustc-1.82.0/library/core/src/ops/function.rs:250:5:
Unexpected return code, failed var == 0
└── var: 1

command=`cd "tests/data/cert-lint" && SEQUOIA_CRYPTO_POLICY="/tmp/.tmpdb9WUh/empty-policy.toml" "/target/debug/sq" "--batch" "--home" "/tmp/.tmpdb9WUh/home" "--time" "2024-12-03T14:17:03Z" "cert" "lint" "--time" "20220101" "--cert-file" "-"`
stdin=`<143 lines total>
` ``
-----BEGIN PGP PRIVATE KEY BLOCK-----

xcSYBF+r4VEBDACwtLvhy9Rmgeh/Y6Dd4KLAR/j9iERMtXZHNf+G/SvTUeRbIqcu
w4lqqne2r+mAmCqHSDw8qEP4II4rwT2KQ2lEubd8xpeDPRQO4Nl09nhyZiIYwvUT
WUXEcojppOT9hpM5OkQIlZYUdrtuswdgBjmTGs85/tpy/TCVh+ed2SYxOQtNGtpQ
BO8u0aFGme7Id5W72ctgCLqtuklejo/+0QWe37hHYELNCVW3RcRqs3jEGxR2fIa9
gf4jkWK08srPMoFByNdwmAS9cMreckLctAOKz14Pa/80Wb/mXx3hKC2+k2YFki27
V8cdwcZhfCzwlw2wL/J0YQ3LZ+7Zujtp59k8oHd/FHQYlKwgUFi0IhCWjJJEDVaR
gd6EpR0SLoU8nTed/WbWC276fJtm+K8FpwmHVOSgVJmLQwRj0ktfpSIum8yGyKdT
XjJj3PyVDeyU3OP1zOuN08cK9jtugjBqmt7u34wclzdHSi2cfH4Oz5xJaW2se83h
FXneKml82QxzfEUAEQEAAQAL+QGl9BV2j6aOquJJnnaYSSALGpc8DhUxZkcdxKxV
cF9xjMzmXLHvDNa0kDQ59iU9KJVRsMnXv6d6xuAZwvUdSAMXaBPmkbSdmtmZmfAh
SGwG6FINHaUuoogx4GHUT4qAAxXakdGU1XcBtXB6+pCOMgBdgPYbJIpXvI/k0EBY
cmuZbXa2bQZs+ke153wOQnJR8gIlQbMUUIjYAXSUQxRbUzuO1oNvnoEgfbPOoVR5
drSICphIpibyOTxBY+nt3nRseD1ISvDitDVK/nzlr7P4rqo873cifYnP27x4xObn
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aCJkpeircJjN6TtyV6YifTgqiKT0OuS
9clvqFoBi+mW5Gw4F50/SfiCh+8zsgt87MLA/AQYAQIAJhYhBEtvRiz1F1TXX2mW
Pw5G5/3RaQz/BQJfq+FRAhsMBQkDwmcAAAoJEA5G5/3RaQz/iEQL/2VrUh62pkx6
tLoHObJgmvHD2WZmpTQH+QjR/LtkvwyD3hS+kRlcN09Mb5/LTG25vz2qG7m2ZYXP
CceWcqnXORTd6OrlaPNU45CLmSv1gQUwDdgwF+gH9QZ+GjdlldBTLFfFpOmpFOWq
n4QySXB+k583lJNCDSBoyR1VuSw5CFr36W/Z4NFgM/5DcZaXw9B77QtVRv9hkqhf
xsRanTR2aBTFo+m1LPN3HWwXJE9iuZ7WZ7vAgwrbypas5/kKxzuFncebtaGTZXeI
9aZM1lknaO8S5UQJNtHOzcHrTedfGwiz3Z+doJkjeTLaf6k4GqkfWDCACCURmLC3
yGM3/CN6TBP/fPozdNo43H/XEHIxHkRc/bT5PnocCrwu51k+zpCAvbsNLn/HEM3B
IqZQm9H4yj8wJs7Lqm85iEMXXywCto1N9XyMUlb4lqHm4pD0OX/NkGFU6BfHYu1E
6OUMVjSAuug71XalrwxdCKrUdGvONlM0YfBvsgJlIITIZB9fw+G24w==
=k0Y8
-----END PGP PRIVATE KEY BLOCK-----
` ``
`
code=1
stdout=""
stderr=```
Certificate 0E46E7FDD1690CFF, key 95722DD2AF2BA4B6 uses a SHA-1-protected binding signature.
Examined 1 certificate.
  0 certificates are invalid and were not linted. (GOOD)
  1 certificate was linted.
  1 of the 1 certificates (100%) has at least one issue. (BAD)
0 of the linted certificates were revoked.
  0 of the 0 certificates has revocation certificates that are weaker than the certificate and should be recreated. (GOOD)
0 of the linted certificates were expired.
1 of the non-revoked linted certificate has at least one non-revoked User ID:
  0 have at least one User ID protected by SHA-1. (GOOD)
  0 have all User IDs protected by SHA-1. (GOOD)
1 of the non-revoked linted certificates has at least one non-revoked, live subkey:
  1 has at least one non-revoked, live subkey with a binding signature that uses SHA-1. (BAD)
0 of the non-revoked linted certificates have at least one non-revoked, live, signing-capable subkey:
  0 certificates have at least one non-revoked, live, signing-capable subkey with a strong binding signature, but a backsig that uses SHA-1. (GOOD)

  Error: 1 certificate have at least one issue
` ``

Sadly, the intermediate value has been truncated, so we cannot reproduce the problem locally.

@s373r
Copy link

s373r commented Dec 16, 2024

@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.

@gibfahn
Copy link
Author

gibfahn commented Dec 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants