From 9606d0b3a27d0785fcf29c26abcfcc4ed5923e75 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 5 Jun 2025 14:09:22 +0100 Subject: [PATCH] test(php): add native and pytest cases --- e2e/binary/php/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/php/hello.php | 3 +++ e2e/binary/php/php.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/php/hello.php create mode 100644 e2e/binary/php/php.py diff --git a/e2e/binary/php/BUILD.bazel b/e2e/binary/php/BUILD.bazel index 50a61e0c..2e64b9f9 100644 --- a/e2e/binary/php/BUILD.bazel +++ b/e2e/binary/php/BUILD.bazel @@ -1,11 +1,32 @@ -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 `php` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["php.py"], + data = [ + "hello.php", + "@ape//ape:php", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "php", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:php"], + src = "@ape//ape:php", + args = ["-v"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "php", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/php/hello.php b/e2e/binary/php/hello.php new file mode 100644 index 00000000..6b3ad3e1 --- /dev/null +++ b/e2e/binary/php/hello.php @@ -0,0 +1,3 @@ + diff --git a/e2e/binary/php/php.py b/e2e/binary/php/php.py new file mode 100644 index 00000000..14e1398c --- /dev/null +++ b/e2e/binary/php/php.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from subprocess import PIPE, run + +from binary import Relative, Tool + + +def test_script(tool: Tool, relative: Relative) -> None: + binary = tool("php") + hello = relative("hello.php") + + cmd = (binary, hello) + r = run(cmd, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode, r.stdout + assert "Hello, world!" == r.stdout + + +def test_command(tool: Tool) -> None: + binary = tool("php") + + cmd = ( + binary, + "-r", + "echo 'Hello, world!';", + ) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode, r.stdout + assert "Hello, world!" == r.stdout -- GitLab