forked from objectionary/eo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadmeSnippetsIT.java
More file actions
97 lines (93 loc) · 3.32 KB
/
Copy pathReadmeSnippetsIT.java
File metadata and controls
97 lines (93 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package integration;
import com.jcabi.manifests.Manifests;
import com.yegor256.MayBeSlow;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import com.yegor256.WeAreOnline;
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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
/**
* Integration test for EO snippets in `README.md`.
* @since 0.56.3
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
final class ReadmeSnippetsIT {
@Tag("snippets")
@ParameterizedTest
@ExtendWith(MktmpResolver.class)
@ExtendWith(WeAreOnline.class)
@ExtendWith(MayBeSlow.class)
@MethodSource("snippets")
@SuppressWarnings("PMD.UnitTestShouldIncludeAssert")
void validatesReadmeSnippets(final String snippet, @Mktmp final Path temp) throws IOException {
new Farea(temp).together(
f -> {
f.properties()
.set("project.build.sourceEncoding", StandardCharsets.UTF_8.name())
.set("project.reporting.outputEncoding", StandardCharsets.UTF_8.name());
f.files()
.file(String.format("src/main/eo/%s.eo", "app"))
.write(
String.format("%s\n", snippet).getBytes(StandardCharsets.UTF_8)
);
f.dependencies()
.append(
"org.eolang",
"eo-runtime",
System.getProperty(
"eo.version",
Manifests.read("EO-Version")
)
);
f.build()
.properties()
.set("directory", "target");
new EoSourceRun(f).exec("app");
f.exec("clean", "test");
MatcherAssert.assertThat(
String.format(
"EO snippet was not been executed as expected:\n%s",
snippet
),
f.log().content(),
Matchers.containsString("BUILD SUCCESS")
);
}
);
}
/**
* EO snippets from README.md file.
* @return Stream of EO snippets
* @throws IOException if I/O fails
*/
private static Stream<Arguments> snippets() throws IOException {
final Stream.Builder<Arguments> result = Stream.builder();
final Matcher matcher = Pattern.compile("(?ms)```eo\\s+(.*?)```").matcher(
Files.readString(
Paths.get("").toAbsolutePath().getParent().resolve("README.md")
)
);
while (matcher.find()) {
result.add(Arguments.of(matcher.group(1)));
}
return result.build();
}
}