Skip to content

Deliver the interpreter output of tests to RunTests - #1205

Open
Donach wants to merge 1 commit into
wurstscript:masterfrom
Code-Fixxers:fix/interpreter-output-redirect
Open

Deliver the interpreter output of tests to RunTests#1205
Donach wants to merge 1 commit into
wurstscript:masterfrom
Code-Fixxers:fix/interpreter-output-redirect

Conversation

@Donach

@Donach Donach commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

RunTests.redirectInterpreterOutput installs a stream so that whatever the tests print
goes to RunTests' own output. That stream never received anything: the output went
straight to System.err, bypassing RunTests entirely. A side effect is that
-compactOutput cannot suppress it either, so it still shows up in CI logs.

Three independent reasons, each fixed here:

  • ProgramStateIO shadows the stream. It declares its own private PrintStream outStream and overrides getOutStream/setOutStream on top of ProgramState, which
    already has both. The base implementation forwards the new stream to every registered
    NativesProvider; the override did not, so the providers kept their old stream. The
    field and the two overrides are removed and the base class does the work.

  • ReflectionNativeProvider.setOutStream is empty. It is the provider that owns
    OutputProvider, which implements println, BJDebugMsg, DisplayTextToPlayer and the
    other printing natives. Because the setter did nothing, OutputProvider kept its
    default System.err. It now forwards to the OutputProvider instances it holds, and
    OutputProvider gets the corresponding setter.

  • The PrintStream has no autoflush. Even with the two fixes above, output sat in the
    8 KB buffer of new PrintStream(os) and was never flushed, so a normal test run
    delivered nothing. It now autoflushes, with an explicit UTF-8 charset on the encoding
    side and the matching new String(bytes, UTF_8) on the decoding side, which also fixes
    non-ASCII output being decoded with the platform default charset.

Effect

Output printed by tests during -runtests now reaches the stream RunTests prints to
(stdout on the CLI) instead of System.err, which is what the redirection was written to
do, and -compactOutput suppresses it as intended.

Tests

RunTestsOutputRedirectTests compiles a package with one passing and one failing test that
both print, and asserts the printed output arrives in RunTests' sink, that
-compactOutput suppresses it, and that the summary and assertion message are unaffected.
interpreterOutputIsRedirected fails on unmodified master and passes with this change;
the full ./gradlew test suite passes.

RunTests.redirectInterpreterOutput never received anything, so whatever a
test printed went to System.err instead of the stream RunTests writes to.
As a consequence -compactOutput could not suppress that output either.

Three independent reasons, all fixed here:

- ProgramStateIO shadowed ProgramState.outStream with its own field and
  overrode getOutStream/setOutStream without forwarding to the native
  providers. Removed, the base class already implements both correctly.
- ReflectionNativeProvider.setOutStream was an empty method, so
  OutputProvider, which implements println/BJDebugMsg/DisplayTextToPlayer
  and friends, kept writing to its default System.err.
- The PrintStream wrapping the redirect had no autoflush, so its buffer
  was never emptied. It now autoflushes and uses an explicit UTF-8
  charset on both the encoding and the decoding side.
@Frotty

Frotty commented Jul 26, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4427ebbdd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

public void write(byte[] b, int off, int len) throws IOException {
if (!compactOutput) {
println(new String(b, off, len));
println(new String(b, off, len, StandardCharsets.UTF_8));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid appending a second line separator

In non-compact runs, every output native calls PrintStream.println, and PrintStream passes bytes that already contain the line separator to this bulk-write method. Calling RunTests.println here appends another separator, so each interpreter output line is delivered with an unintended blank line; forward the decoded chunk with print instead.

Useful? React with 👍 / 👎.

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

Successfully merging this pull request may close these issues.

2 participants