From 9215f0c2688386aa07c9ba2e984a691165ce0d17 Mon Sep 17 00:00:00 2001 From: Suban05 Date: Mon, 24 Feb 2025 13:44:55 +0500 Subject: [PATCH] #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(