Skip to content

Commit

Permalink
Merge branch 'master' into feat/objectionary#2674/add-test-for-verify…
Browse files Browse the repository at this point in the history
…-mojo
  • Loading branch information
Yanich96 committed Dec 27, 2023
2 parents 1b5a22d + da9e7dc commit 32f28d3
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ebnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
cp "eo-parser/target/ebnf/org/eolang/parser/${p}.pdf" .
pdfcrop --margins '10 10 10 10' "${p}.pdf" "${p}-cropped.pdf"
pdf2svg "${p}-cropped.pdf" "${p}.svg"
convert -density 300 -quality 100 -colorspace RGB "${p}.svg" "${p}.png"
convert -verbose -density 300 -quality 100 -colorspace RGB "${p}.svg" "${p}.png"
mkdir -p gh-pages/ebnf
cp "${p}.png" gh-pages/ebnf
cp "${p}.svg" gh-pages/ebnf
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ All of them have something **we don't tolerate**:
* static/class methods or attributes ([why?](http://www.yegor256.com/2014/05/05/oop-alternative-to-utility-classes.html))
* classes ([why?](http://www.yegor256.com/2016/09/20/oop-without-classes.html))
* implementation inheritance ([why?](http://www.yegor256.com/2016/09/13/inheritance-is-procedural.html))
* mutability ([why?](http://www.yegor256.com/2014/06/09/objects-should-be-immutable.html))
* mutability ([why?](http://www.yegor256.com/2014/06/09/objects-should-be-immutable.html) and [why not?](https://www.yegor256.com/2016/09/07/gradients-of-immutability.html))
* NULL ([why?](http://www.yegor256.com/2014/05/13/why-null-is-bad.html))
* global scope ([why?](https://www.yegor256.com/2018/07/03/global-variables.html))
* type casting ([why?](http://www.yegor256.com/2015/04/02/class-casting-is-anti-pattern.html))
Expand Down
4 changes: 2 additions & 2 deletions eo-maven-plugin/src/main/java/org/eolang/maven/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Path;
import org.eolang.maven.name.DelimitedName;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.util.JoinedUnderscore;

/**
* Make the place for the object.
Expand Down Expand Up @@ -67,8 +68,7 @@ public Path make(final Path dir, final String ext) {
out.append(this.name.title().replace(".", File.separator));
this.name.label().ifPresent(
version -> {
out.append('_');
out.append(version);
out.append(new JoinedUnderscore("", version).asString());
});
if (!ext.isEmpty()) {
out.append('.').append(ext);
Expand Down
40 changes: 25 additions & 15 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PrintMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.experimental.Threads;
import org.cactoos.iterable.Mapped;
import org.cactoos.number.SumOf;
import org.cactoos.text.TextOf;
import org.eolang.maven.util.HmBase;
import org.eolang.maven.util.Home;
Expand Down Expand Up @@ -72,23 +74,31 @@ public final class PrintMojo extends SafeMojo {

@Override
void exec() throws IOException {
final Collection<Path> sources = new Walk(this.printSourcesDir.toPath());
final Home home = new HmBase(this.printOutputDir);
for (final Path source : sources) {
final Path relative = Paths.get(
this.printSourcesDir.toPath().relativize(source).toString()
.replace(".xmir", ".eo")
);
home.save(new XMIR(new TextOf(source)).toEO(), relative);
Logger.info(
this,
"Printed: %s => %s", source, this.printOutputDir.toPath().resolve(relative)
);
}
if (sources.isEmpty()) {
final int total = new SumOf(
new Threads<>(
Runtime.getRuntime().availableProcessors(),
new Mapped<>(
source -> () -> {
final Path relative = Paths.get(
this.printSourcesDir.toPath().relativize(source).toString()
.replace(".xmir", ".eo")
);
home.save(new XMIR(new TextOf(source)).toEO(), relative);
Logger.info(
this,
"Printed: %s => %s", source, this.printOutputDir.toPath().resolve(relative)
);
return 1;
},
new Walk(this.printSourcesDir.toPath())
)
)
).intValue();
if (total == 0) {
Logger.info(this, "No XMIR sources found");
} else {
Logger.info(this, "Printed %d XMIR sources into EO", sources.size());
Logger.info(this, "Printed %d XMIR sources into EO", total);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.util;

import java.util.List;
import org.cactoos.Text;
import org.cactoos.list.ListOf;

/**
* Text joined with underscore.
*
* @since 0.34.1
*/
public final class JoinedUnderscore implements Text {

/**
* Strings to join.
*/
private final List<String> strings;

/**
* Ctor.
* @param strngs Strings to join
*/
public JoinedUnderscore(final String... strngs) {
this(new ListOf<>(strngs));
}

/**
* Ctor.
* @param strngs Strings to join
*/
public JoinedUnderscore(final List<String> strngs) {
this.strings = strngs;
}

@Override
public String asString() {
return String.join("_", this.strings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eolang.maven.log.Logs;
import org.eolang.maven.objectionary.ObjsDefault;
import org.eolang.maven.objectionary.OyRemote;
import org.eolang.maven.util.JoinedUnderscore;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
Expand All @@ -47,14 +48,6 @@
/**
* Test case for {@link AssembleMojo}.
*
* @since 0.1
* @todo #1602:30min Create new object that will join two strings with "_".
* {@link Place} object makes a path for versioned objects using "_" as
* delimiter between name and hash. Here to test stored files after
* {@link AssembleMojo} execution "joinedWithUnderscore" function was
* introduced. So there's a code duplication and an ugly design. Need to
* create a new object that will join two strings with underscore and use it
* here and in {@link Place}.
* @todo #1602:30min Make up how to get rid of excessive usage of
* {@code ParseMojo.DIR}, {@code ResolveMojo.DIR} and so on. It would be nice
* to replace them with corresponding classes, or something similar
Expand All @@ -68,6 +61,7 @@
* from older repositories are not parsed successfully because of the presence of varargs there.
* So we need to make 2-3 releases and then refactor the test with more fresh versions. Don't
* forget to remove the puzzle.
* @since 0.1
*/
@ExtendWith(WeAreOnline.class)
final class AssembleMojoTest {
Expand Down Expand Up @@ -157,8 +151,8 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception {
.execute(AssembleMojo.class)
.result();
final String stdout = "**/io/stdout";
final String fifth = AssembleMojoTest.joinedWithUnderscore(stdout, "17f8929.xmir");
final String sixth = AssembleMojoTest.joinedWithUnderscore(stdout, "9c93528.xmir");
final String fifth = new JoinedUnderscore(stdout, "17f8929.xmir").asString();
final String sixth = new JoinedUnderscore(stdout, "9c93528.xmir").asString();
final String path = "target/%s/org/eolang";
final String parse = String.format(path, ParseMojo.DIR);
final String optimize = String.format(path, OptimizeMojo.DIR);
Expand All @@ -167,7 +161,7 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception {
final String seq = "**/seq.xmir";
final String string = "**/string.xmir";
final String hash = String.join(".", master.value(), "eo");
final String[] jars = new String[] {
final String[] jars = {
"**/eo-runtime-0.28.5.jar",
"**/eo-runtime-0.28.6.jar",
};
Expand All @@ -194,10 +188,10 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception {
),
result.get(pull).toAbsolutePath(),
new ContainsFiles(
AssembleMojoTest.joinedWithUnderscore(stdout, "17f8929.eo"),
AssembleMojoTest.joinedWithUnderscore(stdout, "9c93528.eo"),
AssembleMojoTest.joinedWithUnderscore("**/seq", hash),
AssembleMojoTest.joinedWithUnderscore("**/string", hash)
new JoinedUnderscore(stdout, "17f8929.eo").asString(),
new JoinedUnderscore(stdout, "9c93528.eo").asString(),
new JoinedUnderscore("**/seq", hash).asString(),
new JoinedUnderscore("**/string", hash).asString()
)
);
MatcherAssert.assertThat(
Expand Down Expand Up @@ -272,8 +266,4 @@ void configuresChildParameters(@TempDir final Path temp) throws IOException {
)
);
}

private static String joinedWithUnderscore(final String first, final String second) {
return String.join("_", first, second);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.hamcrest.io.FileMatchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
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;
Expand Down Expand Up @@ -112,7 +113,12 @@ void optimizesIfExpired(@TempDir final Path temp) throws Exception {
*
* @param temp Temporary test directory.
* @throws Exception if unexpected error happened.
* @todo #2422:60min This test is unstable for now.
* We should resolve issues with unstable failures and only
* then enable the test.
* Also, see this <a href="https://github.com/objectionary/eo/issues/2727">issue</a>.
*/
@Disabled
@Test
void getsAlreadyOptimizedResultsFromCache(@TempDir final Path temp) throws Exception {
final TextOf cached = new TextOf(
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 @@ -23,19 +23,24 @@
*/
package org.eolang.maven;

import com.jcabi.matchers.XhtmlMatchers;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.IOException;
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.io.InputOf;
import org.cactoos.list.ListOf;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.util.HmBase;
import org.eolang.parser.EoSyntax;
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;
Expand Down Expand Up @@ -124,4 +129,37 @@ void convertsToXmirAndBack(final String pack, @TempDir final Path temp) throws E
)
);
}

@Disabled
@Test
void convertsValidXmirAndParsableEO(@TempDir final Path temp) throws IOException {
final Map<String, Path> map = new FakeMaven(temp)
.withProgram(
"[args] > app",
" QQ.io.stdout > @",
" \"Hello, world!\""
)
.with("printSourcesDir", temp.resolve("target/1-parse").toFile())
.with("printOutputDir", temp.resolve("target/generated-sources").toFile())
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(PhiMojo.class)
.execute(UnphiMojo.class)
.execute(PrintMojo.class)
.result();
MatcherAssert.assertThat(
"Result EO code should be parsable",
new EoSyntax(
"test",
new InputOf(
new TextOf(
temp.resolve(
map.get("target/generated-sources/foo/x/main.eo")
)
)
)
).parsed(),
XhtmlMatchers.hasXPath("//errors[count(error)=0]")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.io.FileMatchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.xembly.Directives;
Expand All @@ -44,7 +45,19 @@
* Test case for {@link org.eolang.maven.optimization.OptCached}.
* @since 0.28.12
*/
class OptCachedTest {
final class OptCachedTest {

/**
* Test case for XML program in cache.
*
* @param tmp Temp dir
* @throws IOException if I/O fails
* @todo #2422:60min returnsFromCacheIfXmlAlreadyInCache: this test is unstable.
* We should resolve issues with unstable failures and only
* then enable the test.
* Also, see this <a href="https://github.com/objectionary/eo/issues/2727">issue</a>.
*/
@Disabled
@Test
void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path tmp) throws IOException {
final XML program = OptCachedTest.program(ZonedDateTime.now());
Expand Down Expand Up @@ -78,7 +91,7 @@ void optimizesIfXmlIsAbsentInCache(@TempDir final Path tmp) {
}

@Test
void optimizesBecauseChacheIsExpired(@TempDir final Path tmp) throws IOException {
void optimizesBecauseCacheIsExpired(@TempDir final Path tmp) throws IOException {
final XML outdated = OptCachedTest.program(ZonedDateTime.now().minusMinutes(1));
final XML updated = OptCachedTest.program(ZonedDateTime.now());
OptCachedTest.save(tmp, outdated);
Expand Down
Loading

0 comments on commit 32f28d3

Please sign in to comment.