Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell: stabilize test_shell_command target type #22016

Merged
merged 6 commits into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ files(
)

# NB: This should be in `lint` when we implement `lint` in https://github.com/pantsbuild/pants/issues/17729
experimental_test_shell_command(
test_shell_command(
name="checks-empty-init-files",
command="""
NONEMPTY_INITS=$(find . -type f -name "*.py" -size +0);
Expand Down
2 changes: 1 addition & 1 deletion docs/notes/2.26.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ A bug in the Django backend has been fixed so that a repo may have no Django app

#### Shell

The `experiemental_test_shell_command` target type learned several new features:
The `experiemental_test_shell_command` target type is no longer experimental and is stabilized as the `test_shell_command` target type. As part of stablilizing it, `test_shell_command` learned several new features:

- It now supports the `test` goal's `--debug` flag to execute tests interactively.
- Outputs may now be captured as test "extra outputs" as specified by the new `output_files`, `output_directories`, `root_output_directory`, and `outputs_match_mode` fields. (These fields operate in the same manner as for the `shell_command` target type.) Captured output will be written in a directory under `dist/` based on the target name when a test completes.
Expand Down
18 changes: 9 additions & 9 deletions src/python/pants/backend/shell/goals/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ def test_basic_usage_of_test_shell_command(rule_runner: RuleRunner) -> None:
output_files=["msg.txt"],
)

experimental_test_shell_command(
test_shell_command(
name="pass",
execution_dependencies=[":msg-gen", ":src"],
tools=["echo"],
command="./test.sh msg.txt message",
)

experimental_test_shell_command(
test_shell_command(
name="fail",
execution_dependencies=[":msg-gen", ":src"],
tools=["echo"],
Expand All @@ -96,7 +96,7 @@ def test_basic_usage_of_test_shell_command(rule_runner: RuleRunner) -> None:
binary_name="test",
fingerprint_args=["1", "=", "1"]
)
experimental_test_shell_command(
test_shell_command(
name="pass_with_runnable_dependency",
execution_dependencies=[":msg-gen", ":src"],
tools=["echo"],
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_extra_outputs_support(rule_runner: RuleRunner) -> None:
"""\
shell_sources(name="src")

experimental_test_shell_command(
test_shell_command(
name="test",
execution_dependencies=[":src"],
tools=["echo", "mkdir"],
Expand Down Expand Up @@ -205,38 +205,38 @@ def test_outputs_match_mode_support(rule_runner: RuleRunner) -> None:
{
"BUILD": dedent(
"""\
experimental_test_shell_command(
test_shell_command(
name="allow_empty",
command="true",
output_files=["non-existent-file"],
output_directories=["non-existent-dir"],
outputs_match_mode="allow_empty",
)
experimental_test_shell_command(
test_shell_command(
name="all_with_present_file",
command="touch some-file",
tools=["touch"],
output_files=["some-file"],
output_directories=["some-directory"],
outputs_match_mode="all",
)
experimental_test_shell_command(
test_shell_command(
name="all_with_present_directory",
command="mkdir some-directory",
tools=["mkdir"],
output_files=["some-file"],
output_directories=["some-directory"],
outputs_match_mode="all",
)
experimental_test_shell_command(
test_shell_command(
name="at_least_one_with_present_file",
command="touch some-file",
tools=["touch"],
output_files=["some-file"],
output_directories=["some-directory"],
outputs_match_mode="at_least_one",
)
experimental_test_shell_command(
test_shell_command(
name="at_least_one_with_present_directory",
command="mkdir some-directory && touch some-directory/foo.txt",
tools=["mkdir", "touch"],
Expand Down
12 changes: 8 additions & 4 deletions src/python/pants/backend/shell/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,11 @@ class ShellCommandRunTarget(Target):


class ShellCommandTestTarget(Target):
alias = "experimental_test_shell_command"
alias = "test_shell_command"

deprecated_alias = "experimental_test_shell_command"
deprecated_alias_removal_version = "2.29.0.dev0"

core_fields = (
*COMMON_TARGET_FIELDS,
ShellCommandTestDependenciesField,
Expand All @@ -512,15 +516,15 @@ class ShellCommandTestTarget(Target):

Example BUILD file:

experimental_test_shell_command(
test_shell_command(
name="test",
tools=["test"],
command="test -r $CHROOT/some-data-file.txt",
execution_dependencies=["src/project/files:data"],
)

The `command` may use either `{chroot}` on the command line, or the `$CHROOT`
environment variable to get the root directory for where any dependencies are located.
The `command` may use the `{chroot}` marker on the command line or in environment variables
to get the root directory where any dependencies are materialized during execution.

In contrast to the `run_shell_command`, this target is intended to run shell commands as tests
and will only run them via the `test` goal.
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ files(
)

# NB: This should be in `lint` when we implement `lint` in https://github.com/pantsbuild/pants/issues/17729
experimental_test_shell_command(
test_shell_command(
name="checks-rust-banned-imports",
command=f"""
BAD_FILES=$(grep -r -l -E "^use std::sync::.*(Mutex|RwLock)" {build_file_dir()});
Expand Down
Loading