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

1 participant