Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 9, 2024
2 parents fe57bd3 + 42bb26d commit 9e5a08c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
30 changes: 13 additions & 17 deletions eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.Xsline;
import java.nio.file.Path;
import java.util.Arrays;
import org.cactoos.io.ResourceOf;
import org.eolang.maven.log.CaptureLogs;
import org.eolang.maven.log.Logs;
import org.eolang.maven.util.HmBase;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand All @@ -50,11 +52,6 @@
* /org/eolang/parser/warnings/mandatory-version-meta.xsl and
* /org/eolang/parser/warnings/mandatory-home-meta.xsl.
* After you need fix {@code createRegEx()}.
* @todo #2890:30min Fix this {@link VerifyMojoTest#detectsErrorsSuccessfully}
* flaky test and enable it. It failed in ci
* <a href="https://github.com/objectionary/eo/actions/runs/8041230784/job/21960239171?pr=2892">here</a>
* without providing the regex and message. Also may be it would be cleaner to fix
* error Assertion since now it is hard to get why it failed.
*/
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
final class VerifyMojoTest {
Expand All @@ -70,7 +67,6 @@ void doesNotFailWithNoErrorsAndWarnings(@TempDir final Path temp) {
}

@Test
@Disabled
@CaptureLogs
void detectsErrorsSuccessfully(
@TempDir final Path temp,
Expand All @@ -88,18 +84,18 @@ void detectsErrorsSuccessfully(
.execute(new FakeMaven.Verify()),
"Program with noname attributes should have failed or error, but it didn't"
);
final String message = this.getMessage(out, "Errors identified");
Assertions.assertTrue(
message.matches(this.createRegEx(temp, "Errors identified")),
"Errors message should have program name and error line number"
MatcherAssert.assertThat(
"Errors message should have program name and error line number",
this.getMessage(out, "Errors identified", temp.toString()),
Matchers.matchesPattern(this.createRegEx(temp, "Errors identified"))
);
}

@Test
@CaptureLogs
void detectsCriticalErrorsSuccessfully(
@TempDir final Path temp,
final Logs out) throws Exception {
final Logs out) {
Assertions.assertThrows(
IllegalStateException.class,
() -> new FakeMaven(temp)
Expand All @@ -112,7 +108,7 @@ void detectsCriticalErrorsSuccessfully(
.execute(new FakeMaven.Verify()),
"Wrong program should have failed or error, but it didn't"
);
final String message = this.getMessage(out, "Critical error identified");
final String message = this.getMessage(out, "Critical error identified", temp.toString());
Assertions.assertTrue(
message.matches(this.createRegEx(temp, "Critical error identified")),
"Critical error message should have program name and error line number"
Expand All @@ -139,7 +135,7 @@ void detectsWarningWithCorrespondingFlag(
.execute(new FakeMaven.Verify()),
"Program with sparse decorated object should have failed on warning, but it didn't"
);
final String message = this.getMessage(out, "Warnings identified");
final String message = this.getMessage(out, "Warnings identified", temp.toString());
Assertions.assertTrue(
message.matches(this.createRegEx(temp, "Warnings identified")),
"Warnings message should have program name and error line number"
Expand Down Expand Up @@ -268,12 +264,12 @@ private static void applyXsl(final String xsl, final Path xml) throws Exception
/**
* Parse the error message to program name and error line number for checking.
* @param logs Logs logs
* @param error String needed error message
* @param parts String needed error message
*/
private String getMessage(final Logs logs, final String error) {
private String getMessage(final Logs logs, final String... parts) {
return String.valueOf(logs.captured().stream()
.filter(
log -> log.contains(error)
log -> Arrays.stream(parts).allMatch(log::contains)
).findFirst()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@

/**
* Captured logs annotation for tests.
* @todo #2896:90min Make '@CaptureLogs' thread-safe.
* 'Logs' should contain only messages related to the test.
* Currently, '@CaptureLogs' appends all messages that
* were logged via 'Logger' to 'Logs', so messages from
* other tests (run in parallel) are also included, which causes
* problems when tests are run in parallel.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
Expand Down

2 comments on commit 9e5a08c

@0pdd
Copy link

@0pdd 0pdd commented on 9e5a08c May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2890-c492b9ca disappeared from eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java), that's why I closed #2896. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 9e5a08c May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2896-621330ec discovered in eo-maven-plugin/src/test/java/org/eolang/maven/log/CaptureLogs.java) and submitted as #3181. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.