@@ -0,0 +1,2876 @@
+// 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.CompileOnlyTestCase;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.JUnit4;%0A%0A/** Unit tests that validate --compile_only behavior. */%0A@RunWith(JUnit4.class)%0Apublic class GoCompileOnlyTest extends CompileOnlyTestCase %7B%0A%0A  @Test%0A  public void testGoCompileOnly() throws Exception %7B%0A    scratch.file(%0A        %22go_test/main/BUILD%22,%0A        %22go_binary(%22,%0A        %22    name = 'main',%22,%0A        %22    deps = %5B'//go_test/hello'%5D,%22,%0A        %22    srcs = %5B'main.go'%5D,%22,%0A        %22)%22);%0A    scratch.file(%0A        %22go_test/hello/BUILD%22,%0A        %22go_test(%22,%0A        %22    name = 'hello_test',%22,%0A        %22    srcs = %5B%22,%0A        %22        'hello_test.go'%22,%0A        %22    %5D,%22,%0A        %22    library = ':hello'%22,%0A        %22)%22,%0A        %22go_library(%22,%0A        %22    name = 'hello',%22,%0A        %22    srcs = %5B%22,%0A        %22        'hello.go'%22,%0A        %22    %5D,%22,%0A        %22)%22);%0A    scratch.file(%0A        %22go_test/main/main.go%22,%0A        %22package main%22,%0A        %22import %5C%22go_test/hello/hello%5C%22%22,%0A        %22func main() %7B%22,%0A        %22  hello.Hello();%22,%0A        %22%7D%22);%0A    scratch.file(%0A        %22go/hello/hello.go%22,%0A        %22package hello;%22,%0A        %22%22,%0A        %22func Hello() %7B%22,%0A        %22  fmt.Println(%60Hello!%60)%22,%0A        %22%7D%22);%0A    scratch.file(%0A        %22go_test/hello/hello_test.go%22,%0A        %22package hello_test%22,%0A        %22import %5C%22testing%5C%22%22,%0A        %22func TestHello(t *testing.T) %7B%7D%22);%0A%0A    ConfiguredTarget binaryTarget = getConfiguredTarget(%22//go_test/main:main%22);%0A    // Check that only the package been compiled and not the linked binary.%0A    assertThat(getArtifactByExecPathSuffix(binaryTarget, %22/main.a%22)).isNotNull();%0A    assertThat(getArtifactByExecPathSuffix(binaryTarget, %22/main%22)).isNull();%0A%0A    ConfiguredTarget libTarget = getConfiguredTarget(%22//go_test/hello:hello%22);%0A    assertThat(getArtifactByExecPathSuffix(libTarget, %22/hello.a%22)).isNotNull();%0A%0A    ConfiguredTarget testTarget = getConfiguredTarget(%22//go_test/hello:hello_test%22);%0A    assertThat(getArtifactByExecPathSuffix(testTarget, %22/hello_test_testlib.a%22)).isNotNull();%0A  %7D%0A%7D%0A

Enable GoCompileOnlyTest in Bazel.