Skip to content

Commit 2932991

Browse files
committed
objectionary#3941 add integration tests for transpile
1 parent cdfa752 commit 2932991

File tree

3 files changed

+129
-72
lines changed

3 files changed

+129
-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,128 @@
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+
"+unlint object-has-data",
38+
"",
39+
"# no comments.",
40+
"[] > foo",
41+
" QQ.io.stdout > @",
42+
" \"Hello, world!\\n\""
43+
).getBytes(StandardCharsets.UTF_8)
44+
);
45+
new AppendedPlugin(f).value()
46+
.goals("register", "parse", "shake", "transpile");
47+
f.exec("process-sources");
48+
final String java = "EOfoo.java";
49+
final String pname = "EOone";
50+
final String pinfo = "package-info.java";
51+
MatcherAssert.assertThat(
52+
String.format(
53+
"The %s file must be generated, but it didn't",
54+
java
55+
),
56+
temp.resolve(
57+
String.format(
58+
"target/generated-sources/%s/%s",
59+
pname,
60+
java
61+
)
62+
).toFile().exists(),
63+
Matchers.is(true)
64+
);
65+
MatcherAssert.assertThat(
66+
String.format(
67+
"The %s file must contain the %s package name",
68+
pinfo,
69+
pname
70+
),
71+
Files.readString(
72+
temp.resolve(
73+
String.format(
74+
"target/generated-sources/%s/%s",
75+
pname,
76+
pinfo
77+
)
78+
),
79+
StandardCharsets.UTF_8
80+
),
81+
Matchers.containsString(String.format("package %s;", pname))
82+
);
83+
}
84+
);
85+
}
86+
87+
@Test
88+
void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog)
89+
throws Exception {
90+
new Farea(temp).together(
91+
f -> {
92+
f.clean();
93+
f.files().file("src/main/eo/foo.eo").write(prog.getBytes());
94+
new AppendedPlugin(f).value()
95+
.goals("register", "parse", "shake", "transpile");
96+
f.exec("process-sources");
97+
final String java = "EOfoo.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+
final String pinfo = "package-info.java";
112+
MatcherAssert.assertThat(
113+
String.format(
114+
"The %s file must not exist, but it doesn't",
115+
pinfo
116+
),
117+
temp.resolve(
118+
String.format(
119+
"target/generated-sources/%s",
120+
pinfo
121+
)
122+
).toFile().exists(),
123+
Matchers.is(false)
124+
);
125+
}
126+
);
127+
}
128+
}

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)