Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 11, 2023
1 parent 7d4c28c commit adae354
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/go/core/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ This builds a set of tests that can be run with `bazel test`.<br><br>
| <a id="go_test-msan"></a>msan | Controls whether code is instrumented for memory sanitization. May be one of <code>on</code>, <code>off</code>, or <code>auto</code>. Not available when cgo is disabled. In most cases, it's better to control this on the command line with <code>--@io_bazel_rules_go//go/config:msan</code>. See [mode attributes], specifically [msan]. | String | optional | "auto" |
| <a id="go_test-pure"></a>pure | Controls whether cgo source code and dependencies are compiled and linked, similar to setting <code>CGO_ENABLED</code>. May be one of <code>on</code>, <code>off</code>, or <code>auto</code>. If <code>auto</code>, pure mode is enabled when no C/C++ toolchain is configured or when cross-compiling. It's usually better to control this on the command line with <code>--@io_bazel_rules_go//go/config:pure</code>. See [mode attributes], specifically [pure]. | String | optional | "auto" |
| <a id="go_test-race"></a>race | Controls whether code is instrumented for race detection. May be one of <code>on</code>, <code>off</code>, or <code>auto</code>. Not available when cgo is disabled. In most cases, it's better to control this on the command line with <code>--@io_bazel_rules_go//go/config:race</code>. See [mode attributes], specifically [race]. | String | optional | "auto" |
| <a id="go_test-rundir"></a>rundir | A directory to cd to before the test is run. This should be a path relative to the subdirectory of the runfiles directory corresponding to the test's repository.<br><br> The default behaviour is to change to the relative path corresponding to the test's package, which replicates the normal behaviour of <code>go test</code> so it is easy to write compatible tests.<br><br> Setting it to <code>.</code> makes the test behave the normal way for a bazel test, except that the working directory is always that of the test's repository, which is not necessarily the main repository.<br><br> Note: If runfile symlinks are disabled (such as on Windows by default), the test will run in the working directory set by Bazel, which is the subdirectory of the runfiles directory corresponding to the main repository. | String | optional | "" |
| <a id="go_test-rundir"></a>rundir | A directory to cd to before the test is run. This should be a path relative to the root directory of the repository in which the test is defined, which can be the main or an external repository.<br><br> The default behaviour is to change to the relative path corresponding to the test's package, which replicates the normal behaviour of <code>go test</code> so it is easy to write compatible tests.<br><br> Setting it to <code>.</code> makes the test behave the normal way for a bazel test, except that the working directory is always that of the test's repository, which is not necessarily the main repository.<br><br> Note: If runfile symlinks are disabled (such as on Windows by default), the test will run in the working directory set by Bazel, which is the subdirectory of the runfiles directory corresponding to the main repository. | String | optional | "" |
| <a id="go_test-srcs"></a>srcs | The list of Go source files that are compiled to create the package. Only <code>.go</code> and <code>.s</code> files are permitted, unless the <code>cgo</code> attribute is set, in which case, <code>.c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm</code> files are also permitted. Files may be filtered at build time using Go [build constraints]. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="go_test-static"></a>static | Controls whether a binary is statically linked. May be one of <code>on</code>, <code>off</code>, or <code>auto</code>. Not available on all platforms or in all modes. It's usually better to control this on the command line with <code>--@io_bazel_rules_go//go/config:static</code>. See [mode attributes], specifically [static]. | String | optional | "auto" |
| <a id="go_test-x_defs"></a>x_defs | Map of defines to add to the go link command. See [Defines and stamping] for examples of how to use these. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
Expand Down
11 changes: 7 additions & 4 deletions go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def _go_test_impl(ctx):
# now generate the main function
repo_relative_rundir = ctx.attr.rundir or ctx.label.package or "."
if ctx.label.workspace_name:
# The test is contained in an external repository. The test runner cd's into the directory
# corresponding to the main repository, so walk up and then down.
# The test is contained in an external repository (Label.workspace_name is always the empty
# string for the main repository, which is the canonical repository name of this repo).
# The test runner cd's into the directory corresponding to the main repository, so walk up
# and then down.
run_dir = "../" + ctx.label.workspace_name + "/" + repo_relative_rundir
else:
run_dir = repo_relative_rundir
Expand Down Expand Up @@ -261,8 +263,9 @@ _go_test_kwargs = {
),
"rundir": attr.string(
doc = """ A directory to cd to before the test is run.
This should be a path relative to the subdirectory of the runfiles
directory corresponding to the test's repository.
This should be a path relative to the root directory of the
repository in which the test is defined, which can be the main or an
external repository.
The default behaviour is to change to the relative path
corresponding to the test's package, which replicates the normal
Expand Down

0 comments on commit adae354

Please sign in to comment.