From d476488f764cd655762e90aad55a39ea5dddeb46 Mon Sep 17 00:00:00 2001 From: tomsht01 Date: Wed, 23 Apr 2025 13:00:33 +0300 Subject: [PATCH] test(yes): add native and pytest tests --- e2e/binary/yes/BUILD.bazel | 32 ++++++++++++++++++++++++++------ e2e/binary/yes/expected.txt | 5 +++++ e2e/binary/yes/yes.py | 22 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/yes/expected.txt create mode 100644 e2e/binary/yes/yes.py diff --git a/e2e/binary/yes/BUILD.bazel b/e2e/binary/yes/BUILD.bazel index e9605cc4..2f2534de 100644 --- a/e2e/binary/yes/BUILD.bazel +++ b/e2e/binary/yes/BUILD.bazel @@ -1,11 +1,31 @@ -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 `yes` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["yes.py"], + data = [ + "@ape//ape:yes", + "expected.txt", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "yes", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:yes"], + src = "@ape//ape:yes", + args = ["--version"], +) + +test_suite( + name = "yes", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/yes/expected.txt b/e2e/binary/yes/expected.txt new file mode 100644 index 00000000..57dc54cc --- /dev/null +++ b/e2e/binary/yes/expected.txt @@ -0,0 +1,5 @@ +y +y +y +y +y diff --git a/e2e/binary/yes/yes.py b/e2e/binary/yes/yes.py new file mode 100644 index 00000000..d34a3c17 --- /dev/null +++ b/e2e/binary/yes/yes.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from subprocess import Popen, PIPE +from pathlib import Path + +from binary import Tool, Relative, Diff + + +def test_yes(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("yes") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + process = Popen(binary, stdout=PIPE, text=True) + + with open(output, "w") as stream: + for i in range(5): + stream.write(process.stdout.readline()) + + process.terminate() + + assert Diff(expected) == Diff(output) -- GitLab