#3236 include EOorg tests

This commit is contained in:
Roman Korostinskiy 2024-08-05 18:42:12 +03:00
parent 7741191203
commit 2be544b23b
No known key found for this signature in database
18 changed files with 90 additions and 55 deletions

View File

@ -343,7 +343,6 @@ SOFTWARE.
resolved.
-->
<exclude>pmd:/src/main/java/EOorg/.*</exclude>
<exclude>pmd:/src/test/java/EOorg/.*</exclude>
<exclude>dependencies:org.eolang:eo-maven-plugin</exclude>
</excludes>
</configuration>

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (4 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import org.eolang.AtCompositeTest;
import org.eolang.Data;

View File

@ -24,14 +24,14 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import org.eolang.AtCompositeTest;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhWith;
import org.eolang.Phi;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import org.eolang.AtCompositeTest;
import org.eolang.Data;

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -202,7 +203,7 @@ final class EOcageTest {
*/
@Nested
@Execution(ExecutionMode.SAME_THREAD)
class RecursionTests {
final class RecursionTests {
/**
* DEPTH.
@ -212,7 +213,7 @@ final class EOcageTest {
@BeforeEach
void setDepth() {
System.setProperty(
PhTraced.RECURSION_LIMIT, String.valueOf(MAX_DEPTH)
PhTraced.RECURSION_LIMIT, String.valueOf(EOcageTest.RecursionTests.MAX_DEPTH)
);
}
@ -403,6 +404,7 @@ final class EOcageTest {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
Dummy() {
this.add("x", new AtVoid("x"));
}

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import java.util.stream.Stream;
import org.eolang.AtComposite;
@ -109,6 +110,7 @@ final class EOerrorTest {
* Ctor.
* @param data The data inside error.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
MyError(final Object data) {
this.add(
"φ",

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import com.jcabi.log.Logger;
import org.eolang.PhDefault;
@ -46,6 +47,7 @@ public final class EOfailed extends PhDefault {
* Ctor.
* @param arg Argument
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
public EOfailed(final String arg) {
super();
Logger.info(this, "EOfailed %s", arg);

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang.EOfs;
package EOorg.EOeolang.EOfs; // NOPMD
import java.nio.file.Path;
import org.eolang.Data;

View File

@ -24,10 +24,11 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang.EOfs;
package EOorg.EOeolang.EOfs; // NOPMD
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
@ -85,11 +86,10 @@ final class FilesTest {
@Test
void readsFromFile(@TempDir final Path dir) throws IOException {
final String file = FilesTest.tempFile(dir);
final FileWriter writer = new FileWriter(
Paths.get(file).toFile()
);
writer.write("Hello, world");
writer.close();
try (BufferedWriter writer =
java.nio.file.Files.newBufferedWriter(Paths.get(file))) {
writer.write("Hello, world");
}
FilesTest.INSTANCE.open(file);
MatcherAssert.assertThat(
"The string should have been read from file",
@ -102,11 +102,10 @@ final class FilesTest {
@Test
void writesToFile(@TempDir final Path dir) throws IOException {
final String file = FilesTest.tempFile(dir);
final FileWriter writer = new FileWriter(
Paths.get(file).toFile()
);
writer.write("Hello, world");
writer.close();
try (BufferedWriter writer =
java.nio.file.Files.newBufferedWriter(Paths.get(file))) {
writer.write("Hello, world");
}
FilesTest.INSTANCE.open(file);
FilesTest.INSTANCE.write(file, "!".getBytes(StandardCharsets.UTF_8));
MatcherAssert.assertThat(

View File

@ -24,6 +24,7 @@
/*
* @checkstyle PackageNameCheck (20 lines)
* @checkstyle TrailingCommentCheck (20 lines)
*/
/**
@ -31,4 +32,4 @@
*
* @since 0.40
*/
package EOorg.EOeolang.EOfs;
package EOorg.EOeolang.EOfs; // NOPMD

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang.EOio;
package EOorg.EOeolang.EOio; // NOPMD
import org.eolang.Data;
import org.eolang.Dataized;
@ -47,13 +48,19 @@ import org.junitpioneer.jupiter.StdOut;
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
final class EOconsoleTest {
/**
* Hello.
*/
private static final String HELLO = "Hello";
@Test
@StdIo
void printsFromTuple(final StdOut output) {
final Phi tuple = Phi.Φ.take("org").take("eolang").take("tuple");
final Phi copy = tuple.copy();
copy.put(0, tuple.take("empty"));
copy.put(1, new Data.ToPhi("Hello"));
copy.put(1, new Data.ToPhi(EOconsoleTest.HELLO));
final Phi ret = copy.take("at").copy();
ret.put(0, new Data.ToPhi(0L));
final Phi written = new EOconsole$EOwrite$EOwritten_bytes();
@ -62,7 +69,7 @@ final class EOconsoleTest {
MatcherAssert.assertThat(
"The `console.write.written-bytes` object should have printed string from `tuple`, but it didn't",
output.capturedString(),
Matchers.equalTo("Hello")
Matchers.equalTo(EOconsoleTest.HELLO)
);
}
@ -83,7 +90,7 @@ final class EOconsoleTest {
@StdIo
void writesToConsoleSequentially(final StdOut output) {
final Phi console = Phi.Φ.take("org.eolang.io.console");
final Phi buffer = new Data.ToPhi("Hello");
final Phi buffer = new Data.ToPhi(EOconsoleTest.HELLO);
final Phi first = new PhWith(
new PhCopy(
new PhMethod(console, "write")
@ -120,7 +127,7 @@ final class EOconsoleTest {
}
@Test
@StdIo("Hello")
@StdIo(EOconsoleTest.HELLO)
void readsOnlyAvailableBytes(final StdIn input) {
MatcherAssert.assertThat(
String.join(
@ -134,7 +141,7 @@ final class EOconsoleTest {
0, new Data.ToPhi(10)
)
).asString(),
Matchers.equalTo("Hello".concat(System.lineSeparator()))
Matchers.equalTo(EOconsoleTest.HELLO.concat(System.lineSeparator()))
);
}
@ -168,7 +175,7 @@ final class EOconsoleTest {
0, new Data.ToPhi(5)
)
).asString(),
Matchers.equalTo("Hello")
Matchers.equalTo(EOconsoleTest.HELLO)
);
MatcherAssert.assertThat(
"The object `console.read.read-bytes` should have read second 5 bytes from standard input, but it didn't",

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang.EOio;
package EOorg.EOeolang.EOio; // NOPMD
import org.eolang.AtCompositeTest;
import org.eolang.Dataized;
@ -47,11 +48,17 @@ import org.junitpioneer.jupiter.StdIo;
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
final class EOstdinTest {
/**
* Next line.
*/
private static final String NEXT_LINE = "next-line";
@StdIo("this is a test input!")
@Test
void dataizesNextLineOneLine() {
final String expected = "this is a test input!";
final Phi phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
final Phi phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
final String actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
@ -77,7 +84,7 @@ final class EOstdinTest {
@Test
void dataizesNextLineMultiLine() {
final String expected = "this is a test input!";
final Phi phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
final Phi phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
final String actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
@ -89,7 +96,7 @@ final class EOstdinTest {
@StdIo("")
@Test
void dataizesNextLineEmpty() {
final Phi phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
final Phi phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
final String input = Assertions.assertDoesNotThrow(
() -> new Dataized(phi).asString(),
AtCompositeTest.TO_ADD_MESSAGE
@ -132,21 +139,21 @@ final class EOstdinTest {
final String first = "\u0066\u0069\u0072\u0073\u0074";
final String second = "\u0073\u0065\u0063\u006F\u006E\u0064";
final String third = "\u0074\u0068\u0069\u0072\u0064";
Phi phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
Phi phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
String actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
actual,
Matchers.equalTo(first)
);
phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
actual,
Matchers.equalTo(second)
);
phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
@ -160,21 +167,21 @@ final class EOstdinTest {
void dataizesStdinEmptyLineBetweenNonEmpty() {
final String first = "\u0066\u0069\u0072\u0073\u0074";
final String third = "\u0074\u0068\u0069\u0072\u0064";
Phi phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
Phi phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
String actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
actual,
Matchers.equalTo(first)
);
phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
actual,
Matchers.equalTo("")
);
phi = new PhMethod(new PhCopy(new EOstdin()), "next-line");
phi = new PhMethod(new PhCopy(new EOstdin()), EOstdinTest.NEXT_LINE);
actual = new Dataized(phi).asString();
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,

View File

@ -24,6 +24,7 @@
/*
* @checkstyle PackageNameCheck (20 lines)
* @checkstyle TrailingCommentCheck (20 lines)
*/
/**
@ -31,4 +32,4 @@
*
* @since 0.1
*/
package EOorg.EOeolang.EOio;
package EOorg.EOeolang.EOio; // NOPMD

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import org.eolang.AtComposite;
import org.eolang.AtCompositeTest;
@ -108,6 +109,7 @@ final class EOmallocTest {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
Dummy() {
this.add("m", new AtVoid("m"));
this.add(
@ -138,6 +140,7 @@ final class EOmallocTest {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
ErrorDummy() {
this.add("m", new AtVoid("m"));
this.add(

View File

@ -24,12 +24,12 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import EOorg.EOeolang.EOio.EOconsole$EOwrite$EOwritten_bytes;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import org.eolang.AtComposite;
import org.eolang.AtCompositeTest;
@ -137,6 +137,7 @@ final class EOnumberTest {
* @param value Phi value to be compared
* @param stdout Object that can print
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
PrintWithCmp(final Phi method, final Phi value, final Phi stdout) {
super();
this.add(

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import org.eolang.AtComposite;
import org.eolang.AtCompositeTest;
@ -49,7 +50,7 @@ import org.junit.jupiter.api.Test;
final class EOtryTest {
@Test
public void catchesException() {
void catchesException() {
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
new Dataized(
@ -70,7 +71,7 @@ final class EOtryTest {
}
@Test
public void usesCatcherOutput() {
void usesCatcherOutput() {
final Phi body = new PhWith(
new PhWith(
new PhWith(
@ -90,7 +91,7 @@ final class EOtryTest {
}
@Test
public void worksWithoutException() {
void worksWithoutException() {
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
new Dataized(
@ -111,7 +112,7 @@ final class EOtryTest {
}
@Test
public void doesNotDataizeBodyTwice() {
void doesNotDataizeBodyTwice() {
final Phi trier = new EOtry();
final MainWithCounter main = new MainWithCounter();
trier.put(0, main);
@ -138,6 +139,7 @@ final class EOtryTest {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
MainWithCounter() {
super();
this.add(
@ -162,6 +164,7 @@ final class EOtryTest {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
Main() {
this.add(
"φ",
@ -183,6 +186,7 @@ final class EOtryTest {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
Broken() {
this.add(
"φ",
@ -204,6 +208,7 @@ final class EOtryTest {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
Catcher() {
this.add("ex", new AtVoid("ex"));
this.add(

View File

@ -24,8 +24,9 @@
/*
* @checkstyle PackageNameCheck (10 lines)
* @checkstyle TrailingCommentCheck (3 lines)
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD
import org.eolang.AtCompositeTest;
import org.eolang.ExFailure;
@ -41,6 +42,7 @@ import org.junit.jupiter.api.Test;
*
* @since 0.19
*/
@SuppressWarnings("PMD.TooManyMethods")
final class HeapsTest {
/**
* Heaps.
@ -83,7 +85,7 @@ final class HeapsTest {
@Test
void writesAndReads() {
final int idx = HeapsTest.HEAPS.malloc(new PhFake(), 5);
final byte[] bytes = new byte[] {1, 2, 3, 4, 5};
final byte[] bytes = {1, 2, 3, 4, 5};
HeapsTest.HEAPS.write(idx, 0, bytes);
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
@ -135,7 +137,7 @@ final class HeapsTest {
@Test
void failsOnWriteMoreThanAllocated() {
final int idx = HeapsTest.HEAPS.malloc(new PhFake(), 2);
final byte[] bytes = new byte[] {1, 2, 3, 4, 5};
final byte[] bytes = {1, 2, 3, 4, 5};
Assertions.assertThrows(
ExFailure.class,
() -> HeapsTest.HEAPS.write(idx, 0, bytes),
@ -147,7 +149,7 @@ final class HeapsTest {
@Test
void failsToWriteMoreThanAllocatedWithOffset() {
final int idx = HeapsTest.HEAPS.malloc(new PhFake(), 3);
final byte[] bytes = new byte[] {1, 2, 3};
final byte[] bytes = {1, 2, 3};
Assertions.assertThrows(
ExFailure.class,
() -> HeapsTest.HEAPS.write(idx, 1, bytes),

View File

@ -24,6 +24,7 @@
/*
* @checkstyle PackageNameCheck (20 lines)
* @checkstyle TrailingCommentCheck (20 lines)
*/
/**
@ -33,4 +34,4 @@
* @see <a href="https://www.eolang.org">project site www.eolang.org</a>
* @see <a href="https://github.com/objectionary/eo">GitHub project</a>
*/
package EOorg.EOeolang;
package EOorg.EOeolang; // NOPMD