Skip to content

Commit

Permalink
Fix dep inference from shuint2_tests targets. (#17417)
Browse files Browse the repository at this point in the history
Fixes #16949
  • Loading branch information
benjyw authored Nov 1, 2022
1 parent 7eb4180 commit 954f080
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/python/pants/backend/shell/dependency_inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
ShellDependenciesInferenceFieldSet,
ShellMapping,
)
from pants.backend.shell.target_types import ShellSourcesGeneratorTarget
from pants.backend.shell.target_types import (
ShellSourcesGeneratorTarget,
Shunit2TestsGeneratorTarget,
)
from pants.backend.shell.target_types import rules as target_types_rules
from pants.core.util_rules import external_tool
from pants.engine.addresses import Address
Expand All @@ -35,7 +38,7 @@ def rule_runner() -> RuleRunner:
QueryRule(ParsedShellImports, [ParseShellImportsRequest]),
QueryRule(InferredDependencies, [InferShellDependencies]),
],
target_types=[ShellSourcesGeneratorTarget],
target_types=[ShellSourcesGeneratorTarget, Shunit2TestsGeneratorTarget],
)


Expand Down Expand Up @@ -104,7 +107,8 @@ def test_dependency_inference(rule_runner: RuleRunner, caplog) -> None:
"a/f2.sh": "source a/f1.sh",
"a/BUILD": "shell_sources()",
"b/f.sh": "",
"b/BUILD": "shell_sources()",
"b/f_test.sh": "source b/f.sh",
"b/BUILD": "shell_sources()\nshunit2_tests(name='tests', shell='bash')",
# Test handling of ambiguous imports. We should warn on the ambiguous dependency, but
# not warn on the disambiguated one and should infer a dep.
"ambiguous/dep.sh": "",
Expand Down Expand Up @@ -139,6 +143,9 @@ def run_dep_inference(address: Address) -> InferredDependencies:
assert run_dep_inference(Address("a", relative_file_path="f1.sh")) == InferredDependencies(
[Address("b", relative_file_path="f.sh")]
)
assert run_dep_inference(
Address("b", target_name="tests", relative_file_path="f_test.sh")
) == InferredDependencies([Address("b", relative_file_path="f.sh")])

caplog.clear()
assert run_dep_inference(
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/shell/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def binary_path_test(self) -> BinaryPathTest | None:
return BinaryPathTest((arg,))


class Shunit2TestDependenciesField(Dependencies):
class Shunit2TestDependenciesField(ShellDependenciesField):
supports_transitive_excludes = True


Expand Down Expand Up @@ -269,8 +269,8 @@ class ShellCommandOutputsField(StringSequenceField):
)


class ShellCommandDependenciesField(Dependencies):
pass
class ShellCommandDependenciesField(ShellDependenciesField):
supports_transitive_excludes = True


class ShellCommandSourcesField(MultipleSourcesField):
Expand Down

0 comments on commit 954f080

Please sign in to comment.