Add ToolchainTypeRequirement to ToolchainTestCase.

Part of Optional Toolchains (#14726).

Closes #15186.

PiperOrigin-RevId: 439663330
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java b/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java
index 77626e5..cbdfeac 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java
@@ -50,7 +50,7 @@
     ToolchainContextKey toolchainContextKey =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     // Create a static UnloadedToolchainContext.
@@ -58,13 +58,13 @@
         UnloadedToolchainContextImpl.builder(toolchainContextKey)
             .setExecutionPlatform(linuxPlatform)
             .setTargetPlatform(linuxPlatform)
-            .setRequiredToolchainTypes(ImmutableSet.of(testToolchainType))
+            .setRequiredToolchainTypes(ImmutableSet.of(testToolchainTypeInfo))
             .setRequestedLabelToToolchainType(
-                ImmutableMap.of(testToolchainTypeLabel, testToolchainType))
+                ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo))
             .setToolchainTypeToResolved(
                 ImmutableSetMultimap.<ToolchainTypeInfo, Label>builder()
                     .put(
-                        testToolchainType,
+                        testToolchainTypeInfo,
                         Label.parseAbsoluteUnchecked("//extra:extra_toolchain_linux_impl"))
                     .build())
             .build();
@@ -102,7 +102,7 @@
     ToolchainContextKey toolchainContextKey =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     // Create a static UnloadedToolchainContext.
@@ -110,12 +110,12 @@
         UnloadedToolchainContextImpl.builder(toolchainContextKey)
             .setExecutionPlatform(linuxPlatform)
             .setTargetPlatform(linuxPlatform)
-            .setRequiredToolchainTypes(ImmutableSet.of(testToolchainType))
+            .setRequiredToolchainTypes(ImmutableSet.of(testToolchainTypeInfo))
             .setRequestedLabelToToolchainType(
-                ImmutableMap.of(testToolchainTypeLabel, testToolchainType))
+                ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo))
             .setToolchainTypeToResolved(
                 ImmutableSetMultimap.<ToolchainTypeInfo, Label>builder()
-                    .put(testToolchainType, Label.parseAbsoluteUnchecked("//alias:toolchain"))
+                    .put(testToolchainTypeInfo, Label.parseAbsoluteUnchecked("//alias:toolchain"))
                     .build())
             .build();
 
@@ -144,7 +144,7 @@
     ToolchainContextKey toolchainContextKey =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     // Create a static UnloadedToolchainContext.
@@ -152,12 +152,14 @@
         UnloadedToolchainContextImpl.builder(toolchainContextKey)
             .setExecutionPlatform(linuxPlatform)
             .setTargetPlatform(linuxPlatform)
-            .setRequiredToolchainTypes(ImmutableSet.of(testToolchainType))
+            .setRequiredToolchainTypes(ImmutableSet.of(testToolchainTypeInfo))
             .setRequestedLabelToToolchainType(
-                ImmutableMap.of(testToolchainTypeLabel, testToolchainType))
+                ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo))
             .setToolchainTypeToResolved(
                 ImmutableSetMultimap.<ToolchainTypeInfo, Label>builder()
-                    .put(testToolchainType, Label.parseAbsoluteUnchecked("//foo:not_a_toolchain"))
+                    .put(
+                        testToolchainTypeInfo,
+                        Label.parseAbsoluteUnchecked("//foo:not_a_toolchain"))
                     .build())
             .build();
 
@@ -179,7 +181,10 @@
     // Add new toolchain rule that provides template variables.
     Label variableToolchainTypeLabel =
         Label.parseAbsoluteUnchecked("//variable:variable_toolchain_type");
-    ToolchainTypeInfo variableToolchainType = ToolchainTypeInfo.create(variableToolchainTypeLabel);
+    ToolchainTypeRequirement variableToolchainType =
+        ToolchainTypeRequirement.create(variableToolchainTypeLabel);
+    ToolchainTypeInfo variableToolchainTypeInfo =
+        ToolchainTypeInfo.create(variableToolchainTypeLabel);
     scratch.file(
         "variable/variable_toolchain_def.bzl",
         "def _impl(ctx):",
@@ -203,7 +208,7 @@
     ToolchainContextKey toolchainContextKey =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     // Create a static UnloadedToolchainContext.
@@ -211,13 +216,13 @@
         UnloadedToolchainContextImpl.builder(toolchainContextKey)
             .setExecutionPlatform(linuxPlatform)
             .setTargetPlatform(linuxPlatform)
-            .setRequiredToolchainTypes(ImmutableSet.of(variableToolchainType))
+            .setRequiredToolchainTypes(ImmutableSet.of(variableToolchainTypeInfo))
             .setRequestedLabelToToolchainType(
-                ImmutableMap.of(variableToolchainTypeLabel, variableToolchainType))
+                ImmutableMap.of(variableToolchainTypeLabel, variableToolchainTypeInfo))
             .setToolchainTypeToResolved(
                 ImmutableSetMultimap.<ToolchainTypeInfo, Label>builder()
                     .put(
-                        variableToolchainType,
+                        variableToolchainTypeInfo,
                         Label.parseAbsoluteUnchecked("//variable:variable_toolchain_impl"))
                     .build())
             .build();
diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD b/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD
index 8f8cffa..e084c8d 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD
@@ -40,6 +40,7 @@
     name = "testutil",
     srcs = TESTUTIL_SRCS,
     deps = [
+        "//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement",
         "//src/main/java/com/google/devtools/build/lib/analysis/platform",
         "//src/main/java/com/google/devtools/build/lib/cmdline",
         "//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_cluster",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java
index 2eaaf76..30cd583 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java
@@ -19,6 +19,7 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.truth.IterableSubject;
+import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
 import com.google.devtools.build.lib.analysis.platform.ConstraintSettingInfo;
 import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo;
 import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
@@ -50,7 +51,8 @@
   public ConstraintValueInfo defaultedConstraint;
 
   public Label testToolchainTypeLabel;
-  public ToolchainTypeInfo testToolchainType;
+  public ToolchainTypeRequirement testToolchainType;
+  public ToolchainTypeInfo testToolchainTypeInfo;
 
   protected static IterableSubject assertToolchainLabels(
       RegisteredToolchainsValue registeredToolchainsValue) {
@@ -195,7 +197,8 @@
         "bar");
 
     testToolchainTypeLabel = Label.parseAbsoluteUnchecked("//toolchain:test_toolchain");
-    testToolchainType = ToolchainTypeInfo.create(testToolchainTypeLabel);
+    testToolchainType = ToolchainTypeRequirement.create(testToolchainTypeLabel);
+    testToolchainTypeInfo = ToolchainTypeInfo.create(testToolchainTypeLabel);
   }
 
   protected EvaluationResult<RegisteredToolchainsValue> requestToolchainsFromSkyframe(
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
index 6734597..3ca6970 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
@@ -87,7 +87,7 @@
     // Check that the number of toolchains created for this test is correct.
     assertThat(
             value.registeredToolchains().stream()
-                .filter(toolchain -> toolchain.toolchainType().equals(testToolchainType))
+                .filter(toolchain -> toolchain.toolchainType().equals(testToolchainTypeInfo))
                 .collect(Collectors.toList()))
         .hasSize(2);
 
@@ -95,7 +95,7 @@
             value.registeredToolchains().stream()
                 .anyMatch(
                     toolchain ->
-                        toolchain.toolchainType().equals(testToolchainType)
+                        toolchain.toolchainType().equals(testToolchainTypeInfo)
                             && toolchain.execConstraints().get(setting).equals(linuxConstraint)
                             && toolchain.targetConstraints().get(setting).equals(macConstraint)
                             && toolchain
@@ -108,7 +108,7 @@
             value.registeredToolchains().stream()
                 .anyMatch(
                     toolchain ->
-                        toolchain.toolchainType().equals(testToolchainType)
+                        toolchain.toolchainType().equals(testToolchainTypeInfo)
                             && toolchain.execConstraints().get(setting).equals(macConstraint)
                             && toolchain.targetConstraints().get(setting).equals(linuxConstraint)
                             && toolchain
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java
index 511d6e5..78cb21e 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java
@@ -143,33 +143,33 @@
     new EqualsTester()
         .addEqualityGroup(
             SingleToolchainResolutionValue.create(
-                testToolchainType,
+                testToolchainTypeInfo,
                 ImmutableMap.of(
                     linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1"))),
             SingleToolchainResolutionValue.create(
-                testToolchainType,
+                testToolchainTypeInfo,
                 ImmutableMap.of(
                     linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1"))))
         // Different execution platform, same label.
         .addEqualityGroup(
             SingleToolchainResolutionValue.create(
-                testToolchainType,
+                testToolchainTypeInfo,
                 ImmutableMap.of(macCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1"))))
         // Same execution platform, different label.
         .addEqualityGroup(
             SingleToolchainResolutionValue.create(
-                testToolchainType,
+                testToolchainTypeInfo,
                 ImmutableMap.of(
                     linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_2"))))
         // Different execution platform, different label.
         .addEqualityGroup(
             SingleToolchainResolutionValue.create(
-                testToolchainType,
+                testToolchainTypeInfo,
                 ImmutableMap.of(macCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_2"))))
         // Multiple execution platforms.
         .addEqualityGroup(
             SingleToolchainResolutionValue.create(
-                testToolchainType,
+                testToolchainTypeInfo,
                 ImmutableMap.<ConfiguredTargetKey, Label>builder()
                     .put(linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1"))
                     .put(macCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1"))
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java
index 1d4da43..7cc35cd 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java
@@ -71,7 +71,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     EvaluationResult<UnloadedToolchainContext> result = invokeToolchainResolution(key);
@@ -187,7 +187,7 @@
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
             .toolchainTypes(
-                ToolchainTypeRequirement.create(testToolchainTypeLabel),
+                testToolchainType,
                 ToolchainTypeRequirement.create(
                     Label.parseAbsoluteUnchecked("//fake/toolchain:type_1")))
             .build();
@@ -210,7 +210,7 @@
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
             .toolchainTypes(
-                ToolchainTypeRequirement.create(testToolchainTypeLabel),
+                testToolchainType,
                 ToolchainTypeRequirement.create(
                     Label.parseAbsoluteUnchecked("//fake/toolchain:type_1")),
                 ToolchainTypeRequirement.create(
@@ -233,7 +233,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     EvaluationResult<UnloadedToolchainContext> result = invokeToolchainResolution(key);
@@ -259,7 +259,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     EvaluationResult<UnloadedToolchainContext> result = invokeToolchainResolution(key);
@@ -283,7 +283,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     EvaluationResult<UnloadedToolchainContext> result = invokeToolchainResolution(key);
@@ -308,7 +308,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .build();
 
     EvaluationResult<UnloadedToolchainContext> result = invokeToolchainResolution(key);
@@ -349,7 +349,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .execConstraintLabels(Label.parseAbsoluteUnchecked("//constraints:linux"))
             .build();
 
@@ -370,7 +370,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .execConstraintLabels(Label.parseAbsoluteUnchecked("//platforms:linux"))
             .build();
 
@@ -461,7 +461,7 @@
     ToolchainContextKey key =
         ToolchainContextKey.key()
             .configurationKey(targetConfigKey)
-            .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel))
+            .toolchainTypes(testToolchainType)
             .forceExecutionPlatform(Label.parseAbsoluteUnchecked("//platforms:linux"))
             .build();
 
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java
index 6dfb6d6..27b846d 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java
@@ -85,7 +85,7 @@
 
     Map<Label, ToolchainTypeInfo> toolchainTypes = result.get(key).toolchainTypes();
     assertThat(toolchainTypes)
-        .containsExactlyEntriesIn(ImmutableMap.of(testToolchainTypeLabel, testToolchainType));
+        .containsExactlyEntriesIn(ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo));
   }
 
   @Test
@@ -111,9 +111,9 @@
         .containsExactlyEntriesIn(
             ImmutableMap.of(
                 testToolchainTypeLabel,
-                testToolchainType,
+                testToolchainTypeInfo,
                 aliasToolchainTypeLabel,
-                testToolchainType));
+                testToolchainTypeInfo));
   }
 
   @Test