Skip to content

Commit

Permalink
objectionary#2937 add empty assertion message in eo-maven-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Mar 25, 2024
1 parent 5472352 commit bcc8bcd
Show file tree
Hide file tree
Showing 50 changed files with 324 additions and 17 deletions.
Expand Up @@ -45,6 +45,11 @@
*/
final class BinarizeMojoTest {

/**
* Empty message for JUnit Assertions.
*/
private static final String EMPTY_MSG = "EMPTY MESSAGE";

/**
* Sources for the tests.
*/
Expand Down Expand Up @@ -98,12 +103,14 @@ void savesToCache(@TempDir final Path temp) throws IOException {
.execute(new FakeMaven.Binarize())
.result();
MatcherAssert.assertThat(
BinarizeMojoTest.EMPTY_MSG,
res,
Matchers.hasValue(
cache.resolve("Lib")
)
);
MatcherAssert.assertThat(
BinarizeMojoTest.EMPTY_MSG,
res,
Matchers.not(
Matchers.hasValue(
Expand Down Expand Up @@ -137,6 +144,7 @@ void boostsSecondCompilation(@TempDir final Path temp) throws IOException {
finish = System.currentTimeMillis();
final long second = finish - start;
MatcherAssert.assertThat(
BinarizeMojoTest.EMPTY_MSG,
second,
Matchers.lessThan(first)
);
Expand All @@ -160,8 +168,13 @@ void doesNotRecompile(@TempDir final Path temp) throws IOException {
final long first = executable.lastModified();
maven.execute(new FakeMaven.Binarize());
final long second = executable.lastModified();
MatcherAssert.assertThat(first, Matchers.not(0L));
MatcherAssert.assertThat(
BinarizeMojoTest.EMPTY_MSG,
first,
Matchers.not(0L)
);
MatcherAssert.assertThat(
BinarizeMojoTest.EMPTY_MSG,
second,
Matchers.equalTo(first)
);
Expand Down
Expand Up @@ -47,6 +47,11 @@
@Execution(ExecutionMode.CONCURRENT)
final class BinarizeParseTest {

/**
* Empty message for JUnit Assertions.
*/
private static final String EMPTY_MSG = "EMPTY MESSAGE";

@Test
void parsesSimpleEoProgram(@TempDir final Path temp) throws Exception {
final Map<String, Path> res = execParse(
Expand All @@ -62,9 +67,11 @@ void parsesSimpleEoProgram(@TempDir final Path temp) throws Exception {
function
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
res, Matchers.hasKey(rust)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
new TextOf(res.get(rust)).asString(),
Matchers.stringContainsInOrder(
"use rand::Rng;",
Expand All @@ -77,6 +84,7 @@ void parsesSimpleEoProgram(@TempDir final Path temp) throws Exception {
)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
new TextOf(
res.get(
String.format(
Expand Down Expand Up @@ -104,12 +112,15 @@ void binarizesTwiceRustProgram(@TempDir final Path temp) throws Exception {
Names.PREFIX
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
res, Matchers.hasKey(one)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
res, Matchers.hasKey(two)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
new TextOf(res.get(one)).asString(),
Matchers.stringContainsInOrder(
"use eo::eo_enum::EO;",
Expand All @@ -119,6 +130,7 @@ void binarizesTwiceRustProgram(@TempDir final Path temp) throws Exception {
)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
new TextOf(res.get(two)).asString(),
Matchers.stringContainsInOrder(
"use eo::eo_enum::EO;",
Expand All @@ -133,6 +145,7 @@ void binarizesTwiceRustProgram(@TempDir final Path temp) throws Exception {
@ClasspathSource(value = "org/eolang/maven/binarize/add_rust/", glob = "**.yaml")
void createsDependenciesSection(final String yaml) {
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
new XaxStory(yaml),
Matchers.is(true)
);
Expand All @@ -156,15 +169,19 @@ void createsCorrectRustProject(@TempDir final Path temp) throws Exception {
dir
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
res, Matchers.hasKey(cargo)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
res, Matchers.hasKey(lib)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
res, Matchers.hasKey(module)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
new TextOf(res.get(cargo)).asString(),
Matchers.stringContainsInOrder(
"[lib]",
Expand All @@ -174,6 +191,7 @@ void createsCorrectRustProject(@TempDir final Path temp) throws Exception {
)
);
MatcherAssert.assertThat(
BinarizeParseTest.EMPTY_MSG,
new TextOf(res.get(cargo)).asString(),
Matchers.stringContainsInOrder(
"[dependencies]",
Expand Down
Expand Up @@ -54,6 +54,7 @@ final class CatalogsTest {
void readsFromTojosConcurrently(@TempDir final Path tmp) {
final Tojos tojos = Catalogs.INSTANCE.make(tmp.resolve("foreign"), "json");
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new SumOf(
new Threads<>(
CatalogsTest.CORES,
Expand Down
Expand Up @@ -54,6 +54,7 @@ void cleansSuccessfully(@TempDir final Path temp) throws IOException {
.with("targetDir", dir.toFile())
.execute(CleanMojo.class);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
!file.toFile().exists() && !small.toFile().exists(),
Matchers.is(true)
);
Expand All @@ -75,6 +76,7 @@ void makesFullCompilingLifecycleSuccessfully(@TempDir final Path temp) throws IO
.execute(AssembleMojo.class)
.execute(CleanMojo.class);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
temp.resolve("target").toFile().exists(),
Matchers.is(false)
);
Expand Down
Expand Up @@ -57,10 +57,12 @@ void copiesSources(@TempDir final Path temp) throws Exception {
.execute(CopyMojo.class);
final Path out = classes.resolve("EO-SOURCES/foo/main.eo");
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new HmBase(classes).exists(classes.relativize(out)),
Matchers.is(true)
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new TextOf(new HmBase(classes).load(classes.relativize(out))).asString(),
Matchers.allOf(
Matchers.containsString("+rt foo:"),
Expand Down Expand Up @@ -88,6 +90,7 @@ void skipsCopyMojo(@TempDir final Path temp) throws IOException {
.execute(CopyMojo.class);
final Path out = classes.resolve("EO-SOURCES/foo/main.eo");
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new HmBase(classes).exists(classes.relativize(out)),
Matchers.is(false)
);
Expand Down
Expand Up @@ -47,10 +47,12 @@ void findsDirs(@TempDir final Path temp) throws IOException {
new HmBase(temp).save("", Paths.get("test/f.txt"));
new HmBase(temp).save("", Paths.get("a/g"));
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new DepDirs(temp),
Matchers.contains(String.format("a%sb%1$sc%1$sf", File.separator))
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new DepDirs(temp),
Matchers.iterableWithSize(1)
);
Expand Down
Expand Up @@ -88,8 +88,13 @@ void executesDiscoveryPhaseForCorrectEoPrograms(
new MnCsv(maven.foreignPath()).read()
);
final Map<String, String> first = json.removeFirst();
MatcherAssert.assertThat(dependencies, Matchers.equalTo(json.size()));
MatcherAssert.assertThat(
"EMPTY MESSAGE",
dependencies,
Matchers.equalTo(json.size())
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
String.valueOf(dependencies),
Matchers.equalTo(first.get("discovered"))
);
Expand Down
Expand Up @@ -66,6 +66,7 @@ void convertsXmirtoJavaSuccessfully(@TempDir final Path temp) throws Exception {
Paths.get("sum.xmir")
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new TextOf(
new InputOf(
new JavaFiles(
Expand All @@ -85,6 +86,7 @@ void convertsXmirtoJavaWithoutJavaClasses(@TempDir final Path temp) throws Excep
Paths.get("sum.xmir")
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new JavaFiles(
temp.resolve("xml").resolve("sum.xmir"),
temp.resolve("java")
Expand Down
Expand Up @@ -46,6 +46,7 @@ final class LatexMojoTest {
@Test
void generatesTexFile(@TempDir final Path temp) throws Exception {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new FakeMaven(temp)
.withHelloWorld()
.execute(new FakeMaven.Latex())
Expand All @@ -63,6 +64,7 @@ void generatesTexFile(@TempDir final Path temp) throws Exception {
@Test
void checksLastName() {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
LatexMojo.last("foo.bar.hello"),
Matchers.equalTo("hello")
);
Expand Down
Expand Up @@ -78,6 +78,7 @@ void printsFormattedMessage(final Logs out) {
@Test
void matchesCorrectly() {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
"16:02:08 [INFO] org.eolang.maven.LogFormatTest: Wake up, Neo...\n",
Matchers.matchesPattern(LogFormatTest.FORMAT)
);
Expand Down
Expand Up @@ -52,6 +52,7 @@ void extendsForeignWithNewObjects(@TempDir final Path temp) throws IOException {
final FakeMaven maven = new FakeMaven(temp);
maven.execute(MarkMojo.class);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
maven.foreignTojos()
.all()
.iterator()
Expand All @@ -70,10 +71,12 @@ void updatesVersionIfItExists(@TempDir final Path temp) throws IOException {
.withVersion("*.*.*");
maven.execute(MarkMojo.class);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
foreign.all().iterator().next().version(),
Matchers.equalTo(MarkMojoTest.VERSION)
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
foreign.size(),
Matchers.equalTo(1)
);
Expand Down
Expand Up @@ -66,6 +66,7 @@ void checksPacks(final String pack) throws IOException {
);
}
MatcherAssert.assertThat(
"EMPTY MESSAGE",
check.failures(),
Matchers.empty()
);
Expand All @@ -82,6 +83,7 @@ void skipsAlreadyOptimized(@TempDir final Path temp) throws IOException {
final long mtime = path.toFile().lastModified();
maven.execute(OptimizeMojo.class);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
path.toFile().lastModified(),
Matchers.is(mtime)
);
Expand Down Expand Up @@ -143,6 +145,7 @@ void getsAlreadyOptimizedResultsFromCache(@TempDir final Path temp) throws Excep
.allTojosWithHash(() -> hash)
.execute(new FakeMaven.Optimize());
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new XMLDocument(
new HmBase(temp).load(
Paths.get(
Expand All @@ -168,6 +171,7 @@ void savesOptimizedResultsToCache(@TempDir final Path temp) throws IOException {
.allTojosWithHash(() -> hash)
.execute(new FakeMaven.Optimize());
MatcherAssert.assertThat(
"EMPTY MESSAGE",
cache.resolve(OptimizeMojo.OPTIMIZED)
.resolve(hash)
.resolve("foo/x/main.xmir").toFile(),
Expand All @@ -184,12 +188,14 @@ void optimizesSuccessfully(@TempDir final Path temp) throws IOException {
.execute(new FakeMaven.Optimize())
.result();
MatcherAssert.assertThat(
"EMPTY MESSAGE",
res,
Matchers.hasKey(
String.format("target/%s/foo/x/main/01-not-empty-atoms.xml", OptimizeMojo.STEPS)
)
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
res,
Matchers.hasKey(
String.format("target/%s/foo/x/main.%s", OptimizeMojo.DIR, TranspileMojo.EXT)
Expand All @@ -215,6 +221,7 @@ void optimizesConcurrentlyWithLotsOfPrograms(@TempDir final Path temp) throws IO
.result();
for (int program = 0; program < total; ++program) {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
res,
Matchers.hasKey(
String.format(
Expand All @@ -231,6 +238,7 @@ void optimizesConcurrentlyWithLotsOfPrograms(@TempDir final Path temp) throws IO
@Test
void doesNotCrashesOnError(@TempDir final Path temp) throws Exception {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new FakeMaven(temp)
.withProgram(
"+package f\n",
Expand All @@ -250,6 +258,7 @@ void doesNotCrashesOnError(@TempDir final Path temp) throws Exception {
@Test
void choosesTransformerFactoryOnce() {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
TransformerFactory.newInstance().getClass(),
Matchers.typeCompatibleWith(TransformerFactoryImpl.class)
);
Expand All @@ -261,6 +270,7 @@ void choosesTransformerFactoryInConcurrentEnvironment() {
.mapToObj(i -> TransformerFactory.newInstance().getClass())
.collect(Collectors.toList())) {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
clazz,
Matchers.typeCompatibleWith(TransformerFactoryImpl.class)
);
Expand Down
Expand Up @@ -59,6 +59,7 @@ final class ParseMojoTest {
void parsesSuccessfully(@TempDir final Path temp) throws Exception {
final FakeMaven maven = new FakeMaven(temp);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
maven.withHelloWorld()
.execute(new FakeMaven.Parse())
.result(),
Expand All @@ -67,6 +68,7 @@ void parsesSuccessfully(@TempDir final Path temp) throws Exception {
)
);
MatcherAssert.assertThat(
"EMPTY MESSAGE",
maven.foreign().getById("foo.x.main").exists("xmir"),
Matchers.is(true)
);
Expand Down Expand Up @@ -119,6 +121,7 @@ void parsesWithCache(@TempDir final Path temp) throws Exception {
@Test
void doesNotCrashesOnError(@TempDir final Path temp) throws Exception {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
new FakeMaven(temp)
.withProgram("something < is wrong here")
.execute(new FakeMaven.Parse())
Expand Down Expand Up @@ -165,6 +168,7 @@ void parsesConcurrentlyWithLotsOfPrograms(@TempDir final Path temp) throws IOExc
final Map<String, Path> res = maven.execute(new FakeMaven.Parse()).result();
for (int program = 0; program < total; ++program) {
MatcherAssert.assertThat(
"EMPTY MESSAGE",
res,
Matchers.hasKey(
String.format(
Expand Down

0 comments on commit bcc8bcd

Please sign in to comment.