diff --git a/Sources/Extensions.swift b/Sources/Extensions.swift index 6cb9f74..d03eaef 100644 --- a/Sources/Extensions.swift +++ b/Sources/Extensions.swift @@ -34,6 +34,11 @@ public extension Bundle { var path: Path { return Path(string: bundlePath) } + + /// Returns the executable for this bundle, if there is one, not all bundles have one hence `Optional`. + var executable: Path? { + return executablePath.flatMap(Path.init) + } } /// Extensions on `String` that work with `Path` rather than `String` or `URL` diff --git a/Tests/PathTests/PathTests.swift b/Tests/PathTests/PathTests.swift index 9560286..108c9ca 100644 --- a/Tests/PathTests/PathTests.swift +++ b/Tests/PathTests/PathTests.swift @@ -403,6 +403,7 @@ class PathTests: XCTestCase { XCTAssertEqual(bndl.privateFrameworks, tmpdir.Frameworks) XCTAssertEqual(bndl.resources, tmpdir) XCTAssertNil(bndl.path(forResource: "foo", ofType: "bar")) + XCTAssertNil(bndl.executable) #if os(macOS) XCTAssertEqual(bndl.defaultSharedFrameworksPath, tmpdir.Contents.Frameworks)