Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bug/#3708/tests-xmi…
Browse files Browse the repository at this point in the history
…r-to-phi
  • Loading branch information
ArtemGet committed Jan 10, 2025
2 parents d5e2111 + 6466088 commit ec613a9
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 155 deletions.
5 changes: 5 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public final class PhiMojo extends SafeMojo {
*/
public static final String EXT = "phi";

/**
* Subdirectory for parsed cache.
*/
static final String CACHE = "phied";

/**
* The directory where to take xmir files for translation from.
* @checkstyle MemberNameCheck (10 lines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eolang.maven.log.Logs;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

Expand All @@ -54,19 +53,6 @@
@ExtendWith(MktmpResolver.class)
final class AssembleMojoTest {

/**
* Invalid eo program for testing.
*/
static final String[] INVALID_PROGRAM = {
"+alias stdout org.eolang.io.stdout",
"+home https://github.com/objectionary/eo",
"+package test",
"+version 0.0.0",
"",
"[x] < wrong>",
" (stdout \"Hello!\" x).print",
};

@Test
void assemblesTogether(@Mktmp final Path temp) throws IOException {
final Map<String, Path> result = new FakeMaven(temp)
Expand Down Expand Up @@ -111,7 +97,15 @@ void assemblesTogether(@Mktmp final Path temp) throws IOException {
@Test
void assemblesNotFailWithFailOnError(@Mktmp final Path temp) throws IOException {
final Map<String, Path> result = new FakeMaven(temp)
.withProgram(AssembleMojoTest.INVALID_PROGRAM)
.withProgram(
"+alias stdout org.eolang.io.stdout",
"+home https://github.com/objectionary/eo",
"+package test",
"+version 0.0.0",
"",
"[x] < wrong>",
" (stdout \"Hello!\" x).print"
)
.execute(new FakeMaven.Shake())
.result();
MatcherAssert.assertThat(
Expand All @@ -128,14 +122,12 @@ void assemblesNotFailWithFailOnError(@Mktmp final Path temp) throws IOException

@CaptureLogs
@Test
void assemblesSuccessfullyInOfflineMode(final Logs out, @Mktmp final Path temp) {
Assertions.assertDoesNotThrow(
() -> new FakeMaven(temp)
.withHelloWorld()
.with("offline", true)
.execute(AssembleMojo.class),
"AssembleMojo should have executed successfully with eo.offline=TRUE, but it didn't"
);
void assemblesSuccessfullyInOfflineMode(final Logs out,
@Mktmp final Path temp) throws IOException {
new FakeMaven(temp)
.withHelloWorld()
.with("offline", true)
.execute(AssembleMojo.class);
MatcherAssert.assertThat(
"While execution AssembleMojo log should have contained message about offline mode, but it didn't",
String.join("\n", out.captured()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,15 @@ void failsOnInvalidProgram(@Mktmp final Path temp) {
Assertions.assertThrows(
IllegalStateException.class,
() -> new FakeMaven(temp)
.withProgram(AssembleMojoTest.INVALID_PROGRAM)
.withProgram(
"+alias stdout org.eolang.io.stdout",
"+home https://github.com/objectionary/eo",
"+package test",
"+version 0.0.0",
"",
"[x] < wrong>",
" (stdout \"Hello!\" x).print"
)
.execute(new FakeMaven.Lint()),
"Invalid program with wrong syntax should have failed to assemble, but it didn't"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
/**
* Tests of the log4j logger messages format.
*
* All log messages are written to System.out. System.out is a shared resource among all other
* <p>All log messages are written to System.out. System.out is a shared resource among all other
* threads. For this reason, we run tests in this class in the same thread (disabling parallelism).
* This approach prevents log messages from other threads from interfering. Since all the tests in
* this class are relatively fast, it does not significantly impact overall performance.
* We disable parallelism by using the {@link Execution} annotation with
* {@link ExecutionMode#SAME_THREAD}. DO NOT REMOVE THAT ANNOTATION!
* {@link ExecutionMode#SAME_THREAD}. DO NOT REMOVE THAT ANNOTATION!</p>
*
* @since 0.28.11
*/
Expand All @@ -54,16 +54,12 @@ final class LogFormatTest {
private static final String FORMAT =
"^\\d{2}:\\d{2}:\\d{2} \\[INFO] org.eolang.maven.LogFormatTest: Wake up, Neo...\\R";

/**
* Message to log.
*/
private static final String MESSAGE = "Wake up, Neo...";

@Test
@CaptureLogs
void printsFormattedMessage(final Logs out) {
Logger.info(this, LogFormatTest.MESSAGE);
final String actual = out.waitForMessage(LogFormatTest.MESSAGE);
final String msg = "Wake up, Neo...";
Logger.info(this, msg);
final String actual = out.waitForMessage(msg);
MatcherAssert.assertThat(
String.format(
"Actual log output is '%s', but expected pattern is: '%s'",
Expand Down
74 changes: 74 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,32 @@
import com.yegor256.MktmpResolver;
import com.yegor256.WeAreOnline;
import com.yegor256.farea.Farea;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
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.xax.XtSticky;
import org.eolang.xax.XtYaml;
import org.eolang.xax.Xtory;
import org.hamcrest.MatcherAssert;
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;

/**
* Test cases for {@link PhiMojo}.
* @since 0.34.0
* @todo #3708:30min Remove @Disabled annotation on
* {@code PhiMojoTest.usesCache()} and {@code PhiMojoTest.invalidatesCache()}
* when cache is implemented, check that tests is valid otherwise fix them.
*/
@SuppressWarnings({"PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals"})
@ExtendWith(MktmpResolver.class)
Expand Down Expand Up @@ -223,4 +231,70 @@ void checksSaltyPhiPacks(final String pack, @Mktmp final Path temp) throws Excep
Matchers.equalTo(xtory.map().get("salty").toString())
);
}

@Test
@Disabled
void usesCache(
@Mktmp final Path temp,
@RandomProgram final String program
) throws Exception {
final Path cache = temp.resolve("cache");
final String hash = "123ZaRiFcHiK321";
final Path cached = new Saved(
"some valid phi from cache",
new CachePath(
cache.resolve(PhiMojo.CACHE),
FakeMaven.pluginVersion(),
hash,
Path.of("foo/x/main.phi")
).get()
).value();
Files.setLastModifiedTime(
cached,
FileTime.fromMillis(System.currentTimeMillis() + 50_000)
);
MatcherAssert.assertThat(
"Phi is not loaded from cache",
new TextOf(
new FakeMaven(temp)
.with("cache", cache.toFile())
.withProgram(program)
.allTojosWithHash(() -> hash)
.execute(new FakeMaven.Phi())
.result()
.get("target/phi/foo/x/main.phi")
).asString(),
Matchers.equalTo(new TextOf(cached).asString())
);
}

@Test
@Disabled
void invalidatesCache(
@Mktmp final Path temp,
final @RandomProgram String program
) throws Exception {
final Path cache = temp.resolve("cache");
final String hash = "123ZaRiFcHiK321";
final File cached = new Saved(
"some invalid phi (old) from cache",
new CachePath(
cache.resolve(PhiMojo.CACHE),
FakeMaven.pluginVersion(),
hash,
Path.of("foo/x/main.phi")
).get()
).value().toFile();
final long old = cached.lastModified();
new FakeMaven(temp)
.with("cache", cache.toFile())
.withProgram(program)
.allTojosWithHash(() -> hash)
.execute(new FakeMaven.Phi());
MatcherAssert.assertThat(
"PHI cache not invalidated",
old,
Matchers.lessThan(cached.lastModified())
);
}
}
26 changes: 19 additions & 7 deletions eo-parser/src/test/java/org/eolang/parser/DrProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.jcabi.matchers.XhtmlMatchers;
import com.jcabi.xml.StrictXML;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.nio.file.Paths;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -61,24 +60,37 @@ void buildsProgramElement() throws Exception {
@Test
@DisabledOnOs(OS.WINDOWS)
void setsSchemaLocation() throws Exception {
final XML xml = new XMLDocument(new Xembler(new DrProgram("foo")).xml());
MatcherAssert.assertThat(
"XSD location is set",
xml.toString(),
new XMLDocument(new Xembler(new DrProgram("xxx")).xml()).toString(),
Matchers.containsString(
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
)
);
final String url = xml.xpath("/program/@xsi:noNamespaceSchemaLocation").get(0);
}

@Test
@DisabledOnOs(OS.WINDOWS)
void checksThatSchemaLocationPointToFile() throws Exception {
MatcherAssert.assertThat(
"URL of XSD is set to file",
url,
new XMLDocument(new Xembler(new DrProgram("bar")).xml()).xpath(
"/program/@xsi:noNamespaceSchemaLocation"
).get(0),
Matchers.startsWith("file:///")
);
final String path = url.substring("file:///".length());
}

@Test
@DisabledOnOs(OS.WINDOWS)
void checksThatSchemaLocationPointToExistingFile() throws Exception {
MatcherAssert.assertThat(
"XSD file exists",
Paths.get(path).toFile().exists(),
Paths.get(
new XMLDocument(new Xembler(new DrProgram("boom")).xml()).xpath(
"/program/@xsi:noNamespaceSchemaLocation"
).get(0).substring("file:///".length())
).toFile().exists(),
Matchers.is(true)
);
}
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ SOFTWARE.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.15</version>
<version>1.5.16</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions eo-runtime/src/main/eo/org/eolang/math/angle.eo
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
# The angle.
[value] > angle
value > @
# Converts this from radians to degrees
# Converts this from radians to degrees.
angle > in-degrees
div.
^.times 180.0
pi
# Converts this from degrees to radians
# Converts this from degrees to radians.
angle > in-radians
div.
$.times pi
Expand Down
15 changes: 8 additions & 7 deletions eo-runtime/src/main/eo/org/eolang/nan.eo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
+package org.eolang
+version 0.0.0

# Not a number.
# The `not a number` object is an abstraction
# for representing undefined or unrepresentable numerical results.
[] > nan
number 7F-F8-00-00-00-00-00-00 > @
$ > floor
Expand All @@ -35,25 +36,25 @@
false > is-integer
error "Can't convert NaN to i64" > as-i64

# Tests that $ = x.
# Tests that $ value is equal to x.
false > [x] > eq

# Tests that $ < x.
# Tests that the value $ less than x.
false > [x] > lt

# Tests that $ <= x.
# Tests that $ less or equal than x.
false > [x] > lte

# Tests that $ > x.
# Tests that $ value greater than x.
false > [x] > gt

# Tests that $ >= x.
# Tests that $ greater or equal than x.
false > [x] > gte

# Returns the multiplication of $ and x.
^ > [x] > times

# Sum of $ and x.
# Returns the result of the sum of $ and x.
^ > [x] > plus

# Returns the difference between $ and x.
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/src/main/eo/org/eolang/negative-infinity.eo
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
nan
^

# Quotient of the division of $ by x
# Quotient of the division of $ by x.
[x] > div
x > value!
number value > num
Expand Down
4 changes: 2 additions & 2 deletions eo-runtime/src/main/eo/org/eolang/structs/list.eo
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
accum.with item > [accum item]

# Returns index of the first particular item in list.
# If the list has no this item, index-of returns -1
# If the list has no this item, index-of returns -1.
[wanted] > index-of
^.reducedi > @
-1
Expand All @@ -182,7 +182,7 @@
accum

# Returns index of the last particular item in list.
# If the list has no this item, returns -1
# If the list has no this item, returns -1.
[wanted] > last-index-of
^.reducedi > @
-1
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/src/main/eo/org/eolang/txt/text.eo
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
^.index-of substring

# Returns index of `substring` in current `text`.
# If no `substring` was found, it returns -1
# If no `substring` was found, it returns -1.
[substring] > index-of
(string ^.origin.as-bytes).length > self-len!
string > substr
Expand Down
Loading

0 comments on commit ec613a9

Please sign in to comment.