Skip to content

Commit

Permalink
Merge pull request #183 from h1alexbel/179
Browse files Browse the repository at this point in the history
fix(#179): `Program#defects()` does not declare `IOException`
  • Loading branch information
yegor256 authored Dec 27, 2024
2 parents e2e485e + 8dc8a6c commit b207038
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/lints/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Program(final XML xml) {
* Find defects possible defects in the XM§IR file.
* @return All defects found
*/
public Collection<Defect> defects() throws IOException {
public Collection<Defect> defects() {
try {
final Collection<Defect> messages = new ArrayList<>(0);
for (final Lint<XML> lint : this.lints) {
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/eolang/lints/Programs.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,21 @@ public Programs(final Map<String, XML> map) {
* Find defects possible defects in the XMIR file.
* @return All defects found
*/
public Collection<Defect> defects() throws IOException {
public Collection<Defect> defects() {
final Collection<Defect> messages = new LinkedList<>();
for (final Lint<Map<String, XML>> lint : this.lints) {
messages.addAll(lint.defects(this.pkg));
try {
messages.addAll(lint.defects(this.pkg));
} catch (final IOException exception) {
throw new IllegalStateException(
String.format(
"Failed to find defects in the '%s' package with '%s' lint",
this.pkg,
lint
),
exception
);
}
}
return messages;
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/eolang/lints/ProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eolang.parser.TrParsing;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -192,6 +193,17 @@ void acceptsCanonicalCode() throws IOException {
);
}

@Test
void doesNotThrowIoException() {
Assertions.assertDoesNotThrow(
() ->
new Program(
new XMLDocument("<program/>")
).defects(),
"Exception was thrown, but it should not be"
);
}

@Test
@Tag("benchmark")
@ExtendWith(MktmpResolver.class)
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/eolang/lints/ProgramsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
import java.nio.file.Files;
import java.nio.file.Path;
import org.cactoos.io.InputOf;
import org.cactoos.list.ListOf;
import org.cactoos.set.SetOf;
import org.eolang.parser.EoSyntax;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -84,4 +86,12 @@ void checksInParallel(@Mktmp final Path dir) throws IOException {
);
}

@Test
void doesNotThrowIoException() {
Assertions.assertDoesNotThrow(
() -> new Programs(new ListOf<>()).defects(),
"Exception was thrown, but it should not be"
);
}

}

0 comments on commit b207038

Please sign in to comment.