forked from bazel-contrib/rules_go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/core/nogo: migrate to go_bazel_test
Updates bazel-contrib#2285
- Loading branch information
Jay Conrod
committed
Nov 20, 2019
1 parent
3c4bce0
commit 3b2a0a5
Showing
30 changed files
with
879 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.