Skip to content

Commit

Permalink
feat(objectionary#2638): added messages in tests + removed dublicates…
Browse files Browse the repository at this point in the history
… in FakeMaven
  • Loading branch information
Yanich96 committed Dec 20, 2023
1 parent 5d3d8e8 commit 2e14de5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
16 changes: 16 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 @@ -626,6 +626,22 @@ public Iterator<Class<? extends AbstractMojo>> iterator() {
}
}

/**
* Shake full pipeline.
*
* @since 0.35.0
*/
static final class Shake implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class
).iterator();
}
}

/**
* Latex full pipeline.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

/**
* Test case for {@link OptimizeMojo}.
* @todo #2638:15min This test has the error:
* @todo #2638:15min The test {@link #doesNotCrashesOnError(Path path)} has the mistake:
* Here "Matchers.hasKey(String.format("target/%s/foo/x/main.%s",
* ParseMojo.DIR, TranspileMojo.EXT)".
* But it should be "Matchers.hasKey(String.format("target/%s/foo/x/main.%s",
Expand Down
41 changes: 14 additions & 27 deletions eo-maven-plugin/src/test/java/org/eolang/maven/ShakeMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ void shakesSuccessfully(@TempDir final Path temp) throws IOException {
final Map<String, Path> res = maven
.withHelloWorld()
.with("trackOptimizationSteps", true)
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class)
.execute(new FakeMaven.Shake())
.result();
MatcherAssert.assertThat(
"After successful operation of the ShakeMojo, a xml should appear.",
res,
Matchers.hasKey(
String.format("target/%s/foo/x/main/01-remove-refs.xml", ShakeMojo.STEPS)
)
);
MatcherAssert.assertThat(
"After successful operation of the ShakeMojo, a xmir should appear.",
res,
Matchers.hasKey(
String.format(this.key, ShakeMojo.DIR, TranspileMojo.EXT)
Expand All @@ -98,10 +98,9 @@ void getsAlreadyShakenResultsFromCache(@TempDir final Path temp) throws Exceptio
.withHelloWorld()
.with("cache", cache)
.allTojosWithHash(() -> hash)
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class);
.execute(new FakeMaven.Shake());
MatcherAssert.assertThat(
"Ready shaken results should be loaded from cache.",
new XMLDocument(
new HmBase(temp).load(
Paths.get(
Expand All @@ -121,15 +120,14 @@ void getsAlreadyShakenResultsFromCache(@TempDir final Path temp) throws Exceptio
void skipsAlreadyShaken(@TempDir final Path temp) throws IOException {
final FakeMaven maven = new FakeMaven(temp)
.withHelloWorld()
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class);
.execute(new FakeMaven.Shake());
final Path path = maven.result().get(
String.format(this.key, ShakeMojo.DIR, TranspileMojo.EXT)
);
final long mtime = path.toFile().lastModified();
maven.execute(ShakeMojo.class);
MatcherAssert.assertThat(
"Re-shaken of the program should be skipped.",
path.toFile().lastModified(),
Matchers.is(mtime)
);
Expand All @@ -140,9 +138,7 @@ void shakesIfExpired(@TempDir final Path temp) throws Exception {
final FakeMaven maven = new FakeMaven(temp);
final Path tgt = maven
.withHelloWorld()
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class)
.execute(new FakeMaven.Shake())
.result()
.get(
String.format(this.key, ShakeMojo.DIR, TranspileMojo.EXT)
Expand All @@ -167,23 +163,16 @@ void savesShakenResultsToCache(@TempDir final Path temp) throws IOException {
.withHelloWorld()
.with("cache", cache)
.allTojosWithHash(() -> hash)
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class);
.execute(new FakeMaven.Shake());
MatcherAssert.assertThat(
"Shaken results should be saved.",
cache.resolve(ShakeMojo.SHAKEN)
.resolve(hash)
.resolve("foo/x/main.xmir").toFile(),
FileMatchers.anExistingFile()
);
}

/**
* The test with high number of eo programs reveals concurrency problems of the OptimizeMojo.
* Since other tests works only with single program - it's hard to find concurrency mistakes.
* @param temp Test directory.
* @throws java.io.IOException If problem with filesystem happened.
*/
@Test
void shakesConcurrentlyWithLotsOfPrograms(@TempDir final Path temp) throws IOException {
final FakeMaven maven = new FakeMaven(temp);
Expand All @@ -192,12 +181,11 @@ void shakesConcurrentlyWithLotsOfPrograms(@TempDir final Path temp) throws IOExc
maven.withHelloWorld();
}
final Map<String, Path> res = maven
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class)
.execute(new FakeMaven.Shake())
.result();
for (int program = 0; program < total; ++program) {
MatcherAssert.assertThat(
"Shaken results of all executed programs must be found.",
res,
Matchers.hasKey(
String.format(
Expand All @@ -214,6 +202,7 @@ void shakesConcurrentlyWithLotsOfPrograms(@TempDir final Path temp) throws IOExc
@Test
void doesNotCrashesOnError(@TempDir final Path temp) throws Exception {
MatcherAssert.assertThat(
"The program should run without errors.",
new FakeMaven(temp)
.withProgram(
"+package f\n",
Expand All @@ -222,9 +211,7 @@ void doesNotCrashesOnError(@TempDir final Path temp) throws Exception {
" TRUE > x",
" FALSE > x"
).with("trackOptimizationSteps", true)
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class)
.execute(new FakeMaven.Shake())
.result(),
Matchers.hasKey(
String.format(this.key, ShakeMojo.DIR, TranspileMojo.EXT)
Expand Down

0 comments on commit 2e14de5

Please sign in to comment.