diff --git a/.travis.yml b/.travis.yml index 08c0ffa..94ab09e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ if: type != push OR branch = master OR branch =~ /^\d+\.\d+(\.\d+)?(-\S*)?$/ stages: + - name: pretest - name: test - name: deploy if: branch =~ ^\d+\.\d+\.\d+$ @@ -34,7 +35,6 @@ jobs: -destination 'platform=watchOS Simulator,OS=latest,name=Apple Watch Series 4 - 40mm' \ build | xcpretty - - env: SWIFT_VERSION=4.2.1 os: linux name: Linux @@ -43,30 +43,34 @@ jobs: sudo: false install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" script: swift test + + - stage: pretest + name: Check if Linux tests are up-to-date + install: swift test --generate-linuxmain + script: git diff --exit-code - - <<: *xcodebuild - stage: deploy + - stage: deploy name: Jazzy before_install: | - cat << EOF > .jazzy.yml + cat << EOF > .jazzy.yaml + module: Path + module_version: $TRAVIS_TAG custom_categories: - name: Path children: - Path - /(_:_:) + xcodebuild_arguments: + - UseModernBuildSystem=NO + output: output + github_url: https://github.com/mxcl/Path.swift EOF - touch Contents.md - install: gem install jazzy + install: | + gem install jazzy + swift package generate-xcodeproj script: | - jazzy \ - --no-hide-documentation-coverage \ - --theme fullwidth \ - --output output \ - --readme Contents.md \ - --root-url https://mxcl.github.io/Path.swift/ \ - --github_url https://github.com/mxcl/Path.swift \ - --module Path \ - --module-version $TRAVIS_TAG + jazzy + rm -rf output/docsets deploy: provider: pages skip-cleanup: true @@ -75,7 +79,25 @@ jobs: on: tags: true - - stage: deploy - name: CocoaPods + - name: CocoaPods + before_install: | + cat << EOF > Path.swift.podspec + Pod::Spec.new do |s| + s.name = 'Path.swift' + s.version = '$TRAVIS_TAG' + s.summary = 'Delightful, robust file-pathing functions' + s.homepage = 'https://github.com/mxcl/Path.swift' + s.license = { :type => 'Unlicense', :file => 'LICENSE.md' } + s.author = { 'mxcl' => 'mxcl@me.com' } + s.source = { :git => 'https://github.com/mxcl/Path.swift.git', :tag => s.version.to_s } + s.social_media_url = 'https://twitter.com/mxcl' + s.osx.deployment_target = '10.10' + s.ios.deployment_target = '8.0' + s.tvos.deployment_target = '10.0' + s.watchos.deployment_target = '3.0' + s.source_files = 'Sources/*' + s.swift_version = "4.2" + end + EOF install: gem install cocoapods --pre script: pod trunk push --allow-warnings diff --git a/Path.swift.podspec b/Path.swift.podspec deleted file mode 100644 index 8bb1869..0000000 --- a/Path.swift.podspec +++ /dev/null @@ -1,19 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'Path.swift' - s.version = '0.4.1' - s.summary = 'Delightful, robust file-pathing functions' - s.homepage = 'https://github.com/mxcl/Path.swift' - s.license = { :type => 'Unlicense', :file => 'LICENSE.md' } - s.author = { 'mxcl' => 'mxcl@me.com' } - s.source = { :git => 'https://github.com/mxcl/Path.swift.git', :tag => s.version.to_s } - s.social_media_url = 'https://twitter.com/mxcl' - - s.osx.deployment_target = '10.10' - s.ios.deployment_target = '8.0' - s.tvos.deployment_target = '10.0' - s.watchos.deployment_target = '3.0' - - s.source_files = 'Sources/*' - - s.swift_version = "4.2" -end diff --git a/README.md b/README.md index 935a18b..173d81b 100644 --- a/README.md +++ b/README.md @@ -208,4 +208,4 @@ https://codebasesaga.com/canopy/ [badge-platforms]: https://img.shields.io/badge/platforms-macOS%20%7C%20Linux%20%7C%20iOS%20%7C%20tvOS%20%7C%20watchOS-lightgrey.svg [badge-languages]: https://img.shields.io/badge/swift-4.2-orange.svg -[online API documentation]: https://mxcl.github.io/Path.swift/ +[online API documentation]: https://mxcl.github.io/Path.swift/Structs/Path.html diff --git a/Sources/Path+ls.swift b/Sources/Path+ls.swift index 08d42eb..13bfa6e 100644 --- a/Sources/Path+ls.swift +++ b/Sources/Path+ls.swift @@ -1,13 +1,19 @@ import Foundation public extension Path { - /// Same as the `ls` command ∴ is ”shallow” - /// - Parameter skipHiddenFiles: Same as the `ls -a` if false. Otherwise returns only the non hidden files. Default is false. - func ls(skipHiddenFiles: Bool = false) throws -> [Entry] { - let options: FileManager.DirectoryEnumerationOptions = skipHiddenFiles ? [.skipsHiddenFiles] : [] - let paths = try FileManager.default.contentsOfDirectory(at: url, - includingPropertiesForKeys: nil, - options: options) + /** + Same as the `ls -a` command ∴ is ”shallow” + - Parameter includeHiddenFiles: If `true`, hidden files are included in the results. Defaults to `true`. + - Important: `includeHiddenFiles` does not work on Linux + */ + func ls(includeHiddenFiles: Bool = true) throws -> [Entry] { + var opts = FileManager.DirectoryEnumerationOptions() + #if !os(Linux) + if !includeHiddenFiles { + opts.insert(.skipsHiddenFiles) + } + #endif + let paths = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: opts) func convert(url: URL) -> Entry? { guard let path = Path(url.path) else { return nil } return Entry(kind: path.isDirectory ? .directory : .file, path: path) diff --git a/Tests/PathTests/PathTests.swift b/Tests/PathTests/PathTests.swift index c5a9e9f..8048f4e 100644 --- a/Tests/PathTests/PathTests.swift +++ b/Tests/PathTests/PathTests.swift @@ -31,8 +31,9 @@ class PathTests: XCTestCase { XCTAssertEqual(paths, ["a", "b", "c", ".d"]) } - + func testEnumerationSkippingHiddenFiles() throws { + #if !os(Linux) let tmpdir_ = try TemporaryDirectory() let tmpdir = tmpdir_.path try tmpdir.join("a").mkdir().join("c").touch() @@ -42,7 +43,7 @@ class PathTests: XCTestCase { var paths = Set() var dirs = 0 - for entry in try tmpdir.ls(skipHiddenFiles: true) { + for entry in try tmpdir.ls(includeHiddenFiles: false) { if entry.kind == .directory { dirs += 1 } @@ -50,7 +51,7 @@ class PathTests: XCTestCase { } XCTAssertEqual(dirs, 1) XCTAssertEqual(paths, ["a", "b", "c"]) - + #endif } func testRelativeTo() { diff --git a/Tests/PathTests/TemporaryDirectory.swift b/Tests/PathTests/TemporaryDirectory.swift index 1e1577f..1b9261d 100644 --- a/Tests/PathTests/TemporaryDirectory.swift +++ b/Tests/PathTests/TemporaryDirectory.swift @@ -52,3 +52,20 @@ extension Path { return try body(tmp.path) } } + + +#if !os(macOS) && !os(Linux) +import XCTest + +// SwiftPM generates code that is improperly escaped thus we require this to +// compile on iOS & tvOS. +public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(String, (XCTestCase) throws -> Void)]) + +public func testCase(_ allTests: [(String, (T) -> () throws -> Void)]) -> XCTestCaseEntry { + fatalError() +} + +public func testCase(_ allTests: [(String, (T) -> () -> Void)]) -> XCTestCaseEntry { + fatalError() +} +#endif diff --git a/Tests/PathTests/XCTestManifests.swift b/Tests/PathTests/XCTestManifests.swift index 8095888..9104303 100644 --- a/Tests/PathTests/XCTestManifests.swift +++ b/Tests/PathTests/XCTestManifests.swift @@ -6,8 +6,10 @@ extension PathTests { ("testCodable", testCodable), ("testConcatenation", testConcatenation), ("testEnumeration", testEnumeration), + ("testEnumerationSkippingHiddenFiles", testEnumerationSkippingHiddenFiles), ("testExists", testExists), ("testIsDirectory", testIsDirectory), + ("testJoin", testJoin), ("testMkpathIfExists", testMkpathIfExists), ("testMktemp", testMktemp), ("testRelativePathCodable", testRelativePathCodable), @@ -15,7 +17,7 @@ extension PathTests { ] } -#if os(Linux) +#if !os(macOS) public func __allTests() -> [XCTestCaseEntry] { return [ testCase(PathTests.__allTests),