aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@gmail.com>2018-05-23 17:32:17 -0400
committerGitHub <noreply@github.com>2018-05-23 17:32:17 -0400
commit0b731fe1dc34cca054349061d79b3359ccdf29af (patch)
tree6a64f91edf4ff8c63e939ca398362c9bc7802d54 /tests
parent6ed1cd146058991b8d0691e232d9b537f7becf73 (diff)
downloadbazelbuild-rules_go-0b731fe1dc34cca054349061d79b3359ccdf29af.tar.gz
Format .bzl files with buildifier
Fixes #1458
Diffstat (limited to 'tests')
-rw-r--r--tests/bazel_tests.bzl287
-rw-r--r--tests/core/stdlib/stdlib_files.bzl12
-rw-r--r--tests/integration/popular_repos/popular_repos.bzl94
-rw-r--r--tests/legacy/examples/cgo/example_command/generate_test.bzl10
-rw-r--r--tests/legacy/race/generate_test.bzl10
-rw-r--r--tests/legacy/test_chdir/remote.bzl12
6 files changed, 214 insertions, 211 deletions
diff --git a/tests/bazel_tests.bzl b/tests/bazel_tests.bzl
index d81895ed..077b6634 100644
--- a/tests/bazel_tests.bzl
+++ b/tests/bazel_tests.bzl
@@ -92,68 +92,71 @@ filegroup(
CURRENT_VERSION = "current"
def _bazel_test_script_impl(ctx):
- go = go_context(ctx)
- script_file = go.declare_file(go, ext=".bash")
-
- if not ctx.attr.targets:
- # Skip test when there are no targets. Targets may be platform-specific,
- # and we may not have any targets on some platforms.
- ctx.actions.write(script_file, "", is_executable = True)
- return [DefaultInfo(files = depset([script_file]))]
-
- if ctx.attr.go_version == CURRENT_VERSION:
- register = 'go_register_toolchains()\n'
- elif ctx.attr.go_version != None:
- register = 'go_register_toolchains(go_version="{}")\n'.format(ctx.attr.go_version)
-
- workspace_content = 'workspace(name = "bazel_test")\n\n'
- for ext in ctx.attr.externals:
- root = ext.label.workspace_root
- _,_,name = ext.label.workspace_root.rpartition("/")
- workspace_content += 'local_repository(name="{name}", path="{exec_root}/{root}")\n'.format(
- name = name,
- root = root,
- exec_root = ctx.attr._settings.exec_root,
+ go = go_context(ctx)
+ script_file = go.declare_file(go, ext = ".bash")
+
+ if not ctx.attr.targets:
+ # Skip test when there are no targets. Targets may be platform-specific,
+ # and we may not have any targets on some platforms.
+ ctx.actions.write(script_file, "", is_executable = True)
+ return [DefaultInfo(files = depset([script_file]))]
+
+ if ctx.attr.go_version == CURRENT_VERSION:
+ register = "go_register_toolchains()\n"
+ elif ctx.attr.go_version != None:
+ register = 'go_register_toolchains(go_version="{}")\n'.format(ctx.attr.go_version)
+
+ workspace_content = 'workspace(name = "bazel_test")\n\n'
+ for ext in ctx.attr.externals:
+ root = ext.label.workspace_root
+ _, _, name = ext.label.workspace_root.rpartition("/")
+ workspace_content += 'local_repository(name="{name}", path="{exec_root}/{root}")\n'.format(
+ name = name,
+ root = root,
+ exec_root = ctx.attr._settings.exec_root,
+ )
+ if ctx.attr.workspace:
+ workspace_content += ctx.attr.workspace
+ else:
+ workspace_content += _basic_workspace.format()
+ workspace_content += register
+
+ workspace_file = go.declare_file(go, path = "WORKSPACE.in")
+ ctx.actions.write(workspace_file, workspace_content)
+ build_file = go.declare_file(go, path = "BUILD.in")
+ ctx.actions.write(build_file, ctx.attr.build)
+
+ output = "external/" + ctx.workspace_name + "/" + ctx.label.package
+ targets = ["@" + ctx.workspace_name + "//" + ctx.label.package + t if t.startswith(":") else t for t in ctx.attr.targets]
+ logs = []
+ if ctx.attr.command in ("test", "coverage"):
+ # TODO(jayconrod): read logs for other packages
+ logs = [
+ "bazel-testlogs/{}/{}/test.log".format(output, t[1:])
+ for t in ctx.attr.targets
+ if t.startswith(":")
+ ]
+
+ script_content = _bazel_test_script_template.format(
+ bazelrc = ctx.attr._settings.exec_root + "/" + ctx.file._bazelrc.path,
+ config = ctx.attr.config,
+ command = ctx.attr.command,
+ args = " ".join(ctx.attr.args),
+ target = " ".join(targets),
+ logs = " ".join(logs),
+ check = ctx.attr.check,
+ workspace = workspace_file.short_path,
+ build = build_file.short_path,
+ output = output,
+ bazel = ctx.attr._settings.bazel,
+ work_dir = ctx.attr._settings.scratch_dir + "/" + ctx.attr.config,
+ cache_dir = ctx.attr._settings.scratch_dir + "/cache",
+ )
+ ctx.actions.write(output = script_file, is_executable = True, content = script_content)
+ return struct(
+ files = depset([script_file]),
+ runfiles = ctx.runfiles([workspace_file, build_file], collect_data = True),
)
- if ctx.attr.workspace:
- workspace_content += ctx.attr.workspace
- else:
- workspace_content += _basic_workspace.format()
- workspace_content += register
-
- workspace_file = go.declare_file(go, path="WORKSPACE.in")
- ctx.actions.write(workspace_file, workspace_content)
- build_file = go.declare_file(go, path="BUILD.in")
- ctx.actions.write(build_file, ctx.attr.build)
-
- output = "external/" + ctx.workspace_name + "/" + ctx.label.package
- targets = ["@" + ctx.workspace_name + "//" + ctx.label.package + t if t.startswith(":") else t for t in ctx.attr.targets]
- logs = []
- if ctx.attr.command in ("test", "coverage"):
- # TODO(jayconrod): read logs for other packages
- logs = ["bazel-testlogs/{}/{}/test.log".format(output, t[1:])
- for t in ctx.attr.targets if t.startswith(":")]
-
- script_content = _bazel_test_script_template.format(
- bazelrc = ctx.attr._settings.exec_root+"/"+ctx.file._bazelrc.path,
- config = ctx.attr.config,
- command = ctx.attr.command,
- args = " ".join(ctx.attr.args),
- target = " ".join(targets),
- logs = " ".join(logs),
- check = ctx.attr.check,
- workspace = workspace_file.short_path,
- build = build_file.short_path,
- output = output,
- bazel = ctx.attr._settings.bazel,
- work_dir = ctx.attr._settings.scratch_dir + "/" + ctx.attr.config,
- cache_dir = ctx.attr._settings.scratch_dir + "/cache",
- )
- ctx.actions.write(output=script_file, is_executable=True, content=script_content)
- return struct(
- files = depset([script_file]),
- runfiles = ctx.runfiles([workspace_file, build_file], collect_data=True)
- )
_bazel_test_script = go_rule(
_bazel_test_script_impl,
@@ -188,53 +191,53 @@ _bazel_test_script = go_rule(
},
)
-def bazel_test(name, command = None, args=None, targets = None, go_version = None, tags=[], externals=[], workspace="", build="", check="", config=None):
- script_name = name+"_script"
- externals = externals + [
- "@io_bazel_rules_go//:AUTHORS",
- ]
- if go_version == None or go_version == CURRENT_VERSION:
- externals.append("@go_sdk//:packages.txt")
-
- _bazel_test_script(
- name = script_name,
- command = command,
- args = args,
- targets = targets,
- externals = externals,
- go_version = go_version,
- workspace = workspace,
- build = build,
- check = check,
- config = config,
- )
- native.sh_test(
- name = name,
- size = "large",
- timeout = "moderate",
- srcs = [":" + script_name],
- tags = ["local", "bazel", "exclusive"] + tags,
- data = [
- "@bazel_gazelle//cmd/gazelle",
- "@bazel_test//:bazelrc",
- "@io_bazel_rules_go//tests:rules_go_deps",
- ],
- )
+def bazel_test(name, command = None, args = None, targets = None, go_version = None, tags = [], externals = [], workspace = "", build = "", check = "", config = None):
+ script_name = name + "_script"
+ externals = externals + [
+ "@io_bazel_rules_go//:AUTHORS",
+ ]
+ if go_version == None or go_version == CURRENT_VERSION:
+ externals.append("@go_sdk//:packages.txt")
+
+ _bazel_test_script(
+ name = script_name,
+ command = command,
+ args = args,
+ targets = targets,
+ externals = externals,
+ go_version = go_version,
+ workspace = workspace,
+ build = build,
+ check = check,
+ config = config,
+ )
+ native.sh_test(
+ name = name,
+ size = "large",
+ timeout = "moderate",
+ srcs = [":" + script_name],
+ tags = ["local", "bazel", "exclusive"] + tags,
+ data = [
+ "@bazel_gazelle//cmd/gazelle",
+ "@bazel_test//:bazelrc",
+ "@io_bazel_rules_go//tests:rules_go_deps",
+ ],
+ )
def _md5_sum_impl(ctx):
- go = go_context(ctx)
- out = go.declare_file(go, ext=".md5")
- arguments = ctx.actions.args()
- arguments.add(["-output", out.path])
- arguments.add(ctx.files.srcs)
- ctx.actions.run(
- inputs = ctx.files.srcs,
- outputs = [out],
- mnemonic = "GoMd5sum",
- executable = ctx.file._md5sum,
- arguments = [arguments],
- )
- return struct(files=depset([out]))
+ go = go_context(ctx)
+ out = go.declare_file(go, ext = ".md5")
+ arguments = ctx.actions.args()
+ arguments.add(["-output", out.path])
+ arguments.add(ctx.files.srcs)
+ ctx.actions.run(
+ inputs = ctx.files.srcs,
+ outputs = [out],
+ mnemonic = "GoMd5sum",
+ executable = ctx.file._md5sum,
+ arguments = [arguments],
+ )
+ return struct(files = depset([out]))
md5_sum = go_rule(
_md5_sum_impl,
@@ -249,36 +252,36 @@ md5_sum = go_rule(
)
def _test_environment_impl(ctx):
- # Find bazel
- bazel = ""
- if "BAZEL" in ctx.os.environ:
- bazel = ctx.os.environ["BAZEL"]
- elif "BAZEL_VERSION" in ctx.os.environ:
- home = ctx.os.environ["HOME"]
- bazel = home + "/.bazel/{0}/bin/bazel".format(ctx.os.environ["BAZEL_VERSION"])
- if bazel == "" or not ctx.path(bazel).exists:
- bazel = ctx.which("bazel")
-
- # Get a temporary directory to use as our scratch workspace
- if ctx.os.name.startswith('windows'):
- scratch_dir = ctx.os.environ["TMP"].replace("\\","/") + "/bazel_go_test"
- else:
- result = env_execute(ctx, ["mktemp", "-d"])
- if result.return_code:
- fail("failed to create temporary directory for bazel tests: {}".format(result.stderr))
- scratch_dir = result.stdout.strip()
-
- # Work out where we are running so we can find externals
- exec_root, _, _ = str(ctx.path(".")).rpartition("/external/")
-
- # build the basic environment
- ctx.file("WORKSPACE", 'workspace(name = "{}")'.format(ctx.name))
- ctx.file("BUILD.bazel", _env_build_template.format(
- bazel = bazel,
- exec_root = exec_root,
- scratch_dir = scratch_dir,
- ))
- ctx.file("test.bazelrc", content=_bazelrc)
+ # Find bazel
+ bazel = ""
+ if "BAZEL" in ctx.os.environ:
+ bazel = ctx.os.environ["BAZEL"]
+ elif "BAZEL_VERSION" in ctx.os.environ:
+ home = ctx.os.environ["HOME"]
+ bazel = home + "/.bazel/{0}/bin/bazel".format(ctx.os.environ["BAZEL_VERSION"])
+ if bazel == "" or not ctx.path(bazel).exists:
+ bazel = ctx.which("bazel")
+
+ # Get a temporary directory to use as our scratch workspace
+ if ctx.os.name.startswith("windows"):
+ scratch_dir = ctx.os.environ["TMP"].replace("\\", "/") + "/bazel_go_test"
+ else:
+ result = env_execute(ctx, ["mktemp", "-d"])
+ if result.return_code:
+ fail("failed to create temporary directory for bazel tests: {}".format(result.stderr))
+ scratch_dir = result.stdout.strip()
+
+ # Work out where we are running so we can find externals
+ exec_root, _, _ = str(ctx.path(".")).rpartition("/external/")
+
+ # build the basic environment
+ ctx.file("WORKSPACE", 'workspace(name = "{}")'.format(ctx.name))
+ ctx.file("BUILD.bazel", _env_build_template.format(
+ bazel = bazel,
+ exec_root = exec_root,
+ scratch_dir = scratch_dir,
+ ))
+ ctx.file("test.bazelrc", content = _bazelrc)
_test_environment = repository_rule(
implementation = _test_environment_impl,
@@ -291,11 +294,11 @@ _test_environment = repository_rule(
)
def _bazel_test_settings_impl(ctx):
- return struct(
- bazel = ctx.attr.bazel,
- exec_root = ctx.attr.exec_root,
- scratch_dir = ctx.attr.scratch_dir,
- )
+ return struct(
+ bazel = ctx.attr.bazel,
+ exec_root = ctx.attr.exec_root,
+ scratch_dir = ctx.attr.scratch_dir,
+ )
bazel_test_settings = rule(
_bazel_test_settings_impl,
@@ -307,4 +310,4 @@ bazel_test_settings = rule(
)
def test_environment():
- _test_environment(name="bazel_test")
+ _test_environment(name = "bazel_test")
diff --git a/tests/core/stdlib/stdlib_files.bzl b/tests/core/stdlib/stdlib_files.bzl
index ce21d859..b42d02e3 100644
--- a/tests/core/stdlib/stdlib_files.bzl
+++ b/tests/core/stdlib/stdlib_files.bzl
@@ -15,12 +15,12 @@
load("@io_bazel_rules_go//go/private:providers.bzl", "GoSource")
def _stdlib_files_impl(ctx):
- files = ctx.attr._stdlib[GoSource].stdlib.files
- runfiles = ctx.runfiles(files = files)
- return [DefaultInfo(
- files = depset(files),
- runfiles = runfiles,
- )]
+ files = ctx.attr._stdlib[GoSource].stdlib.files
+ runfiles = ctx.runfiles(files = files)
+ return [DefaultInfo(
+ files = depset(files),
+ runfiles = runfiles,
+ )]
stdlib_files = rule(
_stdlib_files_impl,
diff --git a/tests/integration/popular_repos/popular_repos.bzl b/tests/integration/popular_repos/popular_repos.bzl
index 0ac5ac11..ee91a9ba 100644
--- a/tests/integration/popular_repos/popular_repos.bzl
+++ b/tests/integration/popular_repos/popular_repos.bzl
@@ -19,52 +19,52 @@
load("@io_bazel_rules_go//go/private:go_repository.bzl", "go_repository")
def _maybe(repo_rule, name, **kwargs):
- if name not in native.existing_rules():
- repo_rule(name=name, **kwargs)
+ if name not in native.existing_rules():
+ repo_rule(name = name, **kwargs)
def popular_repos():
- _maybe(
- go_repository,
- name="org_golang_x_crypto",
- importpath="golang.org/x/crypto",
- strip_prefix="crypto-81e90905daefcd6fd217b62423c0908922eadb30",
- type="zip",
- urls=['https://codeload.github.com/golang/crypto/zip/81e90905daefcd6fd217b62423c0908922eadb30'],
- )
- _maybe(
- go_repository,
- name="org_golang_x_net",
- importpath="golang.org/x/net",
- commit="57efc9c3d9f91fb3277f8da1cff370539c4d3dc5",
- )
- _maybe(
- go_repository,
- name="org_golang_x_sys",
- importpath="golang.org/x/sys",
- commit="0b25a408a50076fbbcae6b7ac0ea5fbb0b085e79",
- )
- _maybe(
- go_repository,
- name="org_golang_x_text",
- importpath="golang.org/x/text",
- commit="a9a820217f98f7c8a207ec1e45a874e1fe12c478",
- )
- _maybe(
- go_repository,
- name="org_golang_x_tools",
- importpath="golang.org/x/tools",
- commit="663269851cdddc898f963782f74ea574bcd5c814",
- )
- _maybe(
- go_repository,
- name="org_golang_google_grpc",
- importpath="google.golang.org/grpc",
- commit="3f10311ccf076b6b7cba28273df3290d42e60982",
- build_file_proto_mode="disable",
- )
- _maybe(
- go_repository,
- name="com_github_mattn_go_sqlite3",
- importpath="github.com/mattn/go-sqlite3",
- commit="83772a7051f5e30d8e59746a9e43dfa706b72f3b",
- )
+ _maybe(
+ go_repository,
+ name = "org_golang_x_crypto",
+ importpath = "golang.org/x/crypto",
+ strip_prefix = "crypto-81e90905daefcd6fd217b62423c0908922eadb30",
+ type = "zip",
+ urls = ["https://codeload.github.com/golang/crypto/zip/81e90905daefcd6fd217b62423c0908922eadb30"],
+ )
+ _maybe(
+ go_repository,
+ name = "org_golang_x_net",
+ importpath = "golang.org/x/net",
+ commit = "57efc9c3d9f91fb3277f8da1cff370539c4d3dc5",
+ )
+ _maybe(
+ go_repository,
+ name = "org_golang_x_sys",
+ importpath = "golang.org/x/sys",
+ commit = "0b25a408a50076fbbcae6b7ac0ea5fbb0b085e79",
+ )
+ _maybe(
+ go_repository,
+ name = "org_golang_x_text",
+ importpath = "golang.org/x/text",
+ commit = "a9a820217f98f7c8a207ec1e45a874e1fe12c478",
+ )
+ _maybe(
+ go_repository,
+ name = "org_golang_x_tools",
+ importpath = "golang.org/x/tools",
+ commit = "663269851cdddc898f963782f74ea574bcd5c814",
+ )
+ _maybe(
+ go_repository,
+ name = "org_golang_google_grpc",
+ importpath = "google.golang.org/grpc",
+ commit = "3f10311ccf076b6b7cba28273df3290d42e60982",
+ build_file_proto_mode = "disable",
+ )
+ _maybe(
+ go_repository,
+ name = "com_github_mattn_go_sqlite3",
+ importpath = "github.com/mattn/go-sqlite3",
+ commit = "83772a7051f5e30d8e59746a9e43dfa706b72f3b",
+ )
diff --git a/tests/legacy/examples/cgo/example_command/generate_test.bzl b/tests/legacy/examples/cgo/example_command/generate_test.bzl
index af264e9f..53ceee7a 100644
--- a/tests/legacy/examples/cgo/example_command/generate_test.bzl
+++ b/tests/legacy/examples/cgo/example_command/generate_test.bzl
@@ -1,11 +1,11 @@
def _generate_script_impl(ctx):
- script_file = ctx.actions.declare_file(ctx.label.name + ".bash")
- ctx.actions.write(output=script_file, is_executable=True, content="""
+ script_file = ctx.actions.declare_file(ctx.label.name + ".bash")
+ ctx.actions.write(output = script_file, is_executable = True, content = """
{0}
""".format(ctx.file.binary.short_path))
- return struct(
- files = depset([script_file]),
- )
+ return struct(
+ files = depset([script_file]),
+ )
generate_script = rule(
_generate_script_impl,
diff --git a/tests/legacy/race/generate_test.bzl b/tests/legacy/race/generate_test.bzl
index 14cbd246..75f2b20f 100644
--- a/tests/legacy/race/generate_test.bzl
+++ b/tests/legacy/race/generate_test.bzl
@@ -1,6 +1,6 @@
def _generate_script_impl(ctx):
- script_file = ctx.actions.declare_file(ctx.label.name + ".bash")
- ctx.actions.write(output=script_file, is_executable=True, content="""
+ script_file = ctx.actions.declare_file(ctx.label.name + ".bash")
+ ctx.actions.write(output = script_file, is_executable = True, content = """
OUTPUT="$({0} 2>&1)"
if [ $? -eq 0 ]; then
echo success
@@ -15,9 +15,9 @@ if [[ $OUTPUT != *"WARNING: DATA RACE"* ]]; then
fi
exit 0
""".format(ctx.file.binary.short_path))
- return struct(
- files = depset([script_file]),
- )
+ return struct(
+ files = depset([script_file]),
+ )
generate_script = rule(
_generate_script_impl,
diff --git a/tests/legacy/test_chdir/remote.bzl b/tests/legacy/test_chdir/remote.bzl
index 4067ec16..03642fe2 100644
--- a/tests/legacy/test_chdir/remote.bzl
+++ b/tests/legacy/test_chdir/remote.bzl
@@ -1,9 +1,9 @@
def _test_chdir_remote_impl(ctx):
- ctx.file("WORKSPACE", """workspace("test_chdir_remote")""")
- ctx.file("BUILD.bazel", "")
- for f in ["BUILD.bazel", "data_test.go", "data.txt"]:
- input = Label("@io_bazel_rules_go//tests/legacy/test_chdir:{}".format(f))
- ctx.template("sub/" + f, input)
+ ctx.file("WORKSPACE", """workspace("test_chdir_remote")""")
+ ctx.file("BUILD.bazel", "")
+ for f in ["BUILD.bazel", "data_test.go", "data.txt"]:
+ input = Label("@io_bazel_rules_go//tests/legacy/test_chdir:{}".format(f))
+ ctx.template("sub/" + f, input)
_test_chdir_remote = repository_rule(
implementation = _test_chdir_remote_impl,
@@ -11,4 +11,4 @@ _test_chdir_remote = repository_rule(
)
def test_chdir_remote():
- _test_chdir_remote(name="test_chdir_remote") \ No newline at end of file
+ _test_chdir_remote(name = "test_chdir_remote")