Skip to content

Commit 3708818

Browse files
Merge pull request #7 from Alexander-Ignition/swift-testing
swift-testing
2 parents 6c6ac00 + 433c8a4 commit 3708818

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
Apple:
2626
name: Test ${{ matrix.name }}
2727
runs-on: macOS-latest
28+
env:
29+
DEVELOPER_DIR: /Applications/Xcode_16.1.app/Contents/Developer
2830
strategy:
2931
fail-fast: false
3032
matrix:
@@ -42,6 +44,8 @@ jobs:
4244
SPM:
4345
name: Test with SPM
4446
runs-on: macOS-latest
47+
env:
48+
DEVELOPER_DIR: /Applications/Xcode_16.1.app/Contents/Developer
4549
steps:
4650
- name: Checkout
4751
uses: actions/checkout@v4

Sources/SQLyra/PreparedStatement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public final class PreparedStatement {
2121
/// Retrieving statement SQL.
2222
public var sql: String { sqlite3_sql(stmt).string ?? "" }
2323

24-
@available(macOS 12.0, *)
24+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
2525
public var normalizedSQL: String { sqlite3_normalized_sql(stmt).string ?? "" }
2626

2727
/// Retrieving statement SQL with parameters.
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1+
import Foundation
12
import SQLyra
2-
import XCTest
3+
import Testing
34

4-
final class DatabaseTests: XCTestCase {
5+
struct DatabaseTests {
56
private let fileManager = FileManager.default
67
private let path = "Tests/new.db"
78

8-
override func setUp() {
9-
super.setUp()
9+
init() {
1010
#if Xcode // for relative path
1111
fileManager.changeCurrentDirectoryPath(#file.components(separatedBy: "/Tests")[0])
1212
#endif
1313
}
1414

15-
func testOpen() throws {
15+
@Test func open() throws {
1616
let url = URL(fileURLWithPath: path)
1717
let database = try Database.open(at: path, options: [.readwrite, .create])
1818
defer {
19-
XCTAssertNoThrow(try fileManager.removeItem(at: url))
19+
#expect(throws: Never.self) { try fileManager.removeItem(at: url) }
2020
}
21-
XCTAssertFalse(database.isReadonly)
22-
XCTAssertEqual(database.path, url.path)
23-
XCTAssertTrue(fileManager.fileExists(atPath: url.path))
21+
#expect(!database.isReadonly)
22+
#expect(database.path == url.path)
23+
#expect(fileManager.fileExists(atPath: url.path))
2424
}
2525

26-
func testOpenError() {
27-
XCTAssertThrowsError(try Database.open(at: path, options: [])) { err in
28-
guard let error = err as? DatabaseError else {
29-
return XCTFail("Unexpected error: \(err)")
30-
}
31-
XCTAssertEqual(error.code, 21) // SQLITE_MISUSE
32-
XCTAssertEqual(error.message, "bad parameter or other API misuse")
33-
XCTAssertEqual(error.reason, "flags must include SQLITE_OPEN_READONLY or SQLITE_OPEN_READWRITE")
26+
@Test func openError() {
27+
let error = DatabaseError(
28+
code: 21, // SQLITE_MISUSE
29+
message: "bad parameter or other API misuse",
30+
reason: "flags must include SQLITE_OPEN_READONLY or SQLITE_OPEN_READWRITE"
31+
)
32+
#expect(throws: error) {
33+
try Database.open(at: path, options: [])
3434
}
3535
}
3636

37-
func testPathInMemory() throws {
37+
@Test func pathInMemory() throws {
3838
let database = try Database.open(at: path, options: [.readwrite, .memory])
39-
XCTAssertEqual(database.path, "")
39+
#expect(database.path == "")
4040
}
4141

42-
func testExecute() throws {
42+
@Test func execute() throws {
4343
let database = try Database.open(at: path, options: [.readwrite, .memory])
4444

4545
try database.execute("CREATE TABLE contacts(id INT PRIMARY KEY NOT NULL, name CHAR(255));")
@@ -52,7 +52,7 @@ final class DatabaseTests: XCTestCase {
5252
["id": "1", "name": "Paul"],
5353
["id": "2", "name": "John"],
5454
]
55-
XCTAssertEqual(rows, expected)
55+
#expect(rows == expected)
5656
// try database.execute("SELECT name FROM sqlite_master WHERE type ='table';")
5757
}
5858
}

0 commit comments

Comments
 (0)