From cc73d373a86d73a6cb8675804811c7c2660f0f30 Mon Sep 17 00:00:00 2001 From: Philip Niedertscheider Date: Sun, 11 Oct 2026 17:53:01 +0200 Subject: [PATCH] build: Declare Swift package test targets unconditionally --- .git-hooks/check-testing-disabled.sh | 22 -------------------- .pre-commit-config.yaml | 7 ------- AGENTS.md | 2 +- Makefile | 30 ++++++---------------------- Package.swift | 28 ++++++++++---------------- 5 files changed, 17 insertions(+), 72 deletions(-) delete mode 100755 .git-hooks/check-testing-disabled.sh diff --git a/.git-hooks/check-testing-disabled.sh b/.git-hooks/check-testing-disabled.sh deleted file mode 100755 index 5190a16b..00000000 --- a/.git-hooks/check-testing-disabled.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# Check that testing dependencies are not accidentally committed - -has_error=0 - -for file in "$@"; do - if [[ "$file" == "Package.swift" ]]; then - if grep -q 'isTestingEnabled = /\*TESTING_FLAG\*/true/\*TESTING_FLAG\*/' "$file"; then - echo "ERROR: Package.swift has testing enabled." - echo "Please set isTestingEnabled to false before committing." - has_error=1 - fi - fi - - if [[ "$file" == "Package.resolved" ]]; then - echo "ERROR: Package.resolved should not be committed." - echo "Please unstage this file with: git reset HEAD Package.resolved" - has_error=1 - fi -done - -exit $has_error diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b992aef..ad7bd413 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,10 +54,3 @@ repos: language: system args: - "fmt" - - - id: check-testing-disabled - name: Check testing is disabled - description: "Ensure Package.swift has testing disabled and Package.resolved is not committed" - files: ^(Package\.swift|Package\.resolved)$ - entry: .git-hooks/check-testing-disabled.sh - language: script diff --git a/AGENTS.md b/AGENTS.md index 565f0da6..482cfa4a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,5 +13,5 @@ - Watch the regression fail before implementing the fix, then verify it passes. Cover relevant boundaries and unchanged behavior. - For PDF rendering or pagination bugs, add generated-PDF integration coverage when practical, not just layout assertions. - Use the Makefile. Run focused tests first, then `make test-macos`, `make lint`, and `git diff --check` before reporting completion. -- Test targets temporarily enable the flag in `Package.swift`. If initially disabled, restore it with `make test-disable` after testing. +- Test targets are always declared in `Package.swift`. Test commands must not modify the package manifest. - Report which platforms were tested and any remaining failures or diagnostics. Do not imply all-platform verification from macOS alone. diff --git a/Makefile b/Makefile index 12e66bd9..67906705 100644 --- a/Makefile +++ b/Makefile @@ -184,30 +184,12 @@ build-xcframework: .PHONY: test test: test-ios test-macos test-maccatalyst test-tvos test-watchos test-visionos -## Enable test targets by setting testing flag to true -# -# Modifies the Package.swift to set the testing flag to true, enabling test targets. -.PHONY: test-enable -test-enable: - @echo "Setting testing flag to enable test targets..." - @sed -i.bak 's|/\*TESTING_FLAG\*/false/\*TESTING_FLAG\*/|/\*TESTING_FLAG\*/true/\*TESTING_FLAG\*/|g' Package.swift - @rm Package.swift.bak - -## Disable test targets by setting testing flag to false -# -# Modifies the Package.swift to set the testing flag to false, disabling test targets. -.PHONY: test-disable -test-disable: - @echo "Setting testing flag to disable test targets..." - @sed -i.bak 's|/\*TESTING_FLAG\*/true/\*TESTING_FLAG\*/|/\*TESTING_FLAG\*/false/\*TESTING_FLAG\*/|g' Package.swift - @rm Package.swift.bak - ## Run unit tests for TPPDF on latest iOS Simulator # # Runs unit tests for the TPPDF scheme on the latest iOS Simulator (iPhone 17 Pro). # Writes logs to raw-test-ios.log and formats output with xcbeautify. .PHONY: test-ios -test-ios: build-ios test-enable +test-ios: build-ios set -o pipefail && NSUnbufferedIO=YES xcrun xcodebuild \ -scheme $(XCODE_SCHEME) \ -destination 'platform=iOS Simulator,OS=$(IOS_SIMULATOR_OS),name=$(IOS_DEVICE_NAME)' \ @@ -218,7 +200,7 @@ test-ios: build-ios test-enable # Runs unit tests for the TPPDF scheme on macOS. # Writes logs to raw-test-macos.log and formats output with xcbeautify. .PHONY: test-macos -test-macos: build-macos test-enable +test-macos: build-macos set -o pipefail && NSUnbufferedIO=YES xcrun xcodebuild \ -scheme $(XCODE_SCHEME) \ -destination 'platform=macOS' \ @@ -229,7 +211,7 @@ test-macos: build-macos test-enable # Runs unit tests for the TPPDF scheme on Mac Catalyst. # Writes logs to raw-test-maccatalyst.log and formats output with xcbeautify. .PHONY: test-maccatalyst -test-maccatalyst: build-maccatalyst test-enable +test-maccatalyst: build-maccatalyst set -o pipefail && NSUnbufferedIO=YES xcrun xcodebuild \ -scheme $(XCODE_SCHEME) \ -destination 'platform=macOS,variant=Mac Catalyst' \ @@ -240,7 +222,7 @@ test-maccatalyst: build-maccatalyst test-enable # Runs unit tests for the TPPDF scheme on the latest tvOS Simulator (Apple TV 4K 3rd generation). # Writes logs to raw-test-tvos.log and formats output with xcbeautify. .PHONY: test-tvos -test-tvos: build-tvos test-enable +test-tvos: build-tvos set -o pipefail && NSUnbufferedIO=YES xcrun xcodebuild \ -scheme $(XCODE_SCHEME) \ -destination 'platform=tvOS Simulator,OS=$(TVOS_SIMULATOR_OS),name=$(TVOS_DEVICE_NAME)' \ @@ -251,7 +233,7 @@ test-tvos: build-tvos test-enable # Runs unit tests for the TPPDF scheme on the latest watchOS Simulator (Apple Watch Series 11). # Writes logs to raw-test-watchos.log and formats output with xcbeautify. .PHONY: test-watchos -test-watchos: build-watchos test-enable +test-watchos: build-watchos set -o pipefail && NSUnbufferedIO=YES xcrun xcodebuild \ -scheme $(XCODE_SCHEME) \ -destination 'platform=watchOS Simulator,OS=$(WATCHOS_SIMULATOR_OS),name=$(WATCHOS_DEVICE_NAME)' \ @@ -262,7 +244,7 @@ test-watchos: build-watchos test-enable # Runs unit tests for the TPPDF scheme on the latest visionOS Simulator (Apple Vision Pro). # Writes logs to raw-test-visionos.log and formats output with xcbeautify. .PHONY: test-visionos -test-visionos: build-visionos test-enable +test-visionos: build-visionos set -o pipefail && NSUnbufferedIO=YES xcrun xcodebuild \ -scheme $(XCODE_SCHEME) \ -destination 'platform=visionOS Simulator,OS=$(VISION_OS_SIMULATOR_OS),name=$(VISION_OS_DEVICE_NAME)' \ diff --git a/Package.swift b/Package.swift index fe91a713..fd1db8c8 100644 --- a/Package.swift +++ b/Package.swift @@ -2,23 +2,6 @@ import PackageDescription -var testingTargets: [Target] = [] - -let isTestingEnabled = /*TESTING_FLAG*/false/*TESTING_FLAG*/ -if isTestingEnabled { - testingTargets = [ - .testTarget(name: "TPPDFTests", dependencies: ["TPPDF"], resources: [ - .copy("resources/graphics-fixture.gif"), - .copy("resources/sample.pdf"), - .copy("resources/image-fixture.jpg"), - .copy("resources/table-content-fixture.png"), - ]), - .testTarget(name: "TPPDFIntegrationTests", dependencies: ["TPPDF"], resources: [ - .copy("resources/50-pages.pdf"), - ]), - ] -} - let package = Package( name: "TPPDF", platforms: [ @@ -34,5 +17,14 @@ let package = Package( ], targets: [ .target(name: "TPPDF", path: "Source"), - ] + testingTargets + .testTarget(name: "TPPDFTests", dependencies: ["TPPDF"], resources: [ + .copy("resources/graphics-fixture.gif"), + .copy("resources/sample.pdf"), + .copy("resources/image-fixture.jpg"), + .copy("resources/table-content-fixture.png"), + ]), + .testTarget(name: "TPPDFIntegrationTests", dependencies: ["TPPDF"], resources: [ + .copy("resources/50-pages.pdf"), + ]), + ] )