diff options
author | 2017-07-11 11:39:59 +0200 | |
---|---|---|
committer | 2017-07-11 11:42:00 +0200 | |
commit | 4634ff903d1aaec59d545bd28a139d6cf2b95e0d (patch) | |
tree | 8e39ea1f67cae6e27c9c53fa657b1af707789c5c /src/test/java/com/google/devtools | |
parent | e0ea0f6c3f0121ca5e5ac54b0a6ffabc53efbc67 (diff) |
Make information about the Java runtime in use available in Skylark using a dependency.
RELNOTES: None.
PiperOrigin-RevId: 161504700
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/java/JavaRuntimeProviderTest.java | 48 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java | 25 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaRuntimeProviderTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaRuntimeProviderTest.java new file mode 100644 index 0000000000..750390dd5d --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaRuntimeProviderTest.java @@ -0,0 +1,48 @@ +// Copyright 2017 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.rules.java; + +import com.google.common.testing.EqualsTester; +import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; +import com.google.devtools.build.lib.collect.nestedset.Order; +import com.google.devtools.build.lib.vfs.PathFragment; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Unit tests for {@code JavaRuntimeProvider} + */ +@RunWith(JUnit4.class) +public class JavaRuntimeProviderTest { + @Test + public void equalityIsObjectIdentity() { + JavaRuntimeProvider a = new JavaRuntimeProvider( + NestedSetBuilder.emptySet(Order.STABLE_ORDER), + PathFragment.create(""), + PathFragment.create(""), + PathFragment.create("")); + JavaRuntimeProvider b = new JavaRuntimeProvider( + NestedSetBuilder.emptySet(Order.STABLE_ORDER), + PathFragment.create(""), + PathFragment.create(""), + PathFragment.create("")); + + new EqualsTester() + .addEqualityGroup(a) + .addEqualityGroup(b) + .testEquals(); + } +} diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java index f594ca2cfd..b16dd4e24e 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.Skyl import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar; import com.google.devtools.build.lib.syntax.SkylarkList; import com.google.devtools.build.lib.syntax.SkylarkNestedSet; +import com.google.devtools.build.lib.vfs.PathFragment; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -43,6 +44,30 @@ import org.junit.runners.JUnit4; public class JavaSkylarkApiTest extends BuildViewTestCase { @Test + public void testJavaRuntimeProvider() throws Exception { + scratch.file("a/BUILD", + "load(':rule.bzl', 'jrule')", + "java_runtime(name='jvm', srcs=[], java_home='/foo/bar/')", + "java_runtime_suite(name='suite', default=':jvm')", + "jrule(name='r')"); + + scratch.file( + "a/rule.bzl", + "def _impl(ctx):", + " provider = ctx.attr._java_runtime[java_common.JavaRuntimeInfo]", + " return struct(", + " java_executable = provider.java_executable_exec_path,", + ")", + "jrule = rule(_impl, attrs = { '_java_runtime': java_common.java_runtime_attr})"); + + useConfiguration("--javabase=//a:suite"); + ConfiguredTarget ct = getConfiguredTarget("//a:r"); + @SuppressWarnings("unchecked") PathFragment javaExecutable = + (PathFragment) ct.get("java_executable"); + assertThat(javaExecutable.getPathString()).startsWith("/foo/bar/bin/java"); + } + + @Test public void testExposesJavaSkylarkApiProvider() throws Exception { scratch.file( "java/test/BUILD", |