From 14f03abaad725c48425e7fdf62e5ce6bd2178788 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Wed, 16 Jun 2021 11:04:51 -0400 Subject: [PATCH] typealias PathStruct and add Swift 5.5 niceness Fixes #55 --- .github/workflows/ci.yml | 4 +++- Sources/Path+CommonDirectories.swift | 10 ++++++++++ Sources/Path.swift | 2 ++ Tests/PathTests/PathTests.swift | 13 +++++++++++++ Tests/PathTests/XCTestManifests.swift | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3b0666..a4395b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,11 +6,13 @@ on: - .github/workflows/ci.yml schedule: - cron: '3 3 * * 5' # 3:03 AM, every Friday +concurrency: + group: ${{ github.head_ref || 'push' }} + cancel-in-progress: true jobs: smoke: runs-on: macos-latest steps: - - uses: technote-space/auto-cancel-redundant-job@v1 - uses: actions/checkout@v2 - run: swift test --generate-linuxmain - run: git diff --exit-code diff --git a/Sources/Path+CommonDirectories.swift b/Sources/Path+CommonDirectories.swift index c0edb20..2475902 100644 --- a/Sources/Path+CommonDirectories.swift +++ b/Sources/Path+CommonDirectories.swift @@ -108,3 +108,13 @@ func defaultUrl(for searchPath: FileManager.SearchPathDirectory) -> DynamicPath } #endif +#if swift(>=5.5) +extension Pathish where Self == Path { + static var home: DynamicPath { Path.home } + static var root: DynamicPath { Path.root } + static var cwd: DynamicPath { Path.cwd } + static var documents: DynamicPath { Path.documents } + static var caches: DynamicPath { Path.caches } + static var applicationSupport: DynamicPath { Path.applicationSupport } +} +#endif diff --git a/Sources/Path.swift b/Sources/Path.swift index 519e509..5252faa 100644 --- a/Sources/Path.swift +++ b/Sources/Path.swift @@ -7,6 +7,8 @@ import func Glibc.realpath let _realpath = Glibc.realpath #endif +public typealias PathStruct = Path + /** A `Path` represents an absolute path on a filesystem. diff --git a/Tests/PathTests/PathTests.swift b/Tests/PathTests/PathTests.swift index 898d236..65a5ada 100644 --- a/Tests/PathTests/PathTests.swift +++ b/Tests/PathTests/PathTests.swift @@ -3,7 +3,20 @@ import func XCTest.XCTAssertEqual import Foundation import XCTest +extension PathStruct { + var foo: Int { fatalError()} +} + class PathTests: XCTestCase { + func testNewStuff() { + #if swift(>=5.5) + func foo(_ path: P) {} + + foo(.home) + foo(.root) + #endif + } + func testConcatenation() { XCTAssertEqual((Path.root/"bar").string, "/bar") XCTAssertEqual(Path.cwd.string, FileManager.default.currentDirectoryPath) diff --git a/Tests/PathTests/XCTestManifests.swift b/Tests/PathTests/XCTestManifests.swift index b4d31d5..09fcb82 100644 --- a/Tests/PathTests/XCTestManifests.swift +++ b/Tests/PathTests/XCTestManifests.swift @@ -45,6 +45,7 @@ extension PathTests { ("testMktemp", testMktemp), ("testMoveInto", testMoveInto), ("testMoveTo", testMoveTo), + ("testNewStuff", testNewStuff), ("testNoUndesiredSymlinkResolution", testNoUndesiredSymlinkResolution), ("testOptionalInitializer", testOptionalInitializer), ("testParent", testParent),