Skip to content

Commit

Permalink
tests/core/nogo: migrate to go_bazel_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Conrod committed Nov 20, 2019
1 parent 3c4bce0 commit 3b2a0a5
Show file tree
Hide file tree
Showing 30 changed files with 879 additions and 707 deletions.
15 changes: 0 additions & 15 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ platforms:
- "-//tests/core/go_proto_library:wrap_lib"
- "-//tests/core/go_test:data_test"
- "-//tests/core/go_test:pwd_test"
- "-//tests/core/nogo/custom:custom_analyzers_custom_config"
- "-//tests/core/nogo/custom:custom_analyzers_default_config"
- "-//tests/core/nogo/custom:custom_analyzers_no_errors"
- "-//tests/core/nogo/deps:dep_graph"
- "-//tests/core/nogo/vet:vet_default"
- "-//tests/core/nogo/vet:vet_enabled_has_errors"
- "-//tests/core/nogo/vet:vet_enabled_no_errors"
- "-//tests/core/output_groups:compilation_outputs_test"
- "-//tests/core/race:race_bin"
- "-//tests/core/race:race_feature_test"
Expand Down Expand Up @@ -299,15 +292,7 @@ platforms:
- "-//tests/core/go_proto_library:transitive_test"
- "-//tests/core/go_test:data_test"
- "-//tests/core/go_test:pwd_test"
- "-//tests/core/nogo/config:pure_aspect_test"
- "-//tests/core/nogo/coverage:coverage_test"
- "-//tests/core/nogo/custom:custom_analyzers_custom_config"
- "-//tests/core/nogo/custom:custom_analyzers_default_config"
- "-//tests/core/nogo/custom:custom_analyzers_no_errors"
- "-//tests/core/nogo/deps:dep_graph"
- "-//tests/core/nogo/vet:vet_default"
- "-//tests/core/nogo/vet:vet_enabled_has_errors"
- "-//tests/core/nogo/vet:vet_enabled_no_errors"
- "-//tests/core/output_groups:compilation_outputs_test"
- "-//tests/core/race:race_auto_test"
- "-//tests/core/race:race_bin"
Expand Down
26 changes: 4 additions & 22 deletions tests/core/nogo/config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@io_bazel_rules_go//tests:bazel_tests.bzl", "bazel_test")
load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test")

bazel_test(
name = "pure_aspect_test",
command = "build",
nogo = "@io_bazel_rules_go//:tools_nogo",
targets = [":pure_bin"],
)

go_binary(
name = "pure_bin",
srcs = ["pure_bin.go"],
pure = "on",
tags = ["manual"],
deps = [":pure_lib"],
)

go_library(
name = "pure_lib",
srcs = ["pure_lib.go"],
importpath = "github.com/bazelbuild/rules_go/tests/core/nogo/config/pure_lib",
tags = ["manual"],
go_bazel_test(
name = "config_test",
srcs = ["config_test.go"],
)
9 changes: 5 additions & 4 deletions tests/core/nogo/config/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Tests that verify nogo_ works on targets compiled in non-default configurations.

.. contents::

pure_aspect_test
----------------
Verifies that a `go_binary`_ with ``pure = "on"`` (compiled with the aspect)
builds successfully with nogo. Verifies #1850.
config_test
-----------

Verifies that a `go_binary`_ can be built in non-default configurations with
nogo. Verifies #1850.
62 changes: 62 additions & 0 deletions tests/core/nogo/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2019 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 config_test

import (
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel_testing"
)

func TestMain(m *testing.M) {
bazel_testing.TestMain(m, bazel_testing.Args{
Nogo: "@io_bazel_rules_go//:tools_nogo",
Main: `
-- BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_binary(
name = "pure_bin",
srcs = ["pure_bin.go"],
pure = "on",
deps = [":pure_lib"],
)
go_library(
name = "pure_lib",
srcs = ["pure_lib.go"],
importpath = "example.com/nogo/config/pure_lib",
)
-- pure_bin.go --
package main
import _ "example.com/nogo/config/pure_lib"
func main() {
}
-- pure_lib.go --
package pure_lib
`,
})
}

func TestPureAspect(t *testing.T) {
if err := bazel_testing.RunBazel("build", "//:pure_bin"); err != nil {
t.Fatal(err)
}
}
6 changes: 0 additions & 6 deletions tests/core/nogo/config/pure_bin.go

This file was deleted.

1 change: 0 additions & 1 deletion tests/core/nogo/config/pure_lib.go

This file was deleted.

125 changes: 4 additions & 121 deletions tests/core/nogo/custom/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,123 +1,6 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_tool_library")
load("@io_bazel_rules_go//tests:bazel_tests.bzl", "bazel_test")
load(
"@io_bazel_rules_go//tests/core/nogo:common.bzl",
"BUILD_FAILED_TMPL",
"BUILD_PASSED_TMPL",
"CONTAINS_ERR_TMPL",
"DOES_NOT_CONTAIN_ERR_TMPL",
)

BUILD_TMPL = """
load("@io_bazel_rules_go//go:def.bzl", "nogo", "go_tool_library")
nogo(
name = "nogo",
deps = [
":foofuncname",
":importfmt",
":visibility",
],
{config}
visibility = ["//visibility:public"],
)
go_tool_library(
name = "importfmt",
srcs = ["importfmt.go"],
importpath = "importfmtanalyzer",
deps = ["@org_golang_x_tools//go/analysis:go_tool_library"],
visibility = ["//visibility:public"],
)
go_tool_library(
name = "foofuncname",
srcs = ["foofuncname.go"],
importpath = "foofuncanalyzer",
deps = ["@org_golang_x_tools//go/analysis:go_tool_library"],
visibility = ["//visibility:public"],
)
go_tool_library(
name = "visibility",
srcs = ["visibility.go"],
importpath = "visibilityanalyzer",
deps = [
"@org_golang_x_tools//go/analysis:go_tool_library",
"@org_golang_x_tools//go/ast/inspector:go_tool_library",
],
visibility = ["//visibility:public"],
)
"""

EXTRA_FILES = [
":foofuncname.go",
":importfmt.go",
":visibility.go",
":config.json",
]

NOGO = "@//:nogo"

bazel_test(
name = "custom_analyzers_default_config",
build = BUILD_TMPL.format(config = ""),
check = BUILD_FAILED_TMPL.format(
check_err =
CONTAINS_ERR_TMPL.format(err = "custom/has_errors.go:.*package fmt must not be imported") +
CONTAINS_ERR_TMPL.format(err = "custom/has_errors.go:.*function must not be named Foo") +
CONTAINS_ERR_TMPL.format(err = "custom/has_errors.go:.*function D is not visible in this package"),
),
command = "build",
extra_files = EXTRA_FILES,
nogo = NOGO,
targets = [":has_errors"],
)

bazel_test(
name = "custom_analyzers_custom_config",
build = BUILD_TMPL.format(config = "config = \":config.json\","),
check = BUILD_FAILED_TMPL.format(
check_err =
CONTAINS_ERR_TMPL.format(err = "custom/has_errors.go:.*package fmt must not be imported") +
DOES_NOT_CONTAIN_ERR_TMPL.format(err = "custom/has_errors.go:.*function D is not visible in this package") +
CONTAINS_ERR_TMPL.format(err = "custom/has_errors.go:.*function must not be named Foo"),
),
command = "build",
extra_files = EXTRA_FILES,
nogo = NOGO,
targets = [":has_errors"],
)

bazel_test(
name = "custom_analyzers_no_errors",
build = BUILD_TMPL.format(config = ""),
check = BUILD_PASSED_TMPL.format(
check_err =
DOES_NOT_CONTAIN_ERR_TMPL.format(err = "no_errors.go:"),
),
command = "build",
extra_files = EXTRA_FILES,
nogo = NOGO,
targets = [":no_errors"],
)

go_library(
name = "has_errors",
srcs = ["has_errors.go"],
importpath = "haserrors",
deps = [":dep"],
)

go_library(
name = "no_errors",
srcs = ["no_errors.go"],
importpath = "noerrors",
deps = [":dep"],
)
load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test")

go_library(
name = "dep",
srcs = ["dep.go"],
importpath = "dep",
go_bazel_test(
name = "custom_test",
srcs = ["custom_test.go"],
)
19 changes: 4 additions & 15 deletions tests/core/nogo/custom/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,9 @@ Tests to ensure that custom `nogo`_ analyzers run and detect errors.

.. contents::

custom_analyzers_default_config
-------------------------------
custom_test
-----------
Verifies that custom analyzers print errors and fail a `go_library`_ build when
a configuration file is not provided, and that analyzers with the same package
name do not conflict.

custom_analyzers_custom_config
------------------------------
Verifies that custom analyzers can be configured to apply only to certain file
paths using a custom configuration file, and that analyzers with the same
package name do not conflict.

custom_analyzers_no_errors
--------------------------
Verifies that a library build succeeds if custom analyzers do not find any
errors in the library's source code, and that analyzers with the same package
name do not conflict.
name do not conflict. Also checks that custom analyzers can be configured to
apply only to certain file paths using a custom configuration file.
15 changes: 0 additions & 15 deletions tests/core/nogo/custom/config.json

This file was deleted.

Loading

0 comments on commit 3b2a0a5

Please sign in to comment.