Gentoo Archives: gentoo-commits

From: "Miroslav Šulc" <fordfrog@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-java/stringtemplate/
Date: Sun, 27 Feb 2022 08:11:33
Message-Id: 1645949486.74072f9f3ff905b4683cd482fdf756cb3ea807f8.fordfrog@gentoo
1 commit: 74072f9f3ff905b4683cd482fdf756cb3ea807f8
2 Author: Yuan Liao <liaoyuan <AT> gmail <DOT> com>
3 AuthorDate: Sun Feb 27 05:52:13 2022 +0000
4 Commit: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
5 CommitDate: Sun Feb 27 08:11:26 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=74072f9f
7
8 dev-java/stringtemplate: Fix 4.3.1 test failure when upgrading slot 4
9
10 A test failure (as reported in the linked bug) might occur when an older
11 version of ST 4 is already installed on the system. The failure is
12 caused by multiple factors: the way java-pkg-simple.eclass generates the
13 test classpath, the fact that the tests launch new JVM instances under a
14 different working directory, and the behavior of the JVM upon an invalid
15 path in the classpath.
16
17 As of the time when this commit is created, the test classpath computed
18 by java-pkg-simple.eclass will contain the following elements, in order:
19 1. The directory containing the test classes compiled by the eclass
20 2. The path to the JAR built by the eclass **relative to ${S}**
21 3. Absolute paths to dependency JARs, for both compile and test
22 dependencies
23
24 ST 4 has an implicit test dependency on itself via ANTLR 3.5 (which is
25 yet another issue pertaining to the troublesome, malformed ANTLR 3.5 and
26 ST 4 circular dependency). This means a version of slot 4 that is
27 possibly older than 4.3.1 might be installed on the system and added to
28 the test classpath within element No. 3 when the tests are being run.
29
30 Some of the tests will call the 'java' command to execute ST 4 in a new
31 JVM instance; the test classpath generated by java-pkg-simple.eclass
32 will be reused in the classpath of the new JVM. The unfortunate factor
33 that triggers the test failure is that the new JVM's working directory
34 can become different from the one of the original JVM running the JUnit
35 tests, which is ${S} when this package is being built by Portage.
36
37 Note that element No. 2 in the test classpath is a relative path: after
38 the working directory is changed, it will be invalid. However, JVM is
39 lax in invalid path elements in the classpath: it will just ignore them
40 and emit a "class not found" error or alike only after it has tried all
41 other paths in the classpath to locate a class.
42
43 With this behavior, JVM will pick up the copy of ST 4 already installed
44 on the system from element No. 3 in the classpath after it detects that
45 element No. 2 is an invalid path. Therefore, the tests will be run
46 against ST 4 that is *installed on the system* instead of the copy that
47 has just been built.
48
49 This explains why some tests would fail when an older version of ST 4 is
50 already installed; effectively, that old version was being tested by the
51 test suite for the new version, and there is no guarantee that all tests
52 would pass in this case. A corollary conclusion is that if the same
53 version of ST 4 is being built and installed twice, and the second build
54 has tests enabled, then the tests would pass, although effectively it
55 would be the artifact produced by the first build being tested against.
56
57 Closes: https://bugs.gentoo.org/834138
58 Signed-off-by: Yuan Liao <liaoyuan <AT> gmail.com>
59 Closes: https://github.com/gentoo/gentoo/pull/24368
60 Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org>
61
62 .../stringtemplate/stringtemplate-4.3.1.ebuild | 23 ++++++++++++++++++++++
63 1 file changed, 23 insertions(+)
64
65 diff --git a/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild b/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild
66 index 27b01afa316f..ed368f6c2c6d 100644
67 --- a/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild
68 +++ b/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild
69 @@ -68,6 +68,29 @@ src_prepare() {
70 rm -v "${JAVA_TEST_SRC_DIR}/org/stringtemplate/v4/test/TestEarlyEvaluation.java" || die
71 }
72
73 +src_test() {
74 + # Make sure no older versions of this slot are present in the classpath
75 + # https://bugs.gentoo.org/834138#c4
76 + local old_ver_cp="$(nonfatal java-pkg_getjars "${PN}-${SLOT}")"
77 + local new_test_cp="$(\
78 + java-pkg_getjars --with-dependencies "${JAVA_TEST_GENTOO_CLASSPATH}")"
79 + new_test_cp="${new_test_cp//"${old_ver_cp}"/}"
80 +
81 + # Some of the test cases require an absolute path to the JAR being tested
82 + # against to be in the classpath, due to the fact that they call the 'java'
83 + # command outside ${S} and reuse the classpath for the tests:
84 + # https://github.com/antlr/stringtemplate4/blob/4.3.1/test/org/stringtemplate/v4/test/TestImports.java#L103
85 + # https://github.com/antlr/stringtemplate4/blob/4.3.1/test/org/stringtemplate/v4/test/BaseTest.java#L174
86 + new_test_cp="${S}/${JAVA_JAR_FILENAME}:${new_test_cp}"
87 +
88 + # Use JAVA_GENTOO_CLASSPATH_EXTRA to set test classpath
89 + local JAVA_TEST_GENTOO_CLASSPATH=""
90 + [[ -n "${JAVA_GENTOO_CLASSPATH_EXTRA}" ]] &&
91 + JAVA_GENTOO_CLASSPATH_EXTRA+=":"
92 + JAVA_GENTOO_CLASSPATH_EXTRA+="${new_test_cp}"
93 + java-pkg-simple_src_test
94 +}
95 +
96 src_install() {
97 java-pkg-simple_src_install
98 einstalldocs # https://bugs.gentoo.org/789582