diff --git a/Pods/CatchingFire/src/CatchingFire.swift b/Pods/CatchingFire/src/CatchingFire.swift index 0ced4f1..085deb8 100644 --- a/Pods/CatchingFire/src/CatchingFire.swift +++ b/Pods/CatchingFire/src/CatchingFire.swift @@ -8,6 +8,10 @@ import XCTest +#if !swift(>=3.0) + typealias ErrorProtocol = ErrorType +#endif + /// This allows you to write safe tests for the happy path of failable functions. /// It helps you to avoid the `try!` operator in tests. @@ -77,11 +81,11 @@ public func AssertNoThrow(@noescape closure: () throws -> ()) { /// /// If the expression or closure doesn't throw the expected error, your test fails. /// -public func AssertThrows(expectedError: E, @autoclosure _ closure: () throws -> R) -> () { +public func AssertThrows(expectedError: E, @autoclosure _ closure: () throws -> R) -> () { AssertThrows(expectedError) { try closure() } } -public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { +public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { do { try closure() XCTFail("Expected to catch <\(expectedError)>, " @@ -95,11 +99,11 @@ public func AssertThrows(expectedError: E, @noescape _ clo } } -public func AssertThrows(expectedError: E, @autoclosure _ closure: () throws -> R) -> () { +public func AssertThrows(expectedError: E, @autoclosure _ closure: () throws -> R) -> () { AssertThrows(expectedError) { try closure() } } -public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { +public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { do { try closure() XCTFail("Expected to catch <\(expectedError)>, " @@ -116,7 +120,7 @@ public func AssertThrows(expectedError: E, @ } /// Implement pattern matching for ErrorTypes -internal func ~=(lhs: ErrorType, rhs: ErrorType) -> Bool { +internal func ~=(lhs: ErrorProtocol, rhs: ErrorProtocol) -> Bool { return lhs._domain == rhs._domain && rhs._code == rhs._code } @@ -131,7 +135,7 @@ internal func ~=(lhs: ErrorType, rhs: ErrorType) -> Bool { //// put them in a separate enum and import your framework as `@testable` in your tests without /// affecting the public API, if that matters. /// -public struct Error : ErrorType { +public struct Error : ErrorProtocol { public let domain: String public let code: Int @@ -153,7 +157,7 @@ public func ==(lhs: Error, rhs: Error) -> Bool { } /// Implement pattern matching for Error & ErrorType -public func ~=(lhs: Error, rhs: ErrorType) -> Bool { +public func ~=(lhs: Error, rhs: ErrorProtocol) -> Bool { return lhs._domain == rhs._domain && rhs._code == rhs._code } diff --git a/Sources/PathKit.swift b/Sources/PathKit.swift index 9632986..38d8ec5 100644 --- a/Sources/PathKit.swift +++ b/Sources/PathKit.swift @@ -12,6 +12,12 @@ let system_glob = Darwin.glob import Foundation +#if !swift(>=3.0) + typealias Collection = CollectionType + typealias Sequence = SequenceType + typealias IteratorProtocol = GeneratorType +#endif + /// Represents a filesystem path. public struct Path { @@ -35,7 +41,8 @@ public struct Path { } /// Create a Path by joining multiple path components together - public init(components: S) { + #if !swift(>=3.0) + public init(components: S) { if components.isEmpty { path = "." } else if components.first == Path.separator && components.count > 1 { @@ -50,9 +57,27 @@ public struct Path { } else { path = components.joinWithSeparator(Path.separator) } + } + #else + public init(components: S) { + if components.isEmpty { + path = "." + } else if components.first == Path.separator && components.count > 1 { + let p = components.joined(separator: Path.separator) +#if os(Linux) + let index = p.startIndex.distance( to: p.startIndex.successor()) + path = NSString(string: p).substringFromIndex(index) +#else + path = p.substring(from: p.startIndex.successor()) +#endif + + } else { + path = components.joined(separator: Path.separator) + } } -} + #endif +} // MARK: StringLiteralConvertible @@ -130,7 +155,15 @@ extension Path { /// representation. /// public func normalize() -> Path { + #if !swift(>=3.0) return Path(NSString(string: self.path).stringByStandardizingPath) + #else + #if os(Linux) + return Path(NSString(string: self.path).stringByStandardizingPath) + #else + return Path(NSString(string: self.path).standardizingPath) + #endif + #endif } /// De-normalizes the path, by replacing the current user home directory with "~". @@ -143,7 +176,11 @@ extension Path { // TODO: actually de-normalize the path return self #else + #if !swift(>=3.0) return Path(NSString(string: self.path).stringByAbbreviatingWithTildeInPath) + #else + return Path(NSString(string: self.path).abbreviatingWithTildeInPath) + #endif #endif } @@ -152,7 +189,15 @@ extension Path { /// - Returns: the path of directory or file to which the symbolic link refers /// public func symlinkDestination() throws -> Path { + #if !swift(>=3.0) let symlinkDestination = try Path.fileManager.destinationOfSymbolicLinkAtPath(path) + #else + #if os(Linux) + let symlinkDestination = try Path.fileManager.destinationOfSymbolicLinkAtPath(path) + #else + let symlinkDestination = try Path.fileManager.destinationOfSymbolicLink(atPath:path) + #endif + #endif let symlinkPath = Path(symlinkDestination) if symlinkPath.isRelative { return self + ".." + symlinkPath @@ -181,7 +226,15 @@ extension Path { /// - Returns: the last path component without file extension /// public var lastComponentWithoutExtension: String { + #if !swift(>=3.0) return NSString(string: lastComponent).stringByDeletingPathExtension + #else + #if os(Linux) + return NSString(string: lastComponent).stringByDeletingPathExtension + #else + return NSString(string: lastComponent).deletingPathExtension + #endif + #endif } /// Splits the string representation on the directory separator. @@ -199,7 +252,7 @@ extension Path { /// public var `extension`: String? { let pathExtension = NSString(string: path).pathExtension - if pathExtension.isEmpty { + if pathExtension.isEmpty { return nil } @@ -217,7 +270,15 @@ extension Path { /// determined /// public var exists: Bool { + #if !swift(>=3.0) return Path.fileManager.fileExistsAtPath(self.path) + #else + #if os(Linux) + return Path.fileManager.fileExistsAtPath(self.path) + #else + return Path.fileManager.fileExists(atPath:self.path) + #endif + #endif } /// Test whether a path is a directory. @@ -228,9 +289,21 @@ extension Path { /// public var isDirectory: Bool { var directory = ObjCBool(false) + #if !swift(>=3.0) guard Path.fileManager.fileExistsAtPath(normalize().path, isDirectory: &directory) else { return false } + #else + #if os(Linux) + guard Path.fileManager.fileExistsAtPath(normalize().path, isDirectory: &directory) else { + return false + } + #else + guard Path.fileManager.fileExists(atPath: normalize().path, isDirectory: &directory) else { + return false + } + #endif + #endif return directory.boolValue } @@ -243,9 +316,21 @@ extension Path { /// public var isFile: Bool { var directory = ObjCBool(false) + #if !swift(>=3.0) guard Path.fileManager.fileExistsAtPath(normalize().path, isDirectory: &directory) else { return false } + #else + #if os(Linux) + guard Path.fileManager.fileExistsAtPath(normalize().path, isDirectory: &directory) else { + return false + } + #else + guard Path.fileManager.fileExists(atPath: normalize().path, isDirectory: &directory) else { + return false + } + #endif + #endif return !directory.boolValue } @@ -256,7 +341,15 @@ extension Path { /// public var isSymlink: Bool { do { + #if !swift(>=3.0) let _ = try Path.fileManager.destinationOfSymbolicLinkAtPath(path) + #else + #if os(Linux) + let _ = try Path.fileManager.destinationOfSymbolicLinkAtPath(path) + #else + let _ = try Path.fileManager.destinationOfSymbolicLink(atPath: path) + #endif + #endif return true } catch { return false @@ -270,7 +363,15 @@ extension Path { /// file could not be determined. /// public var isReadable: Bool { + #if !swift(>=3.0) return Path.fileManager.isReadableFileAtPath(self.path) + #else + #if os(Linux) + return Path.fileManager.isReadableFileAtPath(self.path) + #else + return Path.fileManager.isReadableFile(atPath: self.path) + #endif + #endif } /// Test whether a path is writeable @@ -280,7 +381,15 @@ extension Path { /// file could not be determined. /// public var isWritable: Bool { + #if !swift(>=3.0) return Path.fileManager.isWritableFileAtPath(self.path) + #else + #if os(Linux) + return Path.fileManager.isWritableFileAtPath(self.path) + #else + return Path.fileManager.isWritableFile(atPath: self.path) + #endif + #endif } /// Test whether a path is executable @@ -290,7 +399,15 @@ extension Path { /// file could not be determined. /// public var isExecutable: Bool { + #if !swift(>=3.0) return Path.fileManager.isExecutableFileAtPath(self.path) + #else + #if os(Linux) + return Path.fileManager.isExecutableFileAtPath(self.path) + #else + return Path.fileManager.isExecutableFile(atPath: self.path) + #endif + #endif } /// Test whether a path is deletable @@ -300,7 +417,15 @@ extension Path { /// file could not be determined. /// public var isDeletable: Bool { + #if !swift(>=3.0) return Path.fileManager.isDeletableFileAtPath(self.path) + #else + #if os(Linux) + return Path.fileManager.isDeletableFileAtPath(self.path) + #else + return Path.fileManager.isDeletableFile(atPath: self.path) + #endif + #endif } } @@ -315,7 +440,15 @@ extension Path { /// not a directory. /// public func mkdir() throws -> () { + #if !swift(>=3.0) try Path.fileManager.createDirectoryAtPath(self.path, withIntermediateDirectories: false, attributes: nil) + #else + #if os(Linux) + try Path.fileManager.createDirectoryAtPath(self.path, withIntermediateDirectories: false, attributes: nil) + #else + try Path.fileManager.createDirectory(atPath: self.path, withIntermediateDirectories: false, attributes: nil) + #endif + #endif } /// Create the directory and any intermediate parent directories that do not exist. @@ -324,7 +457,15 @@ extension Path { /// not a directory. /// public func mkpath() throws -> () { + #if !swift(>=3.0) try Path.fileManager.createDirectoryAtPath(self.path, withIntermediateDirectories: true, attributes: nil) + #else + #if os(Linux) + try Path.fileManager.createDirectoryAtPath(self.path, withIntermediateDirectories: true, attributes: nil) + #else + try Path.fileManager.createDirectory(atPath: self.path, withIntermediateDirectories: true, attributes: nil) + #endif + #endif } /// Delete the file or directory. @@ -333,7 +474,15 @@ extension Path { /// removed. /// public func delete() throws -> () { + #if !swift(>=3.0) try Path.fileManager.removeItemAtPath(self.path) + #else + #if os(Linux) + try Path.fileManager.removeItemAtPath(self.path) + #else + try Path.fileManager.removeItem(atPath: self.path) + #endif + #endif } /// Move the file or directory to a new location synchronously. @@ -342,7 +491,15 @@ extension Path { /// directory in its new location. /// public func move(destination: Path) throws -> () { + #if !swift(>=3.0) try Path.fileManager.moveItemAtPath(self.path, toPath: destination.path) + #else + #if os(Linux) + try Path.fileManager.moveItemAtPath(self.path, toPath: destination.path) + #else + try Path.fileManager.moveItem(atPath: self.path, toPath: destination.path) + #endif + #endif } /// Copy the file or directory to a new location synchronously. @@ -351,7 +508,15 @@ extension Path { /// directory in its new location. /// public func copy(destination: Path) throws -> () { + #if !swift(>=3.0) try Path.fileManager.copyItemAtPath(self.path, toPath: destination.path) + #else + #if os(Linux) + try Path.fileManager.copyItemAtPath(self.path, toPath: destination.path) + #else + try Path.fileManager.copyItem(atPath: self.path, toPath: destination.path) + #endif + #endif } /// Creates a hard link at a new destination. @@ -359,7 +524,15 @@ extension Path { /// - Parameter destination: The location where the link will be created. /// public func link(destination: Path) throws -> () { + #if !swift(>=3.0) try Path.fileManager.linkItemAtPath(self.path, toPath: destination.path) + #else + #if os(Linux) + try Path.fileManager.linkItemAtPath(self.path, toPath: destination.path) + #else + try Path.fileManager.linkItem(atPath: self.path, toPath: destination.path) + #endif + #endif } /// Creates a symbolic link at a new destination. @@ -367,7 +540,15 @@ extension Path { /// - Parameter destintation: The location where the link will be created. /// public func symlink(destination: Path) throws -> () { + #if !swift(>=3.0) try Path.fileManager.createSymbolicLinkAtPath(self.path, withDestinationPath: destination.path) + #else + #if os(Linux) + try Path.fileManager.createSymbolicLinkAtPath(self.path, withDestinationPath: destination.path) + #else + try Path.fileManager.createSymbolicLink(atPath: self.path, withDestinationPath: destination.path) + #endif + #endif } } @@ -400,7 +581,7 @@ extension Path { Path.current = self defer { Path.current = previous } try closure() - } + } } @@ -443,7 +624,15 @@ extension Path { /// - Note: Based on `NSUUID`. /// public static func uniqueTemporary() throws -> Path { + #if !swift(>=3.0) let path = try processUniqueTemporary() + NSUUID().UUIDString + #else + #if os(Linux) + let path = try processUniqueTemporary() + NSUUID().UUIDString + #else + let path = try processUniqueTemporary() + NSUUID().uuidString + #endif + #endif try path.mkdir() return path } @@ -469,7 +658,15 @@ extension Path { /// - Returns: the contents of the file at the specified path as string. /// public func read(encoding: NSStringEncoding = NSUTF8StringEncoding) throws -> String { + #if !swift(>=3.0) return try NSString(contentsOfFile: path, encoding: encoding).substringFromIndex(0) as String + #else + #if os(Linux) + return try NSString(contentsOfFile: path, encoding: encoding).substringFromIndex(0) as String + #else + return try NSString(contentsOfFile: path, encoding: encoding).substring(from:0) as String + #endif + #endif } /// Write a file. @@ -480,7 +677,15 @@ extension Path { /// - Parameter data: the contents to write to file. /// public func write(data: NSData) throws { + #if !swift(>=3.0) try data.writeToFile(normalize().path, options: .DataWritingAtomic) + #else + #if os(Linux) + try data.writeToFile(normalize().path, options: .DataWritingAtomic) + #else + try data.write(toFile:normalize().path, options: .dataWritingAtomic) + #endif + #endif } /// Reads the file. @@ -496,7 +701,15 @@ extension Path { /// - Returns: the contents of the file at the specified path as string. /// public func write(string: String, encoding: NSStringEncoding = NSUTF8StringEncoding) throws { + #if !swift(>=3.0) try NSString(string: string).writeToFile(normalize().path, atomically: true, encoding: encoding) + #else + #if os(Linux) + try NSString(string: string).writeToFile(normalize().path, atomically: true, encoding: encoding) + #else + try NSString(string: string).write(toFile:normalize().path, atomically: true, encoding: encoding) + #endif + #endif } } @@ -517,9 +730,22 @@ extension Path { /// - Returns: paths to all files, directories and symbolic links contained in the directory /// public func children() throws -> [Path] { + #if !swift(>=3.0) return try Path.fileManager.contentsOfDirectoryAtPath(path).map { self + Path($0) } + #else + #if os(Linux) + return try Path.fileManager.contentsOfDirectoryAtPath(path).map { + self + Path($0) + } + #else + return try Path.fileManager.contentsOfDirectory(atPath:path).map { + self + Path($0) + } + #endif + #endif + } /// Performs a deep enumeration in a directory @@ -528,9 +754,21 @@ extension Path { /// any subdirectory. /// public func recursiveChildren() throws -> [Path] { + #if !swift(>=3.0) return try Path.fileManager.subpathsOfDirectoryAtPath(path).map { self + Path($0) } + #else + #if os(Linux) + return try Path.fileManager.subpathsOfDirectoryAtPath(path).map { + self + Path($0) + } + #else + return try Path.fileManager.subpathsOfDirectory(atPath:path).map { + self + Path($0) + } + #endif + #endif } } @@ -553,6 +791,7 @@ extension Path { #else let matchc = gt.gl_matchc #endif + #if !swift(>=3.0) return (0..=3.0) self.directoryEnumerator = Path.fileManager.enumeratorAtPath(path.path)! + #else + #if os(Linux) + self.directoryEnumerator = Path.fileManager.enumeratorAtPath(path.path)! + #else + self.directoryEnumerator = Path.fileManager.enumerator(atPath:path.path)! + #endif + #endif } public func next() -> Path? { @@ -606,12 +862,20 @@ extension Path : SequenceType { /// - Returns: a directory enumerator that can be used to perform a deep enumeration of the /// directory. /// + #if !swift(>=3.0) public func generate() -> DirectoryEnumerator { return DirectoryEnumerator(path: self) } + #else + public func makeIterator() -> DirectoryEnumerator { + return DirectoryEnumerator(path: self) + } + #endif } + + // MARK: Equatable extension Path : Equatable {}