From e7fef985112c213884ef9a320cdc292f4af7be7b Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Thu, 6 Mar 2025 12:17:46 +0000 Subject: [PATCH] test(tsort): add native and pytest tests --- e2e/binary/tsort/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/tsort/expected.txt | 8 ++++++++ e2e/binary/tsort/fixture.txt | 9 +++++++++ e2e/binary/tsort/tsort.py | 19 +++++++++++++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/tsort/expected.txt create mode 100644 e2e/binary/tsort/fixture.txt create mode 100644 e2e/binary/tsort/tsort.py diff --git a/e2e/binary/tsort/BUILD.bazel b/e2e/binary/tsort/BUILD.bazel index 85d14ce9..b118cd63 100644 --- a/e2e/binary/tsort/BUILD.bazel +++ b/e2e/binary/tsort/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 `tsort` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["tsort.py"], + data = [ + "fixture.txt", + "expected.txt", + "@ape//ape:tsort", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "tsort", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:tsort"], + src = "@ape//ape:tsort", + args = ["--version"], +) + +test_suite( + name = "tsort", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/tsort/expected.txt b/e2e/binary/tsort/expected.txt new file mode 100644 index 00000000..00f76ca5 --- /dev/null +++ b/e2e/binary/tsort/expected.txt @@ -0,0 +1,8 @@ +3 +5 +7 +11 +8 +10 +2 +9 diff --git a/e2e/binary/tsort/fixture.txt b/e2e/binary/tsort/fixture.txt new file mode 100644 index 00000000..46ad26c3 --- /dev/null +++ b/e2e/binary/tsort/fixture.txt @@ -0,0 +1,9 @@ +3 8 +3 10 +5 11 +7 8 +7 11 +8 9 +11 2 +11 9 +11 10 diff --git a/e2e/binary/tsort/tsort.py b/e2e/binary/tsort/tsort.py new file mode 100644 index 00000000..7aaf8bec --- /dev/null +++ b/e2e/binary/tsort/tsort.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_tsort(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("tsort") + 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) -- GitLab