Skip to content

Commit 5c091bd

Browse files
committed
LargeXmir
1 parent 8a97f18 commit 5c091bd

File tree

2 files changed

+104
-62
lines changed

2 files changed

+104
-62
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2025 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package fixtures;
25+
26+
import com.jcabi.xml.XML;
27+
import com.jcabi.xml.XMLDocument;
28+
import com.yegor256.farea.Farea;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
31+
import java.util.concurrent.atomic.AtomicReference;
32+
import org.cactoos.Scalar;
33+
import org.cactoos.bytes.BytesOf;
34+
import org.cactoos.bytes.UncheckedBytes;
35+
import org.cactoos.io.ResourceOf;
36+
37+
/**
38+
* Large XMIR document.
39+
*
40+
* @since 0.0.31
41+
*/
42+
public final class LargeXmir implements Scalar<XML> {
43+
44+
@Override
45+
public XML value() throws Exception {
46+
final Path home = Files.createTempDirectory("tmp");
47+
final String path = "com/sun/jna/Pointer.class";
48+
final AtomicReference<XML> ref = new AtomicReference<>();
49+
new Farea(home).together(
50+
f -> {
51+
f.clean();
52+
f.files()
53+
.file(String.format("target/classes/%s", path))
54+
.write(
55+
new UncheckedBytes(
56+
new BytesOf(
57+
new ResourceOf(
58+
"com/sun/jna/Pointer.class"
59+
)
60+
)
61+
).asBytes()
62+
);
63+
f.build()
64+
.plugins()
65+
.append("org.eolang", "jeo-maven-plugin", "0.7.2")
66+
.execution("default")
67+
.phase("process-classes")
68+
.goals("disassemble");
69+
f.exec("process-classes");
70+
ref.set(
71+
new XMLDocument(
72+
f.files().file(
73+
"target/generated-sources/jeo-xmir/com/sun/jna/Pointer.xmir"
74+
).path()
75+
)
76+
);
77+
}
78+
);
79+
return ref.get();
80+
}
81+
}

src/test/java/org/eolang/lints/ProgramTest.java

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,24 @@
3030
import com.yegor256.Mktmp;
3131
import com.yegor256.MktmpResolver;
3232
import com.yegor256.Together;
33-
import com.yegor256.farea.Farea;
3433
import com.yegor256.tojos.MnCsv;
3534
import com.yegor256.tojos.TjCached;
3635
import com.yegor256.tojos.TjDefault;
3736
import com.yegor256.tojos.Tojos;
3837
import com.yegor256.xsline.Xsline;
38+
import fixtures.LargeXmir;
3939
import java.io.IOException;
4040
import java.nio.charset.StandardCharsets;
4141
import java.nio.file.Files;
4242
import java.nio.file.Path;
4343
import java.nio.file.Paths;
4444
import java.util.ArrayList;
4545
import java.util.Collection;
46-
import org.cactoos.bytes.BytesOf;
47-
import org.cactoos.bytes.UncheckedBytes;
4846
import org.cactoos.io.InputOf;
4947
import org.cactoos.io.ResourceOf;
5048
import org.cactoos.iterable.Sticky;
5149
import org.cactoos.iterable.Synced;
50+
import org.cactoos.scalar.Unchecked;
5251
import org.cactoos.set.SetOf;
5352
import org.eolang.parser.EoSyntax;
5453
import org.eolang.parser.TrParsing;
@@ -242,66 +241,28 @@ void doesNotThrowIoException() {
242241
@ExtendWith(MktmpResolver.class)
243242
@ExtendWith(MayBeSlow.class)
244243
@Timeout(600L)
245-
void lintsLargeJnaClass(@Mktmp final Path home) throws Exception {
244+
void lintsLargeJnaClass() throws Exception {
246245
final String path = "com/sun/jna/Pointer.class";
247-
final Path bin = Paths.get("target")
248-
.resolve("jna-classes")
249-
.resolve(path);
250-
new Farea(home).together(
251-
f -> {
252-
f.clean();
253-
f.files()
254-
.file(String.format("target/classes/%s", path))
255-
.write(
256-
new UncheckedBytes(
257-
new BytesOf(
258-
new ResourceOf(
259-
"com/sun/jna/Pointer.class"
260-
)
261-
)
262-
).asBytes()
263-
);
264-
f.build()
265-
.plugins()
266-
.append("org.eolang", "jeo-maven-plugin", "0.7.2")
267-
.execution("default")
268-
.phase("process-classes")
269-
.goals("disassemble");
270-
f.exec("process-classes");
271-
final Path pre = f.files().file(
272-
"target/generated-sources/jeo-xmir/com/sun/jna/Pointer.xmir"
273-
).path();
274-
final XML xmir = new XMLDocument(pre);
275-
final long start = System.currentTimeMillis();
276-
final Collection<Defect> defects = new ProgramTest.BcProgram(xmir).defects();
277-
final long msec = System.currentTimeMillis() - start;
278-
final Path target = Paths.get("target");
279-
Files.write(
280-
target.resolve("lint-summary.txt"),
281-
String.join(
282-
"\n",
283-
String.format("Input: %s", path),
284-
Logger.format(
285-
"Size of .class: %[size]s (%1$s bytes)",
286-
bin.toFile().length()
287-
),
288-
Logger.format(
289-
"Size of .xmir after disassemble: %[size]s (%1$s bytes, %d lines)",
290-
pre.toFile().length(),
291-
Files.readString(pre, StandardCharsets.UTF_8).split("\n").length
292-
),
293-
Logger.format(
294-
"Lint time: %[ms]s (%d ms)",
295-
msec, msec
296-
)
297-
).getBytes(StandardCharsets.UTF_8)
298-
);
299-
MatcherAssert.assertThat(
300-
"Defects are empty, but they should not be",
301-
defects,
302-
Matchers.hasSize(Matchers.greaterThan(0))
303-
);
304-
}
246+
final XML xmir = new Unchecked<>(new LargeXmir()).value();
247+
final long start = System.currentTimeMillis();
248+
final Collection<Defect> defects = new ProgramTest.BcProgram(xmir).defects();
249+
final long msec = System.currentTimeMillis() - start;
250+
final Path target = Paths.get("target");
251+
Files.write(
252+
target.resolve("lint-summary.txt"),
253+
String.join(
254+
"\n",
255+
String.format("Input: %s", path),
256+
Logger.format(
257+
"Lint time: %[ms]s (%d ms)",
258+
msec, msec
259+
)
260+
).getBytes(StandardCharsets.UTF_8)
261+
);
262+
MatcherAssert.assertThat(
263+
"Defects are empty, but they should not be",
264+
defects,
265+
Matchers.hasSize(Matchers.greaterThan(0))
305266
);
306267
}
307268

0 commit comments

Comments
 (0)