diff --git a/.codacy.yml b/.codacy.yml index f1eff60bd23..8fa1ab2f131 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -6,4 +6,4 @@ # package name contains capital letter and such names are conventional. --- exclude_paths: - - "eo-maven-plugin/src/test/java/org/eolang/maven/RegisterMojoIT.java" + - "eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java" diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java new file mode 100644 index 00000000000..d6a2540eb89 --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java @@ -0,0 +1,127 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com + * SPDX-License-Identifier: MIT + */ +package org.eolang.maven; + +import com.yegor256.MayBeSlow; +import com.yegor256.Mktmp; +import com.yegor256.MktmpResolver; +import com.yegor256.WeAreOnline; +import com.yegor256.farea.Farea; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Integration tests for {@link TranspileMojo}. + * + * @since 0.52 + */ +@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"}) +@ExtendWith({WeAreOnline.class, MktmpResolver.class, MayBeSlow.class, RandomProgramResolver.class}) +final class TranspileMojoIT { + @Test + void transpilesWithPackage(@Mktmp final Path temp) throws Exception { + new Farea(temp).together( + f -> { + f.clean(); + f.files().file("src/main/eo/one/foo.eo").write( + String.join( + "\n", + "+package one", + "", + "# no comments.", + "[] > foo", + " QQ.io.stdout > @", + " \"Hello, world!\\n\"" + ).getBytes(StandardCharsets.UTF_8) + ); + new AppendedPlugin(f).value() + .goals("register", "parse", "shake", "transpile"); + f.exec("process-sources"); + final String java = "EOfoo.java"; + final String pname = "EOone"; + final String pinfo = "package-info.java"; + MatcherAssert.assertThat( + String.format( + "The %s file must be generated, but it didn't", + java + ), + temp.resolve( + String.format( + "target/generated-sources/%s/%s", + pname, + java + ) + ).toFile().exists(), + Matchers.is(true) + ); + MatcherAssert.assertThat( + String.format( + "The %s file must contain the %s package name", + pinfo, + pname + ), + Files.readString( + temp.resolve( + String.format( + "target/generated-sources/%s/%s", + pname, + pinfo + ) + ), + StandardCharsets.UTF_8 + ), + Matchers.containsString(String.format("package %s;", pname)) + ); + } + ); + } + + @Test + void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog) + throws Exception { + new Farea(temp).together( + f -> { + f.clean(); + f.files().file("src/main/eo/foo.eo").write(prog.getBytes()); + new AppendedPlugin(f).value() + .goals("register", "parse", "shake", "transpile"); + f.exec("process-sources"); + final String java = "EOfoo.java"; + final String pinfo = "package-info.java"; + MatcherAssert.assertThat( + String.format( + "The %s file is re-generated", + java + ), + temp.resolve( + String.format( + "target/generated-sources/%s", + java + ) + ).toFile().exists(), + Matchers.is(true) + ); + MatcherAssert.assertThat( + String.format( + "The %s file must not exist, but it doesn't", + pinfo + ), + temp.resolve( + String.format( + "target/generated-sources/%s", + pinfo + ) + ).toFile().exists(), + Matchers.is(false) + ); + } + ); + } +} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java index 408b83cb292..2b0f266d944 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java @@ -6,9 +6,7 @@ import com.yegor256.Mktmp; import com.yegor256.MktmpResolver; -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; @@ -101,75 +99,6 @@ void doesNotTouchAtom(@Mktmp final Path temp) throws IOException { ); } - @Test - void transpilesWithPackage(@Mktmp final Path temp) - throws Exception { - new Farea(temp).together( - f -> { - f.clean(); - f.files().file("src/main/eo/one/foo.eo").write( - String.join( - "\n", - "+package one", - "+unlint object-has-data", - "", - "# no comments.", - "[] > foo", - " QQ.io.stdout > @", - " \"Hello, world!\\n\"", - "" - ).getBytes(StandardCharsets.UTF_8) - ); - f.build() - .plugins() - .appendItself() - .execution() - .goals("register", "parse", "shake", "transpile"); - f.exec("process-sources"); - } - ); - MatcherAssert.assertThat( - "the .java file is generated", - temp.resolve("target/generated-sources/EOone/EOfoo.java").toFile().exists(), - Matchers.is(true) - ); - MatcherAssert.assertThat( - "the package-info.java file contains the right package name", - Files.readString( - temp.resolve("target/generated-sources/EOone/package-info.java"), - StandardCharsets.UTF_8 - ), - Matchers.containsString("package EOone;") - ); - } - - @Test - void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog) - throws Exception { - new Farea(temp).together( - f -> { - f.clean(); - f.files().file("src/main/eo/foo.eo").write(prog.getBytes()); - f.build() - .plugins() - .appendItself() - .execution() - .goals("register", "parse", "shake", "transpile"); - f.exec("process-sources"); - } - ); - MatcherAssert.assertThat( - "the .java file is re-generated", - temp.resolve("target/generated-sources/EOfoo.java").toFile().exists(), - Matchers.is(true) - ); - MatcherAssert.assertThat( - "the package-info.java file contains the right package name", - temp.resolve("target/generated-sources/package-info.java").toFile().exists(), - Matchers.is(false) - ); - } - @Test void recompilesIfModified(@Mktmp final Path temp) throws IOException { final FakeMaven maven = new FakeMaven(temp);