Skip to content

Commit 3d63cb2

Browse files
authored
Merge pull request objectionary#3987 from Suban05/3941-transpile-it
objectionary#3941 add integration tests for `TranspileMojo`
2 parents ad6af0f + 4b4403e commit 3d63cb2

File tree

3 files changed

+128
-72
lines changed

3 files changed

+128
-72
lines changed

.codacy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# package name contains capital letter and such names are conventional.
77
---
88
exclude_paths:
9-
- "eo-maven-plugin/src/test/java/org/eolang/maven/RegisterMojoIT.java"
9+
- "eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
package org.eolang.maven;
6+
7+
import com.yegor256.MayBeSlow;
8+
import com.yegor256.Mktmp;
9+
import com.yegor256.MktmpResolver;
10+
import com.yegor256.WeAreOnline;
11+
import com.yegor256.farea.Farea;
12+
import java.nio.charset.StandardCharsets;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import org.hamcrest.MatcherAssert;
16+
import org.hamcrest.Matchers;
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.extension.ExtendWith;
19+
20+
/**
21+
* Integration tests for {@link TranspileMojo}.
22+
*
23+
* @since 0.52
24+
*/
25+
@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"})
26+
@ExtendWith({WeAreOnline.class, MktmpResolver.class, MayBeSlow.class, RandomProgramResolver.class})
27+
final class TranspileMojoIT {
28+
@Test
29+
void transpilesWithPackage(@Mktmp final Path temp) throws Exception {
30+
new Farea(temp).together(
31+
f -> {
32+
f.clean();
33+
f.files().file("src/main/eo/one/foo.eo").write(
34+
String.join(
35+
"\n",
36+
"+package one",
37+
"",
38+
"# no comments.",
39+
"[] > foo",
40+
" QQ.io.stdout > @",
41+
" \"Hello, world!\\n\""
42+
).getBytes(StandardCharsets.UTF_8)
43+
);
44+
new AppendedPlugin(f).value()
45+
.goals("register", "parse", "shake", "transpile");
46+
f.exec("process-sources");
47+
final String java = "EOfoo.java";
48+
final String pname = "EOone";
49+
final String pinfo = "package-info.java";
50+
MatcherAssert.assertThat(
51+
String.format(
52+
"The %s file must be generated, but it didn't",
53+
java
54+
),
55+
temp.resolve(
56+
String.format(
57+
"target/generated-sources/%s/%s",
58+
pname,
59+
java
60+
)
61+
).toFile().exists(),
62+
Matchers.is(true)
63+
);
64+
MatcherAssert.assertThat(
65+
String.format(
66+
"The %s file must contain the %s package name",
67+
pinfo,
68+
pname
69+
),
70+
Files.readString(
71+
temp.resolve(
72+
String.format(
73+
"target/generated-sources/%s/%s",
74+
pname,
75+
pinfo
76+
)
77+
),
78+
StandardCharsets.UTF_8
79+
),
80+
Matchers.containsString(String.format("package %s;", pname))
81+
);
82+
}
83+
);
84+
}
85+
86+
@Test
87+
void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog)
88+
throws Exception {
89+
new Farea(temp).together(
90+
f -> {
91+
f.clean();
92+
f.files().file("src/main/eo/foo.eo").write(prog.getBytes());
93+
new AppendedPlugin(f).value()
94+
.goals("register", "parse", "shake", "transpile");
95+
f.exec("process-sources");
96+
final String java = "EOfoo.java";
97+
final String pinfo = "package-info.java";
98+
MatcherAssert.assertThat(
99+
String.format(
100+
"The %s file is re-generated",
101+
java
102+
),
103+
temp.resolve(
104+
String.format(
105+
"target/generated-sources/%s",
106+
java
107+
)
108+
).toFile().exists(),
109+
Matchers.is(true)
110+
);
111+
MatcherAssert.assertThat(
112+
String.format(
113+
"The %s file must not exist, but it doesn't",
114+
pinfo
115+
),
116+
temp.resolve(
117+
String.format(
118+
"target/generated-sources/%s",
119+
pinfo
120+
)
121+
).toFile().exists(),
122+
Matchers.is(false)
123+
);
124+
}
125+
);
126+
}
127+
}

eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java

-71
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
import com.yegor256.Mktmp;
88
import com.yegor256.MktmpResolver;
9-
import com.yegor256.farea.Farea;
109
import java.io.IOException;
11-
import java.nio.charset.StandardCharsets;
1210
import java.nio.file.Files;
1311
import java.nio.file.Path;
1412
import java.nio.file.Paths;
@@ -101,75 +99,6 @@ void doesNotTouchAtom(@Mktmp final Path temp) throws IOException {
10199
);
102100
}
103101

104-
@Test
105-
void transpilesWithPackage(@Mktmp final Path temp)
106-
throws Exception {
107-
new Farea(temp).together(
108-
f -> {
109-
f.clean();
110-
f.files().file("src/main/eo/one/foo.eo").write(
111-
String.join(
112-
"\n",
113-
"+package one",
114-
"+unlint object-has-data",
115-
"",
116-
"# no comments.",
117-
"[] > foo",
118-
" QQ.io.stdout > @",
119-
" \"Hello, world!\\n\"",
120-
""
121-
).getBytes(StandardCharsets.UTF_8)
122-
);
123-
f.build()
124-
.plugins()
125-
.appendItself()
126-
.execution()
127-
.goals("register", "parse", "shake", "transpile");
128-
f.exec("process-sources");
129-
}
130-
);
131-
MatcherAssert.assertThat(
132-
"the .java file is generated",
133-
temp.resolve("target/generated-sources/EOone/EOfoo.java").toFile().exists(),
134-
Matchers.is(true)
135-
);
136-
MatcherAssert.assertThat(
137-
"the package-info.java file contains the right package name",
138-
Files.readString(
139-
temp.resolve("target/generated-sources/EOone/package-info.java"),
140-
StandardCharsets.UTF_8
141-
),
142-
Matchers.containsString("package EOone;")
143-
);
144-
}
145-
146-
@Test
147-
void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog)
148-
throws Exception {
149-
new Farea(temp).together(
150-
f -> {
151-
f.clean();
152-
f.files().file("src/main/eo/foo.eo").write(prog.getBytes());
153-
f.build()
154-
.plugins()
155-
.appendItself()
156-
.execution()
157-
.goals("register", "parse", "shake", "transpile");
158-
f.exec("process-sources");
159-
}
160-
);
161-
MatcherAssert.assertThat(
162-
"the .java file is re-generated",
163-
temp.resolve("target/generated-sources/EOfoo.java").toFile().exists(),
164-
Matchers.is(true)
165-
);
166-
MatcherAssert.assertThat(
167-
"the package-info.java file contains the right package name",
168-
temp.resolve("target/generated-sources/package-info.java").toFile().exists(),
169-
Matchers.is(false)
170-
);
171-
}
172-
173102
@Test
174103
void recompilesIfModified(@Mktmp final Path temp) throws IOException {
175104
final FakeMaven maven = new FakeMaven(temp);

0 commit comments

Comments
 (0)