From 38b348c2249ada760829c9249919fc9eb8efbe0d Mon Sep 17 00:00:00 2001 From: tomsht01 Date: Sun, 9 Mar 2025 12:18:28 +0200 Subject: [PATCH] test(bc): add native and pytest tests --- e2e/binary/bc/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/bc/calculate.py | 19 +++++++++++++++++++ e2e/binary/bc/expected.txt | 1 + e2e/binary/bc/fixture.txt | 1 + 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/bc/calculate.py create mode 100644 e2e/binary/bc/expected.txt create mode 100644 e2e/binary/bc/fixture.txt diff --git a/e2e/binary/bc/BUILD.bazel b/e2e/binary/bc/BUILD.bazel index a8f7850e..6d937132 100644 --- a/e2e/binary/bc/BUILD.bazel +++ b/e2e/binary/bc/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 `bc` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["calculate.py"], + data = [ + "@ape//ape:bc", + "fixture.txt", + "expected.txt", + ], + deps = [ + "//binary:pytest" + ], +) -build_test( - name = "bc", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:bc"], + src = "@ape//ape:bc", + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "bc", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/bc/calculate.py b/e2e/binary/bc/calculate.py new file mode 100644 index 00000000..a08c23c5 --- /dev/null +++ b/e2e/binary/bc/calculate.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Tool, Relative, Diff + + +def test_copy(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("bc") + 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/bc/expected.txt b/e2e/binary/bc/expected.txt new file mode 100644 index 00000000..60d3b2f4 --- /dev/null +++ b/e2e/binary/bc/expected.txt @@ -0,0 +1 @@ +15 diff --git a/e2e/binary/bc/fixture.txt b/e2e/binary/bc/fixture.txt new file mode 100644 index 00000000..701bda20 --- /dev/null +++ b/e2e/binary/bc/fixture.txt @@ -0,0 +1 @@ +5 + 10 -- GitLab