aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-07-05 14:30:32 -0400
committerGravatar John Cater <jcater@google.com>2017-07-06 07:13:34 -0400
commit948e519093eb82c217e842eec61a88725689d9dc (patch)
treeb948f94c8f3b1a4c90528dc2b6957a7227a1f9bf /src/test/java/com/google
parenta15d648410000cedbde9578c9ee22a023f1b96df (diff)
Improve the ToolchainInfo provider and add more data.
Part of #2219. Change-Id: Ie235d0a75fc50746331b20a7f2060e6d49ae48cb PiperOrigin-RevId: 160982987
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfoTest.java86
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java24
2 files changed, 52 insertions, 58 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfoTest.java b/src/test/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfoTest.java
index 289f72a28b..b37ee76666 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfoTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfoTest.java
@@ -14,12 +14,13 @@
package com.google.devtools.build.lib.analysis.platform;
-import com.google.common.collect.ImmutableList;
+import static com.google.common.truth.Truth.assertThat;
+
import com.google.common.collect.ImmutableMap;
import com.google.common.testing.EqualsTester;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.events.Location;
-import com.google.devtools.build.lib.packages.ClassObjectConstructor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -29,55 +30,68 @@ import org.junit.runners.JUnit4;
public class ToolchainInfoTest extends BuildViewTestCase {
@Test
- public void toolchainInfo_equalsTester() throws Exception {
- ClassObjectConstructor.Key key = new ClassObjectConstructor.Key() {};
- ConstraintSettingInfo setting1 = ConstraintSettingInfo.create(makeLabel("//constraint:basic"));
- ConstraintSettingInfo setting2 = ConstraintSettingInfo.create(makeLabel("//constraint:other"));
+ public void toolchainInfoConstructor() throws Exception {
+ scratch.file(
+ "test/toolchain/my_toolchain.bzl",
+ "def _impl(ctx):",
+ " toolchain = platform_common.ToolchainInfo(",
+ " type = Label('//test/toolchain:my_toolchain_type'),",
+ " extra_label = ctx.attr.extra_label,",
+ " extra_str = ctx.attr.extra_str)",
+ " return [toolchain]",
+ "my_toolchain = rule(",
+ " implementation = _impl,",
+ " attrs = {",
+ " 'extra_label': attr.label(),",
+ " 'extra_str': attr.string(),",
+ " }",
+ ")");
+ scratch.file(
+ "test/toolchain/BUILD",
+ "load('//test/toolchain:my_toolchain.bzl', 'my_toolchain')",
+ "toolchain_type(name = 'my_toolchain_type')",
+ "filegroup(name = 'dep')",
+ "my_toolchain(name = 'toolchain',",
+ " extra_label = ':dep',",
+ " extra_str = 'foo')");
+
+ ConfiguredTarget toolchain = getConfiguredTarget("//test/toolchain:toolchain");
+ assertThat(toolchain).isNotNull();
- ConstraintValueInfo value1 =
- ConstraintValueInfo.create(setting1, makeLabel("//constraint:value1"));
- ConstraintValueInfo value2 =
- ConstraintValueInfo.create(setting2, makeLabel("//constraint:value2"));
- ConstraintValueInfo value3 =
- ConstraintValueInfo.create(setting2, makeLabel("//constraint:value3"));
+ ToolchainInfo provider = PlatformProviderUtils.toolchain(toolchain);
+ assertThat(provider).isNotNull();
+
+ assertThat(provider.type()).isEqualTo(makeLabel("//test/toolchain:my_toolchain_type"));
+
+ ConfiguredTarget extraLabel = (ConfiguredTarget) provider.getValue("extra_label");
+ assertThat(extraLabel).isNotNull();
+ assertThat(extraLabel.getLabel()).isEqualTo(makeLabel("//test/toolchain:dep"));
+ assertThat(provider.getValue("extra_str")).isEqualTo("foo");
+ }
+ @Test
+ public void toolchainInfo_equalsTester() throws Exception {
new EqualsTester()
.addEqualityGroup(
// Base case.
- new ToolchainInfo(
- key,
- ImmutableList.of(value1, value2),
- ImmutableList.of(value1, value3),
+ ToolchainInfo.create(
+ makeLabel("//toolchain:tc1"),
ImmutableMap.<String, Object>of("foo", "val1", "bar", "val2"),
Location.BUILTIN),
- new ToolchainInfo(
- key,
- ImmutableList.of(value1, value2),
- ImmutableList.of(value1, value3),
+ ToolchainInfo.create(
+ makeLabel("//toolchain:tc1"),
ImmutableMap.<String, Object>of("foo", "val1", "bar", "val2"),
Location.BUILTIN))
.addEqualityGroup(
// Different type.
- new ToolchainInfo(
- new ClassObjectConstructor.Key() {},
- ImmutableList.of(value1, value2),
- ImmutableList.of(value1, value3),
- ImmutableMap.<String, Object>of("foo", "val1", "bar", "val2"),
- Location.BUILTIN))
- .addEqualityGroup(
- // Different target constraints.
- new ToolchainInfo(
- key,
- ImmutableList.of(value1, value2),
- ImmutableList.of(value1, value2),
+ ToolchainInfo.create(
+ makeLabel("//toolchain:tc2"),
ImmutableMap.<String, Object>of("foo", "val1", "bar", "val2"),
Location.BUILTIN))
.addEqualityGroup(
// Different data.
- new ToolchainInfo(
- key,
- ImmutableList.of(value1, value2),
- ImmutableList.of(value1, value3),
+ ToolchainInfo.create(
+ makeLabel("//toolchain:tc1"),
ImmutableMap.<String, Object>of("foo", "val1", "bar", "val3"),
Location.BUILTIN))
.testEquals();
diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java
index dc04069f97..e26389a8f8 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java
@@ -17,11 +17,9 @@ package com.google.devtools.build.lib.rules.platform;
import static com.google.common.truth.Truth.assertThat;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-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.ToolchainInfo;
-import com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor;
import com.google.devtools.build.lib.skylark.util.SkylarkTestCase;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -31,6 +29,7 @@ import org.junit.runners.JUnit4;
public class PlatformCommonTest extends SkylarkTestCase {
@Test
+ @Ignore("Remove this test")
public void testCreateToolchainType() throws Exception {
scratch.file(
"test/toolchain_type.bzl",
@@ -79,24 +78,5 @@ public class PlatformCommonTest extends SkylarkTestCase {
ToolchainInfo toolchainInfo =
(ToolchainInfo) configuredTarget.get(ToolchainInfo.SKYLARK_IDENTIFIER);
assertThat(toolchainInfo).isNotNull();
-
- assertThat(toolchainInfo.toolchainConstructorKey()).isNotNull();
- assertThat(toolchainInfo.toolchainConstructorKey())
- .isEqualTo(
- new SkylarkClassObjectConstructor.SkylarkKey(
- makeLabel("//test:toolchain_type.bzl"), "test_toolchain_type"));
-
- assertThat(toolchainInfo.execConstraints())
- .containsExactly(
- ConstraintValueInfo.create(
- ConstraintSettingInfo.create(makeLabel("//test:os")), makeLabel("//test:linux")));
- assertThat(toolchainInfo.targetConstraints())
- .containsExactly(
- ConstraintValueInfo.create(
- ConstraintSettingInfo.create(makeLabel("//test:os")), makeLabel("//test:mac")));
-
- assertThat(((ConfiguredTarget) toolchainInfo.getValue("extra_label")).getLabel())
- .isEqualTo(makeLabel("//test:dep_rule"));
- assertThat(toolchainInfo.getValue("extra_str")).isEqualTo("bar");
}
}