Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(#3708): tests for UnphiMojo cache #3777

Merged
merged 17 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
);
}
}
Loading