From 714a82b56e08d486a236ae3907f0cf110c15cd35 Mon Sep 17 00:00:00 2001 From: Yusuke Ito Date: Tue, 20 Sep 2016 13:17:53 +0900 Subject: [PATCH] undo merge revert(c72f801be3ed2685e28a939cb8b44397e7778201) --- .travis.yml | 24 ++-- Makefile | 35 +++-- .../MySQL/MySQL.xcodeproj/project.pbxproj | 135 ++++++++++-------- .../xcshareddata/xcschemes/MySQL.xcscheme | 2 +- .../SQLFormatter.xcodeproj/project.pbxproj | 22 +-- .../xcschemes/SQLFormatter.xcscheme | 2 +- README.md | 4 +- Sources/MySQL/Connection.swift | 59 ++------ Sources/MySQL/ConnectionPool.swift | 8 +- Sources/MySQL/Date.swift | 48 +++---- Sources/MySQL/Error.swift | 4 +- Sources/MySQL/Query.swift | 11 +- Sources/MySQL/QueryParameterType.swift | 4 +- Sources/MySQL/Sync.swift | 11 +- Sources/MySQL/Transaction.swift | 6 +- Sources/SQLFormatter/Error.swift | 2 +- Tests/LinuxMain.swift | 22 ++- Tests/{MySQL => MySQLTests}/BlobTests.swift | 0 .../ConnectionPoolTests.swift | 2 +- .../ConnectionTests.swift | 0 Tests/{MySQL => MySQLTests}/DateTests.swift | 17 +-- Tests/{MySQL => MySQLTests}/EscapeTests.swift | 0 Tests/{MySQL => MySQLTests}/Model.swift | 0 Tests/{MySQL => MySQLTests}/MySQLTests.swift | 5 +- .../QueryFormatterTests.swift | 0 Tests/{MySQL => MySQLTests}/QueryTests.swift | 2 +- .../{MySQL => MySQLTests}/SQLTypeTests.swift | 0 Tests/MySQLTests/XCTestManifests.swift | 24 ++++ .../SQLFormatterTests.swift | 15 +- 29 files changed, 241 insertions(+), 223 deletions(-) rename Tests/{MySQL => MySQLTests}/BlobTests.swift (100%) rename Tests/{MySQL => MySQLTests}/ConnectionPoolTests.swift (96%) rename Tests/{MySQL => MySQLTests}/ConnectionTests.swift (100%) rename Tests/{MySQL => MySQLTests}/DateTests.swift (74%) rename Tests/{MySQL => MySQLTests}/EscapeTests.swift (100%) rename Tests/{MySQL => MySQLTests}/Model.swift (100%) rename Tests/{MySQL => MySQLTests}/MySQLTests.swift (85%) rename Tests/{MySQL => MySQLTests}/QueryFormatterTests.swift (100%) rename Tests/{MySQL => MySQLTests}/QueryTests.swift (99%) rename Tests/{MySQL => MySQLTests}/SQLTypeTests.swift (100%) create mode 100644 Tests/MySQLTests/XCTestManifests.swift rename Tests/{SQLFormatter => SQLFormatterTests}/SQLFormatterTests.swift (52%) diff --git a/.travis.yml b/.travis.yml index af23dab..bd38b8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,19 @@ -os: - - linux - - osx language: generic sudo: required -dist: trusty -osx_image: xcode7.3 +matrix: + include: + - os: linux + dist: trusty + env: PERFORM_MAKE_TEST=1 + - os: osx + osx_image: xcode8 + env: PERFORM_XCODEBUILD=1 PERFORM_MAKE_TEST=1 addons: mariadb: '10.1' env: - - SWIFT_VERSION=DEVELOPMENT-SNAPSHOT-2016-06-06-a + global: + - SWIFT_VERSION=DEVELOPMENT-SNAPSHOT-2016-09-04-a + - TOOLCHAINS=org.swift.3020160904a before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install mariadb; fi @@ -18,7 +23,8 @@ before_script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mysql.server start; fi - mysql -u root -e "create database IF NOT EXISTS test;" script: - - make - - make test - #- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xcodebuild -project OSX\ Projects/MySQL/MySQL.xcodeproj -scheme MySQL build test ; fi + - make debug + - make release + - if [[ "$PERFORM_MAKE_TEST" == "1" ]]; then make test; fi + - if [[ "$PERFORM_XCODEBUILD" == "1" ]]; then xcodebuild -project OSX\ Projects/MySQL/MySQL.xcodeproj -scheme MySQL build test ; fi \ No newline at end of file diff --git a/Makefile b/Makefile index 34b9207..5f5704c 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,35 @@ -BUILDOPTS=-Xlinker -L/usr/lib +BUILD_OPTS=-Xlinker -L/usr/lib SWIFTC=swiftc SWIFT=swift ifdef SWIFTPATH - SWIFTC=$(SWIFTPATH)/bin/swiftc - SWIFT=$(SWIFTPATH)/bin/swift + SWIFTC=$(SWIFTPATH)/bin/swiftc + SWIFT=$(SWIFTPATH)/bin/swift endif + OS := $(shell uname) ifeq ($(OS),Darwin) - SWIFTC=xcrun -sdk macosx swiftc - BUILDOPTS=-Xlinker -L/usr/local/lib -Xcc -I/usr/local/include/mysql -Xcc -I/usr/local/include + SWIFTC=xcrun -sdk macosx swiftc + BUILD_OPTS=-Xlinker -L/usr/local/opt/mariadb/lib -Xlinker -L/usr/local/opt/openssl/lib -Xcc -I/usr/local/include/mysql -Xcc -I/usr/local/include endif -all: build - -build: - $(SWIFT) build -v $(BUILDOPTS) - -test: build - $(SWIFT) test +all: debug test + +release: CONF_ENV=release +release: build_; + +debug: CONF_ENV=debug +debug: build_; + +build_: + $(SWIFT) build -v --configuration $(CONF_ENV) $(BUILD_OPTS) clean: + $(SWIFT) build --clean build + +distclean: $(SWIFT) build --clean dist + +test: + $(SWIFT) test -v $(BUILD_OPTS) + diff --git a/OSX Projects/MySQL/MySQL.xcodeproj/project.pbxproj b/OSX Projects/MySQL/MySQL.xcodeproj/project.pbxproj index 9c0510e..7edfc68 100644 --- a/OSX Projects/MySQL/MySQL.xcodeproj/project.pbxproj +++ b/OSX Projects/MySQL/MySQL.xcodeproj/project.pbxproj @@ -8,23 +8,22 @@ /* Begin PBXBuildFile section */ 52166C781CEE9C9D00FCF92D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 52166C771CEE9C9D00FCF92D /* libz.tbd */; }; - 52166C7C1CEEA9EE00FCF92D /* libmysqlclient.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 52166C7B1CEEA9EE00FCF92D /* libmysqlclient.dylib */; }; + 5227D5F71D5AF45D0014CC55 /* libmysqlclient.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5227D5F61D5AF45D0014CC55 /* libmysqlclient.a */; }; 523BC35E1CC9C1660007F0A7 /* Blob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523BC35D1CC9C1660007F0A7 /* Blob.swift */; }; - 523BC37D1CC9CBBC0007F0A7 /* BlobTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523BC37C1CC9CBBC0007F0A7 /* BlobTests.swift */; }; - 523BC37F1CC9CBC10007F0A7 /* SQLTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523BC37E1CC9CBC10007F0A7 /* SQLTypeTests.swift */; }; 523BC3811CC9CC180007F0A7 /* SQLType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523BC3801CC9CC180007F0A7 /* SQLType.swift */; }; - 5241952B1CF4392700C6CCE2 /* libcrypto.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5241952A1CF4392700C6CCE2 /* libcrypto.tbd */; }; - 5241952F1CF4392C00C6CCE2 /* libssl.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5241952E1CF4392C00C6CCE2 /* libssl.tbd */; }; + 525B38341D5AF3B600AE29A5 /* BlobTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B38291D5AF3B600AE29A5 /* BlobTests.swift */; }; + 525B38351D5AF3B600AE29A5 /* ConnectionPoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B382A1D5AF3B600AE29A5 /* ConnectionPoolTests.swift */; }; + 525B38361D5AF3B600AE29A5 /* ConnectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B382B1D5AF3B600AE29A5 /* ConnectionTests.swift */; }; + 525B38371D5AF3B600AE29A5 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B382C1D5AF3B600AE29A5 /* DateTests.swift */; }; + 525B38381D5AF3B600AE29A5 /* EscapeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B382D1D5AF3B600AE29A5 /* EscapeTests.swift */; }; + 525B38391D5AF3B600AE29A5 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B382E1D5AF3B600AE29A5 /* Model.swift */; }; + 525B383A1D5AF3B600AE29A5 /* MySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B382F1D5AF3B600AE29A5 /* MySQLTests.swift */; }; + 525B383B1D5AF3B600AE29A5 /* QueryFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B38301D5AF3B600AE29A5 /* QueryFormatterTests.swift */; }; + 525B383C1D5AF3B600AE29A5 /* QueryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B38311D5AF3B600AE29A5 /* QueryTests.swift */; }; + 525B383D1D5AF3B600AE29A5 /* SQLTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B38321D5AF3B600AE29A5 /* SQLTypeTests.swift */; }; + 525B383E1D5AF3B600AE29A5 /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B38331D5AF3B600AE29A5 /* XCTestManifests.swift */; }; 5292158B1BDB8CD6009B031A /* MySQL.h in Headers */ = {isa = PBXBuildFile; fileRef = 5292158A1BDB8CD6009B031A /* MySQL.h */; settings = {ATTRIBUTES = (Public, ); }; }; 529215921BDB8CD6009B031A /* MySQL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529215871BDB8CD6009B031A /* MySQL.framework */; }; - 52965F931C82F6C500E35C64 /* ConnectionPoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F891C82F6C500E35C64 /* ConnectionPoolTests.swift */; }; - 52965F941C82F6C500E35C64 /* ConnectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F8A1C82F6C500E35C64 /* ConnectionTests.swift */; }; - 52965F961C82F6C500E35C64 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F8C1C82F6C500E35C64 /* DateTests.swift */; }; - 52965F971C82F6C500E35C64 /* EscapeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F8D1C82F6C500E35C64 /* EscapeTests.swift */; }; - 52965F991C82F6C500E35C64 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F8F1C82F6C500E35C64 /* Model.swift */; }; - 52965F9A1C82F6C500E35C64 /* MySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F901C82F6C500E35C64 /* MySQLTests.swift */; }; - 52965F9B1C82F6C500E35C64 /* QueryFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F911C82F6C500E35C64 /* QueryFormatterTests.swift */; }; - 52965F9C1C82F6C500E35C64 /* QueryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52965F921C82F6C500E35C64 /* QueryTests.swift */; }; 529828AC1CB3E2A4001FE958 /* Connection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529828A31CB3E2A4001FE958 /* Connection.swift */; }; 529828AD1CB3E2A4001FE958 /* ConnectionPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529828A41CB3E2A4001FE958 /* ConnectionPool.swift */; }; 529828AE1CB3E2A4001FE958 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529828A51CB3E2A4001FE958 /* Date.swift */; }; @@ -78,30 +77,29 @@ /* Begin PBXFileReference section */ 52166C771CEE9C9D00FCF92D /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; - 52166C7B1CEEA9EE00FCF92D /* libmysqlclient.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libmysqlclient.dylib; path = /usr/local/lib/libmysqlclient.dylib; sourceTree = ""; }; + 5227D5F61D5AF45D0014CC55 /* libmysqlclient.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmysqlclient.a; path = ../../../../../../usr/local/Cellar/mysql/5.7.11/lib/libmysqlclient.a; sourceTree = ""; }; 523BC35D1CC9C1660007F0A7 /* Blob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Blob.swift; sourceTree = ""; }; - 523BC37C1CC9CBBC0007F0A7 /* BlobTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlobTests.swift; sourceTree = ""; }; - 523BC37E1CC9CBC10007F0A7 /* SQLTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLTypeTests.swift; sourceTree = ""; }; 523BC3801CC9CC180007F0A7 /* SQLType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLType.swift; sourceTree = ""; }; - 5241952A1CF4392700C6CCE2 /* libcrypto.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcrypto.tbd; path = usr/lib/libcrypto.tbd; sourceTree = SDKROOT; }; - 5241952E1CF4392C00C6CCE2 /* libssl.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libssl.tbd; path = usr/lib/libssl.tbd; sourceTree = SDKROOT; }; + 525B38291D5AF3B600AE29A5 /* BlobTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlobTests.swift; sourceTree = ""; }; + 525B382A1D5AF3B600AE29A5 /* ConnectionPoolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionPoolTests.swift; sourceTree = ""; }; + 525B382B1D5AF3B600AE29A5 /* ConnectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionTests.swift; sourceTree = ""; }; + 525B382C1D5AF3B600AE29A5 /* DateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateTests.swift; sourceTree = ""; }; + 525B382D1D5AF3B600AE29A5 /* EscapeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EscapeTests.swift; sourceTree = ""; }; + 525B382E1D5AF3B600AE29A5 /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; + 525B382F1D5AF3B600AE29A5 /* MySQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MySQLTests.swift; sourceTree = ""; }; + 525B38301D5AF3B600AE29A5 /* QueryFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryFormatterTests.swift; sourceTree = ""; }; + 525B38311D5AF3B600AE29A5 /* QueryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryTests.swift; sourceTree = ""; }; + 525B38321D5AF3B600AE29A5 /* SQLTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLTypeTests.swift; sourceTree = ""; }; + 525B38331D5AF3B600AE29A5 /* XCTestManifests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = ""; }; 529215871BDB8CD6009B031A /* MySQL.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MySQL.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5292158A1BDB8CD6009B031A /* MySQL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MySQL.h; sourceTree = ""; }; 5292158C1BDB8CD6009B031A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 529215911BDB8CD6009B031A /* MySQLTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MySQLTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 529215981BDB8CD6009B031A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 52965F891C82F6C500E35C64 /* ConnectionPoolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionPoolTests.swift; sourceTree = ""; }; - 52965F8A1C82F6C500E35C64 /* ConnectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionTests.swift; sourceTree = ""; }; - 52965F8C1C82F6C500E35C64 /* DateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateTests.swift; sourceTree = ""; }; - 52965F8D1C82F6C500E35C64 /* EscapeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EscapeTests.swift; sourceTree = ""; }; - 52965F8F1C82F6C500E35C64 /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; - 52965F901C82F6C500E35C64 /* MySQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MySQLTests.swift; sourceTree = ""; }; - 52965F911C82F6C500E35C64 /* QueryFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryFormatterTests.swift; sourceTree = ""; }; - 52965F921C82F6C500E35C64 /* QueryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryTests.swift; sourceTree = ""; }; 529828921CB3E27E001FE958 /* SQLFormatter.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SQLFormatter.xcodeproj; path = ../SQLFormatter/SQLFormatter.xcodeproj; sourceTree = ""; }; 529828A31CB3E2A4001FE958 /* Connection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Connection.swift; sourceTree = ""; }; 529828A41CB3E2A4001FE958 /* ConnectionPool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionPool.swift; sourceTree = ""; }; - 529828A51CB3E2A4001FE958 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; + 529828A51CB3E2A4001FE958 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Date.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 529828A61CB3E2A4001FE958 /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = ""; }; 529828A71CB3E2A4001FE958 /* Query.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Query.swift; sourceTree = ""; }; 529828A81CB3E2A4001FE958 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; @@ -120,12 +118,10 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 5241952F1CF4392C00C6CCE2 /* libssl.tbd in Frameworks */, - 5241952B1CF4392700C6CCE2 /* libcrypto.tbd in Frameworks */, - 52166C7C1CEEA9EE00FCF92D /* libmysqlclient.dylib in Frameworks */, 52166C781CEE9C9D00FCF92D /* libz.tbd in Frameworks */, 529828B51CB3E2B3001FE958 /* SQLFormatter.framework in Frameworks */, 52F722011BDBD4C50066B725 /* libstdc++.tbd in Frameworks */, + 5227D5F71D5AF45D0014CC55 /* libmysqlclient.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -140,12 +136,36 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 520D2C0B1D0FD81800D73753 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; + 525B38281D5AF3B600AE29A5 /* MySQLTests */ = { + isa = PBXGroup; + children = ( + 525B38291D5AF3B600AE29A5 /* BlobTests.swift */, + 525B382A1D5AF3B600AE29A5 /* ConnectionPoolTests.swift */, + 525B382B1D5AF3B600AE29A5 /* ConnectionTests.swift */, + 525B382C1D5AF3B600AE29A5 /* DateTests.swift */, + 525B382D1D5AF3B600AE29A5 /* EscapeTests.swift */, + 525B382E1D5AF3B600AE29A5 /* Model.swift */, + 525B382F1D5AF3B600AE29A5 /* MySQLTests.swift */, + 525B38301D5AF3B600AE29A5 /* QueryFormatterTests.swift */, + 525B38311D5AF3B600AE29A5 /* QueryTests.swift */, + 525B38321D5AF3B600AE29A5 /* SQLTypeTests.swift */, + 525B38331D5AF3B600AE29A5 /* XCTestManifests.swift */, + ); + name = MySQLTests; + path = ../../../Tests/MySQLTests; + sourceTree = ""; + }; 5292157D1BDB8CD5009B031A = { isa = PBXGroup; children = ( - 5241952E1CF4392C00C6CCE2 /* libssl.tbd */, - 5241952A1CF4392700C6CCE2 /* libcrypto.tbd */, - 52166C7B1CEEA9EE00FCF92D /* libmysqlclient.dylib */, + 5227D5F61D5AF45D0014CC55 /* libmysqlclient.a */, 52F722001BDBD4C50066B725 /* libstdc++.tbd */, 52166C771CEE9C9D00FCF92D /* libz.tbd */, 529828921CB3E27E001FE958 /* SQLFormatter.xcodeproj */, @@ -153,6 +173,7 @@ 529215891BDB8CD6009B031A /* MySQL */, 529215951BDB8CD6009B031A /* MySQLTests */, 529215881BDB8CD6009B031A /* Products */, + 520D2C0B1D0FD81800D73753 /* Frameworks */, ); sourceTree = ""; }; @@ -179,30 +200,12 @@ isa = PBXGroup; children = ( 52EB7BFA1C96B439009B4F55 /* LinuxMain.swift */, - 52965F881C82F6C500E35C64 /* MySQL */, + 525B38281D5AF3B600AE29A5 /* MySQLTests */, 529215981BDB8CD6009B031A /* Info.plist */, ); path = MySQLTests; sourceTree = ""; }; - 52965F881C82F6C500E35C64 /* MySQL */ = { - isa = PBXGroup; - children = ( - 523BC37C1CC9CBBC0007F0A7 /* BlobTests.swift */, - 52965F891C82F6C500E35C64 /* ConnectionPoolTests.swift */, - 52965F8A1C82F6C500E35C64 /* ConnectionTests.swift */, - 52965F8C1C82F6C500E35C64 /* DateTests.swift */, - 52965F8D1C82F6C500E35C64 /* EscapeTests.swift */, - 52965F8F1C82F6C500E35C64 /* Model.swift */, - 52965F901C82F6C500E35C64 /* MySQLTests.swift */, - 52965F911C82F6C500E35C64 /* QueryFormatterTests.swift */, - 52965F921C82F6C500E35C64 /* QueryTests.swift */, - 523BC37E1CC9CBC10007F0A7 /* SQLTypeTests.swift */, - ); - name = MySQL; - path = ../../../Tests/MySQL; - sourceTree = ""; - }; 529828931CB3E27E001FE958 /* Products */ = { isa = PBXGroup; children = ( @@ -291,11 +294,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Yusuke Ito"; TargetAttributes = { 529215861BDB8CD6009B031A = { CreatedOnToolsVersion = 7.0.1; + LastSwiftMigration = 0800; }; 529215901BDB8CD6009B031A = { CreatedOnToolsVersion = 7.0.1; @@ -385,16 +389,17 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 52965F991C82F6C500E35C64 /* Model.swift in Sources */, - 52965F931C82F6C500E35C64 /* ConnectionPoolTests.swift in Sources */, - 52965F9C1C82F6C500E35C64 /* QueryTests.swift in Sources */, - 52965F971C82F6C500E35C64 /* EscapeTests.swift in Sources */, - 52965F9B1C82F6C500E35C64 /* QueryFormatterTests.swift in Sources */, - 52965F9A1C82F6C500E35C64 /* MySQLTests.swift in Sources */, - 523BC37D1CC9CBBC0007F0A7 /* BlobTests.swift in Sources */, - 52965F941C82F6C500E35C64 /* ConnectionTests.swift in Sources */, - 523BC37F1CC9CBC10007F0A7 /* SQLTypeTests.swift in Sources */, - 52965F961C82F6C500E35C64 /* DateTests.swift in Sources */, + 525B383E1D5AF3B600AE29A5 /* XCTestManifests.swift in Sources */, + 525B383A1D5AF3B600AE29A5 /* MySQLTests.swift in Sources */, + 525B383B1D5AF3B600AE29A5 /* QueryFormatterTests.swift in Sources */, + 525B38341D5AF3B600AE29A5 /* BlobTests.swift in Sources */, + 525B38381D5AF3B600AE29A5 /* EscapeTests.swift in Sources */, + 525B38351D5AF3B600AE29A5 /* ConnectionPoolTests.swift in Sources */, + 525B38391D5AF3B600AE29A5 /* Model.swift in Sources */, + 525B38361D5AF3B600AE29A5 /* ConnectionTests.swift in Sources */, + 525B38371D5AF3B600AE29A5 /* DateTests.swift in Sources */, + 525B383D1D5AF3B600AE29A5 /* SQLTypeTests.swift in Sources */, + 525B383C1D5AF3B600AE29A5 /* QueryTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -517,6 +522,7 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = "\"$(SRCROOT)/External\""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -543,6 +549,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = "\"$(SRCROOT)/External\""; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -568,6 +576,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.novi.MySQLTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; diff --git a/OSX Projects/MySQL/MySQL.xcodeproj/xcshareddata/xcschemes/MySQL.xcscheme b/OSX Projects/MySQL/MySQL.xcodeproj/xcshareddata/xcschemes/MySQL.xcscheme index d4f62b4..ffe8fc4 100644 --- a/OSX Projects/MySQL/MySQL.xcodeproj/xcshareddata/xcschemes/MySQL.xcscheme +++ b/OSX Projects/MySQL/MySQL.xcodeproj/xcshareddata/xcschemes/MySQL.xcscheme @@ -1,6 +1,6 @@ ?) -> String { @@ -31,7 +32,7 @@ public protocol ConnectionOption { var user: String { get } var password: String { get } var database: String { get } - var timeZone: Connection.TimeZone { get } + var timeZone: TimeZone { get } var encoding: Connection.Encoding { get } var timeout: Int { get } var reconnect: Bool { get } @@ -40,8 +41,8 @@ public protocol ConnectionOption { public extension ConnectionOption { // Provide default options - var timeZone: Connection.TimeZone { - return Connection.TimeZone(GMTOffset: 0) + var timeZone: TimeZone { + return TimeZone(identifier: "UTC")! } var encoding: Connection.Encoding { return .UTF8 @@ -58,30 +59,6 @@ public extension ConnectionOption { } extension Connection { - - public final class TimeZone: Equatable, Hashable { - let timeZone: CFTimeZone - public init(name: String) { -#if os(Linux) - let s = name.withCString { p in - CFStringCreateWithCString(nil, p, UInt32(kCFStringEncodingUTF8)) - } -#elseif os(OSX) - let s = name.withCString { p in - CFStringCreateWithCString(nil, p, CFStringBuiltInEncodings.UTF8.rawValue) - } -#endif - - self.timeZone = CFTimeZoneCreateWithName(nil, s, true) - } - public init(GMTOffset: Int) { - self.timeZone = CFTimeZoneCreateWithTimeIntervalFromGMT(nil, Double(GMTOffset)) - } - public var hashValue: Int { - return Int(bitPattern: CFHash(timeZone)) - } - } - public enum Encoding: String { case UTF8 = "utf8" case UTF8MB4 = "utf8mb4" @@ -89,26 +66,8 @@ extension Connection { } -extension Connection.TimeZone: CustomStringConvertible { - public var description: String { - return "\(timeZone)" - } -} - -public func ==(lhs: Connection.TimeZone, rhs: Connection.TimeZone) -> Bool { -#if os(Linux) - return CFEqual(lhs.timeZone, rhs.timeZone) || - CFTimeZoneGetSecondsFromGMT(lhs.timeZone, 0) == CFTimeZoneGetSecondsFromGMT(rhs.timeZone, 0) || - CFStringCompare(CFTimeZoneGetName(lhs.timeZone), CFTimeZoneGetName(rhs.timeZone), 0) == kCFCompareEqualTo -#elseif os(OSX) - return CFEqual(lhs.timeZone, rhs.timeZone) || - CFTimeZoneGetSecondsFromGMT(lhs.timeZone, 0) == CFTimeZoneGetSecondsFromGMT(rhs.timeZone, 0) || - CFStringCompare(CFTimeZoneGetName(lhs.timeZone), CFTimeZoneGetName(rhs.timeZone), []) == .compareEqualTo -#endif -} - extension Connection { - public enum Error: ErrorProtocol { + public enum Error: Swift.Error { case connectionError(String) case connectionPoolGetConnectionError } @@ -139,17 +98,17 @@ public final class Connection { fatalError("mysql_init() failed.") } - var timeoutPtr = UnsafeMutablePointer(allocatingCapacity: 1) + var timeoutPtr = UnsafeMutablePointer.allocate(capacity: 1) timeoutPtr.pointee = options.timeout defer { - timeoutPtr.deallocateCapacity(1) + timeoutPtr.deallocate(capacity: 1) } mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, timeoutPtr) - var reconnectPtr = UnsafeMutablePointer(allocatingCapacity: 1) + var reconnectPtr = UnsafeMutablePointer.allocate(capacity: 1) reconnectPtr.pointee = options.reconnect == false ? 0 : 1 defer { - reconnectPtr.deallocateCapacity(1) + reconnectPtr.deallocate(capacity: 1) } if mysql_real_connect(mysql, diff --git a/Sources/MySQL/ConnectionPool.swift b/Sources/MySQL/ConnectionPool.swift index c0b3475..23634ad 100644 --- a/Sources/MySQL/ConnectionPool.swift +++ b/Sources/MySQL/ConnectionPool.swift @@ -33,10 +33,10 @@ final public class ConnectionPool: CustomStringConvertible { public init(options: ConnectionOption) { self.options = options - if self.dynamicType.libraryInitialized == false && mysql_server_init(0, nil, nil) != 0 { // mysql_library_init + if type(of: self).libraryInitialized == false && mysql_server_init(0, nil, nil) != 0 { // mysql_library_init fatalError("could not initialize MySQL library") } - self.dynamicType.libraryInitialized = true + type(of: self).libraryInitialized = true for _ in 0..( _ block: @noescape(conn: Connection) throws -> T ) throws -> T { + public func execute( _ block: @noescape(_ conn: Connection) throws -> T ) throws -> T { let conn = try getConnection() defer { releaseConnection(conn) } - return try block(conn: conn) + return try block(conn) } } diff --git a/Sources/MySQL/Date.swift b/Sources/MySQL/Date.swift index be2c46c..687946d 100644 --- a/Sources/MySQL/Date.swift +++ b/Sources/MySQL/Date.swift @@ -11,42 +11,42 @@ import Foundation import SQLFormatter internal final class SQLDateCalendar { - private static let mutex = Mutex() + fileprivate static let mutex = Mutex() - private static var cals: [Connection.TimeZone:NSCalendar] = [:] + private static var cals: [TimeZone:Calendar] = [:] - internal static func calendar(forTimezone timeZone: Connection.TimeZone) -> NSCalendar { + internal static func calendar(forTimezone timeZone: TimeZone) -> Calendar { if let cal = cals[timeZone] { return cal } - let newCal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! - newCal.timeZone = unsafeBitCast(timeZone.timeZone, to: NSTimeZone.self) // TODO: in Linux + var newCal = Calendar(identifier: Calendar.Identifier.gregorian) + newCal.timeZone = timeZone self.save(calendar: newCal, forTimeZone: timeZone) return newCal } - private static func save(calendar cal: NSCalendar, forTimeZone timeZone: Connection.TimeZone) { + private static func save(calendar cal: Calendar, forTimeZone timeZone: TimeZone) { cals[timeZone] = cal } } public struct SQLDate { - internal let timeInterval: NSTimeInterval + internal let timeInterval: TimeInterval - public init(_ date: NSDate) { + public init(_ date: Date) { self.timeInterval = date.timeIntervalSince1970 } - public init(_ timeIntervalSince1970: NSTimeInterval) { + public init(_ timeIntervalSince1970: TimeInterval) { self.timeInterval = timeIntervalSince1970 } internal init() { - self.init(NSDate()) + self.init(Date()) } - internal init(sqlDate: String, timeZone: Connection.TimeZone) throws { + internal init(sqlDate: String, timeZone: TimeZone) throws { SQLDateCalendar.mutex.lock() @@ -57,7 +57,7 @@ public struct SQLDate { switch sqlDate.characters.count { case 4: if let year = Int(sqlDate) { - let comp = NSDateComponents() + var comp = DateComponents() comp.year = year comp.month = 1 comp.day = 1 @@ -77,8 +77,8 @@ public struct SQLDate { let day = Int(String(chars[8...9])), let hour = Int(String(chars[11...12])), let minute = Int(String(chars[14...15])), - let second = Int(String(chars[17...18])) where year > 0 && day > 0 && month > 0 { - let comp = NSDateComponents() + let second = Int(String(chars[17...18])), year > 0 && day > 0 && month > 0 { + var comp = DateComponents() comp.year = year comp.month = month comp.day = day @@ -97,14 +97,14 @@ public struct SQLDate { throw QueryError.invalidSQLDate(sqlDate) } - private func pad(num: Int32, digits: Int = 2) -> String { + fileprivate func pad(num: Int32, digits: Int = 2) -> String { return pad(num: Int(num), digits: digits) } - private func pad(num: Int8, digits: Int = 2) -> String { + fileprivate func pad(num: Int8, digits: Int = 2) -> String { return pad(num: Int(num), digits: digits) } - private func pad(num: Int, digits: Int = 2) -> String { + fileprivate func pad(num: Int, digits: Int = 2) -> String { var str = String(num) if num < 0 { return str @@ -118,13 +118,13 @@ public struct SQLDate { extension SQLDate: QueryParameter { public func queryParameter(option: QueryParameterOption) -> QueryParameterType { - let comp = SQLDateCalendar.mutex.sync { () -> NSDateComponents? in + let comp = SQLDateCalendar.mutex.sync { () -> DateComponents in let cal = SQLDateCalendar.calendar(forTimezone: option.timeZone) - return cal.components([ .year, .month, .day, .hour, .minute, .second], from: date()) - }! // TODO: in Linux + return cal.dateComponents([ .year, .month, .day, .hour, .minute, .second], from: date()) + } // TODO: in Linux // YYYY-MM-DD HH:MM:SS - return QueryParameterWrap( "'\(pad(num: comp.year, digits: 4))-\(pad(num: comp.month))-\(pad(num: comp.day)) \(pad(num: comp.hour)):\(pad(num: comp.minute)):\(pad(num: comp.second))'" ) + return QueryParameterWrap( "'\(pad(num: comp.year ?? 0, digits: 4))-\(pad(num: comp.month ?? 0))-\(pad(num: comp.day ?? 0)) \(pad(num: comp.hour ?? 0)):\(pad(num: comp.minute ?? 0)):\(pad(num: comp.second ?? 0))'" ) } } @@ -138,8 +138,8 @@ extension SQLDate { public static func now() -> SQLDate { return SQLDate() } - public func date() -> NSDate { - return NSDate(timeIntervalSince1970: timeInterval) + public func date() -> Date { + return Date(timeIntervalSince1970: timeInterval) } } @@ -151,7 +151,7 @@ public func ==(lhs: SQLDate, rhs: SQLDate) -> Bool { return lhs.timeInterval == rhs.timeInterval } -extension NSDate: QueryParameter { +extension Date: QueryParameter { public func queryParameter(option: QueryParameterOption) throws -> QueryParameterType { return SQLDate(self).queryParameter(option: option) } diff --git a/Sources/MySQL/Error.swift b/Sources/MySQL/Error.swift index 821c704..0c3b4f0 100644 --- a/Sources/MySQL/Error.swift +++ b/Sources/MySQL/Error.swift @@ -6,7 +6,7 @@ // Copyright © 2015 Yusuke Ito. All rights reserved. // -public enum QueryError: ErrorProtocol { +public enum QueryError: Error { case queryExecutionError(message: String, query: String) case resultFetchError(message: String, query: String) @@ -20,4 +20,4 @@ public enum QueryError: ErrorProtocol { case missingKeyError(key: String) case invalidSQLDate(String) -} \ No newline at end of file +} diff --git a/Sources/MySQL/Query.swift b/Sources/MySQL/Query.swift index 1540dc9..99b3c4e 100644 --- a/Sources/MySQL/Query.swift +++ b/Sources/MySQL/Query.swift @@ -8,6 +8,7 @@ import CMySQL import SQLFormatter +import Foundation public struct QueryStatus: CustomStringConvertible { public let affectedRows: Int @@ -99,7 +100,7 @@ extension Connection { } } - private func query(query formattedQuery: String) throws -> ([T], QueryStatus) { + fileprivate func query(query formattedQuery: String) throws -> ([T], QueryStatus) { let mysql = try connectIfNeeded() func queryPrefix() -> String { @@ -159,7 +160,7 @@ extension Connection { var cols:[FieldValue] = [] for i in 0.. QueryParameterType { return QueryParameterWrap( self ? "true" : "false" ) } -} \ No newline at end of file +} diff --git a/Sources/MySQL/Sync.swift b/Sources/MySQL/Sync.swift index bf36dc0..6bbca7b 100644 --- a/Sources/MySQL/Sync.swift +++ b/Sources/MySQL/Sync.swift @@ -33,11 +33,12 @@ final class Mutex { extension Mutex { - func sync( block: @noescape() -> T) -> T { + func sync( block: @noescape() throws -> T) rethrows -> T { lock() - let result = block() - unlock() - return result + defer { + unlock() + } + return try block() } -} \ No newline at end of file +} diff --git a/Sources/MySQL/Transaction.swift b/Sources/MySQL/Transaction.swift index 7f6211d..1079953 100644 --- a/Sources/MySQL/Transaction.swift +++ b/Sources/MySQL/Transaction.swift @@ -24,14 +24,14 @@ extension Connection { extension ConnectionPool { - public func transaction( _ block: @noescape(conn: Connection) throws -> T ) throws -> T { + public func transaction( _ block: @noescape(_ conn: Connection) throws -> T ) throws -> T { let conn = try getConnection() defer { releaseConnection(conn) } try conn.beginTransaction() do { - let result = try block(conn: conn) + let result = try block(conn) try conn.commit() return result } catch (let e) { @@ -43,4 +43,4 @@ extension ConnectionPool { throw e } } -} \ No newline at end of file +} diff --git a/Sources/SQLFormatter/Error.swift b/Sources/SQLFormatter/Error.swift index 69f07bc..1367b08 100644 --- a/Sources/SQLFormatter/Error.swift +++ b/Sources/SQLFormatter/Error.swift @@ -6,7 +6,7 @@ // Copyright © 2016 Yusuke Ito. All rights reserved. // -public enum QueryFormatError: ErrorProtocol { +public enum QueryFormatError: Error { case castError(actual: String, expected: String, key: String) case queryParameterCountMismatch(query: String) case queryParameterIdTypeError(query: String) diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index d756fc8..4b37710 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,16 +1,10 @@ import XCTest -@testable import MySQLTestSuite -@testable import SQLFormatterTestSuite +import MySQLTests +import SQLFormatterTests -XCTMain([ - testCase( DateTests.allTests ), - testCase( EscapeTests.allTests ), - testCase( QueryFormatterTests.allTests ), - testCase( ConnectionPoolTests.allTests ), - testCase( ConnectionTests.allTests ), - testCase( QueryTests.allTests ), - testCase( BlobQueryTests.allTests ), - testCase( SQLTypeTests.allTests ), - - testCase( SQLFormatterTests.allTests ) - ]) \ No newline at end of file +var tests = [XCTestCaseEntry]() + +tests += MySQLTests.allTests() +tests += SQLFormatterTests.allTests() + +XCTMain(tests) diff --git a/Tests/MySQL/BlobTests.swift b/Tests/MySQLTests/BlobTests.swift similarity index 100% rename from Tests/MySQL/BlobTests.swift rename to Tests/MySQLTests/BlobTests.swift diff --git a/Tests/MySQL/ConnectionPoolTests.swift b/Tests/MySQLTests/ConnectionPoolTests.swift similarity index 96% rename from Tests/MySQL/ConnectionPoolTests.swift rename to Tests/MySQLTests/ConnectionPoolTests.swift index 85ef82e..eccce0c 100644 --- a/Tests/MySQL/ConnectionPoolTests.swift +++ b/Tests/MySQLTests/ConnectionPoolTests.swift @@ -10,7 +10,7 @@ import XCTest @testable import MySQL extension ConnectionPoolTests { - static var allTests : [(String, ConnectionPoolTests -> () throws -> Void)] { + static var allTests : [(String, (ConnectionPoolTests) -> () throws -> Void)] { return [ ("testGetConnection", testGetConnection), ("testExecutionBlock", testExecutionBlock) diff --git a/Tests/MySQL/ConnectionTests.swift b/Tests/MySQLTests/ConnectionTests.swift similarity index 100% rename from Tests/MySQL/ConnectionTests.swift rename to Tests/MySQLTests/ConnectionTests.swift diff --git a/Tests/MySQL/DateTests.swift b/Tests/MySQLTests/DateTests.swift similarity index 74% rename from Tests/MySQL/DateTests.swift rename to Tests/MySQLTests/DateTests.swift index 1d1d7bd..b7518cf 100644 --- a/Tests/MySQL/DateTests.swift +++ b/Tests/MySQLTests/DateTests.swift @@ -22,7 +22,7 @@ extension DateTests { extension XCTestCase { var queryOption: QueryParameterOption { - return QueryParameterOption(timeZone: Connection.TimeZone(GMTOffset: 0)) + return QueryParameterOption(timeZone: TimeZone(identifier: "UTC")!) } } @@ -30,16 +30,16 @@ class DateTests : XCTestCase { func testSQLDate() throws { - let gmt = QueryParameterOption(timeZone: Connection.TimeZone(GMTOffset: 0)) - let losAngeles = QueryParameterOption(timeZone: Connection.TimeZone(name: "America/Los_Angeles")) + let gmt = QueryParameterOption(timeZone: TimeZone(identifier: "UTC")!) + let losAngeles = QueryParameterOption(timeZone: TimeZone(identifier: "America/Los_Angeles")!) let expected = "2003-01-02 03:04:05" // no timezone - let date = SQLDate(NSDate(timeIntervalSince1970: 1041476645)) // "2003-01-02 03:04:05" at GMT + let date = SQLDate(Date(timeIntervalSince1970: 1041476645)) // "2003-01-02 03:04:05" at GMT XCTAssertEqual(date.queryParameter(option: gmt).escaped(), "'\(expected)'") let sqlDate = try SQLDate(sqlDate: expected, timeZone: losAngeles.timeZone) - let dateAtLos = SQLDate(NSDate(timeIntervalSince1970: 1041476645 + 3600*8)) + let dateAtLos = SQLDate(Date(timeIntervalSince1970: 1041476645 + 3600*8)) XCTAssertEqual(sqlDate.timeInterval, dateAtLos.timeInterval, "create date from sql string") XCTAssertEqual(sqlDate.queryParameter(option: losAngeles).escaped(), "'\(expected)'") @@ -58,12 +58,13 @@ class DateTests : XCTestCase { } func testSQLCalendar() { - let gmt = Connection.TimeZone(GMTOffset: 100) + let gmt = TimeZone(abbreviation: "PDT")! let cal1 = SQLDateCalendar.calendar(forTimezone: gmt) let cal2 = SQLDateCalendar.calendar(forTimezone: gmt) - XCTAssertTrue(unsafeAddress(of: cal1) == unsafeAddress(of: cal2)) + //Unmanaged.passUnretained(cal1).toOpaque() + //XCTAssertTrue(unsafeAddress(of: cal1 as AnyObject) == unsafeAddress(of: cal2 as AnyObject)) XCTAssertEqual(cal1, cal2) XCTAssertEqual(cal1.hashValue, cal2.hashValue) } -} \ No newline at end of file +} diff --git a/Tests/MySQL/EscapeTests.swift b/Tests/MySQLTests/EscapeTests.swift similarity index 100% rename from Tests/MySQL/EscapeTests.swift rename to Tests/MySQLTests/EscapeTests.swift diff --git a/Tests/MySQL/Model.swift b/Tests/MySQLTests/Model.swift similarity index 100% rename from Tests/MySQL/Model.swift rename to Tests/MySQLTests/Model.swift diff --git a/Tests/MySQL/MySQLTests.swift b/Tests/MySQLTests/MySQLTests.swift similarity index 85% rename from Tests/MySQL/MySQLTests.swift rename to Tests/MySQLTests/MySQLTests.swift index 0482463..c760da6 100644 --- a/Tests/MySQL/MySQLTests.swift +++ b/Tests/MySQLTests/MySQLTests.swift @@ -8,6 +8,7 @@ import XCTest import MySQL +import Foundation /* @@ -32,7 +33,7 @@ struct DummyConstants: TestConstantsType { let database: String = "test" let tableName: String = "unit_test_db_3894" let encoding: Connection.Encoding = .UTF8MB4 - let timeZone: Connection.TimeZone = Connection.TimeZone(GMTOffset: 60 * 60 * 9) // JST + let timeZone: TimeZone = TimeZone(abbreviation: "JST")! // JST } protocol TestConstantsType: ConnectionOption { @@ -49,7 +50,7 @@ extension MySQLTestType { self.constants = DummyConstants() // !!! Replace with your MySQL connection !!! self.pool = ConnectionPool(options: constants) - XCTAssertEqual(constants.timeZone, Connection.TimeZone(GMTOffset: 60 * 60 * 9), "test MySQL's timezone should be JST") + XCTAssertEqual(constants.timeZone, TimeZone(abbreviation: "JST"), "test MySQL's timezone should be JST") } } diff --git a/Tests/MySQL/QueryFormatterTests.swift b/Tests/MySQLTests/QueryFormatterTests.swift similarity index 100% rename from Tests/MySQL/QueryFormatterTests.swift rename to Tests/MySQLTests/QueryFormatterTests.swift diff --git a/Tests/MySQL/QueryTests.swift b/Tests/MySQLTests/QueryTests.swift similarity index 99% rename from Tests/MySQL/QueryTests.swift rename to Tests/MySQLTests/QueryTests.swift index 5e5e844..c9adad3 100644 --- a/Tests/MySQL/QueryTests.swift +++ b/Tests/MySQLTests/QueryTests.swift @@ -99,7 +99,7 @@ class QueryTests: XCTestCase, QueryTestType { } var anotherDate: SQLDate { - return SQLDate(NSDate(timeIntervalSinceReferenceDate: 60*60*24*67)) + return SQLDate(Date(timeIntervalSinceReferenceDate: 60*60*24*67)) } func testInsertRow() throws { diff --git a/Tests/MySQL/SQLTypeTests.swift b/Tests/MySQLTests/SQLTypeTests.swift similarity index 100% rename from Tests/MySQL/SQLTypeTests.swift rename to Tests/MySQLTests/SQLTypeTests.swift diff --git a/Tests/MySQLTests/XCTestManifests.swift b/Tests/MySQLTests/XCTestManifests.swift new file mode 100644 index 0000000..644a12a --- /dev/null +++ b/Tests/MySQLTests/XCTestManifests.swift @@ -0,0 +1,24 @@ +// +// XCTestManifests.swift +// CrawlerKit +// +// Created by Yusuke Ito on 6/4/16. +// Copyright © 2016 Yusuke Ito. All rights reserved. +// + +import XCTest + +#if !os(OSX) + public func allTests() -> [XCTestCaseEntry] { + return [ + testCase( DateTests.allTests ), + testCase( EscapeTests.allTests ), + testCase( QueryFormatterTests.allTests ), + testCase( ConnectionPoolTests.allTests ), + testCase( ConnectionTests.allTests ), + testCase( QueryTests.allTests ), + testCase( BlobQueryTests.allTests ), + testCase( SQLTypeTests.allTests ) + ] + } +#endif diff --git a/Tests/SQLFormatter/SQLFormatterTests.swift b/Tests/SQLFormatterTests/SQLFormatterTests.swift similarity index 52% rename from Tests/SQLFormatter/SQLFormatterTests.swift rename to Tests/SQLFormatterTests/SQLFormatterTests.swift index 92e93f2..1f4ebfc 100644 --- a/Tests/SQLFormatter/SQLFormatterTests.swift +++ b/Tests/SQLFormatterTests/SQLFormatterTests.swift @@ -9,18 +9,25 @@ import XCTest @testable import SQLFormatter -extension SQLFormatterTests { - static var allTests : [(String, SQLFormatterTests -> () throws -> Void)] { +extension SQLFormattingTests { + static var allTests : [(String, (SQLFormattingTests) -> () throws -> Void)] { return [ ("testDummy", testDummy) ] } } -class SQLFormatterTests: XCTestCase { +class SQLFormattingTests: XCTestCase { func testDummy() throws { XCTAssertTrue(true) } - } + +#if !os(OSX) + public func allTests() -> [XCTestCaseEntry] { + return [ + testCase( SQLFormattingTests.allTests ), + ] + } +#endif