From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id ADCA815808B for ; Sun, 27 Feb 2022 08:11:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CFA00E0918; Sun, 27 Feb 2022 08:11:32 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 95F99E0918 for ; Sun, 27 Feb 2022 08:11:32 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6845D342D55 for ; Sun, 27 Feb 2022 08:11:31 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A6D9F287 for ; Sun, 27 Feb 2022 08:11:29 +0000 (UTC) From: "Miroslav Šulc" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Miroslav Šulc" Message-ID: <1645949486.74072f9f3ff905b4683cd482fdf756cb3ea807f8.fordfrog@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: dev-java/stringtemplate/ X-VCS-Repository: repo/gentoo X-VCS-Files: dev-java/stringtemplate/stringtemplate-4.3.1.ebuild X-VCS-Directories: dev-java/stringtemplate/ X-VCS-Committer: fordfrog X-VCS-Committer-Name: Miroslav Šulc X-VCS-Revision: 74072f9f3ff905b4683cd482fdf756cb3ea807f8 X-VCS-Branch: master Date: Sun, 27 Feb 2022 08:11:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: edda91d2-5d5d-4d9a-8307-38e5850b7d52 X-Archives-Hash: 71400b08a055e2a6f2c8213e12fa1835 commit: 74072f9f3ff905b4683cd482fdf756cb3ea807f8 Author: Yuan Liao gmail com> AuthorDate: Sun Feb 27 05:52:13 2022 +0000 Commit: Miroslav Šulc gentoo org> CommitDate: Sun Feb 27 08:11:26 2022 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=74072f9f dev-java/stringtemplate: Fix 4.3.1 test failure when upgrading slot 4 A test failure (as reported in the linked bug) might occur when an older version of ST 4 is already installed on the system. The failure is caused by multiple factors: the way java-pkg-simple.eclass generates the test classpath, the fact that the tests launch new JVM instances under a different working directory, and the behavior of the JVM upon an invalid path in the classpath. As of the time when this commit is created, the test classpath computed by java-pkg-simple.eclass will contain the following elements, in order: 1. The directory containing the test classes compiled by the eclass 2. The path to the JAR built by the eclass **relative to ${S}** 3. Absolute paths to dependency JARs, for both compile and test dependencies ST 4 has an implicit test dependency on itself via ANTLR 3.5 (which is yet another issue pertaining to the troublesome, malformed ANTLR 3.5 and ST 4 circular dependency). This means a version of slot 4 that is possibly older than 4.3.1 might be installed on the system and added to the test classpath within element No. 3 when the tests are being run. Some of the tests will call the 'java' command to execute ST 4 in a new JVM instance; the test classpath generated by java-pkg-simple.eclass will be reused in the classpath of the new JVM. The unfortunate factor that triggers the test failure is that the new JVM's working directory can become different from the one of the original JVM running the JUnit tests, which is ${S} when this package is being built by Portage. Note that element No. 2 in the test classpath is a relative path: after the working directory is changed, it will be invalid. However, JVM is lax in invalid path elements in the classpath: it will just ignore them and emit a "class not found" error or alike only after it has tried all other paths in the classpath to locate a class. With this behavior, JVM will pick up the copy of ST 4 already installed on the system from element No. 3 in the classpath after it detects that element No. 2 is an invalid path. Therefore, the tests will be run against ST 4 that is *installed on the system* instead of the copy that has just been built. This explains why some tests would fail when an older version of ST 4 is already installed; effectively, that old version was being tested by the test suite for the new version, and there is no guarantee that all tests would pass in this case. A corollary conclusion is that if the same version of ST 4 is being built and installed twice, and the second build has tests enabled, then the tests would pass, although effectively it would be the artifact produced by the first build being tested against. Closes: https://bugs.gentoo.org/834138 Signed-off-by: Yuan Liao gmail.com> Closes: https://github.com/gentoo/gentoo/pull/24368 Signed-off-by: Miroslav Šulc gentoo.org> .../stringtemplate/stringtemplate-4.3.1.ebuild | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild b/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild index 27b01afa316f..ed368f6c2c6d 100644 --- a/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild +++ b/dev-java/stringtemplate/stringtemplate-4.3.1.ebuild @@ -68,6 +68,29 @@ src_prepare() { rm -v "${JAVA_TEST_SRC_DIR}/org/stringtemplate/v4/test/TestEarlyEvaluation.java" || die } +src_test() { + # Make sure no older versions of this slot are present in the classpath + # https://bugs.gentoo.org/834138#c4 + local old_ver_cp="$(nonfatal java-pkg_getjars "${PN}-${SLOT}")" + local new_test_cp="$(\ + java-pkg_getjars --with-dependencies "${JAVA_TEST_GENTOO_CLASSPATH}")" + new_test_cp="${new_test_cp//"${old_ver_cp}"/}" + + # Some of the test cases require an absolute path to the JAR being tested + # against to be in the classpath, due to the fact that they call the 'java' + # command outside ${S} and reuse the classpath for the tests: + # https://github.com/antlr/stringtemplate4/blob/4.3.1/test/org/stringtemplate/v4/test/TestImports.java#L103 + # https://github.com/antlr/stringtemplate4/blob/4.3.1/test/org/stringtemplate/v4/test/BaseTest.java#L174 + new_test_cp="${S}/${JAVA_JAR_FILENAME}:${new_test_cp}" + + # Use JAVA_GENTOO_CLASSPATH_EXTRA to set test classpath + local JAVA_TEST_GENTOO_CLASSPATH="" + [[ -n "${JAVA_GENTOO_CLASSPATH_EXTRA}" ]] && + JAVA_GENTOO_CLASSPATH_EXTRA+=":" + JAVA_GENTOO_CLASSPATH_EXTRA+="${new_test_cp}" + java-pkg-simple_src_test +} + src_install() { java-pkg-simple_src_install einstalldocs # https://bugs.gentoo.org/789582