Skip to content

Commit

Permalink
feat(objectionary#2674): changed tests for checking error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanich96 committed Dec 26, 2023
1 parent 26bf178 commit 018a08b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
* Returns already optimized XML if it's found in the cache.
*
* @since 0.28.11
* @todo #2674:30min The function {@code OptCached.contains(final XML xml)}
* isn't work properly. This function compares caching and compilation times,
* which may lead to erroneous results. We need to fix this.
*/
public final class OptCached implements Optimization {

Expand Down Expand Up @@ -113,9 +116,9 @@ private boolean contains(final XML xml) throws IOException {
res = Files.readAttributes(path, BasicFileAttributes.class)
.creationTime()
.toInstant()
.truncatedTo(ChronoUnit.SECONDS)
.truncatedTo(ChronoUnit.MINUTES)
.equals(
ZonedDateTime.parse(time.get()).toInstant().truncatedTo(ChronoUnit.SECONDS)
ZonedDateTime.parse(time.get()).toInstant().truncatedTo(ChronoUnit.MINUTES)
);
} else {
res = false;
Expand Down
25 changes: 14 additions & 11 deletions eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ void detectsErrorsSuccessfully(
.execute(new FakeMaven.Verify()),
"Program with noname attributes should have failed or error, but it didn't"
);
String parse = parserMessage(out, "Errors identified:");
final String parse = this.parserMessage(out, "Errors identified:");
Assertions.assertTrue(
parse.matches(temp.resolve("foo/x/main.eo") + ", \\d+"),
parse.matches(temp.resolve("foo/x/main.eo").toString().concat(", \\d+")),
"Errors message should have program name and error line number"
);
}
Expand All @@ -97,9 +97,9 @@ void detectsCriticalErrorsSuccessfully(
.execute(new FakeMaven.Verify()),
"Wrong program should have failed or error, but it didn't"
);
String parse = parserMessage(out, "Critical error identified:");
final String parse = this.parserMessage(out, "Critical error identified:");
Assertions.assertTrue(
parse.matches(temp.resolve("foo/x/main.eo") + ", \\d+"),
parse.matches(temp.resolve("foo/x/main.eo").toString().concat(", \\d+")),
"Critical error message should have program name and error line number"
);
}
Expand All @@ -122,9 +122,9 @@ void detectsWarningWithCorrespondingFlag(
.execute(new FakeMaven.Verify()),
"Program with sparse decorated object should have failed on warning, but it didn't"
);
String parse = parserMessage(out, "Warnings identified:");
final String parse = this.parserMessage(out, "Warnings identified:");
Assertions.assertTrue(
parse.matches(temp.resolve("foo/x/main.eo") + ", \\d+"),
parse.matches(temp.resolve("foo/x/main.eo").toString().concat(", \\d+")),
"Warnings message should have program name and error line number"
);
}
Expand Down Expand Up @@ -246,11 +246,14 @@ private static void applyXsl(final String xsl, final Path xml) throws Exception
* @param logs Logs logs
* @param error String needed error message
*/
private String parserMessage(final Logs logs, final String error){
final String message = String.valueOf(logs.captured().stream().filter
(log -> log.contains(error)).findFirst());
final String str = error + "\n ";
final String result = message.substring(message.indexOf(str) + str.length());
private String parserMessage(final Logs logs, final String error) {
final String message = String.valueOf(logs.captured().stream()
.filter(
log -> log.contains(error)
).findFirst()
);
final String str = error.concat("\n ");
final String result = message.substring(message.indexOf(str) + str.length());
return result.substring(0, result.indexOf(": "));
}
}

0 comments on commit 018a08b

Please sign in to comment.