From 2ecd9dfe6825e4c912545f61d11236f259f54fa6 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Fri, 1 Mar 2024 17:47:07 +0300 Subject: [PATCH] fix(#2909): tests --- .../main/java/org/eolang/maven/UnphiMojo.java | 5 ++- .../java/org/eolang/maven/UnphiMojoTest.java | 38 +++++++++++++++++++ .../java/org/eolang/parser/PhiSyntax.java | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java index 93ce623cdc..3019e74658 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java @@ -151,7 +151,7 @@ private static class Metas extends IterableEnvelope { /** * Package meta. */ - private static final String PACKAGE = "+package"; + private static final String PACKAGE = "package"; /** * Ctor. @@ -166,11 +166,12 @@ private static class Metas extends IterableEnvelope { 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) { diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index e2bede1666..2d5ba2c682 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -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; @@ -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 { diff --git a/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java b/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java index 35a2743dd4..c62b372bac 100644 --- a/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java @@ -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();