From 73c9fb9b58ec46b1c94719da980d1622a427d503 Mon Sep 17 00:00:00 2001 From: Jordan Bonser Date: Wed, 26 Feb 2025 11:51:05 +0000 Subject: [PATCH] test(dir): add native and pytest dir test --- e2e/binary/dir/BUILD.bazel | 33 ++++++++++++++++++++++++++------- e2e/binary/dir/dir.py | 17 +++++++++++++++++ e2e/binary/dir/expected.txt | 1 + 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 e2e/binary/dir/dir.py create mode 100644 e2e/binary/dir/expected.txt diff --git a/e2e/binary/dir/BUILD.bazel b/e2e/binary/dir/BUILD.bazel index 3249d822..bddf96c4 100644 --- a/e2e/binary/dir/BUILD.bazel +++ b/e2e/binary/dir/BUILD.bazel @@ -1,11 +1,30 @@ -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 `dir` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["dir.py"], + data = [ + "expected.txt", + "@ape//ape:dir", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "dir", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:dir"], - visibility = ["//:__subpackages__"], + src = "@ape//ape:dir", ) + +test_suite( + name = "dir", + tests = [ + "pytest", + "native", + ], + visibility = ["//:__subpackages__"], +) \ No newline at end of file diff --git a/e2e/binary/dir/dir.py b/e2e/binary/dir/dir.py new file mode 100644 index 00000000..1f060e31 --- /dev/null +++ b/e2e/binary/dir/dir.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Relative, Tool, Diff + + +def test_dir(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("dir") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, tmp_path) + with open(output, "w", encoding="utf-8") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + assert Diff(expected) == Diff(output) diff --git a/e2e/binary/dir/expected.txt b/e2e/binary/dir/expected.txt new file mode 100644 index 00000000..8617481f --- /dev/null +++ b/e2e/binary/dir/expected.txt @@ -0,0 +1 @@ +output.txt -- GitLab