From 382d1f6837c6d38d1f931dc5b55eb4981c1ccf11 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 4 Jun 2025 14:14:43 +0100 Subject: [PATCH] test: add `od` convert and version cases --- e2e/binary/od/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/od/convert.py | 19 +++++++++++++++++++ e2e/binary/od/expected.txt | 2 ++ e2e/binary/od/fixture.txt | 1 + 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/od/convert.py create mode 100644 e2e/binary/od/expected.txt create mode 100644 e2e/binary/od/fixture.txt diff --git a/e2e/binary/od/BUILD.bazel b/e2e/binary/od/BUILD.bazel index 09a1c195..0803db05 100644 --- a/e2e/binary/od/BUILD.bazel +++ b/e2e/binary/od/BUILD.bazel @@ -1,11 +1,32 @@ -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 `od` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["convert.py"], + data = [ + "expected.txt", + "fixture.txt", + "@ape//ape:od", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "od", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:od"], + src = "@ape//ape:od", + args = ["--version"], +) + +test_suite( + name = "od", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/od/convert.py b/e2e/binary/od/convert.py new file mode 100644 index 00000000..8192ab38 --- /dev/null +++ b/e2e/binary/od/convert.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Diff, Relative, Tool + + +def test_convert(tool: Tool, relative: Relative, tmp_path: Path) -> None: + tool = tool("od") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (tool, f"{fixture}") + with output.open("w") as stream: + run(cmd, check=True, stdout=stream) + + assert Diff(expected) == Diff(output) diff --git a/e2e/binary/od/expected.txt b/e2e/binary/od/expected.txt new file mode 100644 index 00000000..99419798 --- /dev/null +++ b/e2e/binary/od/expected.txt @@ -0,0 +1,2 @@ +0000000 062510 066154 026157 073440 071157 062154 005041 +0000016 diff --git a/e2e/binary/od/fixture.txt b/e2e/binary/od/fixture.txt new file mode 100644 index 00000000..af5626b4 --- /dev/null +++ b/e2e/binary/od/fixture.txt @@ -0,0 +1 @@ +Hello, world! -- GitLab