diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOstdout.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOstdout.java index 5ea0d851df..79ad77080f 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOstdout.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOstdout.java @@ -27,6 +27,7 @@ */ package EOorg.EOeolang.EOio; +import java.io.PrintStream; import org.eolang.AtComposite; import org.eolang.AtFree; import org.eolang.Data; @@ -44,10 +45,24 @@ @XmirObject(oname = "stdout") public class EOstdout extends PhDefault { /** - * Ctor. + * Default out print stream. + */ + private static final PrintStream OUT = System.out; + + /** + * Default ctor. * @param sigma Sigma */ public EOstdout(final Phi sigma) { + this(sigma, EOstdout.OUT); + } + + /** + * Ctor for the tests. + * @param sigma Sigma + * @param out Stream to print + */ + EOstdout(final Phi sigma, final PrintStream out) { super(sigma); this.add("text", new AtFree()); this.add( @@ -55,7 +70,7 @@ public EOstdout(final Phi sigma) { new AtComposite( this, rho -> { - System.out.print( + out.print( new Param(rho, "text").strong(String.class) ); return new Data.ToPhi(true); diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java index 3260caee0a..cd48dec879 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java @@ -28,6 +28,8 @@ package EOorg.EOeolang.EOio; import EOorg.EOeolang.EOseq; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; import org.eolang.Data; import org.eolang.Dataized; import org.eolang.PhCopy; @@ -36,28 +38,18 @@ import org.eolang.Phi; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -import org.junitpioneer.jupiter.StdIo; -import org.junitpioneer.jupiter.StdOut; /** * Test case for {@link EOstdout}. * * @since 0.1 - * @todo #2336:90min Enable all the tests in EOstdoutTest. - * The tests are disabled because they are flaky. - * The original issue is here: - * - https://github.com/objectionary/eo/issues/2371 - * When the issue is fixed, enable the tests and remove the @Disabled annotation. - * Don't forget to remove the puzzle itself. */ public final class EOstdoutTest { @Test - @Disabled("https://github.com/objectionary/eo/issues/2371") public void printsString() { final Phi format = new Data.ToPhi("Hello, world!\n"); final Phi phi = new PhWith( @@ -71,11 +63,10 @@ public void printsString() { ); } - @StdIo @ParameterizedTest @CsvSource({"lt", "gt", "lte", "gte"}) - @Disabled("https://github.com/objectionary/eo/issues/2371") - public void doesNotPrintTwiceOnIntComparisonMethods(final String method, final StdOut out) { + public void doesNotPrintTwiceOnIntComparisonMethods(final String method) { + final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final String str = "Hello world"; new Dataized( new PhWith( @@ -89,7 +80,7 @@ public void doesNotPrintTwiceOnIntComparisonMethods(final String method, final S new EOseq(Phi.Φ), 0, new PhWith( - new EOstdout(Phi.Φ), + new EOstdout(Phi.Φ, new PrintStream(stream)), "text", new Data.ToPhi(str) ) @@ -100,17 +91,15 @@ public void doesNotPrintTwiceOnIntComparisonMethods(final String method, final S ) ).take(); MatcherAssert.assertThat( - out.capturedLines()[0], + stream.toString(), Matchers.equalTo(str) ); - out.capturedLines(); } - @StdIo - @ParameterizedTest + @ParameterizedTest() @CsvSource({"lt", "gt", "lte", "gte"}) - @Disabled("https://github.com/objectionary/eo/issues/2371") - public void doesNotPrintTwiceOnFloatComparisonMethods(final String method, final StdOut out) { + public void doesNotPrintTwiceOnFloatComparisonMethods(final String method) { + final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final String str = "Hello world"; new Dataized( new PhWith( @@ -124,7 +113,7 @@ public void doesNotPrintTwiceOnFloatComparisonMethods(final String method, final new EOseq(Phi.Φ), 0, new PhWith( - new EOstdout(Phi.Φ), + new EOstdout(Phi.Φ, new PrintStream(stream)), "text", new Data.ToPhi(str) ) @@ -135,7 +124,7 @@ public void doesNotPrintTwiceOnFloatComparisonMethods(final String method, final ) ).take(); MatcherAssert.assertThat( - out.capturedLines()[0], + stream.toString(), Matchers.equalTo(str) ); }