Skip to content

Commit

Permalink
#3468 new farea
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 6, 2024
1 parent 389dd3e commit 065254f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 164 deletions.
2 changes: 1 addition & 1 deletion eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ SOFTWARE.
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>farea</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
135 changes: 38 additions & 97 deletions eo-runtime/src/test/java/org/eolang/PhiUnphiIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@
import com.yegor256.farea.RequisiteMatcher;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.stream.Collectors;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -50,52 +45,21 @@
@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"})
final class PhiUnphiIT {

/**
* True.
*/
private static final String TRUE = "true";

/**
* False.
*/
private static final String FALSE = "false";

/**
* UTF-8.
*/
private static final String UTF_8 = "UTF-8";

/**
* The eo.version.
*/
private static final String EO_VERSION = "eo.version";

/**
* The eo-maven-plugin.
*/
private static final String EO_PLUGIN = "eo-maven-plugin";

/**
* The org.eolang.
*/
private static final String EO_GROUP = "org.eolang";

/**
* The 1.0-SNAPSHOT.
*/
private static final String SNAPSHOT_1_0 = "1.0-SNAPSHOT";

// @checkstyle MethodLengthCheck (170 lines)
@Test
@ExtendWith(WeAreOnline.class)
void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
new Farea(temp).together(
f -> {
PhiUnphiIT.copySources(f, "src/main");
PhiUnphiIT.copySources(f, "src/test/eo");
f.files().file("src/main").save(
Paths.get(System.getProperty("user.dir")).resolve("src/main")
);
f.files().file("src/test/eo").save(
Paths.get(System.getProperty("user.dir")).resolve("src/test/eo")
);
f.properties()
.set("project.build.sourceEncoding", PhiUnphiIT.UTF_8)
.set("project.reporting.outputEncoding", PhiUnphiIT.UTF_8);
.set("project.build.sourceEncoding", StandardCharsets.UTF_8.name())
.set("project.reporting.outputEncoding", StandardCharsets.UTF_8.name());
f.dependencies().append(
"net.sf.saxon",
"Saxon-HE",
Expand All @@ -104,11 +68,11 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
f.build()
.plugins()
.append(
PhiUnphiIT.EO_GROUP,
PhiUnphiIT.EO_PLUGIN,
"org.eolang",
"eo-maven-plugin",
System.getProperty(
PhiUnphiIT.EO_VERSION,
PhiUnphiIT.SNAPSHOT_1_0
"eo.version",
"1.0-SNAPSHOT"
)
)
.execution("phi-unphi")
Expand All @@ -132,7 +96,7 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
.set("unphiMetas", new String[]{"+tests"})
.set("printSourcesDir", "${project.build.directory}/generated-eo-test/1-parse")
.set("printOutputDir", "${project.basedir}/src/test/generated-eo")
.set("printReversed", PhiUnphiIT.TRUE);
.set("printReversed", Boolean.TRUE.toString());
f.exec("clean", "compile");
final String phi = f.log().content();
MatcherAssert.assertThat(
Expand All @@ -142,8 +106,8 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
);
f.files().file("pom.xml").delete();
f.properties()
.set("project.build.sourceEncoding", PhiUnphiIT.UTF_8)
.set("project.reporting.outputEncoding", PhiUnphiIT.UTF_8);
.set("project.build.sourceEncoding", StandardCharsets.UTF_8.name())
.set("project.reporting.outputEncoding", StandardCharsets.UTF_8.name());
f.dependencies().append(
"org.junit.jupiter",
"junit-jupiter-engine",
Expand All @@ -167,11 +131,11 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
f.build()
.plugins()
.append(
PhiUnphiIT.EO_GROUP,
PhiUnphiIT.EO_PLUGIN,
"org.eolang",
"eo-maven-plugin",
System.getProperty(
PhiUnphiIT.EO_VERSION,
PhiUnphiIT.SNAPSHOT_1_0
"eo.version",
"1.0-SNAPSHOT"
)
)
.execution("compile")
Expand All @@ -187,18 +151,18 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
.configuration()
.set("foreign", "${project.basedir}/target/eo-foreign.csv")
.set("foreignFormat", "csv")
.set("failOnWarning", PhiUnphiIT.FALSE)
.set("offline", PhiUnphiIT.TRUE)
.set("withRuntimeDependency", PhiUnphiIT.FALSE)
.set("placeBinariesThatHaveSources", PhiUnphiIT.TRUE);
.set("failOnWarning", Boolean.FALSE.toString())
.set("offline", Boolean.TRUE.toString())
.set("withRuntimeDependency", Boolean.FALSE.toString())
.set("placeBinariesThatHaveSources", Boolean.TRUE.toString());
f.build()
.plugins()
.append(
PhiUnphiIT.EO_GROUP,
PhiUnphiIT.EO_PLUGIN,
"org.eolang",
"eo-maven-plugin",
System.getProperty(
PhiUnphiIT.EO_VERSION,
PhiUnphiIT.SNAPSHOT_1_0
"eo.version",
"1.0-SNAPSHOT"
)
)
.execution("deps")
Expand All @@ -207,11 +171,11 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
f.build()
.plugins()
.append(
PhiUnphiIT.EO_GROUP,
PhiUnphiIT.EO_PLUGIN,
"org.eolang",
"eo-maven-plugin",
System.getProperty(
PhiUnphiIT.EO_VERSION,
PhiUnphiIT.SNAPSHOT_1_0
"eo.version",
"1.0-SNAPSHOT"
)
)
.execution("tests")
Expand All @@ -226,17 +190,17 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
.configuration()
.set("foreign", "${project.basedir}/target/eo-foreign.csv")
.set("foreignFormat", "csv")
.set("failOnWarning", PhiUnphiIT.FALSE)
.set("offline", PhiUnphiIT.TRUE)
.set("failOnWarning", Boolean.FALSE.toString())
.set("offline", Boolean.TRUE.toString())
.set("scope", "test")
.set("sourcesDir", "${project.basedir}/src/test/generated-eo")
.set("targetDir", "${project.basedir}/target/eo-test")
.set("addSourcesRoot", PhiUnphiIT.FALSE)
.set("addTestSourcesRoot", PhiUnphiIT.TRUE)
.set("failOnWarning", PhiUnphiIT.FALSE)
.set("addSourcesRoot", Boolean.FALSE.toString())
.set("addTestSourcesRoot", Boolean.TRUE.toString())
.set("failOnWarning", Boolean.FALSE.toString())
.set("generatedDir", "${project.basedir}/target/generated-test-sources")
.set("withRuntimeDependency", PhiUnphiIT.FALSE)
.set("placeBinariesThatHaveSources", PhiUnphiIT.TRUE);
.set("withRuntimeDependency", Boolean.FALSE.toString())
.set("placeBinariesThatHaveSources", Boolean.TRUE.toString());
f.exec("clean", "test");
MatcherAssert.assertThat(
"Some tests weren't passed after converting to phi and back",
Expand All @@ -246,27 +210,4 @@ void runsTestsAfterPhiAndUnphi(final @TempDir Path temp) throws IOException {
}
);
}

/**
* Copy EO sources.
* @param farea Farea instance
* @param target Directory to copy from
* @throws IOException If fails to copy files
*/
private static void copySources(final Farea farea, final String target) throws IOException {
final Path runtime = Paths.get(System.getProperty("user.dir"))
.resolve(target);
final Collection<Path> sources = Files.walk(runtime)
.filter(src -> !src.toFile().isDirectory())
.collect(Collectors.toList());
for (final Path src : sources) {
farea.files()
.file(String.format("%s/%s", target, runtime.relativize(src)))
.write(
new UncheckedText(new TextOf(src))
.asString()
.getBytes(StandardCharsets.UTF_8)
);
}
}
}
76 changes: 10 additions & 66 deletions eo-runtime/src/test/java/org/eolang/SnippetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@
import com.yegor256.farea.Farea;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.cactoos.iterable.Mapped;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.eolang.jucs.ClasspathSource;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -62,36 +57,6 @@
@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"})
final class SnippetIT {

/**
* False.
*/
private static final String FALSE = "false";

/**
* UTF-8.
*/
private static final String UTF_8 = "UTF-8";

/**
* The eo.version.
*/
private static final String EO_VERSION = "eo.version";

/**
* The eo-maven-plugin.
*/
private static final String EO_PLUGIN = "eo-maven-plugin";

/**
* The org.eolang.
*/
private static final String EO_GROUP = "org.eolang";

/**
* The 1.0-SNAPSHOT.
*/
private static final String SNAPSHOT_1_0 = "1.0-SNAPSHOT";

@ParameterizedTest
@ExtendWith(WeAreOnline.class)
@ClasspathSource(value = "org/eolang/snippets/", glob = "**.yaml")
Expand All @@ -103,9 +68,11 @@ void runsAllSnippets(final String yml, final @TempDir Path temp) throws IOExcept
new Farea(temp).together(
f -> {
f.properties()
.set("project.build.sourceEncoding", SnippetIT.UTF_8)
.set("project.reporting.outputEncoding", SnippetIT.UTF_8);
SnippetIT.copySources(f, "src/main/eo");
.set("project.build.sourceEncoding", StandardCharsets.UTF_8.name())
.set("project.reporting.outputEncoding", StandardCharsets.UTF_8.name());
f.files().file("src/main/eo").save(
Paths.get(System.getProperty("user.dir")).resolve("src/main/eo")
);
f.files()
.file(String.format("src/main/eo/%s", file))
.write(
Expand All @@ -116,18 +83,18 @@ void runsAllSnippets(final String yml, final @TempDir Path temp) throws IOExcept
f.build()
.plugins()
.append(
SnippetIT.EO_GROUP,
SnippetIT.EO_PLUGIN,
"org.eolang",
"eo-maven-plugin",
System.getProperty(
SnippetIT.EO_VERSION,
SnippetIT.SNAPSHOT_1_0
"eo.version",
"1.0-SNAPSHOT"
)
)
.execution("compile")
.phase("generate-sources")
.goals("register", "assemble", "verify", "transpile")
.configuration()
.set("failOnWarning", SnippetIT.FALSE);
.set("failOnWarning", Boolean.FALSE.toString());
f.build()
.plugins()
.append("org.codehaus.mojo", "exec-maven-plugin", "3.1.1")
Expand Down Expand Up @@ -155,27 +122,4 @@ void runsAllSnippets(final String yml, final @TempDir Path temp) throws IOExcept
}
);
}

/**
* Copy EO sources.
* @param farea Farea instance
* @param target Directory to copy from
* @throws IOException If fails to copy files
*/
private static void copySources(final Farea farea, final String target) throws IOException {
final Path runtime = Paths.get(System.getProperty("user.dir"))
.resolve(target);
final Collection<Path> sources = Files.walk(runtime)
.filter(src -> !src.toFile().isDirectory())
.collect(Collectors.toList());
for (final Path src : sources) {
farea.files()
.file(String.format("%s/%s", target, runtime.relativize(src)))
.write(
new UncheckedText(new TextOf(src))
.asString()
.getBytes(StandardCharsets.UTF_8)
);
}
}
}

0 comments on commit 065254f

Please sign in to comment.