Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# package name contains capital letter and such names are conventional.
---
exclude_paths:
- "eo-maven-plugin/src/test/java/org/eolang/maven/RegisterMojoIT.java"
- "eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java"
127 changes: 127 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package org.eolang.maven;

import com.yegor256.MayBeSlow;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import com.yegor256.WeAreOnline;
import com.yegor256.farea.Farea;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Integration tests for {@link TranspileMojo}.
*
* @since 0.52
*/
@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"})
@ExtendWith({WeAreOnline.class, MktmpResolver.class, MayBeSlow.class, RandomProgramResolver.class})
final class TranspileMojoIT {
@Test
void transpilesWithPackage(@Mktmp final Path temp) throws Exception {
new Farea(temp).together(
f -> {
f.clean();
f.files().file("src/main/eo/one/foo.eo").write(
String.join(
"\n",
"+package one",
"",
"# no comments.",
"[] > foo",
" QQ.io.stdout > @",
" \"Hello, world!\\n\""
).getBytes(StandardCharsets.UTF_8)
);
new AppendedPlugin(f).value()
.goals("register", "parse", "shake", "transpile");
f.exec("process-sources");
final String java = "EOfoo.java";
final String pname = "EOone";
final String pinfo = "package-info.java";
MatcherAssert.assertThat(
String.format(
"The %s file must be generated, but it didn't",
java
),
temp.resolve(
String.format(
"target/generated-sources/%s/%s",
pname,
java
)
).toFile().exists(),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"The %s file must contain the %s package name",
pinfo,
pname
),
Files.readString(
temp.resolve(
String.format(
"target/generated-sources/%s/%s",
pname,
pinfo
)
),
StandardCharsets.UTF_8
),
Matchers.containsString(String.format("package %s;", pname))
);
}
);
}

@Test
void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog)
throws Exception {
new Farea(temp).together(
f -> {
f.clean();
f.files().file("src/main/eo/foo.eo").write(prog.getBytes());
new AppendedPlugin(f).value()
.goals("register", "parse", "shake", "transpile");
f.exec("process-sources");
final String java = "EOfoo.java";
final String pinfo = "package-info.java";
MatcherAssert.assertThat(
String.format(
"The %s file is re-generated",
java
),
temp.resolve(
String.format(
"target/generated-sources/%s",
java
)
).toFile().exists(),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"The %s file must not exist, but it doesn't",
pinfo
),
temp.resolve(
String.format(
"target/generated-sources/%s",
pinfo
)
).toFile().exists(),
Matchers.is(false)
);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import com.yegor256.farea.Farea;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -101,75 +99,6 @@ void doesNotTouchAtom(@Mktmp final Path temp) throws IOException {
);
}

@Test
void transpilesWithPackage(@Mktmp final Path temp)
throws Exception {
new Farea(temp).together(
f -> {
f.clean();
f.files().file("src/main/eo/one/foo.eo").write(
String.join(
"\n",
"+package one",
"+unlint object-has-data",
"",
"# no comments.",
"[] > foo",
" QQ.io.stdout > @",
" \"Hello, world!\\n\"",
""
).getBytes(StandardCharsets.UTF_8)
);
f.build()
.plugins()
.appendItself()
.execution()
.goals("register", "parse", "shake", "transpile");
f.exec("process-sources");
}
);
MatcherAssert.assertThat(
"the .java file is generated",
temp.resolve("target/generated-sources/EOone/EOfoo.java").toFile().exists(),
Matchers.is(true)
);
MatcherAssert.assertThat(
"the package-info.java file contains the right package name",
Files.readString(
temp.resolve("target/generated-sources/EOone/package-info.java"),
StandardCharsets.UTF_8
),
Matchers.containsString("package EOone;")
);
}

@Test
void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog)
throws Exception {
new Farea(temp).together(
f -> {
f.clean();
f.files().file("src/main/eo/foo.eo").write(prog.getBytes());
f.build()
.plugins()
.appendItself()
.execution()
.goals("register", "parse", "shake", "transpile");
f.exec("process-sources");
}
);
MatcherAssert.assertThat(
"the .java file is re-generated",
temp.resolve("target/generated-sources/EOfoo.java").toFile().exists(),
Matchers.is(true)
);
MatcherAssert.assertThat(
"the package-info.java file contains the right package name",
temp.resolve("target/generated-sources/package-info.java").toFile().exists(),
Matchers.is(false)
);
}

@Test
void recompilesIfModified(@Mktmp final Path temp) throws IOException {
final FakeMaven maven = new FakeMaven(temp);
Expand Down