mirror of
https://github.com/google/guice.git
synced 2026-10-19 16:16:21 +00:00
Extract the one test that requires add_opens to a separate file, run it with add_opens in the one classloading strategy that requires it. Also run it with other strategies/defaults w/o add_opens (in scenarios where it doesn't require it).
PiperOrigin-RevId: 475929909
This commit is contained in:
@@ -64,6 +64,7 @@ public class AllTests {
|
||||
suite.addTestSuite(EagerSingletonTest.class);
|
||||
suite.addTestSuite(GenericInjectionTest.class);
|
||||
suite.addTestSuite(ImplicitBindingTest.class);
|
||||
suite.addTestSuite(ImplicitBindingJdkPackagePrivateTest.class);
|
||||
suite.addTestSuite(InjectorTest.class);
|
||||
suite.addTestSuite(JitBindingsTest.class);
|
||||
suite.addTestSuite(Java8LanguageFeatureBindingTest.class);
|
||||
|
||||
@@ -11,6 +11,10 @@ TEST_SUPPORT_SRCS = [
|
||||
"internal/WeakKeySetUtils.java",
|
||||
]
|
||||
|
||||
ADD_OPENS_SRCS = [
|
||||
"ImplicitBindingJdkPackagePrivateTest.java",
|
||||
]
|
||||
|
||||
# Files that are shared by extensions also.
|
||||
# Typically this would go in a java/../testing package,
|
||||
# but we need to work with the open-source code structure,
|
||||
@@ -37,7 +41,7 @@ java_library(
|
||||
name = "tests",
|
||||
srcs = glob(
|
||||
["**/*.java"], # glob ignores subfolder that has its own BUILD files
|
||||
exclude = TEST_SUPPORT_SRCS + [
|
||||
exclude = TEST_SUPPORT_SRCS + ADD_OPENS_SRCS + [
|
||||
"AllTests.java",
|
||||
],
|
||||
),
|
||||
@@ -59,12 +63,27 @@ java_library(
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "add_opens_tests",
|
||||
srcs = ADD_OPENS_SRCS,
|
||||
javacopts = ["-Xep:BetaApi:OFF"],
|
||||
visibility = [
|
||||
"//:src",
|
||||
],
|
||||
deps = [
|
||||
"//core/src/com/google/inject",
|
||||
"//third_party/java/guava/base",
|
||||
"//third_party/java/junit",
|
||||
],
|
||||
)
|
||||
|
||||
# This target is unused, but exists so that we can more easily
|
||||
# ensure the opensource build maintains compiling code.
|
||||
java_library(
|
||||
name = "AllTests",
|
||||
srcs = ["AllTests.java"],
|
||||
deps = [
|
||||
":add_opens_tests",
|
||||
":tests",
|
||||
"//core/test/com/googlecode/guice:tests",
|
||||
"//third_party/java/junit",
|
||||
@@ -82,7 +101,10 @@ guice_test_suites(
|
||||
"small",
|
||||
"medium",
|
||||
],
|
||||
deps = [":tests"],
|
||||
deps = [
|
||||
":add_opens_tests",
|
||||
":tests",
|
||||
],
|
||||
)
|
||||
|
||||
[guice_test_suites(
|
||||
@@ -100,7 +122,10 @@ guice_test_suites(
|
||||
"medium",
|
||||
],
|
||||
suffix = "_stack_trace_%s" % include_stack_trace_option,
|
||||
deps = [":tests"],
|
||||
deps = [
|
||||
":add_opens_tests",
|
||||
":tests",
|
||||
],
|
||||
) for include_stack_trace_option in [
|
||||
"OFF",
|
||||
]]
|
||||
@@ -120,9 +145,12 @@ guice_test_suites(
|
||||
"medium",
|
||||
],
|
||||
suffix = "_custom_class_loading_%s" % custom_class_loading_option,
|
||||
deps = [":tests"],
|
||||
deps = [
|
||||
":add_opens_tests",
|
||||
":tests",
|
||||
],
|
||||
) for custom_class_loading_option in [
|
||||
"OFF",
|
||||
"CHILD",
|
||||
"ANONYMOUS",
|
||||
"CHILD",
|
||||
]]
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.inject;
|
||||
|
||||
import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* This test is split out from ImplicitBindingTest so that we can run it with --add_opens to
|
||||
* InetAddress, so validate that it will work when opened.
|
||||
*/
|
||||
public class ImplicitBindingJdkPackagePrivateTest extends TestCase {
|
||||
|
||||
public void testImplicitJdkBindings_packagePrivateCxtor() {
|
||||
Injector injector = Guice.createInjector();
|
||||
// Validate that, when the JDK allows it, we can construct package private JDK things.
|
||||
if (Double.parseDouble(JAVA_SPECIFICATION_VERSION.value()) < 17) {
|
||||
assertNotNull(injector.getInstance(InetAddress.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,18 +16,18 @@
|
||||
|
||||
package com.google.inject;
|
||||
|
||||
import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.internal.Annotations;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.inject.spi.Message;
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/** @author crazybob@google.com (Bob Lee) */
|
||||
/**
|
||||
* @author crazybob@google.com (Bob Lee)
|
||||
*/
|
||||
public class ImplicitBindingTest extends TestCase {
|
||||
|
||||
public void testCircularDependency() throws CreationException {
|
||||
@@ -322,10 +322,10 @@ public class ImplicitBindingTest extends TestCase {
|
||||
* sequence of JIT bindings:
|
||||
*
|
||||
* <ol>
|
||||
* <li> A-> B
|
||||
* <li> B -> C, A
|
||||
* <li> C -> A, D
|
||||
* <li> D not JITable
|
||||
* <li>A-> B
|
||||
* <li>B -> C, A
|
||||
* <li>C -> A, D
|
||||
* <li>D not JITable
|
||||
* </ol>
|
||||
*
|
||||
* <p>The problem was that C cleaned up A's binding and then handed control back to B, which tried
|
||||
@@ -434,13 +434,9 @@ public class ImplicitBindingTest extends TestCase {
|
||||
|
||||
private static class EnumWithImplementedByEnum {}
|
||||
|
||||
public void testImplicitJdkBindings() {
|
||||
public void testImplicitJdkBindings_publicCxtor() {
|
||||
Injector injector = Guice.createInjector();
|
||||
// String has a public nullary constructor, so Guice will call it.
|
||||
assertEquals("", injector.getInstance(String.class));
|
||||
// InetAddress has a package private constructor. We probably shouldn't be calling it :(
|
||||
if (Double.parseDouble(JAVA_SPECIFICATION_VERSION.value()) < 17) {
|
||||
assertNotNull(injector.getInstance(InetAddress.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user