diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 041d95b..94ae9e5 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,5 +1,12 @@ name: Pull request -on: pull_request + +on: + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true env: XCODE_VERSION: "16.3" @@ -92,6 +99,7 @@ jobs: - name: Build (SPM) if: ${{ matrix.platform == 'macos' }} run: swift build + - name: Build (Xcode) if: ${{ matrix.platform != 'macos' }} run: | @@ -105,7 +113,13 @@ jobs: if: ${{ matrix.platform == 'macos' }} run: | set -o pipefail - swift test | xcbeautify --renderer github-actions + swift test --enable-code-coverage | xcbeautify --renderer github-actions + TEST_BUNDLE=$(find .build/debug/ -name "*.xctest" | head -n 1) + TEST_EXECUTABLE="$TEST_BUNDLE/Contents/MacOS/$(basename "$TEST_BUNDLE" .xctest)" + xcrun llvm-cov export -format="lcov" \ + -instr-profile .build/debug/codecov/default.profdata \ + "$TEST_EXECUTABLE" > info.lcov + - name: Test (Xcode) if: ${{ matrix.platform != 'macos' }} run: | @@ -114,3 +128,9 @@ jobs: -scheme ${{ needs.prepare.outputs.scheme }} \ -destination "${{ steps.destination.outputs.destination }}" | \ xcbeautify --renderer github-actions + + - name: Check coverage (SPM) + if: ${{ matrix.platform == 'macos' }} + uses: codecov/codecov-action@v5 + with: + fail_ci_if_error: true \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bce3182..d109093 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,5 @@ name: Release + on: push: tags: diff --git a/.spi.yml b/.spi.yml new file mode 100644 index 0000000..775dd8a --- /dev/null +++ b/.spi.yml @@ -0,0 +1,7 @@ +version: 1 +builder: + configs: + - documentation_targets: + - Principle + - PrincipleConcurrency + - PrincipleCollections diff --git a/README.md b/README.md index 45d1775..d8dc9d4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Principle ![Swift](https://img.shields.io/badge/Swift-6.0-EF5239?logo=swift&labelColor=white) +[![Codecov](https://codecov.io/gh/NSFatalError/Principle/graph/badge.svg?token=ITK16CK7NL)](https://codecov.io/gh/NSFatalError/Principle) Essential tools that extend the capabilities of Swift Standard Library. diff --git a/Tests/PrincipleConcurrencyTests/SingleUseTransferTests.swift b/Tests/PrincipleConcurrencyTests/SingleUseTransferTests.swift new file mode 100644 index 0000000..214d5ef --- /dev/null +++ b/Tests/PrincipleConcurrencyTests/SingleUseTransferTests.swift @@ -0,0 +1,44 @@ +// +// SingleUseTransferTests.swift +// Principle +// +// Created by Kamil Strzelecki on 28/04/2025. +// Copyright © 2025 Kamil Strzelecki. All rights reserved. +// + +@testable import PrincipleConcurrency +import Synchronization +import Testing + +internal struct SingleUseTransferTests { + + @Test + func testFinalize() { + let mutex = Mutex(NonSendable()) + let instance = NonSendable() + var transfer = SingleUseTransfer(instance) + + mutex.withLock { protected in + protected = transfer.finalize() + } + } + + @Test + func testTake() async { + let instance = NonSendable() + var transfer = SingleUseTransfer(instance) + + await withTaskGroup { group in + var transfer = transfer.take() + group.addTask { + _ = transfer.finalize() + } + await group.waitForAll() + } + } +} + +extension SingleUseTransferTests { + + private final class NonSendable {} +}