From f270ac14fd757e599aeeda8de4c9227ea5144e47 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 13:59:37 +0100 Subject: [PATCH] test(nl): add native and pytest cases --- e2e/binary/nl/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/nl/expected.txt | 5 +++++ e2e/binary/nl/fixture.txt | 5 +++++ e2e/binary/nl/nolife.py | 19 +++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/nl/expected.txt create mode 100644 e2e/binary/nl/fixture.txt create mode 100644 e2e/binary/nl/nolife.py diff --git a/e2e/binary/nl/BUILD.bazel b/e2e/binary/nl/BUILD.bazel index 542d1d59..1fec296e 100644 --- a/e2e/binary/nl/BUILD.bazel +++ b/e2e/binary/nl/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 `nl` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["nolife.py"], + data = [ + "expected.txt", + "fixture.txt", + "@ape//ape:nl", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "nl", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:nl"], + src = "@ape//ape:nl", + args = ["--version"], +) + +test_suite( + name = "nl", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/nl/expected.txt b/e2e/binary/nl/expected.txt new file mode 100644 index 00000000..7d56bba5 --- /dev/null +++ b/e2e/binary/nl/expected.txt @@ -0,0 +1,5 @@ + 1 /:/:/: + + 2 /:/: + + 3 /: diff --git a/e2e/binary/nl/fixture.txt b/e2e/binary/nl/fixture.txt new file mode 100644 index 00000000..e1a714db --- /dev/null +++ b/e2e/binary/nl/fixture.txt @@ -0,0 +1,5 @@ +/:/:/: + +/:/: + +/: diff --git a/e2e/binary/nl/nolife.py b/e2e/binary/nl/nolife.py new file mode 100644 index 00000000..b4c1bc14 --- /dev/null +++ b/e2e/binary/nl/nolife.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_nl(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("nl") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, fixture) + with output.open("w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + + assert Diff(expected) == Diff(output) -- GitLab