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

Color test output and shorten chapter paths #2259

Merged
merged 1 commit into from May 10, 2024

Conversation

stevecheckoway
Copy link
Contributor

Currently, the output from rustdoc --test is not colored because rustdoc's stdout is not a tty. The output of a failed rustdoc run is sent to mdbook's stderr via the error!() macro. This commit checks if stderr is a tty using the standard .is_terminal() and if so, passes --color always to rustdoc.

The test output from rustdoc includes the full path that rustdoc was called with. This obfuscates the file with the error. E.g.,

---- /var/folders/9v/90bm7kb10fx3_bprxltb3t1r0000gn/T/mdbook-tnGJxp/lab0/index.md - Lab_0__Getting_Started (line 3) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `code`
 --> /var/folders/9v/90bm7kb10fx3_bprxltb3t1r0000gn/T/mdbook-tnGJxp/lab0/index.md:4:6
  |
3 | this code has a bug
  |      ^^^^ expected one of 8 possible tokens

This commit runs rustdoc in the temp directory and replaces any relative library paths with absolute library paths. This leads to simpler error messages. The one above becomes

---- lab0/index.md - Lab_0__Getting_Started (line 3) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `code`
 --> lab0/index.md:4:6
  |
3 | this code has a bug
  |      ^^^^ expected one of 8 possible tokens

error: aborting due to previous error

(with colors, of course).

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Dec 6, 2023
@stevecheckoway
Copy link
Contributor Author

Here's a screenshot of the output mentioned in the commit message.
image

Currently, the output from `rustdoc --test` is not colored because
`rustdoc`'s stdout is not a tty. The output of a failed `rustdoc` run is
sent to `mdbook`'s stderr via the `error!()` macro. This commit checks
if stderr is a tty using the standard `.is_terminal()` and if so, passes
`--color always` to `rustdoc`.

The test output from `rustdoc` includes the full path that `rustdoc` was
called with. This obscures the path of the file with the error. E.g.,
```
---- /var/folders/9v/90bm7kb10fx3_bprxltb3t1r0000gn/T/mdbook-tnGJxp/lab0/index.md - Lab_0__Getting_Started (line 3) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `code`
 --> /var/folders/9v/90bm7kb10fx3_bprxltb3t1r0000gn/T/mdbook-tnGJxp/lab0/index.md:4:6
  |
3 | this code has a bug
  |      ^^^^ expected one of 8 possible tokens

error: aborting due to previous error
```

This commit runs `rustdoc` in the temp directory and replaces any
relative library paths with absolute library paths. This leads to
simpler error messages. The one above becomes
```
---- lab0/index.md - Lab_0__Getting_Started (line 3) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `code`
 --> lab0/index.md:4:6
  |
3 | this code has a bug
  |      ^^^^ expected one of 8 possible tokens

error: aborting due to previous error
```
(with colors, of course).
@stevecheckoway
Copy link
Contributor Author

I realized after creating this PR that I had accidentally included an unrelated change that causes mdbook to mimic how cargo test runs rustdoc by passing-C embed-bitcode=no --error-format human.

I split the commit into two different commits. The first commit makes the changes described above. The second commit just adds these command line options. I'm happy to drop the second commit, but the -C embed-bitcode=no part at least is probably useful to (very slightly) speed up tests, regardless of whether you want the colored output/shorter file paths.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I went ahead and dropped the second commit. -C embed-bitcode=no has no effect, since rustdoc is only generating executables, and those do not have bitcode. And --error-format=human is the default, so there shouldn't be a need to set that.

@ehuss ehuss enabled auto-merge May 10, 2024 18:11
@ehuss ehuss added this pull request to the merge queue May 10, 2024
Merged via the queue into rust-lang:master with commit 2420919 May 10, 2024
8 checks passed
@stevecheckoway stevecheckoway deleted the improve-test-output branch May 10, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: waiting on a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants