@@ -8,66 +8,67 @@ import Foundation
88import FoundationEssentials
99#endif
1010
11- @Test func openOptionsRawValue( ) {
12- typealias Options = Database . OpenOptions
13- #expect( Options . create. rawValue == SQLITE_OPEN_CREATE)
14- #expect( Options . readwrite. rawValue == SQLITE_OPEN_READWRITE)
15- #expect( Options . readonly. rawValue == SQLITE_OPEN_READONLY)
16- #expect( Options . memory. rawValue == SQLITE_OPEN_MEMORY)
17- #expect( Options . extendedResultCode. rawValue == SQLITE_OPEN_EXRESCODE)
18- #expect( Options . uri. rawValue == SQLITE_OPEN_URI)
19- #expect( Options . noFollow. rawValue == SQLITE_OPEN_NOFOLLOW)
20- #expect( Options . noMutex. rawValue == SQLITE_OPEN_NOMUTEX)
21- #expect( Options . fullMutex. rawValue == SQLITE_OPEN_FULLMUTEX)
22- #expect( Options . sharedCache. rawValue == SQLITE_OPEN_SHAREDCACHE)
23- #expect( Options . privateCache. rawValue == SQLITE_OPEN_PRIVATECACHE)
11+ extension Database . OpenOptions : CustomTestStringConvertible {
12+ public var testDescription : String {
13+ String ( rawValue, radix: 16 , uppercase: true )
14+ }
2415}
2516
2617struct DatabaseTests {
27- private let fileManager = FileManager . default
28- private let path = " Tests/new.db "
2918
30- init ( ) {
31- #if Xcode // for relative path
32- fileManager. changeCurrentDirectoryPath ( #file. components ( separatedBy: " /Tests " ) [ 0 ] )
33- #endif
19+ @Test ( arguments: [
20+ ( Database . OpenOptions. create, SQLITE_OPEN_CREATE) ,
21+ ( Database . OpenOptions. readwrite, SQLITE_OPEN_READWRITE) ,
22+ ( Database . OpenOptions. readonly, SQLITE_OPEN_READONLY) ,
23+ ( Database . OpenOptions. memory, SQLITE_OPEN_MEMORY) ,
24+ ( Database . OpenOptions. extendedResultCode, SQLITE_OPEN_EXRESCODE) ,
25+ ( Database . OpenOptions. uri, SQLITE_OPEN_URI) ,
26+ ( Database . OpenOptions. noFollow, SQLITE_OPEN_NOFOLLOW) ,
27+ ( Database . OpenOptions. noMutex, SQLITE_OPEN_NOMUTEX) ,
28+ ( Database . OpenOptions. fullMutex, SQLITE_OPEN_FULLMUTEX) ,
29+ ( Database . OpenOptions. sharedCache, SQLITE_OPEN_SHAREDCACHE) ,
30+ ( Database . OpenOptions. privateCache, SQLITE_OPEN_PRIVATECACHE) ,
31+ ] )
32+ func open( options: Database . OpenOptions , expected: Int32 ) {
33+ #expect( options. rawValue == expected)
3434 }
3535
3636 @Test func open( ) throws {
37- let url = URL ( fileURLWithPath: path)
38- var database : Database ! = try Database . open ( at: path, options: [ . readwrite, . create] )
37+ let fileManager = FileManager . default
38+ try #require( fileManager. changeCurrentDirectoryPath ( fileManager. temporaryDirectory. path) )
39+ let url = URL ( fileURLWithPath: " SQLyra.db " , isDirectory: false )
3940 defer {
40- database = nil // closing before remove a file
41+ // closing database before remove a file
4142 #expect( throws: Never . self) { try fileManager. removeItem ( at: url) }
4243 }
43- #expect( !database. isReadonly)
44- #expect( database. filename == url. path)
45- #expect( fileManager. fileExists ( atPath: url. path) )
44+ do {
45+ let database = try Database . open ( at: " SQLyra.db " , options: [ . readwrite, . create] )
46+ #expect( !database. isReadonly)
47+ #expect( database. filename == url. path)
48+ #expect( fileManager. fileExists ( atPath: url. path) )
49+ }
4650 }
4751
48- @Test func openError( ) throws {
49- do {
50- let database = try Database . open ( at: path, options: [ ] )
51- Issue . record ( " no error \( database) " )
52- } catch let error { // DatabaseError
53- #expect( error. code == SQLITE_MISUSE)
52+ @Test func openError( ) {
53+ #expect( throws: DatabaseError . self) {
54+ try Database . open ( at: " db.sqlite " , options: [ ] )
5455 }
5556 }
5657
5758 @Test func memory( ) throws {
58- let database = try Database . open ( at: path , options: [ . readwrite, . memory] )
59+ let database = try Database . open ( at: " :memory: " , options: [ . readwrite, . memory] )
5960 #expect( !database. isReadonly)
6061 #expect( database. filename == " " )
6162 }
6263
6364 @Test func readonly( ) throws {
64- let database = try Database . open ( at: path , options: [ . readonly, . memory] )
65+ let database = try Database . open ( at: " :memory: " , options: [ . readonly, . memory] )
6566 #expect( database. isReadonly)
6667 #expect( database. filename == " " )
6768 }
6869
6970 @Test func execute( ) throws {
70- let database = try Database . open ( at: path , options: [ . readwrite, . memory] )
71+ let database = try Database . open ( at: " :memory: " , options: [ . readwrite, . memory] )
7172
7273 let sql = """
7374 CREATE TABLE contacts(id INT PRIMARY KEY NOT NULL, name TEXT);
0 commit comments