diff --git a/src/python/pants/backend/shell/dependency_inference_test.py b/src/python/pants/backend/shell/dependency_inference_test.py index 76fe2c090e3..1477e81e3f5 100644 --- a/src/python/pants/backend/shell/dependency_inference_test.py +++ b/src/python/pants/backend/shell/dependency_inference_test.py @@ -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 @@ -35,7 +38,7 @@ def rule_runner() -> RuleRunner: QueryRule(ParsedShellImports, [ParseShellImportsRequest]), QueryRule(InferredDependencies, [InferShellDependencies]), ], - target_types=[ShellSourcesGeneratorTarget], + target_types=[ShellSourcesGeneratorTarget, Shunit2TestsGeneratorTarget], ) @@ -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": "", @@ -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( diff --git a/src/python/pants/backend/shell/target_types.py b/src/python/pants/backend/shell/target_types.py index 24c5f88aebc..e158de12be4 100644 --- a/src/python/pants/backend/shell/target_types.py +++ b/src/python/pants/backend/shell/target_types.py @@ -108,7 +108,7 @@ def binary_path_test(self) -> BinaryPathTest | None: return BinaryPathTest((arg,)) -class Shunit2TestDependenciesField(Dependencies): +class Shunit2TestDependenciesField(ShellDependenciesField): supports_transitive_excludes = True @@ -269,8 +269,8 @@ class ShellCommandOutputsField(StringSequenceField): ) -class ShellCommandDependenciesField(Dependencies): - pass +class ShellCommandDependenciesField(ShellDependenciesField): + supports_transitive_excludes = True class ShellCommandSourcesField(MultipleSourcesField):