Add truth Subjects for ToolchainContext and ToolchainCollection.
PiperOrigin-RevId: 314418679
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainCollection.java b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainCollection.java
index 4991889..41c98f4 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainCollection.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainCollection.java
@@ -40,11 +40,11 @@
/** A map of execution group names to toolchain contexts. */
public abstract ImmutableMap<String, T> getContextMap();
- T getDefaultToolchainContext() {
+ public T getDefaultToolchainContext() {
return getContextMap().get(DEFAULT_EXEC_GROUP_NAME);
}
- boolean hasToolchainContext(String execGroup) {
+ public boolean hasToolchainContext(String execGroup) {
return getContextMap().containsKey(execGroup);
}
@@ -58,7 +58,7 @@
.collect(toImmutableSet());
}
- ImmutableSet<String> getExecGroups() {
+ public ImmutableSet<String> getExecGroups() {
return getContextMap().keySet();
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BUILD b/src/test/java/com/google/devtools/build/lib/analysis/BUILD
index 53da95b..3ad5fc4 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BUILD
@@ -12,6 +12,7 @@
"//src/test/java/com/google/devtools/build/lib/analysis/mock:srcs",
"//src/test/java/com/google/devtools/build/lib/analysis/platform:srcs",
"//src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor:srcs",
+ "//src/test/java/com/google/devtools/build/lib/analysis/testing:srcs",
"//src/test/java/com/google/devtools/build/lib/analysis/util:srcs",
"//src/test/java/com/google/devtools/build/lib/analysis/whitelisting:srcs",
],
@@ -143,6 +144,7 @@
"//src/main/java/net/starlark/java/annot",
"//src/main/protobuf:extra_actions_base_java_proto",
"//src/test/java/com/google/devtools/build/lib/actions/util",
+ "//src/test/java/com/google/devtools/build/lib/analysis/testing",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/exec/util",
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
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 44ff478..56e8fc4 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
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.analysis;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.devtools.build.lib.analysis.testing.ResolvedToolchainContextSubject.assertThat;
import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableBiMap;
@@ -81,8 +82,10 @@
"test",
ImmutableList.of(toolchain));
assertThat(toolchainContext).isNotNull();
- assertThat(toolchainContext.forToolchainType(testToolchainType)).isNotNull();
- assertThat(toolchainContext.forToolchainType(testToolchainType).getValue("data"))
+ assertThat(toolchainContext).hasToolchainType(testToolchainTypeLabel);
+ assertThat(toolchainContext)
+ .forToolchainType(testToolchainTypeLabel)
+ .getValue("data")
.isEqualTo("baz");
}
@@ -130,8 +133,10 @@
"test",
ImmutableList.of(toolchain));
assertThat(toolchainContext).isNotNull();
- assertThat(toolchainContext.forToolchainType(testToolchainType)).isNotNull();
- assertThat(toolchainContext.forToolchainType(testToolchainType).getValue("data"))
+ assertThat(toolchainContext).hasToolchainType(testToolchainTypeLabel);
+ assertThat(toolchainContext)
+ .forToolchainType(testToolchainTypeLabel)
+ .getValue("data")
.isEqualTo("baz");
}
@@ -234,7 +239,7 @@
"test",
ImmutableList.of(toolchain));
assertThat(toolchainContext).isNotNull();
- assertThat(toolchainContext.forToolchainType(variableToolchainType)).isNotNull();
+ assertThat(toolchainContext).hasToolchainType(variableToolchainTypeLabel);
assertThat(toolchainContext.templateVariableProviders()).hasSize(1);
assertThat(toolchainContext.templateVariableProviders().get(0).getVariables())
.containsExactly("VALUE", "foo");
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/testing/BUILD b/src/test/java/com/google/devtools/build/lib/analysis/testing/BUILD
new file mode 100644
index 0000000..556cdff
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/analysis/testing/BUILD
@@ -0,0 +1,35 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
+package(
+ default_testonly = 1,
+ default_visibility = ["//src:__subpackages__"],
+)
+
+filegroup(
+ name = "srcs",
+ testonly = 0,
+ srcs = glob(["*"]),
+ visibility = ["//src:__subpackages__"],
+)
+
+java_library(
+ name = "testing",
+ testonly = 1,
+ srcs = [
+ "ResolvedToolchainContextSubject.java",
+ "ToolchainCollectionSubject.java",
+ "ToolchainContextSubject.java",
+ "ToolchainInfoSubject.java",
+ ],
+ deps = [
+ "//src/main/java/com/google/devtools/build/lib/analysis:resolved_toolchain_context",
+ "//src/main/java/com/google/devtools/build/lib/analysis:toolchain_collection",
+ "//src/main/java/com/google/devtools/build/lib/analysis:toolchain_context",
+ "//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/cmdline:cmdline-primitives",
+ "//src/main/java/com/google/devtools/build/lib/syntax:evaluator",
+ "//third_party:guava",
+ "//third_party:truth",
+ ],
+)
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/testing/ResolvedToolchainContextSubject.java b/src/test/java/com/google/devtools/build/lib/analysis/testing/ResolvedToolchainContextSubject.java
new file mode 100644
index 0000000..2fac2fa
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/analysis/testing/ResolvedToolchainContextSubject.java
@@ -0,0 +1,65 @@
+// Copyright 2020 The Bazel Authors. All rights reserved.
+//
+// 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.devtools.build.lib.analysis.testing;
+
+import static com.google.common.truth.Truth.assertAbout;
+import static com.google.devtools.build.lib.analysis.testing.ToolchainInfoSubject.toolchainInfos;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.truth.FailureMetadata;
+import com.google.common.truth.Subject;
+import com.google.devtools.build.lib.analysis.ResolvedToolchainContext;
+import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+
+/** A Truth {@link Subject} for {@link ResolvedToolchainContext}. */
+public class ResolvedToolchainContextSubject extends ToolchainContextSubject {
+ // Static data.
+
+ /** Entry point for test assertions related to {@link ResolvedToolchainContext}. */
+ public static ResolvedToolchainContextSubject assertThat(
+ ResolvedToolchainContext resolvedToolchainContext) {
+ return assertAbout(RESOLVED_TOOLCHAIN_CONTEXT_SUBJECT_FACTORY).that(resolvedToolchainContext);
+ }
+
+ /** Static method for getting the subject factory (for use with assertAbout()). */
+ public static Factory<ResolvedToolchainContextSubject, ResolvedToolchainContext>
+ resolvedToolchainContexts() {
+ return RESOLVED_TOOLCHAIN_CONTEXT_SUBJECT_FACTORY;
+ }
+
+ static final Factory<ResolvedToolchainContextSubject, ResolvedToolchainContext>
+ RESOLVED_TOOLCHAIN_CONTEXT_SUBJECT_FACTORY = ResolvedToolchainContextSubject::new;
+
+ // Instance fields.
+
+ private final ResolvedToolchainContext actual;
+
+ private ResolvedToolchainContextSubject(
+ FailureMetadata failureMetadata, ResolvedToolchainContext subject) {
+ super(failureMetadata, subject);
+ this.actual = subject;
+ }
+
+ public ToolchainInfoSubject forToolchainType(String toolchainTypeLabel)
+ throws LabelSyntaxException {
+ return forToolchainType(Label.parseAbsolute(toolchainTypeLabel, ImmutableMap.of()));
+ }
+
+ public ToolchainInfoSubject forToolchainType(Label toolchainType) {
+ return check("forToolchainType(%s)", toolchainType)
+ .about(toolchainInfos())
+ .that(actual.forToolchainType(toolchainType));
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainCollectionSubject.java b/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainCollectionSubject.java
new file mode 100644
index 0000000..83da8fb
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainCollectionSubject.java
@@ -0,0 +1,79 @@
+// Copyright 2020 The Bazel Authors. All rights reserved.
+//
+// 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.devtools.build.lib.analysis.testing;
+
+import static com.google.common.truth.Truth.assertAbout;
+import static com.google.devtools.build.lib.analysis.testing.ToolchainContextSubject.toolchainContexts;
+
+import com.google.common.truth.FailureMetadata;
+import com.google.common.truth.IterableSubject;
+import com.google.common.truth.Subject;
+import com.google.devtools.build.lib.analysis.ToolchainCollection;
+
+/** A Truth {@link Subject} for {@link ToolchainCollection}. */
+public class ToolchainCollectionSubject extends Subject {
+ // Static data.
+
+ /** Entry point for test assertions related to {@link ToolchainCollection}. */
+ public static ToolchainCollectionSubject assertThat(ToolchainCollection<?> toolchainCollection) {
+ return assertAbout(TOOLCHAIN_COLLECTION_SUBJECT_FACTORY).that(toolchainCollection);
+ }
+
+ /** Static method for getting the subject factory (for use with assertAbout()). */
+ public static Subject.Factory<ToolchainCollectionSubject, ToolchainCollection<?>>
+ toolchainCollections() {
+ return TOOLCHAIN_COLLECTION_SUBJECT_FACTORY;
+ }
+
+ private static final Subject.Factory<ToolchainCollectionSubject, ToolchainCollection<?>>
+ TOOLCHAIN_COLLECTION_SUBJECT_FACTORY = ToolchainCollectionSubject::new;
+
+ // Instance fields.
+
+ private final ToolchainCollection<?> actual;
+
+ private ToolchainCollectionSubject(
+ FailureMetadata failureMetadata, ToolchainCollection<?> subject) {
+ super(failureMetadata, subject);
+ this.actual = subject;
+ }
+
+ public void hasDefaultExecGroup() {
+ check("hasToolchainContext()")
+ .that(actual.hasToolchainContext(ToolchainCollection.DEFAULT_EXEC_GROUP_NAME))
+ .isTrue();
+ }
+
+ public ToolchainContextSubject defaultToolchainContext() {
+ return check("defaultToolchainContext()")
+ .about(toolchainContexts())
+ .that(actual.getDefaultToolchainContext());
+ }
+
+ public IterableSubject resolvedToolchains() {
+ return check("getResolvedToolchains()").that(actual.getResolvedToolchains());
+ }
+
+ public void hasExecGroup(String execGroup) {
+ check("hasToolchainContext(%s)", execGroup)
+ .that(actual.getToolchainContext(execGroup))
+ .isNotNull();
+ }
+
+ public ToolchainContextSubject execGroup(String execGroup) {
+ return check("getToolchainContext(%s)", execGroup)
+ .about(toolchainContexts())
+ .that(actual.getToolchainContext(execGroup));
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainContextSubject.java b/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainContextSubject.java
new file mode 100644
index 0000000..c791e49
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainContextSubject.java
@@ -0,0 +1,99 @@
+// Copyright 2020 The Bazel Authors. All rights reserved.
+//
+// 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.devtools.build.lib.analysis.testing;
+
+import static com.google.common.truth.Truth.assertAbout;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.truth.FailureMetadata;
+import com.google.common.truth.IterableSubject;
+import com.google.common.truth.Subject;
+import com.google.devtools.build.lib.analysis.ToolchainContext;
+import com.google.devtools.build.lib.analysis.platform.ToolchainTypeInfo;
+import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+import java.util.stream.Collectors;
+
+/** A Truth {@link Subject} for {@link ToolchainContext}. */
+public class ToolchainContextSubject extends Subject {
+ // Static data.
+
+ /** Entry point for test assertions related to {@link ToolchainContext}. */
+ public static ToolchainContextSubject assertThat(ToolchainContext toolchainContext) {
+ return assertAbout(TOOLCHAIN_CONTEXT_SUBJECT_FACTORY).that(toolchainContext);
+ }
+
+ /** Static method for getting the subject factory (for use with assertAbout()). */
+ public static Subject.Factory<ToolchainContextSubject, ToolchainContext> toolchainContexts() {
+ return TOOLCHAIN_CONTEXT_SUBJECT_FACTORY;
+ }
+
+ private static final Subject.Factory<ToolchainContextSubject, ToolchainContext>
+ TOOLCHAIN_CONTEXT_SUBJECT_FACTORY = ToolchainContextSubject::new;
+
+ // Instance fields.
+
+ private final ToolchainContext actual;
+
+ protected ToolchainContextSubject(FailureMetadata failureMetadata, ToolchainContext subject) {
+ super(failureMetadata, subject);
+ this.actual = subject;
+ }
+
+ public void hasExecutionPlatform(String platformLabel) throws LabelSyntaxException {
+ hasExecutionPlatform(Label.parseAbsolute(platformLabel, ImmutableMap.of()));
+ }
+
+ public void hasExecutionPlatform(Label platform) {
+ check("executionPlatform()").that(actual.executionPlatform()).isNotNull();
+ check("executionPlatform()").that(actual.executionPlatform().label()).isEqualTo(platform);
+ }
+
+ public void hasTargetPlatform(String platformLabel) throws LabelSyntaxException {
+ hasTargetPlatform(Label.parseAbsolute(platformLabel, ImmutableMap.of()));
+ }
+
+ public void hasTargetPlatform(Label platform) {
+ check("targetPlatform()").that(actual.targetPlatform()).isNotNull();
+ check("targetPlatform()").that(actual.targetPlatform().label()).isEqualTo(platform);
+ }
+
+ public void hasToolchainType(String toolchainTypeLabel) throws LabelSyntaxException {
+ hasToolchainType(Label.parseAbsolute(toolchainTypeLabel, ImmutableMap.of()));
+ }
+
+ public void hasToolchainType(Label toolchainType) {
+ toolchainTypeLabels().contains(toolchainType);
+ }
+
+ public IterableSubject toolchainTypeLabels() {
+ return check("requiredToolchainTypes()")
+ .that(
+ actual.requiredToolchainTypes().stream()
+ .map(ToolchainTypeInfo::typeLabel)
+ .collect(Collectors.toList()));
+ }
+
+ public void hasResolvedToolchain(String resolvedToolchainLabel) throws LabelSyntaxException {
+ hasResolvedToolchain(Label.parseAbsolute(resolvedToolchainLabel, ImmutableMap.of()));
+ }
+
+ public void hasResolvedToolchain(Label resolvedToolchain) {
+ resolvedToolchainLabels().contains(resolvedToolchain);
+ }
+
+ public IterableSubject resolvedToolchainLabels() {
+ return check("resolevdToolchainLabels()").that(actual.resolvedToolchainLabels());
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainInfoSubject.java b/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainInfoSubject.java
new file mode 100644
index 0000000..d7ee1e8
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/analysis/testing/ToolchainInfoSubject.java
@@ -0,0 +1,52 @@
+// Copyright 2020 The Bazel Authors. All rights reserved.
+//
+// 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.devtools.build.lib.analysis.testing;
+
+import static com.google.common.truth.Truth.assertAbout;
+
+import com.google.common.truth.FailureMetadata;
+import com.google.common.truth.Subject;
+import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
+import com.google.devtools.build.lib.syntax.EvalException;
+
+/** A Truth {@link Subject} for {@link ToolchainInfo}. */
+public class ToolchainInfoSubject extends Subject {
+ // Static data.
+
+ /** Entry point for test assertions related to {@link ToolchainInfo}. */
+ public static ToolchainInfoSubject assertThat(ToolchainInfo toolchainInfo) {
+ return assertAbout(TOOLCHAIN_INFO_SUBJECT_FACTORY).that(toolchainInfo);
+ }
+
+ /** Static method for getting the subject factory (for use with assertAbout()). */
+ public static Factory<ToolchainInfoSubject, ToolchainInfo> toolchainInfos() {
+ return TOOLCHAIN_INFO_SUBJECT_FACTORY;
+ }
+
+ static final Factory<ToolchainInfoSubject, ToolchainInfo> TOOLCHAIN_INFO_SUBJECT_FACTORY =
+ ToolchainInfoSubject::new;
+
+ // Instance fields.
+
+ private final ToolchainInfo actual;
+
+ private ToolchainInfoSubject(FailureMetadata failureMetadata, ToolchainInfo subject) {
+ super(failureMetadata, subject);
+ this.actual = subject;
+ }
+
+ public Subject getValue(String name) throws EvalException {
+ return check("getValue(%s)", name).that(actual.getValue(name));
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
index 40aaf3a..6d32070 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
@@ -248,6 +248,7 @@
"//src/main/protobuf:action_cache_java_proto",
"//src/main/protobuf:analysis_java_proto",
"//src/test/java/com/google/devtools/build/lib/actions/util",
+ "//src/test/java/com/google/devtools/build/lib/analysis/testing",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/analysis/util:test-build-options",
"//src/test/java/com/google/devtools/build/lib/events:testutil",
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java
index bfeeb7e..7012172 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.devtools.build.lib.analysis.testing.ToolchainContextSubject.assertThat;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.RuleContext;
@@ -37,6 +38,7 @@
assertThat(ruleContext.getToolchainContext().resolvedToolchainLabels())
.contains(Label.parseAbsolute("//toolchain:toolchain_1_impl", ImmutableMap.of()));
+ assertThat(ruleContext.getToolchainContext()).hasToolchainType("//toolchain:test_toolchain");
ToolchainInfo toolchain =
ruleContext
.getToolchainContext()
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 4161f47..3c2f0b6 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
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.devtools.build.lib.analysis.testing.ToolchainContextSubject.assertThat;
import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult;
import com.google.common.collect.ImmutableList;
@@ -78,18 +79,10 @@
UnloadedToolchainContext unloadedToolchainContext = result.get(key);
assertThat(unloadedToolchainContext).isNotNull();
- assertThat(unloadedToolchainContext.requiredToolchainTypes())
- .containsExactly(testToolchainType);
- assertThat(unloadedToolchainContext.resolvedToolchainLabels())
- .containsExactly(Label.parseAbsoluteUnchecked("//extra:extra_toolchain_mac_impl"));
-
- assertThat(unloadedToolchainContext.executionPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.executionPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:mac"));
-
- assertThat(unloadedToolchainContext.targetPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.targetPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:linux"));
+ assertThat(unloadedToolchainContext).hasToolchainType(testToolchainTypeLabel);
+ assertThat(unloadedToolchainContext).hasResolvedToolchain("//extra:extra_toolchain_mac_impl");
+ assertThat(unloadedToolchainContext).hasExecutionPlatform("//platforms:mac");
+ assertThat(unloadedToolchainContext).hasTargetPlatform("//platforms:linux");
}
@Test
@@ -122,18 +115,10 @@
UnloadedToolchainContext unloadedToolchainContext = result.get(key);
assertThat(unloadedToolchainContext).isNotNull();
- assertThat(unloadedToolchainContext.requiredToolchainTypes())
- .containsExactly(testToolchainType);
- assertThat(unloadedToolchainContext.resolvedToolchainLabels())
- .containsExactly(Label.parseAbsoluteUnchecked("//extra:extra_toolchain_linux_impl"));
-
- assertThat(unloadedToolchainContext.executionPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.executionPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:linux"));
-
- assertThat(unloadedToolchainContext.targetPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.targetPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:linux"));
+ assertThat(unloadedToolchainContext).hasToolchainType(testToolchainTypeLabel);
+ assertThat(unloadedToolchainContext).hasResolvedToolchain("//extra:extra_toolchain_linux_impl");
+ assertThat(unloadedToolchainContext).hasExecutionPlatform("//platforms:linux");
+ assertThat(unloadedToolchainContext).hasTargetPlatform("//platforms:linux");
}
@Test
@@ -151,11 +136,9 @@
assertThat(unloadedToolchainContext).isNotNull();
assertThat(unloadedToolchainContext.requiredToolchainTypes()).isEmpty();
-
// Even with no toolchains requested, should still select the first execution platform.
- assertThat(unloadedToolchainContext.executionPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.executionPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:mac"));
+ assertThat(unloadedToolchainContext).hasExecutionPlatform("//platforms:mac");
+ assertThat(unloadedToolchainContext).hasTargetPlatform("//platforms:linux");
}
@Test
@@ -190,14 +173,8 @@
assertThat(unloadedToolchainContext).isNotNull();
assertThat(unloadedToolchainContext.requiredToolchainTypes()).isEmpty();
-
- assertThat(unloadedToolchainContext.executionPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.executionPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//sample:sample_b"));
-
- assertThat(unloadedToolchainContext.targetPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.targetPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:linux"));
+ assertThat(unloadedToolchainContext).hasExecutionPlatform("//sample:sample_b");
+ assertThat(unloadedToolchainContext).hasTargetPlatform("//platforms:linux");
}
@Test
@@ -378,18 +355,10 @@
UnloadedToolchainContext unloadedToolchainContext = result.get(key);
assertThat(unloadedToolchainContext).isNotNull();
- assertThat(unloadedToolchainContext.requiredToolchainTypes())
- .containsExactly(testToolchainType);
- assertThat(unloadedToolchainContext.resolvedToolchainLabels())
- .containsExactly(Label.parseAbsoluteUnchecked("//extra:extra_toolchain_linux_impl"));
-
- assertThat(unloadedToolchainContext.executionPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.executionPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:linux"));
-
- assertThat(unloadedToolchainContext.targetPlatform()).isNotNull();
- assertThat(unloadedToolchainContext.targetPlatform().label())
- .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:linux"));
+ assertThat(unloadedToolchainContext).hasToolchainType(testToolchainTypeLabel);
+ assertThat(unloadedToolchainContext).hasResolvedToolchain("//extra:extra_toolchain_linux_impl");
+ assertThat(unloadedToolchainContext).hasExecutionPlatform("//platforms:linux");
+ assertThat(unloadedToolchainContext).hasTargetPlatform("//platforms:linux");
}
@Test