From ef0e2eacf0365f8e4a587323cc6ca96d22dd7d37 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 3 Mar 2026 14:13:49 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Check=20for=20PHP=20prerequisite=20?= =?UTF-8?q?for=20some=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/Commands/CommandTest.swift | 5 +---- tests/unit/Conditions/Binaries.swift | 7 +++++++ .../unit/Testables/Shell/RealShellTest.swift | 21 ++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/unit/Commands/CommandTest.swift b/tests/unit/Commands/CommandTest.swift index 353cfeb3..0b96857a 100644 --- a/tests/unit/Commands/CommandTest.swift +++ b/tests/unit/Commands/CommandTest.swift @@ -10,10 +10,7 @@ import Testing import Foundation struct CommandTest { - @Test(.enabled(if: Binaries.exist(paths: [ - "/opt/homebrew/bin/php", - "/usr/local/bin/php" - ]), "Requires PHP binary")) + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) func determinePhpVersion() { let container = Container.real(minimal: true) diff --git a/tests/unit/Conditions/Binaries.swift b/tests/unit/Conditions/Binaries.swift index 79be5f0e..0ad11000 100644 --- a/tests/unit/Conditions/Binaries.swift +++ b/tests/unit/Conditions/Binaries.swift @@ -16,4 +16,11 @@ class Binaries { return false } + + static func hasLinkedPhp() -> Bool { + return Binaries.exist(paths: [ + "/opt/homebrew/bin/php", + "/usr/local/bin/php" + ]) + } } diff --git a/tests/unit/Testables/Shell/RealShellTest.swift b/tests/unit/Testables/Shell/RealShellTest.swift index 30dbcec9..665ae6e3 100644 --- a/tests/unit/Testables/Shell/RealShellTest.swift +++ b/tests/unit/Testables/Shell/RealShellTest.swift @@ -17,7 +17,8 @@ struct RealShellTest { container = Container.real(minimal: true, commandTracking: false) } - @Test func system_shell_is_default() async { + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) + func system_shell_is_default() async { #expect(container.shell is RealShell) let output = await container.shell.pipe("php -v") @@ -25,7 +26,8 @@ struct RealShellTest { #expect(output.out.contains("Copyright (c) The PHP Group")) } - @Test func system_shell_can_be_used_synchronously() { + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) + func system_shell_can_be_used_synchronously() { #expect(container.shell is RealShell) let output = container.shell.sync("php -v") @@ -40,7 +42,8 @@ struct RealShellTest { #expect(systemShell.PATH.contains(":/usr/bin")) } - @Test func system_shell_can_buffer_output() async { + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) + func system_shell_can_buffer_output() async { var bits: [String] = [] let (_, shellOutput) = try! await container.shell.attach( @@ -54,7 +57,8 @@ struct RealShellTest { #expect("Hello world\nGoodbye world" == shellOutput.out) } - @Test func system_shell_can_timeout_and_throw_error() async { + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) + func system_shell_can_timeout_and_throw_error() async { await #expect(throws: ShellError.timedOut) { try await container.shell.attach( "php -r \"sleep(30);\"", @@ -64,7 +68,8 @@ struct RealShellTest { } } - @Test func pipe_can_timeout_and_return_empty_output() async { + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) + func pipe_can_timeout_and_return_empty_output() async { let start = ContinuousClock.now let output = await container.shell.pipe("php -r \"sleep(30);\"", timeout: 0.5) @@ -79,7 +84,8 @@ struct RealShellTest { #expect(duration < .seconds(2)) } - @Test func pipe_without_timeout_completes_normally() async { + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) + func pipe_without_timeout_completes_normally() async { let output = await container.shell.pipe("php -v") #expect(output.out.contains("Copyright (c) The PHP Group")) @@ -112,7 +118,8 @@ struct RealShellTest { `attach()` method, since the readability handlers actually run on separate threads. */ - @Test func attach_handles_concurrent_stdout_stderr_writes_safely() async throws { + @Test(.enabled(if: Binaries.hasLinkedPhp(), "Requires PHP")) + func attach_handles_concurrent_stdout_stderr_writes_safely() async throws { // Create a PHP script that will output lots of text to STDOUT and STDERR. let phpScript = "php -r 'for ($i = 1; $i <= 500; $i++) { fwrite(STDOUT, \"stdout-$i\" . PHP_EOL); fwrite(STDERR, \"stderr-$i\" . PHP_EOL); flush(); }'"