From 94ae494bb689d5b22055e94d4ef5b09055f6c55c Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 12:20:38 +0100 Subject: [PATCH 1/5] test(printenv): add native and pytest cases --- e2e/binary/printenv/BUILD.bazel | 31 +++++++++++++++++++++++++------ e2e/binary/printenv/print.py | 15 +++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/printenv/print.py diff --git a/e2e/binary/printenv/BUILD.bazel b/e2e/binary/printenv/BUILD.bazel index c4c3e7e3..0110dc89 100644 --- a/e2e/binary/printenv/BUILD.bazel +++ b/e2e/binary/printenv/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 `printenv` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["print.py"], + data = [ + "@ape//ape:printenv", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "printenv", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:printenv"], + src = "@ape//ape:printenv", + args = ["--version"], +) + +test_suite( + name = "printenv", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/printenv/print.py b/e2e/binary/printenv/print.py new file mode 100644 index 00000000..87a9569d --- /dev/null +++ b/e2e/binary/printenv/print.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from subprocess import run + +from binary import Tool + + +def test_copy(tool: Tool) -> None: + binary = tool("printenv") + + cmd = (binary,) + env = {"TEST": "1"} + r = run(cmd, timeout=30, capture_output=True, text=True, env=env) + assert r.returncode == 0 + assert r.stdout.rstrip() == "TEST=1" -- GitLab From f538bf14fb772552fedb26bd4a53e39f17b5d29d Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 12:21:24 +0100 Subject: [PATCH 2/5] test(kill): remove reallocation of `tool` variable --- e2e/binary/kill/grim.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/binary/kill/grim.py b/e2e/binary/kill/grim.py index 684c3aa3..a9abe5f5 100644 --- a/e2e/binary/kill/grim.py +++ b/e2e/binary/kill/grim.py @@ -7,11 +7,11 @@ from binary import Tool def test_kill(tool: Tool) -> None: - tool = tool("kill") + binary = tool("kill") process = Popen((executable, "-c", "from time import sleep; sleep(5)")) - run((tool, f"{process.pid}"), check=True) + run((binary, f"{process.pid}"), check=True) try: process.wait(timeout=1) -- GitLab From ce3c13bcdbc4576661221b081c1698ed67a5368c Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 12:21:44 +0100 Subject: [PATCH 3/5] test(lua): remove reallocation of `tool` variable --- e2e/binary/lua/lua.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/binary/lua/lua.py b/e2e/binary/lua/lua.py index 567fc24b..66a45694 100644 --- a/e2e/binary/lua/lua.py +++ b/e2e/binary/lua/lua.py @@ -7,12 +7,12 @@ from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: - tool = tool("lua") + binary = tool("lua") fixture = relative("fixture.lua") expected = relative("expected.txt") output = tmp_path / "output.txt" - cmd = (tool, fixture) + cmd = (binary, fixture) with open(output, "w") as stream: run(cmd, check=True, stdout=stream) -- GitLab From d0757148a8bb6e453cba9f3b10bdd928270059a5 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 12:22:07 +0100 Subject: [PATCH 4/5] test(numfmt): remove reallocation of `tool` variable --- e2e/binary/numfmt/format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/binary/numfmt/format.py b/e2e/binary/numfmt/format.py index 24020110..05925116 100644 --- a/e2e/binary/numfmt/format.py +++ b/e2e/binary/numfmt/format.py @@ -6,8 +6,8 @@ from binary import Tool def test_format(tool: Tool) -> None: - tool = tool("numfmt") - cmd = (tool, "--to=si", "1000") + binary = tool("numfmt") + cmd = (binary, "--to=si", "1000") r = run(cmd, stdout=PIPE, encoding="utf8") assert r.returncode == 0, r.stdout assert r.stdout.rstrip() == "1.0K" -- GitLab From 60c615517201b9ad41d231f97d7eebe6c8ccd1b1 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 12:22:35 +0100 Subject: [PATCH 5/5] test(od): remove reallocation of `tool` variable --- e2e/binary/od/convert.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/binary/od/convert.py b/e2e/binary/od/convert.py index 8192ab38..338c08f1 100644 --- a/e2e/binary/od/convert.py +++ b/e2e/binary/od/convert.py @@ -7,12 +7,12 @@ from binary import Diff, Relative, Tool def test_convert(tool: Tool, relative: Relative, tmp_path: Path) -> None: - tool = tool("od") + binary = tool("od") fixture = relative("fixture.txt") expected = relative("expected.txt") output = tmp_path / "output.txt" - cmd = (tool, f"{fixture}") + cmd = (binary, f"{fixture}") with output.open("w") as stream: run(cmd, check=True, stdout=stream) -- GitLab