Skip to content

Commit

Permalink
Merge pull request #3777 from ArtemGet/bug/#3708/tests-xmir-to-phi
Browse files Browse the repository at this point in the history
bug(#3708): tests for UnphiMojo cache
  • Loading branch information
yegor256 authored Jan 10, 2025
2 parents 6466088 + ec613a9 commit a762496
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
threadSafe = true
)
public final class UnphiMojo extends SafeMojo {

/**
* Unphi transformations.
*/
Expand Down
75 changes: 75 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 @@ -31,6 +31,7 @@
import com.yegor256.MktmpResolver;
import com.yegor256.WeAreOnline;
import com.yegor256.farea.Farea;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -44,6 +45,8 @@
import org.cactoos.set.SetOf;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.footprint.CachePath;
import org.eolang.maven.footprint.Saved;
import org.eolang.maven.util.HmBase;
import org.eolang.parser.EoSyntax;
import org.eolang.parser.StrictXmir;
Expand All @@ -54,6 +57,7 @@
import org.hamcrest.Matchers;
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.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -62,7 +66,11 @@
/**
* Test cases for {@link UnphiMojo}.
* @since 0.34.0
* @todo #3708:30min Remove @Disabled annotation on
* {@code UnphiMojoTest.usesCache()} and {@code UnphiMojoTest.invalidatesCache()}
* when cache is implemented, check that tests is valid otherwise fix them if needed.
*/
@SuppressWarnings("PMD.TooManyMethods")
@ExtendWith(MktmpResolver.class)
final class UnphiMojoTest {

Expand Down Expand Up @@ -296,4 +304,71 @@ void convertsValidXmirAndParsableEO(final boolean reversed, @Mktmp final Path te
XhtmlMatchers.hasXPath("/program[not(errors)]")
);
}

@Test
@Disabled
void usesCache(@Mktmp final Path temp) throws Exception {
new Saved(
"{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}",
temp.resolve("target/eo/phi/std.phi")
).value();
final String hash = "123ZaRiFcHiK321";
final Path cache = temp.resolve("cache");
final String expected = "some valid XMIR from cache";
new Saved(
expected,
new CachePath(
cache.resolve("unphied"),
FakeMaven.pluginVersion(),
hash,
Path.of("std.xmir")
).get()
).value();
MatcherAssert.assertThat(
"XMIR file is not loaded from cache",
new TextOf(
new FakeMaven(temp)
.with("cache", cache.toFile())
.with("unphiInputDir", temp.resolve("target/eo/phi/").toFile())
.with("unphiOutputDir", temp.resolve("target/eo/1-parse").toFile())
.allTojosWithHash(() -> hash)
.execute(UnphiMojo.class)
.result()
.get("target/eo/1-parse/std.xmir")
).asString(),
Matchers.equalTo(expected)
);
}

@Test
@Disabled
void invalidatesCache(@Mktmp final Path temp) throws Exception {
final String hash = "123ZaRiFcHiK321";
final Path cache = temp.resolve("cache");
final File cached = new Saved(
"some invalid (old) XMIR from cache",
new CachePath(
cache.resolve("unphied"),
FakeMaven.pluginVersion(),
hash,
Path.of("std.xmir")
).get()
).value().toFile();
new Saved(
"{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}",
temp.resolve("target/eo/phi/std.phi")
).value();
final long old = cached.lastModified();
new FakeMaven(temp)
.with("cache", cache.toFile())
.with("unphiInputDir", temp.resolve("target/eo/phi/").toFile())
.with("unphiOutputDir", temp.resolve("target/eo/1-parse").toFile())
.allTojosWithHash(() -> hash)
.execute(UnphiMojo.class);
MatcherAssert.assertThat(
"XMIR cache not invalidated",
old,
Matchers.lessThan(cached.lastModified())
);
}
}

1 comment on commit a762496

@0pdd
Copy link

@0pdd 0pdd commented on a762496 Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 3708-52994f4a discovered in eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java) and submitted as #3806. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.