Skip to content

Commit

Permalink
feat(objectionary#2642): unphi mojo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Dec 5, 2023
1 parent 4878ee9 commit 767563c
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
10 changes: 10 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ public <T extends AbstractMojo> FakeMaven execute(final Class<T> mojo) throws IO
"phiOutputDir",
this.workspace.absolute(Paths.get("target/phi")).toFile()
);
this.params.putIfAbsent(
"unphiInputDir",
this.workspace.absolute(Paths.get("target/phi")).toFile()
);
this.params.putIfAbsent(
"unphiOutputDir",
this.workspace.absolute(
Paths.get(String.format("target/%s", ParseMojo.DIR))
).toFile()
);
}
final Moja<T> moja = new Moja<>(mojo);
for (final Map.Entry<String, ?> entry : this.allowedParams(mojo).entrySet()) {
Expand Down
96 changes: 96 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.maven;

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.cactoos.list.ListOf;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.util.HmBase;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.yaml.snakeyaml.Yaml;

/**
* Test cases for {@link UnphiMojo}.
* @since 0.34.0
*/
class UnphiMojoTest {
@Test
void createsFile(@TempDir final Path temp) throws Exception {
new HmBase(temp).save(
"{std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x}",
Paths.get("target/phi/std.phi")
);
MatcherAssert.assertThat(
String.format(
"There should be file with .%s extension after parsing phi to XMIR, but there isn't",
TranspileMojo.EXT
),
new FakeMaven(temp)
.execute(UnphiMojo.class)
.result(),
Matchers.hasKey(String.format("target/%s/std.xmir", ParseMojo.DIR))
);
}

@ParameterizedTest
@Disabled
@ClasspathSource(value = "org/eolang/maven/unphi", glob = "**.yaml")
void checksUnphiPacks(final String pack, @TempDir final Path temp) throws Exception {
final Map<String, Object> map = new Yaml().load(pack);
final String phi = map.get("phi").toString();
new HmBase(temp).save(phi, Paths.get("target/phi/main.phi"));
final List<String> failures = new ListOf<>();
new FakeMaven(temp).execute(UnphiMojo.class);
for (final String xpath : (Iterable<String>) map.get("tests")) {
final List<XML> nodes = new XMLDocument(
new TextOf(
Paths.get(String.format("target/%s/main.xmir", ParseMojo.DIR))
).asString()
).nodes(xpath);
if (nodes.isEmpty()) {
failures.add(xpath);
}
}
MatcherAssert.assertThat(
String.format(
"Failed to parse phi expression: %s; failed tests: %s",
phi, Arrays.toString(failures.toArray())
),
failures,
Matchers.empty()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
* @since 0.1
*/
final class EoSyntaxTest {

@Test
void parsesSimpleCode() throws Exception {
MatcherAssert.assertThat(
Expand Down

0 comments on commit 767563c

Please sign in to comment.