github.com/0xKiwi/rules_go@v0.24.3/tests/core/nogo/coverage/coverage_test.go (about) 1 // Copyright 2019 The Bazel Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package coverage_test 16 17 import ( 18 "testing" 19 20 "github.com/bazelbuild/rules_go/go/tools/bazel_testing" 21 ) 22 23 func TestMain(m *testing.M) { 24 bazel_testing.TestMain(m, bazel_testing.Args{ 25 Main: ` 26 -- BUILD.bazel -- 27 load("@io_bazel_rules_go//go:def.bzl", "go_test", "go_tool_library", "nogo") 28 29 go_test( 30 name = "coverage_target", 31 srcs = ["coverage_target_test.go"], 32 deps = [":coverage_target_dep"], 33 ) 34 35 go_tool_library( 36 name = "coverage_target_dep", 37 importmap = "mapped/coverage_target/dep", 38 importpath = "coverage_target/dep", 39 ) 40 41 nogo( 42 name = "nogo", 43 vet = True, 44 visibility = ["//visibility:public"], 45 ) 46 -- coverage_target_test.go -- 47 package coverage_target_test 48 `, 49 Nogo: `@//:nogo`, 50 }) 51 } 52 53 func TestCoverageWithNogo(t *testing.T) { 54 if err := bazel_testing.RunBazel("coverage", "//:coverage_target"); err != nil { 55 t.Fatal(err) 56 } 57 } 58 59 func TestCoverageOfNogo(t *testing.T) { 60 if err := bazel_testing.RunBazel("build", "--instrumentation_filter=.*", "--collect_code_coverage", "//:nogo"); err != nil { 61 t.Fatal(err) 62 } 63 }