From 08b65e1333abc77a3bac1f05b7c54ce876d25012 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 12:42:17 +0100 Subject: [PATCH] test(tree): add native and pytest cases --- e2e/binary/tree/BUILD.bazel | 34 +++++++++++++++++++++----- e2e/binary/tree/expected.txt | 4 +++ e2e/binary/tree/fixture/nested/two.txt | 0 e2e/binary/tree/fixture/one.txt | 0 e2e/binary/tree/tree.py | 19 ++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/tree/expected.txt create mode 100644 e2e/binary/tree/fixture/nested/two.txt create mode 100644 e2e/binary/tree/fixture/one.txt create mode 100644 e2e/binary/tree/tree.py diff --git a/e2e/binary/tree/BUILD.bazel b/e2e/binary/tree/BUILD.bazel index a8b99296..093f88b0 100644 --- a/e2e/binary/tree/BUILD.bazel +++ b/e2e/binary/tree/BUILD.bazel @@ -1,11 +1,33 @@ -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 `tree` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["tree.py"], + data = [ + "expected.txt", + "fixture/nested/two.txt", + "fixture/one.txt", + "@ape//ape:tree", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "tree", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:tree"], + src = "@ape//ape:tree", + args = ["--version"], +) + +test_suite( + name = "tree", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/tree/expected.txt b/e2e/binary/tree/expected.txt new file mode 100644 index 00000000..773fefeb --- /dev/null +++ b/e2e/binary/tree/expected.txt @@ -0,0 +1,4 @@ +fixture +└── nested + +2 directories diff --git a/e2e/binary/tree/fixture/nested/two.txt b/e2e/binary/tree/fixture/nested/two.txt new file mode 100644 index 00000000..e69de29b diff --git a/e2e/binary/tree/fixture/one.txt b/e2e/binary/tree/fixture/one.txt new file mode 100644 index 00000000..e69de29b diff --git a/e2e/binary/tree/tree.py b/e2e/binary/tree/tree.py new file mode 100644 index 00000000..3fee4d4c --- /dev/null +++ b/e2e/binary/tree/tree.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_copy(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("tree") + fixture = relative("fixture") + expected = relative("expected.txt") + output = tmp_path / "output" + + cmd = (binary, "-d", fixture.name) + with output.open("w") as stream: + run(cmd, check=True, timeout=30, stdout=stream, cwd=fixture.parent) + + assert Diff(expected) == Diff(output) -- GitLab