1 |
commit: 2ccdc1840126b665f4e74d87a13a1c32ef7bbe61 |
2 |
Author: Yuan Liao <liaoyuan <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue Apr 5 02:50:47 2022 +0000 |
4 |
Commit: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Apr 5 04:41:27 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2ccdc184 |
7 |
|
8 |
dev-java/antlr-runtime: Enable tests for 4.9.3 |
9 |
|
10 |
Signed-off-by: Yuan Liao <liaoyuan <AT> gmail.com> |
11 |
Closes: https://github.com/gentoo/gentoo/pull/24913 |
12 |
Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org> |
13 |
|
14 |
dev-java/antlr-runtime/antlr-runtime-4.9.3.ebuild | 105 +++++++++++++++++++-- |
15 |
.../antlr-runtime/files/4.9.3-test-fixes.patch | 26 +++++ |
16 |
2 files changed, 125 insertions(+), 6 deletions(-) |
17 |
|
18 |
diff --git a/dev-java/antlr-runtime/antlr-runtime-4.9.3.ebuild b/dev-java/antlr-runtime/antlr-runtime-4.9.3.ebuild |
19 |
index 31d041e6a974..cf26c16eb71e 100644 |
20 |
--- a/dev-java/antlr-runtime/antlr-runtime-4.9.3.ebuild |
21 |
+++ b/dev-java/antlr-runtime/antlr-runtime-4.9.3.ebuild |
22 |
@@ -3,13 +3,9 @@ |
23 |
|
24 |
EAPI=8 |
25 |
|
26 |
-# Without annotation processing using runtime-testsuite/processors, |
27 |
-# the tests are bound to fail. However, the annotation processor |
28 |
-# has been dropped from the 'master' branch as of January 2022, so |
29 |
-# when updating this package to a new upstream version, please |
30 |
-# check if it is possible to enable the tests and pass them. |
31 |
-JAVA_PKG_IUSE="doc source" |
32 |
+JAVA_PKG_IUSE="doc source test" |
33 |
MAVEN_ID="org.antlr:antlr4-runtime:4.9.3" |
34 |
+JAVA_TESTING_FRAMEWORKS="junit-4" |
35 |
|
36 |
inherit java-pkg-2 java-pkg-simple |
37 |
|
38 |
@@ -26,6 +22,10 @@ KEYWORDS="amd64 ~arm arm64 ppc64 x86" |
39 |
|
40 |
DEPEND=" |
41 |
>=virtual/jdk-1.8:* |
42 |
+ test? ( |
43 |
+ ~dev-java/antlr-tool-${PV}:${SLOT} |
44 |
+ dev-java/jol-core:0 |
45 |
+ ) |
46 |
" |
47 |
|
48 |
RDEPEND=" |
49 |
@@ -35,3 +35,96 @@ RDEPEND=" |
50 |
S="${WORKDIR}/${MY_PN}4-${PV}" |
51 |
|
52 |
JAVA_SRC_DIR="runtime/Java/src" |
53 |
+ |
54 |
+JAVA_TEST_GENTOO_CLASSPATH=" |
55 |
+ junit-4 |
56 |
+ antlr-tool-${SLOT} |
57 |
+ jol-core |
58 |
+" |
59 |
+JAVA_TEST_SRC_DIR=( |
60 |
+ runtime-testsuite/test |
61 |
+ runtime-testsuite/annotations |
62 |
+) |
63 |
+JAVA_TEST_RESOURCE_DIRS=( |
64 |
+ runtime-testsuite/resources |
65 |
+) |
66 |
+ |
67 |
+src_prepare() { |
68 |
+ java-pkg_clean |
69 |
+ eapply "${FILESDIR}/${PV}-test-fixes.patch" |
70 |
+ java-pkg-2_src_prepare |
71 |
+} |
72 |
+ |
73 |
+src_test() { |
74 |
+ # Build classpath for tests |
75 |
+ # The JAR created during src_compile must appear in the classpath *before* |
76 |
+ # any dependencies to ensure that *it* is the JAR being tested; otherwise, |
77 |
+ # because the test suite depends on antlr-tool, which depends on this |
78 |
+ # package, the copy of this package's JAR installed on the system would be |
79 |
+ # tested instead when it appears earlier in the classpath, which might |
80 |
+ # cause test failures when the version being built differs from the version |
81 |
+ # already installed on the system, like https://bugs.gentoo.org/834138 |
82 |
+ local CP="${S}/${JAVA_JAR_FILENAME}" |
83 |
+ local test_dep res_dir |
84 |
+ for test_dep in ${JAVA_TEST_GENTOO_CLASSPATH}; do |
85 |
+ CP+=":$(java-pkg_getjars --with-dependencies "${test_dep}")" |
86 |
+ done |
87 |
+ for res_dir in "${JAVA_TEST_RESOURCE_DIRS[@]}"; do |
88 |
+ CP+=":${res_dir}" |
89 |
+ done |
90 |
+ |
91 |
+ pushd "${JAVA_TEST_SRC_DIR[0]}" > /dev/null || |
92 |
+ die "Failed to enter test source directory for ${PN}" |
93 |
+ |
94 |
+ einfo "Removing tests for non-Java runtimes ..." |
95 |
+ find org/antlr/v4/test/runtime/* -maxdepth 0 -type d \ |
96 |
+ -not -name category -not -name descriptors -not -name java \ |
97 |
+ -exec einfo " {}" \; -exec rm -r "{}" + || |
98 |
+ die "Failed to remove tests for non-Java runtimes" |
99 |
+ |
100 |
+ einfo "Generating ANTLR 4 parsers for tests ..." |
101 |
+ local java_exe="$(java-config -J)" |
102 |
+ local g4_files=( $(find * -name "*.g4") ) |
103 |
+ local file |
104 |
+ for file in "${g4_files[@]}"; do |
105 |
+ local java_pkg="${file%/*.g4}" |
106 |
+ java_pkg="${java_pkg//\//.}" |
107 |
+ "${java_exe}" -cp "${CP}" org.antlr.v4.Tool \ |
108 |
+ -visitor -package "${java_pkg}" "${file}" || |
109 |
+ die "Failed to generate ANTLR 4 parser from ${file}" |
110 |
+ done |
111 |
+ |
112 |
+ # Create a list of tests to run |
113 |
+ # https://github.com/antlr/antlr4/blob/4.9.3/runtime-testsuite/pom.xml#L100 |
114 |
+ # Excluding classes with "No runnable methods" |
115 |
+ local TESTS=$(find * -type f -name "Test*.java" \ |
116 |
+ -not -name "TestContext.java" \ |
117 |
+ -not -name "TestOutputReading.java" |
118 |
+ ) |
119 |
+ TESTS="${TESTS//.java}" |
120 |
+ TESTS="${TESTS//\//.}" |
121 |
+ |
122 |
+ popd > /dev/null || die "Failed to leave test source directory for ${PN}" |
123 |
+ |
124 |
+ local classes="target/classes" |
125 |
+ |
126 |
+ # Compile the annotation processor of @CommentHasStringValue |
127 |
+ # before the test sources (requires tools.jar) |
128 |
+ ejavac -d "${classes}" -cp "${CP}:$(java-config -t)" \ |
129 |
+ $(find runtime-testsuite/{annotations,processors} -name "*.java") |
130 |
+ local processor_cp="${classes}:runtime-testsuite/processors/resources" |
131 |
+ |
132 |
+ # Compile Java test sources, and process @CommentHasStringValue |
133 |
+ # annotations at the same time |
134 |
+ local javac_extra_args=() |
135 |
+ if ver_test "$(java-config -g PROVIDES_VERSION)" -ge 17; then |
136 |
+ javac_extra_args+=( |
137 |
+ -J--add-opens=jdk.compiler/com.sun.tools.javac.{main,model,tree,util}=ALL-UNNAMED |
138 |
+ ) |
139 |
+ fi |
140 |
+ ejavac -d "${classes}" -cp "${CP}:${processor_cp}" \ |
141 |
+ "${javac_extra_args[@]}" \ |
142 |
+ $(find "${JAVA_TEST_SRC_DIR[@]}" -name "*.java") |
143 |
+ |
144 |
+ ejunit4 -classpath "${classes}:${CP}" ${TESTS} |
145 |
+} |
146 |
|
147 |
diff --git a/dev-java/antlr-runtime/files/4.9.3-test-fixes.patch b/dev-java/antlr-runtime/files/4.9.3-test-fixes.patch |
148 |
new file mode 100644 |
149 |
index 000000000000..9cb6884ba194 |
150 |
--- /dev/null |
151 |
+++ b/dev-java/antlr-runtime/files/4.9.3-test-fixes.patch |
152 |
@@ -0,0 +1,26 @@ |
153 |
+From 3eabbddff69dcbcaf9a59f407cc8bef4be8e215b Mon Sep 17 00:00:00 2001 |
154 |
+From: Yuan Liao <liaoyuan@×××××.com> |
155 |
+Date: Thu, 3 Feb 2022 11:51:53 -0800 |
156 |
+Subject: [PATCH] Use 1.8 as javac -source/-target for running tests on Java 17 |
157 |
+ |
158 |
+Signed-off-by: Yuan Liao <liaoyuan@×××××.com> |
159 |
+--- |
160 |
+ .../test/org/antlr/v4/test/runtime/java/BaseJavaTest.java | 2 +- |
161 |
+ 1 file changed, 1 insertion(+), 1 deletion(-) |
162 |
+ |
163 |
+diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java |
164 |
+index cc03bdc11..82061135e 100644 |
165 |
+--- a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java |
166 |
++++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java |
167 |
+@@ -137,7 +137,7 @@ public class BaseJavaTest extends BaseRuntimeTestSupport implements RuntimeTestS |
168 |
+ fileManager.getJavaFileObjectsFromFiles(files); |
169 |
+ |
170 |
+ Iterable<String> compileOptions = |
171 |
+- Arrays.asList("-g", "-source", "1.6", "-target", "1.6", "-implicit:class", "-Xlint:-options", "-d", getTempDirPath(), "-cp", getTempDirPath() + PATH_SEP + CLASSPATH); |
172 |
++ Arrays.asList("-g", "-source", "1.8", "-target", "1.8", "-implicit:class", "-Xlint:-options", "-d", getTempDirPath(), "-cp", getTempDirPath() + PATH_SEP + CLASSPATH); |
173 |
+ |
174 |
+ JavaCompiler.CompilationTask task = |
175 |
+ compiler.getTask(null, fileManager, null, compileOptions, null, |
176 |
+-- |
177 |
+2.34.1 |
178 |
+ |