Skip to content

Commit

Permalink
Add Swift 5.8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Apr 9, 2023
1 parent eb1afdd commit 9942852
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
27 changes: 27 additions & 0 deletions Package@swift-5.7.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version:5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import Foundation

let package = Package(
name: "app-information",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "AppInformation",
targets: ["AppInformation"]),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(name: "AppInformation"),
.testTarget(
name: "AppInformationTests",
dependencies: ["AppInformation"]),
]
)

if ProcessInfo.processInfo.environment["ENABLE_DOCC_SUPPORT"] == "1" {
package.dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
}
2 changes: 0 additions & 2 deletions Sources/AppInformation/Model/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public struct AppInfo: Equatable, Identifiable, Sendable {
localized.display ?? localized.base ?? unlocalized.display ?? unlocalized.base
}

/// See `Equatable.==`
public static func ==(lhs: Self, rhs: Self) -> Bool {
lhs.unlocalized == rhs.unlocalized && lhs.localized == rhs.localized
}
Expand Down Expand Up @@ -56,7 +55,6 @@ public struct AppInfo: Equatable, Identifiable, Sendable {
/// The appleID of the application.
public var appleID: AppleID?

/// See `Identifiable.id`.
@inlinable
public var id: String { identifier }
}
Expand Down
70 changes: 35 additions & 35 deletions Tests/AppInformationTests/AppInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ final class AppInfoTests: XCTestCase {
private final class FakeBundle: Bundle {
var _identifier: String?
override var bundleIdentifier: String? { _identifier }

var _infoDict: Dictionary<String, Any>?
override var infoDictionary: [String : Any]? { _infoDict }

var _localizedInfoDict: Dictionary<String, Any>?
override var localizedInfoDictionary: [String : Any]? { _localizedInfoDict }

init(path: String,
identifier: String? = nil,
infoDict: Dictionary<String, Any>? = nil,
Expand All @@ -27,17 +27,17 @@ final class AppInfoTests: XCTestCase {
super.init(path: path)!
}
}

private var bundlePath: String!

private func tempDir() -> URL {
if #available(iOS 10, tvOS 10, watchOS 3.0, *) {
return FileManager.default.temporaryDirectory
} else {
return URL(fileURLWithPath: NSTemporaryDirectory())
}
}

override func setUpWithError() throws {
try super.setUpWithError()
bundlePath = tempDir()
Expand All @@ -46,16 +46,16 @@ final class AppInfoTests: XCTestCase {
.path
try FileManager.default.createDirectory(atPath: bundlePath, withIntermediateDirectories: true, attributes: nil)
}

override func tearDownWithError() throws {
try FileManager.default.removeItem(atPath: bundlePath)
bundlePath = nil
try super.tearDownWithError()
}

func testCreationFromEmptyBundle() {
let info = AppInfo(bundle: FakeBundle(path: bundlePath))

XCTAssertEqual(info.identifier, String(ProcessInfo.processInfo.processIdentifier))
XCTAssertEqual(info.names.unlocalized.base, ProcessInfo.processInfo.processName)
XCTAssertNil(info.names.unlocalized.display)
Expand All @@ -66,10 +66,10 @@ final class AppInfoTests: XCTestCase {
XCTAssertNil(info.copyright)
XCTAssertNil(info.appleID)
}

func testCreationFromEmptyBundleAndAppleID() {
let info = AppInfo(bundle: FakeBundle(path: bundlePath), appleID: "12345")

XCTAssertEqual(info.identifier, String(ProcessInfo.processInfo.processIdentifier))
XCTAssertEqual(info.names.unlocalized.base, ProcessInfo.processInfo.processName)
XCTAssertNil(info.names.unlocalized.display)
Expand All @@ -80,7 +80,7 @@ final class AppInfoTests: XCTestCase {
XCTAssertNil(info.copyright)
XCTAssertEqual(info.appleID, "12345")
}

func testCreationFromUnlocalizedBundle() {
let bundle = FakeBundle(path: bundlePath,
identifier: "test-identifier",
Expand All @@ -93,7 +93,7 @@ final class AppInfoTests: XCTestCase {
"AppInformationAppleID": "54321",
])
let info = AppInfo(bundle: bundle)

XCTAssertEqual(info.identifier, "test-identifier")
XCTAssertEqual(info.names.unlocalized.base, "TestName")
XCTAssertEqual(info.names.unlocalized.display, "Test Display Name")
Expand All @@ -104,7 +104,7 @@ final class AppInfoTests: XCTestCase {
XCTAssertEqual(info.copyright, "Some Copyright")
XCTAssertEqual(info.appleID, "54321")
}

func testCreationFromLocalizedBundle() {
let bundle = FakeBundle(path: bundlePath,
identifier: "test-identifier",
Expand All @@ -125,7 +125,7 @@ final class AppInfoTests: XCTestCase {
"AppInformationAppleID": "most-irrelevant",
])
let info = AppInfo(bundle: bundle)

XCTAssertEqual(info.identifier, "test-identifier")
XCTAssertEqual(info.names.unlocalized.base, "TestName")
XCTAssertEqual(info.names.unlocalized.display, "Test Display Name")
Expand All @@ -136,42 +136,42 @@ final class AppInfoTests: XCTestCase {
XCTAssertEqual(info.copyright, "Some Localized Copyright")
XCTAssertEqual(info.appleID, "54321")
}

func testIdentifiableConformance() {
let info = AppInfo(bundle: FakeBundle(path: bundlePath))
XCTAssertEqual(info.id, info.identifier)
}

func testNamingAccessors() {
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "relevant", display: nil),
localized: (nil, nil)).effectiveName,
localized: (nil, nil)).effectiveName,
"relevant")
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "not-relevant", display: "relevant"),
localized: (nil, nil)).effectiveName,
localized: (nil, nil)).effectiveName,
"relevant")
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "not-relevant", display: "not-relevant"),
localized: ("relevant", nil)).effectiveName,
localized: ("relevant", nil)).effectiveName,
"relevant")
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "not-relevant", display: "not-relevant"),
localized: ("not-relevant", "relevant")).effectiveName,
localized: ("not-relevant", "relevant")).effectiveName,
"relevant")
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "relevant", display: nil),
localized: (nil, nil)).effective,
localized: (nil, nil)).effective,
("relevant", nil))
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "relevant", display: "also-relevant"),
localized: (nil, nil)).effective,
localized: (nil, nil)).effective,
("relevant", "also-relevant"))
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "relevant", display: "not-relevant"),
localized: (nil, "also-relevant")).effective,
localized: (nil, "also-relevant")).effective,
("relevant", "also-relevant"))
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "not-relevant", display: "also-relevant"),
localized: ("relevant", nil)).effective,
localized: ("relevant", nil)).effective,
("relevant", "also-relevant"))
XCTAssertEqual(AppInfo.Naming(unlocalized: (base: "not-relevant", display: "not-relevant"),
localized: ("relevant", "also-relevant")).effective,
localized: ("relevant", "also-relevant")).effective,
("relevant", "also-relevant"))
}

func testNamingEquatableConformance() {
let naming1 = AppInfo.Naming(unlocalized: ("base-name", "display-name"), localized: (nil, nil))
let naming2 = AppInfo.Naming(unlocalized: ("base-name", "display-name"), localized: ("loc-base", nil))
Expand All @@ -180,15 +180,15 @@ final class AppInfoTests: XCTestCase {
XCTAssertNotEqual(naming1, naming2)
XCTAssertNotEqual(naming2, naming3)
}

func testVersioningAccessors() {
let versioning = AppInfo.Versioning(version: "1.2.3", build: "42")
XCTAssertEqual(versioning.combined, "1.2.3 (42)")
}

func testSwiftUIEnvironment() throws {
#if arch(arm64) || arch(x86_64)
#if canImport(SwiftUI) && canImport(Combine)
#if arch(arm64) || arch(x86_64)
#if canImport(SwiftUI) && canImport(Combine)
guard #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) else {
throw XCTSkip()
}
Expand All @@ -197,12 +197,12 @@ final class AppInfoTests: XCTestCase {
XCTAssertEqual(env.appInfo, .current)
env.appInfo = info
XCTAssertEqual(env.appInfo, info)
#else
#else
throw XCTSkip()
#endif
#else
#endif
#else
throw XCTSkip()
#endif
#endif
}
}

Expand Down

0 comments on commit 9942852

Please sign in to comment.