From 7138a56caaff63f272167159ae042058db4ba7ca Mon Sep 17 00:00:00 2001 From: Jordan Bonser Date: Fri, 28 Feb 2025 15:50:00 +0000 Subject: [PATCH] test(expr): add native and pytest expr test --- e2e/binary/expr/BUILD.bazel | 34 +++++++++++++++++++++++++++------- e2e/binary/expr/expected.txt | 1 + e2e/binary/expr/expr.py | 17 +++++++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 e2e/binary/expr/expected.txt create mode 100644 e2e/binary/expr/expr.py diff --git a/e2e/binary/expr/BUILD.bazel b/e2e/binary/expr/BUILD.bazel index 15ab8165..7779b16b 100644 --- a/e2e/binary/expr/BUILD.bazel +++ b/e2e/binary/expr/BUILD.bazel @@ -1,11 +1,31 @@ -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 `expr` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["expr.py"], + data = [ + "expected.txt", + "@ape//ape:expr", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "expr", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:expr"], - visibility = ["//:__subpackages__"], + src = "@ape//ape:expr", + args = ["1", "+", "2"] ) + +test_suite( + name = "expr", + tests = [ + "pytest", + "native", + ], + visibility = ["//:__subpackages__"], +) \ No newline at end of file diff --git a/e2e/binary/expr/expected.txt b/e2e/binary/expr/expected.txt new file mode 100644 index 00000000..00750edc --- /dev/null +++ b/e2e/binary/expr/expected.txt @@ -0,0 +1 @@ +3 diff --git a/e2e/binary/expr/expr.py b/e2e/binary/expr/expr.py new file mode 100644 index 00000000..e7a37537 --- /dev/null +++ b/e2e/binary/expr/expr.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Diff, Relative, Tool + + +def test_expr(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("expr") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, "1", "+", "2") + with open(output, "w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + assert Diff(expected) == Diff(output) \ No newline at end of file -- GitLab