From 976ea81f73d3d23d65403c9b9223fc65d40b088d Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 10:09:02 +0100 Subject: [PATCH] test(kill): add native and pytest tests --- e2e/binary/kill/BUILD.bazel | 31 +++++++++++++++++++++++++------ e2e/binary/kill/grim.py | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/kill/grim.py diff --git a/e2e/binary/kill/BUILD.bazel b/e2e/binary/kill/BUILD.bazel index 981e5cd8..a24cbe60 100644 --- a/e2e/binary/kill/BUILD.bazel +++ b/e2e/binary/kill/BUILD.bazel @@ -1,11 +1,30 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `kill` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["grim.py"], + data = [ + "@ape//ape:kill", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "kill", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:kill"], + src = "@ape//ape:kill", + args = ["--version"], +) + +test_suite( + name = "kill", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/kill/grim.py b/e2e/binary/kill/grim.py new file mode 100644 index 00000000..684c3aa3 --- /dev/null +++ b/e2e/binary/kill/grim.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from subprocess import Popen, TimeoutExpired, run +from sys import executable + +from binary import Tool + + +def test_kill(tool: Tool) -> None: + tool = tool("kill") + + process = Popen((executable, "-c", "from time import sleep; sleep(5)")) + + run((tool, f"{process.pid}"), check=True) + + try: + process.wait(timeout=1) + except TimeoutExpired: + process.terminate() -- GitLab