@@ -0,0 +1,2794 @@
+// Copyright 2022 The Bazel Authors. All rights reserved.%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//    http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0Apackage com.google.devtools.build.lib.view.go;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0A%0Aimport com.google.devtools.build.lib.analysis.ConfiguredTarget;%0Aimport com.google.devtools.build.lib.analysis.util.BuildViewTestCase;%0Aimport com.google.devtools.build.lib.packages.util.MockProtoSupport;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.JUnit4;%0A%0A/** Tests Starlark API for Go rules. */%0A@RunWith(JUnit4.class)%0Apublic class GoStarlarkApiTest extends BuildViewTestCase %7B%0A%0A  /**%0A   * Tests that go_proto_library's aspect exposes a Starlark provider %22aspect_proto_go_api_info%22.%0A   */%0A  @Test%0A  public void testGoProtoLibraryAspectProviders() throws Exception %7B%0A    MockProtoSupport.setup(mockToolsConfig);%0A    scratch.file(%0A        %22x/aspect.bzl%22,%0A        %22def _foo_aspect_impl(target,ctx):%22,%0A        %22  proto_found = hasattr(target, 'aspect_proto_go_api_info')%22,%0A        %22  if hasattr(ctx.rule.attr, 'deps'):%22,%0A        %22    for dep in ctx.rule.attr.deps:%22,%0A        %22      proto_found = proto_found or dep.proto_found%22,%0A        %22  return struct(proto_found = proto_found)%22,%0A        %22foo_aspect = aspect(%22,%0A        %22    _foo_aspect_impl,%22,%0A        %22    attr_aspects = %5B'deps'%5D,%22,%0A        %22    required_aspect_providers=%5B'aspect_proto_go_api_info'%5D)%22,%0A        %22def _rule_impl(ctx):%22,%0A        %22  return struct(result = ctx.attr.dep.proto_found)%22,%0A        %22foo_rule = rule(_rule_impl, attrs = %7B'dep' : attr.label(aspects = %5Bfoo_aspect%5D)%7D)%22);%0A    scratch.file(%0A        %22x/BUILD%22,%0A        %22load(':aspect.bzl', 'foo_rule')%22,%0A        %22go_proto_library(%22,%0A        %22    name = 'foo_go_proto',%22,%0A        %22    deps = %5B'foo_proto'%5D,%22,%0A        %22)%22,%0A        %22proto_library(%22,%0A        %22    name = 'foo_proto',%22,%0A        %22    srcs = %5B'foo.proto'%5D,%22,%0A        %22)%22,%0A        %22foo_rule(%22,%0A        %22    name = 'foo_rule',%22,%0A        %22    dep = 'foo_go_proto',%22,%0A        %22)%22);%0A    ConfiguredTarget target = getConfiguredTarget(%22//x:foo_rule%22);%0A    Boolean result = (Boolean) target.get(%22result%22);%0A%0A    // 'result' is true iff %22aspect_proto_go_api_info%22 was found on the proto_library +%0A    // go_proto_library aspect.%0A    assertThat(result).isTrue();%0A  %7D%0A%7D%0A

Enable GoStarlarkApiTest in Bazel.