From 9215f0c2688386aa07c9ba2e984a691165ce0d17 Mon Sep 17 00:00:00 2001 From: Suban05 Date: Mon, 24 Feb 2025 13:44:55 +0500 Subject: [PATCH 1/5] #3941 move LintMojo tests that use `Farea` to integration tests --- .../java/org/eolang/maven/AssembleMojoIT.java | 2 +- .../java/org/eolang/maven/LintMojoIT.java | 103 ++++++++++++++++++ .../java/org/eolang/maven/LintMojoTest.java | 59 ---------- 3 files changed, 104 insertions(+), 60 deletions(-) create mode 100644 eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java index 39da227023..a3bce75fda 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java @@ -4,7 +4,7 @@ */ package org.eolang.maven; -import com.jcabi.manifests.Manifests; +import com.jcabi.manifests.Manifests; import com.yegor256.MayBeSlow; import com.yegor256.Mktmp; import com.yegor256.MktmpResolver; diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java new file mode 100644 index 0000000000..46788d4f34 --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java @@ -0,0 +1,103 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com + * SPDX-License-Identifier: MIT + */ +package org.eolang.maven; + +import com.jcabi.manifests.Manifests; +import com.yegor256.MayBeSlow; +import com.yegor256.Mktmp; +import com.yegor256.MktmpResolver; +import com.yegor256.WeAreOnline; +import com.yegor256.farea.Execution; +import com.yegor256.farea.Farea; +import java.io.IOException; +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 LintMojo}. + * + * @since 0.52 + */ +@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"}) +@ExtendWith({WeAreOnline.class, MktmpResolver.class, MayBeSlow.class, RandomProgramResolver.class}) +final class LintMojoIT { + + /** + * The path to the EO file. + */ + private static final String EO = "src/main/eo/foo.eo"; + + @Test + void lintsAgainAfterModification(@Mktmp final Path temp, @RandomProgram final String program) + throws Exception { + final String xmir = String.format("target/eo/%s/foo.xmir", LintMojo.DIR); + new Farea(temp).together( + f -> { + f.clean(); + f.files().file(LintMojoIT.EO).write(program.getBytes()); + LintMojoIT.appendItself(f) + .configuration() + .set("failOnWarning", "false"); + f.exec("process-classes"); + final long before = f.files() + .file(xmir) + .path() + .toFile() + .lastModified(); + f.files().file(LintMojoIT.EO).write(program.getBytes()); + f.exec("process-classes"); + MatcherAssert.assertThat( + "the .xmir file is re-generated", + f.files().file(xmir).path().toFile().lastModified(), + Matchers.not(Matchers.equalTo(before)) + ); + } + ); + } + + @Test + void printsLintsUrlWithVersion(@Mktmp final Path temp, @RandomProgram final String program) + throws IOException { + new Farea(temp).together( + f -> { + f.clean(); + f.files().file(LintMojoIT.EO).write(program.getBytes()); + LintMojoIT.appendItself(f) + .configuration() + .set("failOnWarning", "false"); + f.exec("process-classes"); + MatcherAssert.assertThat( + "Lints URL was not printed, but it should", + f.log().content(), + Matchers.matchesPattern( + String.join( + " ", + "(?s).*\\[INFO] Read more about lints:", + "https://www\\.objectionary\\.com/lints/\\d+\\.\\d+\\.\\d+.*" + ) + ) + ); + } + ); + } + + private static Execution appendItself(final Farea farea) throws IOException { + return farea.build() + .plugins() + .append( + "org.eolang", + "eo-maven-plugin", + System.getProperty( + "eo.version", + Manifests.read("EO-Version") + ) + ) + .execution("tests") + .goals("register", "parse", "shake", "lint"); + } +} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java index 7224746f52..69e8c7bd3c 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java @@ -7,7 +7,6 @@ import com.jcabi.xml.XMLDocument; import com.yegor256.Mktmp; import com.yegor256.MktmpResolver; -import com.yegor256.farea.Farea; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -31,64 +30,6 @@ @ExtendWith(MktmpResolver.class) @ExtendWith(RandomProgramResolver.class) final class LintMojoTest { - - @Test - void lintsAgainAfterModification(@Mktmp final Path temp, @RandomProgram final String program) - throws Exception { - new Farea(temp).together( - f -> { - f.clean(); - f.files().file("src/main/eo/foo.eo").write(program.getBytes()); - f.build() - .plugins() - .appendItself() - .execution() - .goals("register", "parse", "shake", "lint") - .configuration() - .set("failOnWarning", "false"); - f.exec("process-classes"); - final long before = f.files().file( - "target/eo/6-lint/foo.xmir" - ).path().toFile().lastModified(); - f.files().file("src/main/eo/foo.eo").write(program.getBytes()); - f.exec("process-classes"); - MatcherAssert.assertThat( - "the .xmir file is re-generated", - f.files().file( - "target/eo/6-lint/foo.xmir" - ).path().toFile().lastModified(), - Matchers.not(Matchers.equalTo(before)) - ); - } - ); - } - - @Test - void printsLintsUrlWithVersion(@Mktmp final Path temp, @RandomProgram final String program) - throws IOException { - new Farea(temp).together( - f -> { - f.clean(); - f.files().file("src/main/eo/foo.eo").write(program.getBytes()); - f.build() - .plugins() - .appendItself() - .execution() - .goals("register", "parse", "shake", "lint") - .configuration() - .set("failOnWarning", "false"); - f.exec("process-classes"); - MatcherAssert.assertThat( - "Lints URL was not printed, but it should", - f.log().content(), - Matchers.matchesPattern( - "(?s).*\\[INFO] Read more about lints: https://www\\.objectionary\\.com/lints/\\d+\\.\\d+\\.\\d+.*" - ) - ); - } - ); - } - @Test void doesNotFailWithNoErrorsAndWarnings(@Mktmp final Path temp) { Assertions.assertDoesNotThrow( From 7287278509d97efe441f52e241800f65bcdf7ee1 Mon Sep 17 00:00:00 2001 From: Suban05 Date: Mon, 24 Feb 2025 14:28:37 +0500 Subject: [PATCH 2/5] #3941 exclude `LintMojoIT` in codacy --- .codacy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.codacy.yml b/.codacy.yml index 2fae466ffe..a348c736e4 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -10,3 +10,4 @@ exclude_paths: - "eo-runtime/src/test/java/integration/PhiUnphiIT.java" - "eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java" - "eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java" + - "eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java" From 681207ca62f214142b0660beb92cd2a95436a2d9 Mon Sep 17 00:00:00 2001 From: Suban05 Date: Mon, 24 Feb 2025 17:22:28 +0500 Subject: [PATCH 3/5] #3941 fixes --- .codacy.yml | 2 -- .../src/test/java/org/eolang/maven/LintMojoIT.java | 12 ++++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.codacy.yml b/.codacy.yml index a348c736e4..54c98b03de 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -6,8 +6,6 @@ # package name contains capital letter and such names are conventional. --- exclude_paths: - - "src/test/groovy/*.groovy" - "eo-runtime/src/test/java/integration/PhiUnphiIT.java" - "eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java" - - "eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java" - "eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java" diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java index 46788d4f34..79fbc18092 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java @@ -27,19 +27,15 @@ @ExtendWith({WeAreOnline.class, MktmpResolver.class, MayBeSlow.class, RandomProgramResolver.class}) final class LintMojoIT { - /** - * The path to the EO file. - */ - private static final String EO = "src/main/eo/foo.eo"; - @Test void lintsAgainAfterModification(@Mktmp final Path temp, @RandomProgram final String program) throws Exception { + final String source = "src/main/eo/foo.eo"; final String xmir = String.format("target/eo/%s/foo.xmir", LintMojo.DIR); new Farea(temp).together( f -> { f.clean(); - f.files().file(LintMojoIT.EO).write(program.getBytes()); + f.files().file(source).write(program.getBytes()); LintMojoIT.appendItself(f) .configuration() .set("failOnWarning", "false"); @@ -49,7 +45,7 @@ void lintsAgainAfterModification(@Mktmp final Path temp, @RandomProgram final St .path() .toFile() .lastModified(); - f.files().file(LintMojoIT.EO).write(program.getBytes()); + f.files().file(source).write(program.getBytes()); f.exec("process-classes"); MatcherAssert.assertThat( "the .xmir file is re-generated", @@ -66,7 +62,7 @@ void printsLintsUrlWithVersion(@Mktmp final Path temp, @RandomProgram final Stri new Farea(temp).together( f -> { f.clean(); - f.files().file(LintMojoIT.EO).write(program.getBytes()); + f.files().file("src/main/eo/foo.eo").write(program.getBytes()); LintMojoIT.appendItself(f) .configuration() .set("failOnWarning", "false"); From 41c6bb97a9d68f66b7e4983402a4e187f64beafc Mon Sep 17 00:00:00 2001 From: Suban05 Date: Mon, 24 Feb 2025 17:34:28 +0500 Subject: [PATCH 4/5] #3941 fix codacy --- .codacy.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.codacy.yml b/.codacy.yml index 54c98b03de..464084ae68 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -6,6 +6,4 @@ # package name contains capital letter and such names are conventional. --- exclude_paths: - - "eo-runtime/src/test/java/integration/PhiUnphiIT.java" - - "eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java" - - "eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java" + - "**/*IT.java" From 09c7d4694d85816033aaadcffe1f47857a8c2855 Mon Sep 17 00:00:00 2001 From: Suban05 Date: Mon, 24 Feb 2025 17:53:12 +0500 Subject: [PATCH 5/5] #3941 fix codacy --- .codacy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codacy.yml b/.codacy.yml index 464084ae68..e6ffd83fd7 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -6,4 +6,4 @@ # package name contains capital letter and such names are conventional. --- exclude_paths: - - "**/*IT.java" + - "eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java"