Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Aug 16, 2023
2 parents b9156d2 + d500146 commit b1a895e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.yegor256.tojos.Tojos;
import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.function.Predicate;
Expand Down Expand Up @@ -232,12 +233,12 @@ public boolean contains(final String name) {
}

/**
* Check if the tojos contains a foreign tojo with object name.
* Check if the tojos contains a foreign tojos with object name.
* @param name The name of the tojo.
* @return True if tojo exists.
*/
public boolean contains(final ObjectName name) {
return this.contains(name.toString());
public boolean contains(final ObjectName... name) {
return Arrays.stream(name).map(Object::toString).allMatch(this::contains);
}

/**
Expand Down Expand Up @@ -336,7 +337,25 @@ enum Attribute {
DISCOVERED_AT("discovered-at"),

/**
* Probed.
* How many objects were probed in the tojo.
* Let's consider the next eo code:
* <p>
* {@code
* [] > main
* QQ.io.stdout > @
* QQ.txt.sprintf "I am %d years old"
* plus.
* 1337
* 228
* }
* </p>
* <p>In this code there are 5 objects that were probed:</p>
* - "org.eolang"
* - "org.eolang.io"
* - "org.eolang.txt"
* - "org.eolang.io.stdout"
* - "org.eolang.txt.sprintf"
* <p>For more info see {@link org.eolang.maven.ProbeMojo}. </p>
*/
PROBED("probed"),

Expand All @@ -347,6 +366,7 @@ enum Attribute {

/**
* Hash.
* Object version hash from git.
*/
HASH("hash"),

Expand Down
71 changes: 41 additions & 30 deletions eo-maven-plugin/src/test/java/org/eolang/maven/ProbeMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Map;
import org.cactoos.io.ResourceOf;
import org.cactoos.map.MapEntry;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.eolang.maven.hash.ChCached;
import org.eolang.maven.hash.ChPattern;
import org.eolang.maven.hash.ChRemote;
Expand All @@ -53,8 +52,6 @@
* Test case for {@link ProbeMojo}.
*
* @since 0.28.11
* @todo #2302:30min Refactor tests in the class. Looks like there is a lot of
* code duplication among all tests in the class. Need to reduce it somehow.
*/
@ExtendWith(OnlineCondition.class)
final class ProbeMojoTest {
Expand All @@ -66,29 +63,41 @@ final class ProbeMojoTest {
@Test
@ExtendWith(OnlineCondition.class)
void findsProbes(@TempDir final Path temp) throws Exception {
final String expected = "5";
MatcherAssert.assertThat(
String.format(
"Number of objects that we should find during the probing phase should be equal %s",
expected
),
new FakeMaven(temp)
.with("foreignFormat", "json")
.withProgram(ProbeMojoTest.program())
.execute(new FakeMaven.Probe())
.programTojo()
.probed(),
Matchers.equalTo("5")
Matchers.equalTo(expected)
);
}

@Test
void findsProbesViaOfflineHashFile(@TempDir final Path temp) throws IOException {
final String tag = "master";
final String tags = "org/eolang/maven/commits/tags.txt";
new Home(temp).save(
new ResourceOf("org/eolang/maven/commits/tags.txt"),
new ResourceOf(tags),
Paths.get("tags.txt")
);
MatcherAssert.assertThat(
String.format(
"The hash of the program should be equal to the hash of the commit for the '%s' tag. See '%s' file",
tag,
tags
),
new FakeMaven(temp)
.with(
"hsh",
new ChCached(
new ChText(temp.resolve("tags.txt"), "master")
new ChText(temp.resolve("tags.txt"), tag)
)
)
.withProgram(ProbeMojoTest.program())
Expand All @@ -102,6 +111,7 @@ void findsProbesViaOfflineHashFile(@TempDir final Path temp) throws IOException
@Test
void findsProbesViaOfflineHash(@TempDir final Path temp) throws IOException {
MatcherAssert.assertThat(
"The hash of the program tojo should be equal to the given hash pattern",
new FakeMaven(temp)
.with("hsh", new ChPattern("*.*.*:abcdefg", "1.0.0"))
.withProgram(ProbeMojoTest.program())
Expand All @@ -117,6 +127,10 @@ void findsProbesViaOfflineHash(@TempDir final Path temp) throws IOException {
void findsProbesInOyRemote(@TempDir final Path temp) throws IOException {
final String tag = "0.28.10";
MatcherAssert.assertThat(
String.format(
"The hash of the program tojo should be equal to the hash of the commit for the '%s' tag",
tag
),
new FakeMaven(temp)
.with("tag", tag)
.with(
Expand All @@ -143,19 +157,19 @@ void findsProbesWithVersionsInOneObjectionary(@TempDir final Path temp) throws I
.execute(new FakeMaven.Probe());
MatcherAssert.assertThat(
String.format(
"Tojos should have contained versioned object %s after probing, but they didn't",
"Tojos should contain versioned object %s after probing, but they didn't",
ProbeMojoTest.STDOUT
),
maven.externalTojos().contains(ProbeMojoTest.STDOUT),
Matchers.is(true)
);
MatcherAssert.assertThat(
"Program entry in tojos after probing should contain one probed object",
"Program tojo entry in tojos after probing should contain one probed object",
maven.programExternalTojo().probed(),
Matchers.equalTo("1")
);
MatcherAssert.assertThat(
"Program entry in tojos after probing should contain given hash",
"Program tojo entry in tojos after probing should contain given hash",
maven.programExternalTojo().hash(),
Matchers.equalTo(hash.value())
);
Expand All @@ -168,7 +182,6 @@ void findsProbesWithVersionsInDifferentObjectionaries(@TempDir final Path temp)
final Map<String, CommitHash> hashes = new CommitHashesMap.Fake();
final CommitHash first = hashes.get("0.28.5");
final CommitHash second = hashes.get("0.28.6");
final ObjectName text = new OnVersioned("org.eolang.txt.text", "5f82cc1");
final FakeMaven maven = new FakeMaven(temp)
.with(
"objectionaries",
Expand All @@ -181,39 +194,37 @@ void findsProbesWithVersionsInDifferentObjectionaries(@TempDir final Path temp)
.with("hsh", first)
.withVersionedProgram()
.execute(new FakeMaven.Probe());
final ObjectName text = new OnVersioned("org.eolang.txt.text", "5f82cc1");
MatcherAssert.assertThat(
String.format(
"Tojos should have contained versioned object %s after probing, but they didn't",
ProbeMojoTest.STDOUT
),
maven.externalTojos().contains(ProbeMojoTest.STDOUT),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"Tojos should have contained versioned object %s after probing, but they didn't",
text
"Tojos should contain versioned objects '%s' after probing, but they didn't",
Arrays.asList(text, ProbeMojoTest.STDOUT)
),
maven.externalTojos().contains(text),
maven.externalTojos().contains(text, ProbeMojoTest.STDOUT),
Matchers.is(true)
);
MatcherAssert.assertThat(
"First entry of tojos after probing should have contained two probed objects, but it didn't",
"Program tojo after probing should contain exactly two probed objects",
maven.programExternalTojo().probed(),
Matchers.equalTo("2")
);
MatcherAssert.assertThat(
"First entry of tojos after probing should have contained given hash, but it didn't",
"Program tojo after probing should have given hash",
maven.programExternalTojo().hash(),
Matchers.equalTo(first.value())
);
}

private static String program() {
return new UncheckedText(
new TextOf(
new ResourceOf("org/eolang/maven/simple-io.eo")
)
).asString();
private static String[] program() {
return new String[]{
"+package org.eolang.custom",
"",
"[] > main",
" QQ.io.stdout > @",
" QQ.txt.sprintf \"I am %d years old\"",
" plus.",
" 1337",
" 228",
};
}
}

This file was deleted.

1 comment on commit b1a895e

@0pdd
Copy link

@0pdd 0pdd commented on b1a895e Aug 16, 2023

Choose a reason for hiding this comment

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

Puzzle 2302-8638ac29 disappeared from eo-maven-plugin/src/test/java/org/eolang/maven/ProbeMojoTest.java), that's why I closed #2330. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.