From e063bd9ca09a8b217f168eb3dabcb669c444a4b7 Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Tue, 4 Mar 2025 12:36:08 +0000 Subject: [PATCH] test(uniq): add native and pytest tests --- e2e/binary/uniq/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/uniq/expected.txt | 1 + e2e/binary/uniq/fixture.txt | 6 ++++++ e2e/binary/uniq/unique.py | 18 ++++++++++++++++++ 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/uniq/expected.txt create mode 100644 e2e/binary/uniq/fixture.txt create mode 100644 e2e/binary/uniq/unique.py diff --git a/e2e/binary/uniq/BUILD.bazel b/e2e/binary/uniq/BUILD.bazel index ea2512a8..307d2b5a 100644 --- a/e2e/binary/uniq/BUILD.bazel +++ b/e2e/binary/uniq/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 `uniq` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["unique.py"], + data = [ + "fixture.txt", + "expected.txt", + "@ape//ape:uniq", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "uniq", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:uniq"], + src = "@ape//ape:uniq", + args = ["--version"], +) + +test_suite( + name = "uniq", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/uniq/expected.txt b/e2e/binary/uniq/expected.txt new file mode 100644 index 00000000..6ead505f --- /dev/null +++ b/e2e/binary/uniq/expected.txt @@ -0,0 +1 @@ +I am unique diff --git a/e2e/binary/uniq/fixture.txt b/e2e/binary/uniq/fixture.txt new file mode 100644 index 00000000..95fd729d --- /dev/null +++ b/e2e/binary/uniq/fixture.txt @@ -0,0 +1,6 @@ +Remove me twice +Remove me twice +I am unique +Remove me thrice +Remove me thrice +Remove me thrice \ No newline at end of file diff --git a/e2e/binary/uniq/unique.py b/e2e/binary/uniq/unique.py new file mode 100644 index 00000000..6c6acea6 --- /dev/null +++ b/e2e/binary/uniq/unique.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Diff, Relative, Tool + + +def test_concatenate(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("uniq") + expected = relative("expected.txt") + fixture = relative("fixture.txt") + output = tmp_path / "output.txt" + + cmd = (binary, fixture, "-u") + with open(output, "w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + assert Diff(expected) == Diff(output) -- GitLab