Skip to content

Conversation

Zalathar
Copy link
Contributor

In order to stop using #![feature(internal_output_capture)] in compiletest, we need to be able to capture the console output of individual tests run by the executor.

The approach I have planned is to have all test runners print “console” output into a trait object that is passed around as part of TestCx, since almost all test-runner code has easy access to that context. So println!("foo") will become writeln!(self.stdout, "foo"), and so on.

In order to make that viable, we need to avoid unnecessary printing in places that don't have easy access to TestCx. To do so, we can either get rid of unnecessary print statements, or rearrange the code to make the context available. This PR uses both approaches.

r? jieyouxu

Running `./x --verbose` will still print out the command-line arguments, and
setting `RUST_LOG=compiletest` will now log the full config instead of a
subset.
When working on a new output-capture system, this will make it easier to obtain
a capturing stream from the test context.
The code in this module is always called in the context of running an
individual tests, and sometimes prints output that needs to be captured.

Moving this module into `runtest` will make it easier to find and audit all of
the print statements that need to be updated when overhauling output-capture.
This appears to have been leftover debugging code.

If the capture information turns out to have still been useful, we can find a
way to emit it in a way that doesn't interfere with overhauling compiletests's
output capture system.
@rustbot
Copy link
Collaborator

rustbot commented Aug 29, 2025

jieyouxu is currently at their maximum review capacity.
They may take a while to respond.

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 29, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@Zalathar
Copy link
Contributor Author

I was also going to overhaul panic-capture, but that ended up making the PR much larger, so I've split off this initial chunk to make review a bit easier.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good overall, just a question re. logging the config

View changes since this review

@@ -538,6 +492,8 @@ pub fn opt_str2(maybestr: Option<String>) -> String {

/// Called by `main` after the config has been parsed.
pub fn run_tests(config: Arc<Config>) {
debug!(?config, "run_tests");
Copy link
Member

@jieyouxu jieyouxu Aug 29, 2025

Choose a reason for hiding this comment

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

Discussion: hm, I think it was originally intended so the config gets logged when run in CI?

EDIT: wait no, that can't be right, I don't remember us passing --verbose in CI 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we suspect it's still useful, I can add in a println!("{config:#?}") to just dump the whole config.

(It's mostly redundant with the compiletest command-line arguments that ./x --verbose will print out anyway, but I suppose that seeing the post-parse config could have some value.)

Copy link
Member

Choose a reason for hiding this comment

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

Hm right. I think we might want to dump the post-parse config under CI env, but not necessary for this PR.

@jieyouxu
Copy link
Member

You can r=me after PR CI is 🟢

@Zalathar
Copy link
Contributor Author

@bors r=jieyouxu rollup

@bors
Copy link
Collaborator

bors commented Aug 29, 2025

📌 Commit 6340b97 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 29, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 29, 2025
compiletest: Reduce the number of `println!` calls that don't have access to `TestCx`

In order to stop using `#![feature(internal_output_capture)]` in compiletest, we need to be able to capture the console output of individual tests run by the executor.

The approach I have planned is to have all test runners print “console” output into a trait object that is passed around as part of `TestCx`, since almost all test-runner code has easy access to that context. So `println!("foo")` will become `writeln!(self.stdout, "foo")`, and so on.

In order to make that viable, we need to avoid unnecessary printing in places that don't have easy access to `TestCx`. To do so, we can either get rid of unnecessary print statements, or rearrange the code to make the context available. This PR uses both approaches.

r? jieyouxu
bors added a commit that referenced this pull request Aug 29, 2025
Rollup of 4 pull requests

Successful merges:

 - #145675 (Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#1 of Batch #2])
 - #145676 (Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#2 of Batch #2])
 - #145982 (compiletest: Reduce the number of `println!` calls that don't have access to `TestCx`)
 - #145984 (`TokenStream` cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants