Skip to content

Commit 3779ced

Browse files
authored
Convert all tests from XCTest to SwiftTesting (#198)
* Update CI and docs theme * Require Swift 6.1, enable InternalImportsByDefault, choose most performant version of StringProtocol.replacing(_:with:) based on platform * Convert all tests from XCTest to SwiftTesting
1 parent 46d1a64 commit 3779ced

24 files changed

Lines changed: 2183 additions & 2030 deletions

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
permissions:
2222
contents: read
2323
runs-on: ubuntu-latest
24-
container: swift:6.2-noble
24+
container: swift:6.3-noble
2525
steps:
2626
- name: Check out sql-kit
2727
uses: actions/checkout@v6
@@ -54,7 +54,7 @@ jobs:
5454
strategy:
5555
fail-fast: false
5656
matrix:
57-
swift-image: ['swift:6.2-noble']
57+
swift-image: ['swift:6.3-noble']
5858
driver:
5959
- { sqlkit: 'sqlite-kit', fluent: 'fluent-sqlite-driver' }
6060
- { sqlkit: 'mysql-kit', fluent: 'fluent-mysql-driver' }

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:6.0
1+
// swift-tools-version:6.1
22
import PackageDescription
33

44
let package = Package(
@@ -38,6 +38,8 @@ let package = Package(
3838
.testTarget(
3939
name: "SQLKitTests",
4040
dependencies: [
41+
.product(name: "NIOCore", package: "swift-nio"),
42+
.product(name: "NIOEmbedded", package: "swift-nio"),
4143
.target(name: "SQLKit"),
4244
.target(name: "SQLKitBenchmark"),
4345
],
@@ -48,7 +50,7 @@ let package = Package(
4850

4951
var swiftSettings: [SwiftSetting] { [
5052
.enableUpcomingFeature("ExistentialAny"),
51-
// .enableUpcomingFeature("InternalImportsByDefault"),
53+
.enableUpcomingFeature("InternalImportsByDefault"),
5254
.enableUpcomingFeature("MemberImportVisibility"),
5355
.enableUpcomingFeature("InferIsolatedConformances"),
5456
// .enableUpcomingFeature("NonisolatedNonsendingByDefault"),

Sources/SQLKit/Docs.docc/theme-settings.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
22
"theme": {
3-
"aside": { "border-radius": "16px", "border-width": "3px", "border-style": "double" },
43
"border-radius": "0",
4+
"aside": { "border-radius": "16px", "border-width": "3px", "border-style": "double" },
55
"button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
66
"code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
77
"color": {
8-
"sqlkit": { "dark": "hsl(32, 77%, 63%)", "light": "hsl(32, 80%, 60%)" },
9-
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-sqlkit) 30%, #000 100%)",
8+
"sqlkit": {
9+
"dark": "hsl(32, 77%, 63%)",
10+
"light": "hsl(32, 80%, 60%)"
11+
},
12+
"documentation-intro-fill": {
13+
"dark": "radial-gradient(circle at top, var(--color-sqlkit) 0%, #000000 100%)",
14+
"light": "radial-gradient(circle at top, var(--color-sqlkit) 0%, #f0f0f0 100%)"
15+
},
1016
"documentation-intro-accent": "var(--color-sqlkit)",
11-
"hero-eyebrow": "white",
12-
"documentation-intro-figure": "white",
13-
"hero-title": "white",
1417
"logo-base": { "dark": "#fff", "light": "#000" },
1518
"logo-shape": { "dark": "#000", "light": "#fff" },
1619
"fill": { "dark": "#000", "light": "#fff" }

Sources/SQLKit/Utilities/StringHandling.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
extension StringProtocol where Self: RangeReplaceableCollection, Self.Element: Equatable {
2-
/// Provides a version of `StringProtocol.firstRange(of:)` which is guaranteed to be available on
3-
/// pre-Ventura Apple platforms.
2+
/// Provides a version of `StringProtocol.firstRange(of:)` guaranteed to be available.
43
@inlinable
54
func sqlkit_firstRange(of other: some StringProtocol) -> Range<Self.Index>? {
6-
/// N.B.: This implementation is apparently some 650% faster than `firstRange(of:)`, at least on macOS...
75
guard self.count >= other.count, let starter = other.first else { return nil }
86
var index = self.startIndex
97
let lastIndex = self.index(self.endIndex, offsetBy: -other.count)
@@ -21,15 +19,17 @@ extension StringProtocol where Self: RangeReplaceableCollection, Self.Element: E
2119
return nil
2220
}
2321

24-
/// Provides a version of `StringProtocol.replacing(_:with:)` which is guaranteed to be available on
25-
/// pre-Ventura Apple platforms.
22+
/// Provides a version of `StringProtocol.replacing(_:with:)` which is guaranteed to be available.
23+
#if !DEBUG && !canImport(Darwin)
24+
@inline(__always)
25+
#endif
2626
@inlinable
2727
func sqlkit_replacing(_ search: some StringProtocol, with replacement: some StringProtocol) -> String {
28-
/// N.B.: Even on Ventura/Sonoma, the handwritten implementation is orders of magnitude faster than
29-
/// `replacing(_:with:)`, at least as of the time of this writing. Thus we use the handwritten version
30-
/// unconditionally. It's still 4x slower than Foundation's version, but that's a lot better than 25x.
28+
#if DEBUG || canImport(Darwin)
29+
// On Apple platforms, this hand-rolled implementation is MUCH faster (10x or more) than the stdlib version, for some reason.
30+
// We also want to use this implementation in debug builds, so that the tests test it rather than the stdlib.
3131
guard !self.isEmpty, !search.isEmpty, self.count >= search.count else { return .init(self) }
32-
32+
3333
var result = "", prevIndex = self.startIndex
3434

3535
result.reserveCapacity(self.count + replacement.count)
@@ -40,6 +40,10 @@ extension StringProtocol where Self: RangeReplaceableCollection, Self.Element: E
4040
}
4141
result.append(contentsOf: self[prevIndex...])
4242
return result
43+
#else
44+
// On non-Apple platforms, the stdlib's version is better than our hand-rolled one.
45+
return String(self.replacing(search, with: replacement))
46+
#endif
4347
}
4448

4549
/// Returns the string with its first character lowercased.

Sources/SQLKitBenchmark/SQLBenchmarker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Logging
22
import NIOCore
3-
import SQLKit
3+
public import SQLKit
44
import XCTest
55

66
public final class SQLBenchmarker: Sendable {

0 commit comments

Comments
 (0)