From c674562a18f3e8247238a4e329fc9ba77536c3f8 Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Thu, 6 Mar 2025 12:09:56 +0000 Subject: [PATCH] test(wc): add native and pytest tests --- e2e/binary/wc/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/wc/expected.txt | 1 + e2e/binary/wc/fixture.txt | 4 ++++ e2e/binary/wc/wc.py | 19 +++++++++++++++++++ 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/wc/expected.txt create mode 100644 e2e/binary/wc/fixture.txt create mode 100644 e2e/binary/wc/wc.py diff --git a/e2e/binary/wc/BUILD.bazel b/e2e/binary/wc/BUILD.bazel index 2c6e9581..0d3a5cd0 100644 --- a/e2e/binary/wc/BUILD.bazel +++ b/e2e/binary/wc/BUILD.bazel @@ -1,11 +1,32 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") -# TODO: write an _actual_ test for `wc` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["wc.py"], + data = [ + "fixture.txt", + "expected.txt", + "@ape//ape:wc", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "wc", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:wc"], + src = "@ape//ape:wc", + args = ["--version"], +) + +test_suite( + name = "wc", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/wc/expected.txt b/e2e/binary/wc/expected.txt new file mode 100644 index 00000000..c5fd4833 --- /dev/null +++ b/e2e/binary/wc/expected.txt @@ -0,0 +1 @@ + 4 4 23 diff --git a/e2e/binary/wc/fixture.txt b/e2e/binary/wc/fixture.txt new file mode 100644 index 00000000..ee2ddfb1 --- /dev/null +++ b/e2e/binary/wc/fixture.txt @@ -0,0 +1,4 @@ +Pongo +Gorilla +Pan +Homo diff --git a/e2e/binary/wc/wc.py b/e2e/binary/wc/wc.py new file mode 100644 index 00000000..527584a0 --- /dev/null +++ b/e2e/binary/wc/wc.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_wc(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("wc") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, "-lcw",) + with open(output, "w") as stream, open(fixture, "rb") as stdin: + run(cmd, check=True, timeout=30, stdout=stream, stdin=stdin) + + assert Diff(expected) == Diff(output) -- GitLab