From e033876828ad3ae134c88ce21df250e8df543ecd Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Mon, 10 Mar 2025 15:52:28 +0000 Subject: [PATCH] test(expand): add native and pytest tests --- e2e/binary/expand/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/expand/expand.py | 18 ++++++++++++++++++ e2e/binary/expand/expected.txt | 1 + e2e/binary/expand/fixture.txt | 1 + 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/expand/expand.py create mode 100644 e2e/binary/expand/expected.txt create mode 100644 e2e/binary/expand/fixture.txt diff --git a/e2e/binary/expand/BUILD.bazel b/e2e/binary/expand/BUILD.bazel index 2a3ea408..f5ff8876 100644 --- a/e2e/binary/expand/BUILD.bazel +++ b/e2e/binary/expand/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 `expand` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["expand.py"], + data = [ + "fixture.txt", + "expected.txt", + "@ape//ape:expand", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "expand", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:expand"], + src = "@ape//ape:expand", + args = ["--version"], +) + +test_suite( + name = "expand", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/expand/expand.py b/e2e/binary/expand/expand.py new file mode 100644 index 00000000..827ed8e2 --- /dev/null +++ b/e2e/binary/expand/expand.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_expand(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("expand") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, fixture) + with open(output, "w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + assert Diff(expected) == Diff(output) diff --git a/e2e/binary/expand/expected.txt b/e2e/binary/expand/expected.txt new file mode 100644 index 00000000..fbb6a06c --- /dev/null +++ b/e2e/binary/expand/expected.txt @@ -0,0 +1 @@ + Tabs To Spaces \ No newline at end of file diff --git a/e2e/binary/expand/fixture.txt b/e2e/binary/expand/fixture.txt new file mode 100644 index 00000000..f47d2291 --- /dev/null +++ b/e2e/binary/expand/fixture.txt @@ -0,0 +1 @@ + Tabs To Spaces \ No newline at end of file -- GitLab