From 539f521138299eceb6fbc5ca4fa8946f237f7989 Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Fri, 28 Feb 2025 15:47:11 +0000 Subject: [PATCH] test(split): add native and pytest tests for split --- e2e/binary/split/BUILD.bazel | 34 +++++++++++++++++++++++++------ e2e/binary/split/fixture.txt | 4 ++++ e2e/binary/split/split.py | 21 +++++++++++++++++++ e2e/binary/split/xaa.expected.txt | 2 ++ e2e/binary/split/xab.expected.txt | 2 ++ 5 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/split/fixture.txt create mode 100644 e2e/binary/split/split.py create mode 100644 e2e/binary/split/xaa.expected.txt create mode 100644 e2e/binary/split/xab.expected.txt diff --git a/e2e/binary/split/BUILD.bazel b/e2e/binary/split/BUILD.bazel index d8e53274..17642eab 100644 --- a/e2e/binary/split/BUILD.bazel +++ b/e2e/binary/split/BUILD.bazel @@ -1,11 +1,33 @@ -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 `split` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["split.py"], + data = [ + "xaa.expected.txt", + "xab.expected.txt", + "fixture.txt", + "@ape//ape:split", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "split", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:split"], + src = "@ape//ape:split", + args = ["--version"], +) + +test_suite( + name = "split", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/split/fixture.txt b/e2e/binary/split/fixture.txt new file mode 100644 index 00000000..ee2ddfb1 --- /dev/null +++ b/e2e/binary/split/fixture.txt @@ -0,0 +1,4 @@ +Pongo +Gorilla +Pan +Homo diff --git a/e2e/binary/split/split.py b/e2e/binary/split/split.py new file mode 100644 index 00000000..bec4086b --- /dev/null +++ b/e2e/binary/split/split.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from subprocess import run +from pathlib import Path + +from binary import Diff, Relative, Tool + + +def test_split(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("split") + fixture = Path.cwd() / relative("fixture.txt") + output_map = { + tmp_path / "xaa": relative("xaa.expected.txt"), + tmp_path / "xab": relative("xab.expected.txt"), + } + + cmd = (binary, '-l', '2', fixture,) + run(cmd, check=True, timeout=30, cwd=tmp_path,) + + for output, expected in output_map.items(): + assert Diff(expected) == Diff(output) diff --git a/e2e/binary/split/xaa.expected.txt b/e2e/binary/split/xaa.expected.txt new file mode 100644 index 00000000..13bbd603 --- /dev/null +++ b/e2e/binary/split/xaa.expected.txt @@ -0,0 +1,2 @@ +Pongo +Gorilla diff --git a/e2e/binary/split/xab.expected.txt b/e2e/binary/split/xab.expected.txt new file mode 100644 index 00000000..eb489a27 --- /dev/null +++ b/e2e/binary/split/xab.expected.txt @@ -0,0 +1,2 @@ +Pan +Homo -- GitLab