Skip to content

Commit

Permalink
more polished
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 8, 2025
1 parent 3f6dfe9 commit 41edfc2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 40 deletions.
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
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

0 comments on commit 41edfc2

Please sign in to comment.