From dfe9220fea6f50d0054770e0e439d0cbc907d4b8 Mon Sep 17 00:00:00 2001 From: Jordan Bonser Date: Wed, 26 Feb 2025 11:24:53 +0000 Subject: [PATCH] test(date): add native and pytest date test --- e2e/binary/date/BUILD.bazel | 33 ++++++++++++++++++++++++++------- e2e/binary/date/date.py | 17 +++++++++++++++++ e2e/binary/date/expected.txt | 1 + 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 e2e/binary/date/date.py create mode 100644 e2e/binary/date/expected.txt diff --git a/e2e/binary/date/BUILD.bazel b/e2e/binary/date/BUILD.bazel index cdef4d4c..bcf73292 100644 --- a/e2e/binary/date/BUILD.bazel +++ b/e2e/binary/date/BUILD.bazel @@ -1,11 +1,30 @@ -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 `date` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["date.py"], + data = [ + "expected.txt", + "@ape//ape:date", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "date", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:date"], - visibility = ["//:__subpackages__"], + src = "@ape//ape:date", ) + +test_suite( + name = "date", + tests = [ + "pytest", + "native", + ], + visibility = ["//:__subpackages__"], +) \ No newline at end of file diff --git a/e2e/binary/date/date.py b/e2e/binary/date/date.py new file mode 100644 index 00000000..6613fa46 --- /dev/null +++ b/e2e/binary/date/date.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_date(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("date") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, "+Hello, world") + 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/date/expected.txt b/e2e/binary/date/expected.txt new file mode 100644 index 00000000..a5c19667 --- /dev/null +++ b/e2e/binary/date/expected.txt @@ -0,0 +1 @@ +Hello, world -- GitLab