diff options
author | asteinb <asteinb@google.com> | 2018-03-22 09:42:57 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-22 09:44:11 -0700 |
commit | 6429bc0e060e0a0a2018ef73c2578167ee2b91aa (patch) | |
tree | 16ad5f501ba791af23e9d9af4b92cd3954d17504 /src/test/java/com/google | |
parent | 26603dd2e089f69cd6c9020b69a0d166b3fb0450 (diff) |
Create AndroidManifestInfo provider
This provider is the first part of the Skylark Android Data API.
This provider is not yet used by the native android_* rules, and is subject to change if needed to implement the rest of the Skylark Android data API.
RELNOTES: none
PiperOrigin-RevId: 190078860
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java | 96 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/android/BUILD | 13 |
2 files changed, 109 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java new file mode 100644 index 0000000000..8c912cbb10 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java @@ -0,0 +1,96 @@ +// Copyright 2018 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.android; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests that the AndroidManifestInfo can be moved between Native and Skylark code */ +@RunWith(JUnit4.class) +public class AndroidManifestInfoTest extends BuildViewTestCase { + @Test + public void testGetProvider() throws Exception { + AndroidManifestInfo info = + getInfoFromSkylark("manifest=manifest, package='some.pkg', is_dummy=True"); + + assertThat(info.getManifest()).isNotNull(); + assertThat(info.getManifest().getFilename()).isEqualTo("AndroidManifest.xml"); + assertThat(info.getPackage()).isEqualTo("some.pkg"); + assertThat(info.isDummy()).isTrue(); + } + + @Test + public void testGetProvider_isDummyOptional() throws Exception { + AndroidManifestInfo info = getInfoFromSkylark("manifest=manifest, package='some.pkg'"); + + assertThat(info.getManifest()).isNotNull(); + assertThat(info.getManifest().getFilename()).isEqualTo("AndroidManifest.xml"); + assertThat(info.getPackage()).isEqualTo("some.pkg"); + assertThat(info.isDummy()).isFalse(); + } + + @Test + public void testGetProviderInSkylark() throws Exception { + scratch.file( + "java/skylark/test/rule.bzl", + "def impl(ctx):", + " manifest = ctx.actions.declare_file('AndroidManifest.xml')", + " ctx.actions.write(manifest, 'some values')", + " info = AndroidManifestInfo(manifest=manifest, package='some.pkg', is_dummy=True)", + // Prove that we can access the fields of the provider within Skylark by making a new + // provider from the contents of the current one. + " return [AndroidManifestInfo(", + " manifest=info.manifest, package=info.package, is_dummy=info.is_dummy)]", + "test_rule = rule(implementation=impl)"); + + AndroidManifestInfo copied = + scratchConfiguredTarget( + "java/skylark/test", + "rule", + "load(':rule.bzl', 'test_rule')", + "test_rule(name='rule')") + .get(AndroidManifestInfo.PROVIDER); + + assertThat(copied).isNotNull(); + assertThat(copied.getManifest()).isNotNull(); + assertThat(copied.getManifest().getFilename()).isEqualTo("AndroidManifest.xml"); + assertThat(copied.getPackage()).isEqualTo("some.pkg"); + assertThat(copied.isDummy()).isTrue(); + } + + private AndroidManifestInfo getInfoFromSkylark(String infoArgs) throws Exception { + scratch.file( + "java/skylark/test/rule.bzl", + "def impl(ctx):", + " manifest = ctx.actions.declare_file('AndroidManifest.xml')", + " ctx.actions.write(manifest, 'some values')", + " return [AndroidManifestInfo(" + infoArgs + ")]", + "test_rule = rule(implementation=impl)"); + + AndroidManifestInfo info = + scratchConfiguredTarget( + "java/skylark/test", + "rule", + "load(':rule.bzl', 'test_rule')", + "test_rule(name='rule')") + .get(AndroidManifestInfo.PROVIDER); + assertThat(info).isNotNull(); + + return info; + } +} diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD index ce35e3fe25..34fc1967fa 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD @@ -329,6 +329,19 @@ java_library( ], ) +java_test( + name = "AndroidManifestInfoTest", + srcs = ["AndroidManifestInfoTest.java"], + runtime_deps = ["//src/test/java/com/google/devtools/build/lib:testutil"], + deps = [ + "//src/main/java/com/google/devtools/build/lib:android-rules", + "//src/main/java/com/google/devtools/build/lib:build-base", + "//src/test/java/com/google/devtools/build/lib:analysis_testutil", + "//third_party:junit4", + "//third_party:truth", + ], +) + test_suite( name = "windows_tests", tags = [ |