From 22e35ce2d0a54bdbed53204df1323e6c7e14dfcd Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 14:21:08 +0200 Subject: [PATCH 01/10] - --- .spi.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .spi.yml 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 From 060eb73411d82f1dad94b1a51516b69a318d1f35 Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 14:26:57 +0200 Subject: [PATCH 02/10] - --- .github/workflows/pull-request.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 041d95b..39631c8 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -105,7 +105,7 @@ jobs: if: ${{ matrix.platform == 'macos' }} run: | set -o pipefail - swift test | xcbeautify --renderer github-actions + swift test --enable-code-coverage | xcbeautify --renderer github-actions - name: Test (Xcode) if: ${{ matrix.platform != 'macos' }} run: | @@ -114,3 +114,7 @@ jobs: -scheme ${{ needs.prepare.outputs.scheme }} \ -destination "${{ steps.destination.outputs.destination }}" | \ xcbeautify --renderer github-actions + + - name: Check coverage + if: ${{ matrix.platform == 'macos' }} + uses: codecov/codecov-action@v5 \ No newline at end of file From 8847ee843b20401da08fd28ff0b72fabedcc1664 Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 14:34:31 +0200 Subject: [PATCH 03/10] - --- .github/workflows/pull-request.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 39631c8..f47ad64 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -115,6 +115,9 @@ jobs: -destination "${{ steps.destination.outputs.destination }}" | \ xcbeautify --renderer github-actions - - name: Check coverage + - name: Check coverage (SPM) if: ${{ matrix.platform == 'macos' }} - uses: codecov/codecov-action@v5 \ No newline at end of file + uses: codecov/codecov-action@v5 + with: + files: .build/debug/codecov/*.profraw + fail_ci_if_error: true \ No newline at end of file From 714abdc2f91a8a30550a5f329ba04a30a3dc9d6e Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 14:48:04 +0200 Subject: [PATCH 04/10] - --- .github/workflows/pull-request.yml | 10 ++++++++-- .github/workflows/release.yml | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f47ad64..4d69fd2 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" @@ -119,5 +126,4 @@ jobs: if: ${{ matrix.platform == 'macos' }} uses: codecov/codecov-action@v5 with: - files: .build/debug/codecov/*.profraw 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: From 69cd43da86ba7a52b1797a798a8832fda204d86c Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 14:51:16 +0200 Subject: [PATCH 05/10] - --- .github/workflows/pull-request.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4d69fd2..783ff11 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -113,6 +113,8 @@ jobs: run: | set -o pipefail swift test --enable-code-coverage | xcbeautify --renderer github-actions + xcrun llvm-cov report $BUILD_FOLDER -instr-profile $PROFDATA_FOLDER + xcrun llvm-cov export -format="lcov" $BUILD_FOLDER -instr-profile $PROFDATA_FOLDER > $LCOV_PATH - name: Test (Xcode) if: ${{ matrix.platform != 'macos' }} run: | From cc473a6d4816fe7965c824a9a9373b25aae105a6 Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 15:08:21 +0200 Subject: [PATCH 06/10] - --- .github/workflows/pull-request.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 783ff11..755a7e7 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -3,7 +3,7 @@ name: Pull request on: pull_request: types: [opened, reopened, synchronize, ready_for_review] - + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -99,6 +99,7 @@ jobs: - name: Build (SPM) if: ${{ matrix.platform == 'macos' }} run: swift build + - name: Build (Xcode) if: ${{ matrix.platform != 'macos' }} run: | @@ -113,8 +114,15 @@ jobs: run: | set -o pipefail swift test --enable-code-coverage | xcbeautify --renderer github-actions - xcrun llvm-cov report $BUILD_FOLDER -instr-profile $PROFDATA_FOLDER - xcrun llvm-cov export -format="lcov" $BUILD_FOLDER -instr-profile $PROFDATA_FOLDER > $LCOV_PATH + TEST_BUNDLE=$(find .build/debug -name "*.xctest" | head -n 1) + TEST_EXECUTABLE="$TEST_BUNDLE/Contents/MacOS/$(basename "$TEST_BUNDLE" .xctest)" + llvm-profdata merge -sparse .build/debug/codecov/*.profraw \ + -o coverage.profdata + llvm-cov export \ + "$TEST_EXECUTABLE" \ + -instr-profile=coverage.profdata \ + -format=lcov > coverage/lcov.info + - name: Test (Xcode) if: ${{ matrix.platform != 'macos' }} run: | @@ -123,7 +131,7 @@ 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 From 998af0bb07d840d10ca99e6d512bc69a539f6e8a Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 15:11:05 +0200 Subject: [PATCH 07/10] - --- .github/workflows/pull-request.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 755a7e7..9c46693 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -116,9 +116,10 @@ jobs: 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)" - llvm-profdata merge -sparse .build/debug/codecov/*.profraw \ + xcrun llvm-profdata merge -sparse \ + .build/debug/codecov/*.profraw \ -o coverage.profdata - llvm-cov export \ + xcrun llvm-cov export \ "$TEST_EXECUTABLE" \ -instr-profile=coverage.profdata \ -format=lcov > coverage/lcov.info From d49c1569206b12a0d498e52803afa73d8ac08e51 Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 15:24:01 +0200 Subject: [PATCH 08/10] - --- .github/workflows/pull-request.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9c46693..94ae9e5 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -114,15 +114,11 @@ jobs: run: | set -o pipefail swift test --enable-code-coverage | xcbeautify --renderer github-actions - TEST_BUNDLE=$(find .build/debug -name "*.xctest" | head -n 1) + TEST_BUNDLE=$(find .build/debug/ -name "*.xctest" | head -n 1) TEST_EXECUTABLE="$TEST_BUNDLE/Contents/MacOS/$(basename "$TEST_BUNDLE" .xctest)" - xcrun llvm-profdata merge -sparse \ - .build/debug/codecov/*.profraw \ - -o coverage.profdata - xcrun llvm-cov export \ - "$TEST_EXECUTABLE" \ - -instr-profile=coverage.profdata \ - -format=lcov > coverage/lcov.info + xcrun llvm-cov export -format="lcov" \ + -instr-profile .build/debug/codecov/default.profdata \ + "$TEST_EXECUTABLE" > info.lcov - name: Test (Xcode) if: ${{ matrix.platform != 'macos' }} From e48a57cd4504129f128b0f314a261dc48312336b Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 15:34:28 +0200 Subject: [PATCH 09/10] - --- README.md | 1 + 1 file changed, 1 insertion(+) 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. From d844249fc4c6146eb53cebe012729d7c4f3d81db Mon Sep 17 00:00:00 2001 From: Kamil Strzelecki Date: Mon, 28 Apr 2025 15:59:22 +0200 Subject: [PATCH 10/10] Added SingleUseTransferTests --- .../SingleUseTransferTests.swift | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Tests/PrincipleConcurrencyTests/SingleUseTransferTests.swift 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 {} +}