Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/test/java/fixtures/EoProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.jcabi.xml.XMLDocument;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.cactoos.Input;
import org.cactoos.io.ResourceOf;
import org.eolang.parser.EoSyntax;

Expand All @@ -32,17 +33,32 @@ public final class EoProgram {
.maximumSize(EoProgram.MAX)
.build();

/**
* Program name for caching.
*/
private final String name;

/**
* Resource path.
*/
private final String resource;
private final Input resource;

/**
* Constructor.
* @param res Classpath resource path to the EO source file
*/
public EoProgram(final String res) {
this.resource = res;
this(res, new ResourceOf(res));
}

/**
* Constructor.
* @param nme Cache key and log label for this program
* @param input EO source input
*/
public EoProgram(final String nme, final Input input) {
this.name = nme;
this.resource = input;
}

/**
Expand All @@ -51,11 +67,7 @@ public EoProgram(final String res) {
*/
public XML parse() {
try {
return new XMLDocument(
EoProgram.CACHE.get(
this.resource, () -> EoProgram.doParse(this.resource)
).deepCopy()
);
return new XMLDocument(EoProgram.CACHE.get(this.name, this::doParse).deepCopy());
} catch (final ExecutionException ex) {
throw new IllegalStateException(
String.format("Failed to parse EO resource '%s'", this.resource),
Expand All @@ -66,18 +78,17 @@ public XML parse() {

/**
* Perform the actual parse and log timing.
* @param res Resource path to parse
* @return Parsed XMIR document
* @throws IOException If parsing fails
*/
@SuppressWarnings("PMD.UnnecessaryLocalRule")
private static XML doParse(final String res) throws IOException {
private XML doParse() throws IOException {
final long start = System.currentTimeMillis();
final XML xmir = new EoSyntax(new ResourceOf(res)).parsed();
final XML xmir = new EoSyntax(this.resource).parsed();
Logger.info(
EoProgram.class,
"Parsed '%s': %dms",
res,
this.name,
System.currentTimeMillis() - start
);
return xmir;
Expand Down
26 changes: 9 additions & 17 deletions src/test/java/org/eolang/lints/LtByXslTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.util.function.Function;
import java.util.function.Predicate;
import matchers.DefectsMatcher;
import org.cactoos.io.InputOf;
import org.cactoos.io.ReaderOf;
import org.cactoos.io.ResourceOf;
import org.cactoos.list.ListOf;
import org.cactoos.map.MapOf;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.eolang.jucs.ClasspathSource;
import org.eolang.parser.EoSyntax;
import org.eolang.parser.StrictXmir;
import org.eolang.xax.XtSticky;
import org.eolang.xax.XtYaml;
Expand All @@ -41,6 +41,8 @@
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.xembly.Directives;
import org.xembly.ImpossibleModificationException;
Expand Down Expand Up @@ -74,6 +76,7 @@ void lintsOneFile() {
}

@SuppressWarnings("JTCOP.RuleNotContainsTestWord")
@Execution(ExecutionMode.CONCURRENT)
@ParameterizedTest
@ClasspathSource(value = "org/eolang/lints/packs/single/", glob = "**.yaml")
void testsAllLintsByEo(final String yaml) {
Expand All @@ -82,7 +85,7 @@ void testsAllLintsByEo(final String yaml) {
new XtSticky(
new XtYaml(
yaml,
eo -> new EoSyntax(eo).parsed()
eo -> new EoProgram(String.valueOf(eo.hashCode()), new InputOf(eo)).parse()
)
),
new XtoryMatcher(new DefectsMatcher())
Expand Down Expand Up @@ -316,21 +319,10 @@ private static boolean schemaValid(final Map<Path, Map<String, Object>> pack) {
}

private static boolean eoErrorFree(final Map<Path, Map<String, Object>> pack) {
try {
return new Xnav(
new EoSyntax(
(String) pack.values().stream().findFirst().get().get("input")
).parsed().inner()
).path("/object[errors]").findAny().isEmpty();
} catch (final IOException exception) {
throw new IllegalStateException(
String.format(
"Failed to parse EO snippet from '%s' pack",
pack.keySet().iterator().next()
),
exception
);
}
final String src = (String) pack.values().stream().findFirst().get().get("input");
return new Xnav(
new EoProgram(src, new InputOf(src)).parse().inner()
).path("/object[errors]").findAny().isEmpty();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/eolang/lints/LtIncorrectUnlintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.io.IOException;
import java.util.List;
import matchers.DefectMatcher;
import org.cactoos.io.InputOf;
import org.cactoos.list.ListOf;
import org.eolang.parser.EoSyntax;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -36,10 +36,11 @@ void catchesIncorrectUnlints() throws IOException {

@Test
void allowsCorrectUnlints() throws IOException {
final String src = "+unlint ascii-only";
MatcherAssert.assertThat(
"Defects are not empty, but they shouldn't be",
new LtIncorrectUnlint(List.of("ascii-only")).defects(
new EoSyntax("+unlint ascii-only").parsed()
new EoProgram(src, new InputOf(src)).parse()
),
Matchers.emptyIterable()
);
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/org/eolang/lints/LtReservedNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import fixtures.EoProgram;
import java.io.IOException;
import java.util.Collection;
import org.cactoos.io.InputOf;
import org.cactoos.list.ListOf;
import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;
import org.eolang.parser.EoSyntax;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -141,9 +141,12 @@ void scansReservedFromHomeWithCorrectMessage() throws Exception {

@Test
void allowsAllUnique() throws IOException {
final String src = "[] > qux";
MatcherAssert.assertThat(
"Object names should not be reported, since they all unique",
new LtReservedName(new MapOf<>()).defects(new EoSyntax("[] > qux").parsed()),
new LtReservedName(new MapOf<>()).defects(
new EoProgram(src, new InputOf(src)).parse()
),
Matchers.emptyIterable()
);
}
Expand Down
51 changes: 32 additions & 19 deletions src/test/java/org/eolang/lints/LtTestNotVerbTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import fixtures.EoProgram;
import java.io.IOException;
import matchers.DefectMatcher;
import org.cactoos.io.InputOf;
import org.cactoos.set.SetOf;
import org.eolang.parser.EoSyntax;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.RepeatedTest;
Expand All @@ -23,6 +23,13 @@
/**
* Tests for {@link LtTestNotVerb}.
* @since 0.0.22
* @todo #872:60min Extract name-validation logic from LtTestNotVerb into a testable component.
* Currently {@link LtTestNotVerbTest} parses many EO programs that differ only in the
* object name being tested, making the tests slow and hard to maintain. The name-validation
* predicate (verb vs. non-verb check) should be extracted into its own class so it can be
* tested directly with plain strings — no EO parsing required. Once extracted, reduce
* {@link LtTestNotVerbTest} to a few representative end-to-end cases and add a dedicated
* unit test class for the new component.
*/
final class LtTestNotVerbTest {

Expand Down Expand Up @@ -72,19 +79,22 @@ final class LtTestNotVerbTest {
"hope-it-works"
}
)
void catchesBadName(final String name) throws Exception {
void catchesBadName(final String name) throws IOException {
MatcherAssert.assertThat(
"Defects size doesn't match with expected",
new LtTestNotVerb().defects(
new EoSyntax(
String.join(
System.lineSeparator(),
"# Foo",
"[] > foo",
String.format(" [] +> %s", name),
" 42 > @"
new EoProgram(
name,
new InputOf(
String.join(
System.lineSeparator(),
"# Foo",
"[] > foo",
String.format(" [] +> %s", name),
" 42 > @"
)
)
).parsed()
).parse()
),
Matchers.allOf(
Matchers.<Defect>iterableWithSize(1),
Expand Down Expand Up @@ -122,19 +132,22 @@ void catchesBadName(final String name) throws Exception {
"is-almost-correct"
}
)
void allowsGoodNames(final String name) throws Exception {
void allowsGoodNames(final String name) throws IOException {
MatcherAssert.assertThat(
"Defects are not empty, but they shouldn't be",
new LtTestNotVerb().defects(
new EoSyntax(
String.join(
System.lineSeparator(),
"# Foo",
"[] > foo",
String.format(" [] +> %s", name),
" 42 > @"
new EoProgram(
name,
new InputOf(
String.join(
System.lineSeparator(),
"# Foo",
"[] > foo",
String.format(" [] +> %s", name),
" 42 > @"
)
)
).parsed()
).parse()
),
Matchers.hasSize(0)
);
Expand Down
23 changes: 13 additions & 10 deletions src/test/java/org/eolang/lints/SourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
import java.util.stream.Collectors;
import org.cactoos.bytes.BytesOf;
import org.cactoos.bytes.UncheckedBytes;
import org.cactoos.io.InputOf;
import org.cactoos.io.ResourceOf;
import org.cactoos.iterable.Sticky;
import org.cactoos.iterable.Synced;
import org.cactoos.list.ListOf;
import org.cactoos.map.MapOf;
import org.cactoos.scalar.Unchecked;
import org.cactoos.set.SetOf;
import org.eolang.parser.EoSyntax;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -250,19 +250,22 @@ void disablesUnlintNonExistingDefectViaWithout() {
@ValueSource(
strings = {"mandatory-home", "mandatory-home:0"}
)
void catchesBrokenUnlintAfterLintWasRemoved(final String lid) throws IOException {
void catchesBrokenUnlintAfterLintWasRemoved(final String lid) {
MatcherAssert.assertThat(
"Found defect does not match with expected",
new Source(
new EoSyntax(
String.join(
System.lineSeparator(),
String.format("+unlint %s", lid),
"",
"# Foo.",
"[] > foo"
new EoProgram(
lid,
new InputOf(
String.join(
System.lineSeparator(),
String.format("+unlint %s", lid),
"",
"# Foo.",
"[] > foo"
)
)
).parsed()
).parse()
).without(
"mandatory-home",
"mandatory-version",
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# Currently, it fails with the 3s timeout on windows platform. Let's try to configure
# test default timeout exclusively for windows, and keep 3s for other platforms.
junit.jupiter.execution.timeout.test.method.default = 45s
junit.jupiter.execution.parallel.enabled = true
Loading