Skip to content

Instantly share code, notes, and snippets.

View finestructure's full-sized avatar

Sven A. Schmidt finestructure

View GitHub Profile
import Testing
struct DatabasePoolSetupTrait: SuiteTrait, TestScoping {
func provideScope(for test: Test, testCase: Test.Case?, performing function: @Sendable () async throws -> Void) async throws {
try await DatabasePool.shared.setUp()
try await function()
try await DatabasePool.shared.tearDown()
}
}
@finestructure
finestructure / expect-throws.md
Last active February 26, 2025 09:23
#expect issues with throws

I have a test that I initially converted as follows to Swift Testing:

    @Test func S3Store_Key_readme() throws {
        withDependencies {
            $0.environment.awsReadmeBucket = { "readme-bucket" }
        } operation: {
            #expect(try S3Store.Key.readme(owner: "foo", repository: "bar").path == "foo/bar/readme.html")
            #expect(try S3Store.Key.readme(owner: "FOO", repository: "bar").path == "foo/bar/readme.html")
 }
@finestructure
finestructure / Shell.swift
Created November 27, 2024 07:17
Tim's Process helpers
// Via Tim Condon
@discardableResult
func shell(_ args: String..., returnStdOut: Bool = false, stdIn: Pipe? = nil) throws -> (Int32, Pipe) {
return try shell(args, returnStdOut: returnStdOut, stdIn: stdIn)
}
@discardableResult
func shell(_ args: [String], returnStdOut: Bool = false, stdIn: Pipe? = nil) throws -> (Int32, Pipe) {
let task = Process()
2024-07-22 07:19:36.471
2024-07-22 07:19:36.737
2024-07-22 07:21:12.021
*** Signal 4: Backtracing from 0x563b13828f50... done ***
2024-07-22 07:21:12.021
2024-07-22 07:21:12.021
*** Program crashed: Illegal instruction at 0x0000563b13828f50 ***
@finestructure
finestructure / test-build.sh
Last active July 13, 2024 13:28
Swift 6 preview test build
mkdir SwiftPackageIndex-Server && cd SwiftPackageIndex-Server
git init .
git remote add origin https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server
git fetch origin --depth=1 89cbad3846eaef877ec33925eca5867922cf391a
git reset --hard FETCH_HEAD
mkdir .stats
time env DEVELOPER_DIR=/Applications/Xcode-16.0.0-Beta.3.app xcrun swift build --arch arm64 -Xswiftc -Xfrontend -Xswiftc -stats-output-dir -Xswiftc -Xfrontend -Xswiftc .stats -Xswiftc -strict-concurrency=complete
❯ git rev-parse @
903d9ec992451cf80bf80cf82b82992fb331ccfb
~/P/S/spi-server on swift-6-prep
❯ swift package clean
~/P/S/spi-server on swift-6-prep
❯ swift build --build-tests
Building for debugging...
/Users/sas/Projects/SPI/spi-server/.build/checkouts/swift-certificates/Sources/X509/Signature.swift:16:1: remark: add '@preconcurrency' to suppress 'Sendable'-related warnings from module '_CryptoExtras'
import _CryptoExtras
^
@finestructure
finestructure / list-toolchains.swift
Last active March 26, 2024 10:39
List Swift toolchain IDs
#!/usr/bin/env swift
import Foundation
let toolchainsDir = URL(fileURLWithPath: "/Library/Developer/Toolchains")
struct ToolchainInfoPlist: Codable {
var bundleIdentifier: String
var createdDate: Date
var displayName: String
@finestructure
finestructure / Dockerfile
Last active February 3, 2024 09:58
Pkl dockerfile
FROM swift:5.9-slim
RUN apt-get update && apt-get -y install curl fish
ARG PKL_VERSION=0.25.1
RUN curl -L -o /usr/local/bin/pkl https://github.com/apple/pkl/releases/download/${PKL_VERSION}/pkl-linux-aarch64 && chmod +x /usr/local/bin/pkl
# requires Swift runtime libraries, that's why the base image is swift:5.9-slim
ARG PKL_GEN_SWIFT_VERSION=0.2.1
RUN curl -L -o /usr/local/bin/pkl-gen-swift https://github.com/apple/pkl-swift/releases/download/${PKL_GEN_SWIFT_VERSION}/pkl-gen-swift-linux-aarch64.bin && chmod +x /usr/local/bin/pkl-gen-swift
@finestructure
finestructure / ci.yml
Last active December 11, 2023 11:52
Github CI setup
name: CI
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
@finestructure
finestructure / daws-test hang
Created December 8, 2023 12:16
daws-test hang
```
❯ ./.build/debug/daws server
starting server...
running.
2023-12-08T13:09:21+0100 info WebSocketActors : channel=[IPv6]::1/::1:57175 op=handleWebsocketChannel(_:remoteNodeID:) [WebSocketActors] new client connection
```
```
❯ ./.build/debug/daws client
starting client...