From 14897f7884286b4dcc8ca77e8239c373389fb774 Mon Sep 17 00:00:00 2001 From: Jordan Bonser Date: Wed, 26 Feb 2025 10:11:18 +0000 Subject: [PATCH] test(comm): add native and pytest comm test --- e2e/binary/comm/BUILD.bazel | 36 +++++++++++++++++++++++++++++------- e2e/binary/comm/a.txt | 2 ++ e2e/binary/comm/b.txt | 1 + e2e/binary/comm/comm.py | 19 +++++++++++++++++++ e2e/binary/comm/expected.txt | 1 + 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 e2e/binary/comm/a.txt create mode 100644 e2e/binary/comm/b.txt create mode 100644 e2e/binary/comm/comm.py create mode 100644 e2e/binary/comm/expected.txt diff --git a/e2e/binary/comm/BUILD.bazel b/e2e/binary/comm/BUILD.bazel index c1c3dd56..7b003782 100644 --- a/e2e/binary/comm/BUILD.bazel +++ b/e2e/binary/comm/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 `comm` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["comm.py"], + data = [ + "a.txt", + "b.txt", + "expected.txt", + "@ape//ape:comm", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "comm", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:comm"], - visibility = ["//:__subpackages__"], + src = "@ape//ape:comm", + args = ["--version"], ) + +test_suite( + name = "comm", + tests = [ + "pytest", + "version", + ], + visibility = ["//:__subpackages__"], +) \ No newline at end of file diff --git a/e2e/binary/comm/a.txt b/e2e/binary/comm/a.txt new file mode 100644 index 00000000..0a207c06 --- /dev/null +++ b/e2e/binary/comm/a.txt @@ -0,0 +1,2 @@ +a +b \ No newline at end of file diff --git a/e2e/binary/comm/b.txt b/e2e/binary/comm/b.txt new file mode 100644 index 00000000..63d8dbd4 --- /dev/null +++ b/e2e/binary/comm/b.txt @@ -0,0 +1 @@ +b \ No newline at end of file diff --git a/e2e/binary/comm/comm.py b/e2e/binary/comm/comm.py new file mode 100644 index 00000000..909f0bed --- /dev/null +++ b/e2e/binary/comm/comm.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_comm(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("comm") + a = relative("a.txt") + b = relative("b.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, "-1", "-2", a, b) + 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 diff --git a/e2e/binary/comm/expected.txt b/e2e/binary/comm/expected.txt new file mode 100644 index 00000000..61780798 --- /dev/null +++ b/e2e/binary/comm/expected.txt @@ -0,0 +1 @@ +b -- GitLab