Skip to content

Commit

Permalink
objectionary#3941 move LintMojo tests that use Farea to integration…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
Suban05 committed Feb 24, 2025
1 parent 20b20bc commit 9215f0c
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
103 changes: 103 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoIT.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
59 changes: 0 additions & 59 deletions eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 9215f0c

Please sign in to comment.