Skip to content

Commit

Permalink
fix(#2909): tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Mar 1, 2024
1 parent f66eeb2 commit 2ecd9df
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 3 additions & 2 deletions eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static class Metas extends IterableEnvelope<Directive> {
/**
* Package meta.
*/
private static final String PACKAGE = "+package";
private static final String PACKAGE = "package";

/**
* Ctor.
Expand All @@ -166,11 +166,12 @@ private static class Metas extends IterableEnvelope<Directive> {
final String head = pair[0].substring(1);
if (head.equals(UnphiMojo.Metas.PACKAGE)) {
throw new IllegalStateException(
"+package meta can't be attached to unphied XMIR"
"+package meta is prohibited for attaching to unphied XMIR"
);
}
final Directives dirs = new Directives()
.xpath("/program/metas")
.add("meta")
.add("head").set(head).up()
.add("tail");
if (pair.length > 1) {
Expand Down
38 changes: 38 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Map;
import org.cactoos.io.InputOf;
import org.cactoos.list.ListOf;
import org.cactoos.set.SetOf;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.util.HmBase;
Expand Down Expand Up @@ -85,6 +86,43 @@ void failsIfParsedWithErrors(@TempDir final Path temp) throws IOException {
);
}

@Test
void addsMetas(@TempDir final Path temp) throws IOException {
new HmBase(temp).save(
"{⟦std ↦ Φ.org.eolang.io.stdout⟧}",
Paths.get("target/phi/std.phi")
);
MatcherAssert.assertThat(
"Unphied XMIR must contain metas, added via \"unphiMetas\" parameter",
new XMLDocument(
new FakeMaven(temp)
.with("unphiMetas", new SetOf<>("+tests", "+home https://github.com/objectionary/eo"))
.execute(UnphiMojo.class)
.result()
.get(String.format("target/%s/std.xmir", ParseMojo.DIR))
),
XhtmlMatchers.hasXPaths(
"/program/metas/meta[head/text()='tests' and not(tail/text())]",
"/program/metas/meta[head/text()='home' and tail/text()='https://github.com/objectionary/eo']"
)
);
}

@Test
void failsIfPackageMetaIsAdded(@TempDir final Path temp) throws IOException {
new HmBase(temp).save(
"{⟦std ↦ Φ.org.eolang.io.stdout⟧}",
Paths.get("target/phi/std.phi")
);
Assertions.assertThrows(
IllegalStateException.class,
() -> new FakeMaven(temp)
.with("unphiMetas", new SetOf<>("+package org.eolang"))
.execute(UnphiMojo.class),
"UnphiMojo execution should fail if \"+package\" meta is added"
);
}

@ParameterizedTest
@ClasspathSource(value = "org/eolang/maven/unphi", glob = "**.yaml")
void checksUnphiPacks(final String pack, @TempDir final Path temp) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public XML parsed() throws IOException {
new ParseTreeWalker().walk(xel, parser.program());
final XML dom = new XMLDocument(
new Xembler(
new Directives(xel).append(spy).append(extra)
new Directives(xel).append(spy).append(this.extra)
).domQuietly()
);
new Schema(dom).check();
Expand Down

0 comments on commit 2ecd9df

Please sign in to comment.