Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
os:
- linux
- osx
language: generic
sudo: required
dist: trusty
osx_image: xcode9
matrix:
include:
- os: linux
language: generic
sudo: required
dist: trusty
env: SWIFT_VERSION=3.1.1
- os: linux
language: generic
sudo: required
dist: trusty
- os: osx
language: generic
sudo: required
osx_image: xcode8.3
env: SWIFT_VERSION=3.1.1
- os: osx
language: generic
sudo: required
osx_image: xcode9

install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
Expand Down
14 changes: 3 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "PathKit",
products: [
.library(name: "PathKit", targets: ["PathKit"]),
],
dependencies: [
.package(url:"https://github.com/kylef/Spectre.git", .upToNextMinor(from:"0.8.0"))
],
targets: [
.target(name: "PathKit", dependencies: [], path: "Sources"),
.testTarget(name: "PathKitTests", dependencies: ["PathKit", "Spectre"], path:"Tests/PathKitTests")
],
swiftLanguageVersions: [3]
// https://github.com/apple/swift-package-manager/pull/597
.Package(url: "https://github.com/kylef/Spectre.git", majorVersion: 0, minor: 7),
]
)
16 changes: 16 additions & 0 deletions Package@swift-4.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "PathKit",
products: [
.library(name: "PathKit", targets: ["PathKit"]),
],
dependencies: [
.package(url:"https://github.com/kylef/Spectre.git", .upToNextMinor(from:"0.8.0"))
],
targets: [
.target(name: "PathKit", dependencies: [], path: "Sources"),
.testTarget(name: "PathKitTests", dependencies: ["PathKit", "Spectre"], path:"Tests/PathKitTests")
]
)
26 changes: 20 additions & 6 deletions Sources/PathKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public struct Path {
path = "."
} else if components.first == Path.separator && components.count > 1 {
let p = components.joined(separator: Path.separator)
#if swift(>=4.0)
path = String(p[p.index(after: p.startIndex)...])
#else
path = p.substring(from: p.characters.index(after: p.startIndex))
#endif
} else {
path = components.joined(separator: Path.separator)
}
Expand Down Expand Up @@ -276,10 +280,10 @@ extension Path {
guard Path.fileManager.fileExists(atPath: normalize().path, isDirectory: &directory) else {
return false
}
#if os(Linux)
return directory
#else
#if !os(Linux) || swift(>=4.1)
return directory.boolValue
#else
return directory
#endif
}

Expand All @@ -295,10 +299,10 @@ extension Path {
guard Path.fileManager.fileExists(atPath: normalize().path, isDirectory: &directory) else {
return false
}
#if os(Linux)
return !directory
#else
#if !os(Linux) || swift(>=4.1)
return !directory.boolValue
#else
return !directory
#endif
}

Expand Down Expand Up @@ -598,13 +602,23 @@ extension Path {
#else
let matchc = gt.gl_matchc
#endif
#if swift(>=4.1)
return (0..<Int(matchc)).compactMap { index in
if let path = String(validatingUTF8: gt.gl_pathv[index]!) {
return Path(path)
}

return nil
}
#else
return (0..<Int(matchc)).flatMap { index in
if let path = String(validatingUTF8: gt.gl_pathv[index]!) {
return Path(path)
}

return nil
}
#endif
}

// GLOB_NOMATCH
Expand Down
6 changes: 3 additions & 3 deletions Tests/PathKitTests/PathKitSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ describe("PathKit") {

$0.it("can return the last component without extension") {
try expect(Path("a/b/c.d").lastComponentWithoutExtension) == "c"
#if os(Linux) // no longer necessary after Swift 4.1
try expect(Path("a/..").lastComponentWithoutExtension) == "."
#else
#if !os(Linux) || swift(>=4.1)
try expect(Path("a/..").lastComponentWithoutExtension) == ".."
#else
try expect(Path("a/..").lastComponentWithoutExtension) == "."
#endif
}

Expand Down