Skip to content

Commit

Permalink
moved from Farea to FkMaven, get rid of Saved
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemGet committed Jan 8, 2025
1 parent 9c3f879 commit ae78819
Showing 1 changed file with 48 additions and 59 deletions.
107 changes: 48 additions & 59 deletions eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -46,9 +45,9 @@
import org.cactoos.set.SetOf;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.footprint.FpDefault;
import org.eolang.maven.footprint.CachePath;
import org.eolang.maven.footprint.Saved;
import org.eolang.maven.util.HmBase;
import org.eolang.maven.util.Home;
import org.eolang.parser.EoSyntax;
import org.eolang.parser.StrictXmir;
import org.eolang.xax.XtSticky;
Expand Down Expand Up @@ -309,75 +308,65 @@ void convertsValidXmirAndParsableEO(final boolean reversed, @Mktmp final Path te
@Test
@Disabled
void usesCache(@Mktmp final Path temp) throws Exception {
final Home workspace = new HmBase(temp);
final Path phi = Paths.get("target/eo/phi/std.phi");
final Path xmir = Paths.get("target/eo/1-parse/std.xmir");
workspace.save(
new Saved(
"{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}",
phi
);
final String cache = "some valid XMIR from cache";
new FpDefault(
src -> cache,
temp.resolve("cache").resolve(UnphiMojo.CACHE),
"version-1.0",
"123ZaRiFcHiK321",
Path.of("std.xmir")
).apply(temp.resolve(phi), temp.resolve(xmir));
this.executePhiToXmir(new Farea(temp));
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(UnphiMojo.CACHE),
FakeMaven.pluginVersion(),
hash,
Path.of("std.xmir")
).get()
).value();
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 file recreated twice",
new TextOf(workspace.load(xmir)),
Matchers.equalTo(cache)
"XMIR file is not loaded from cache",
new TextOf(Files.readString(temp.resolve("target/eo/1-parse/std.xmir"))),
Matchers.equalTo(expected)
);
}

@Test
@Disabled
void invalidatesCache(@Mktmp final Path temp) throws Exception {
final Home workspace = new HmBase(temp);
final Path phi = Paths.get("target/eo/phi/std.phi");
final Path xmir = Paths.get("target/eo/1-parse/std.xmir");
final Path cache = Path.of("cache")
.resolve(UnphiMojo.CACHE)
.resolve("version-1.0")
.resolve("123ZaRiFcHiK321")
.resolve("std.xmir");
workspace.save(
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(UnphiMojo.CACHE),
FakeMaven.pluginVersion(),
hash,
Path.of("std.xmir")
).get()
).value()
.toFile();
new Saved(
"{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}",
phi
);
new FpDefault(
src -> "some valid XMIR from cache",
temp.resolve("cache").resolve(UnphiMojo.CACHE),
"version-1.0",
"123ZaRiFcHiK321",
Path.of("std.xmir")
).apply(temp.resolve(phi), temp.resolve(xmir));
Files.setLastModifiedTime(
temp.resolve(phi),
FileTime.fromMillis(System.currentTimeMillis() + 50_000)
);
final File cached = temp.resolve(cache).toFile();
temp.resolve("target/eo/phi/std.phi")
).value();
final long old = cached.lastModified();
this.executePhiToXmir(new Farea(temp));
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(
"phi-to-xmir cache not invalidated",
"XMIR cache not invalidated",
old,
Matchers.lessThan(cached.lastModified())
);
}

private void executePhiToXmir(final Farea farea) throws IOException {
farea.together(
f -> {
f.build()
.plugins()
.appendItself()
.execution()
.goals("phi-to-xmir");
f.exec("compile");
}
);
}
}

0 comments on commit ae78819

Please sign in to comment.