From e0c62108e8f569e6d344d05e114f54aa0107e319 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 20 Jan 2019 16:30:02 -0500 Subject: [PATCH 1/6] Update Linux tests --- Tests/PathTests/XCTestManifests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/PathTests/XCTestManifests.swift b/Tests/PathTests/XCTestManifests.swift index 8095888..ce48de0 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), From c0e5023632745a78e29a9359af08c5adfaaf4a04 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 20 Jan 2019 17:13:03 -0500 Subject: [PATCH 2/6] Better deployment of Jazzy and Pods --- .travis.yml | 46 ++++++++++++++++++++++++++++++++-------------- Path.swift.podspec | 19 ------------------- README.md | 2 +- 3 files changed, 33 insertions(+), 34 deletions(-) delete mode 100644 Path.swift.podspec diff --git a/.travis.yml b/.travis.yml index 08c0ffa..d4988e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,29 +44,28 @@ jobs: install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" script: swift test - - <<: *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 @@ -77,5 +76,24 @@ jobs: - stage: deploy 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 From 751b855a261dc39b22b193dc2d2fd577709d28f6 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 20 Jan 2019 17:25:46 -0500 Subject: [PATCH 3/6] Pretest that fails if Linux tests aren't current --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d4988e8..c87cb9e 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+$ @@ -16,6 +17,11 @@ jobs: include: - script: swift test name: macOS + + - stage: pretest + name: Check if Linux tests are up-to-date + install: swift test --generate-linuxmain + script: git diff --exit-code - &xcodebuild before_install: swift package generate-xcodeproj @@ -34,7 +40,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 From 920f007660b111b6ee2a8b4020452245b6fabbc3 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 20 Jan 2019 17:32:37 -0500 Subject: [PATCH 4/6] Fix Linux testEnumerationSkippingHiddenFiles() --- Sources/Path+ls.swift | 20 +++++++++++++------- Tests/PathTests/PathTests.swift | 7 ++++--- Tests/PathTests/XCTestManifests.swift | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) 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/XCTestManifests.swift b/Tests/PathTests/XCTestManifests.swift index ce48de0..9104303 100644 --- a/Tests/PathTests/XCTestManifests.swift +++ b/Tests/PathTests/XCTestManifests.swift @@ -17,7 +17,7 @@ extension PathTests { ] } -#if os(Linux) +#if !os(macOS) public func __allTests() -> [XCTestCaseEntry] { return [ testCase(PathTests.__allTests), From ca4ac3ec8fa0ee300fa7d33e137998a3670df65a Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 20 Jan 2019 17:33:56 -0500 Subject: [PATCH 5/6] Fix stage types in .travis.yml --- .travis.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index c87cb9e..94ab09e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,11 +17,6 @@ jobs: include: - script: swift test name: macOS - - - stage: pretest - name: Check if Linux tests are up-to-date - install: swift test --generate-linuxmain - script: git diff --exit-code - &xcodebuild before_install: swift package generate-xcodeproj @@ -48,6 +43,11 @@ 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 - stage: deploy name: Jazzy @@ -79,8 +79,7 @@ jobs: on: tags: true - - stage: deploy - name: CocoaPods + - name: CocoaPods before_install: | cat << EOF > Path.swift.podspec Pod::Spec.new do |s| From 3644124a36784e3cda184bde034987e1f2b73edd Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 20 Jan 2019 17:39:07 -0500 Subject: [PATCH 6/6] Fix testing on tvOS/iOS --- Tests/PathTests/TemporaryDirectory.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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