Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
x0f0 authored Oct 1, 2024
2 parents 9720e73 + 533a88f commit f21768b
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 78 deletions.
4 changes: 4 additions & 0 deletions docs/notes/2.24.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Pants will now warn if any errors are encountered while fingerprinting candidate

Added a new `cache_scope` field to `adhoc_tool` and `shell_command` targets to allow configuration of the "cache scope" of the invoked process. The cache scope determines how long Pants will cache the result of the invoked process absent any other invalidation of the result via source or dependency changes.

#### Go

Fix a bug where Pants raised an internal exception which occurred when compiling a Go package with coverage support when the package also had an external test which imported the base package.

### Plugin API changes

The `path_metadata_request` intrinsic rule can now access metadata for paths in the local system outside of the build root. Use the new `namespace` field on `PathMetadataRequest` to request metdata on local system paths using namespace `PathNamespace.SYSTEM`.
Expand Down
42 changes: 42 additions & 0 deletions src/python/pants/backend/go/goals/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,45 @@ def test_profile_options_write_results(rule_runner: RuleRunner) -> None:
"test_runner",
"trace.out",
]


def test_external_test_with_use_coverage(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
"foo/BUILD": "go_mod(name='mod')\ngo_package()",
"foo/go.mod": "module foo",
"foo/add.go": textwrap.dedent(
"""
package foo
func Add(x, y int) int {
return x + y
}
"""
),
"foo/add_test.go": textwrap.dedent(
"""
package foo_test
import (
"foo"
"testing"
)
func TestAdd(t *testing.T) {
if foo.Add(2, 3) != 5 {
t.Fail()
}
}
"""
),
}
)
tgt = rule_runner.get_target(Address("foo", generated_name="./"))
rule_runner.set_options(
[
"--test-use-coverage",
],
env_inherit={"PATH"},
)
result = rule_runner.request(
TestResult, [GoTestRequest.Batch("", (GoTestFieldSet.create(tgt),), None)]
)
assert result.exit_code == 0
5 changes: 4 additions & 1 deletion src/python/pants/backend/go/util_rules/build_pkg_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ async def setup_build_go_package_target_request(
maybe_base_pkg_dep = await Get(
FallibleBuildGoPackageRequest,
BuildGoPackageTargetRequest(
request.address, for_tests=True, build_opts=request.build_opts
request.address,
for_tests=True,
with_coverage=request.with_coverage,
build_opts=request.build_opts,
),
)
if maybe_base_pkg_dep.request is None:
Expand Down
Loading

0 comments on commit f21768b

Please sign in to comment.