Skip to content

Commit

Permalink
Project fixes (#1017)
Browse files Browse the repository at this point in the history
* Fix compiling and tests

* Cleans up ResourceTests folder to make it more compatible with SPM
  • Loading branch information
guykogus committed Jun 15, 2022
1 parent c06dd09 commit 98cc80d
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 65 deletions.
14 changes: 6 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ let package = Package(
products: [
.library(name: "SwifterSwift", targets: ["SwifterSwift"])
],
dependencies: [],
targets: [
.target(name: "SwifterSwift", dependencies: []),
.target(name: "SwifterSwift"),
.testTarget(
name: "SwifterSwiftTests",
dependencies: ["SwifterSwift"],
path: "Tests",
exclude: ["Info.plist"],
resources: [.process("ResourcesTests")]
)
name: "SwifterSwiftTests",
dependencies: ["SwifterSwift"],
path: "Tests",
exclude: ["Info.plist"],
resources: [.process("ResourcesTests/Resources")])
])
7 changes: 2 additions & 5 deletions Sources/SwifterSwift/Foundation/DateExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// DateExtensions.swift - Copyright 2020 SwifterSwift
// DateExtensions.swift - Copyright 2022 SwifterSwift

#if canImport(Foundation)
import Foundation
Expand Down Expand Up @@ -49,10 +49,7 @@ public extension Date {

public extension Date {
/// SwifterSwift: User’s current calendar.
var calendar: Calendar {
// Workaround to segfault on corelibs foundation https://bugs.swift.org/browse/SR-10147
return Calendar(identifier: Calendar.current.identifier)
}
var calendar: Calendar { Calendar.current }

/// SwifterSwift: Era.
///
Expand Down
40 changes: 28 additions & 12 deletions SwifterSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,7 @@
8D50E51D24D0D6FB00972E2D /* tvOS */ = {
isa = PBXGroup;
children = (
F88C491824AF73A400BA0503 /* TestStoryboard-tvOS.storyboard */,
8D50E52024D0D73E00972E2D /* UIImageViewTvOS.xib */,
);
path = tvOS;
Expand Down Expand Up @@ -1483,17 +1484,8 @@
CAC5EBBE2125270A00AB27EC /* ResourcesTests */ = {
isa = PBXGroup;
children = (
8D50E51D24D0D6FB00972E2D /* tvOS */,
CAC5EBC52125270A00AB27EC /* big_buck_bunny_720p_1mb.mp4 */,
CAC5EBC22125270A00AB27EC /* test.json */,
CAC5EBBF2125270A00AB27EC /* TestImage.png */,
CAC5EBC02125270A00AB27EC /* TestStoryboard.storyboard */,
F88C491824AF73A400BA0503 /* TestStoryboard-tvOS.storyboard */,
CAC5EBC12125270A00AB27EC /* UICollectionViewCell.xib */,
8D50E51E24D0D71E00972E2D /* UIImageView.xib */,
CAC5EBC32125270A00AB27EC /* UITableViewCell.xib */,
CAC5EBC42125270A00AB27EC /* UITableViewHeaderFooterView.xib */,
5E36CB6424AC9909007727DA /* MyViewController.swift */,
F8830FC3285478EC00C1D802 /* Resources */,
F8830FC2285478EC00C1D802 /* Sources */,
);
path = ResourcesTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1525,6 +1517,30 @@
path = CoreAnimationTests;
sourceTree = "<group>";
};
F8830FC2285478EC00C1D802 /* Sources */ = {
isa = PBXGroup;
children = (
5E36CB6424AC9909007727DA /* MyViewController.swift */,
);
path = Sources;
sourceTree = "<group>";
};
F8830FC3285478EC00C1D802 /* Resources */ = {
isa = PBXGroup;
children = (
8D50E51D24D0D6FB00972E2D /* tvOS */,
CAC5EBC52125270A00AB27EC /* big_buck_bunny_720p_1mb.mp4 */,
CAC5EBC22125270A00AB27EC /* test.json */,
CAC5EBBF2125270A00AB27EC /* TestImage.png */,
CAC5EBC02125270A00AB27EC /* TestStoryboard.storyboard */,
CAC5EBC12125270A00AB27EC /* UICollectionViewCell.xib */,
8D50E51E24D0D71E00972E2D /* UIImageView.xib */,
CAC5EBC32125270A00AB27EC /* UITableViewCell.xib */,
CAC5EBC42125270A00AB27EC /* UITableViewHeaderFooterView.xib */,
);
path = Resources;
sourceTree = "<group>";
};
F8E62DA224D0184E00BF35AE /* XCTestTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1719,7 +1735,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0900;
LastUpgradeCheck = 1250;
LastUpgradeCheck = 1340;
ORGANIZATIONNAME = SwifterSwift;
TargetAttributes = {
07898B5C1F278D7600558C97 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions Tests/AppKitTests/NSColorExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// NSColorExtensionsTests.swift - Copyright 2020 SwifterSwift
// NSColorExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest

#if canImport(AppKit)
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit

final class NSColorExtensionsTests: XCTestCase {
Expand Down
3 changes: 2 additions & 1 deletion Tests/MapKitTests/MKMultiPointTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MKMultiPointTests.swift - Copyright 2020 SwifterSwift
// MKMultiPointTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand All @@ -8,6 +8,7 @@ import MapKit

import struct CoreLocation.CLLocationCoordinate2D

@available(tvOS 9.2, *)
final class MKMultiPointTests: XCTestCase {
let coordinates = [
(37.330514, -121.888863),
Expand Down
3 changes: 2 additions & 1 deletion Tests/MapKitTests/MKPolylineTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MKPolylineTests.swift - Copyright 2020 SwifterSwift
// MKPolylineTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand All @@ -8,6 +8,7 @@ import MapKit

import struct CoreLocation.CLLocationCoordinate2D

@available(tvOS 9.2, *)
final class MKPolylineTests: XCTestCase {
let coordinates = [
(37.330514, -121.888863),
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MyViewController.swift - Copyright 2020 SwifterSwift
// MyViewController.swift - Copyright 2022 SwifterSwift

#if canImport(UIKit) && !os(watchOS)
import UIKit
Expand Down
11 changes: 5 additions & 6 deletions Tests/SpriteKitTests/SKSpriteNodeExtensionTests.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// SKSpriteNodeExtensionTests.swift - Copyright 2021 SwifterSwift
// SKSpriteNodeExtensionTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest

#if canImport(SpriteKit)
#if canImport(SpriteKit) && canImport(UIKit)
import SpriteKit

final class SKSpriteNodeExtensionTests: XCTestCase {

func testAspectFill() {
let bundle = Bundle(for: SKSpriteNodeExtensionTests.self)
let scene = SKScene(size: CGSize(width: 750, height: 1334))
let node = SKSpriteNode()
let image = UIImage(named: "TestImage", in: bundle, compatibleWith: nil)!

node.size = CGSize(width: 300, height: 300)
node.texture = SKTexture(image: image)
scene.addChild(node)

node.aspectFill(to: CGSize(width: 100, height: 100))

let accuracy = CGFloat(0.01)
XCTAssertEqual(node.size.width, 100, accuracy: accuracy)
XCTAssertEqual(node.size.height, 23.2, accuracy: accuracy)
Expand Down
11 changes: 5 additions & 6 deletions Tests/SwiftStdlibTests/ArrayExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ArrayExtensionsTests.swift - Copyright 2020 SwifterSwift
// ArrayExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
//
Expand Down Expand Up @@ -45,7 +45,6 @@ final class ArrayExtensionsTests: XCTestCase {
let candidate2 = [2, 5, 3, 6, 1, 4]
XCTAssertEqual(candidate2.sorted(like: order1, keyPath: \.self), [1, 2, 3, 4, 5, 6])

// swiftlint:disable:next nesting
struct TestStruct { let prop: String }
let order3 = ["1", "2", "3", "4", "5"]
let candidate3 = [
Expand Down Expand Up @@ -115,24 +114,24 @@ final class ArrayExtensionsTests: XCTestCase {
]
XCTAssertEqual(arrayWithoutDuplicatesNHashable, arrayWithoutDuplicatesNHashablePrepared)
}

func testAppendElement() {
var testArray = ["h", "e", "l", "l", "o"]
let optionalString: String? = "f"
testArray.appendIfNonNil(optionalString)
XCTAssertEqual(testArray, ["h", "e", "l", "l", "o", "f"])

let nilString: String? = nil
testArray.appendIfNonNil(nilString)
XCTAssertEqual(testArray, ["h", "e", "l", "l", "o", "f"])
}

func testAppendSequence() {
var testEmptyArray: [Double] = []
let numbersToAppend: [Double]? = [69.0, 68.0, 67.0]
testEmptyArray.appendIfNonNil(contentsOf: numbersToAppend)
XCTAssertEqual(testEmptyArray, numbersToAppend)

var testStringArray: [String] = ["h", "e", "l", "l", "o"]
let nilArray: [String]? = nil
testStringArray.appendIfNonNil(contentsOf: nilArray)
Expand Down
11 changes: 5 additions & 6 deletions Tests/SwiftStdlibTests/DictionaryExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// DictionaryExtensionsTests.swift - Copyright 2020 SwifterSwift
// DictionaryExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand Down Expand Up @@ -84,8 +84,8 @@ final class DictionaryExtensionsTests: XCTestCase {
}

func testOperatorPlus() {
let dict: [String: String] = ["key1": "value1"]
let dict2: [String: String] = ["key2": "value2"]
let dict = ["key1": "value1"]
let dict2 = ["key2": "value2"]
let result = dict + dict2
XCTAssert(result.keys.contains("key1"))
XCTAssert(result.keys.contains("key2"))
Expand All @@ -100,8 +100,8 @@ final class DictionaryExtensionsTests: XCTestCase {
}

func testOperatorPlusEqual() {
var dict: [String: String] = ["key1": "value1"]
let dict2: [String: String] = ["key2": "value2"]
var dict = ["key1": "value1"]
let dict2 = ["key2": "value2"]
dict += dict2
XCTAssert(dict.keys.contains("key1"))
XCTAssert(dict.keys.contains("key2"))
Expand All @@ -126,7 +126,6 @@ final class DictionaryExtensionsTests: XCTestCase {
}

func testCompactMapKeysAndValues() {
// swiftlint:disable:next nesting
enum IntWord: String {
case zero
case one
Expand Down
4 changes: 2 additions & 2 deletions Tests/UIKitTests/UIBezierPathExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// UIBezierPathExtensionsTests.swift - Copyright 2020 SwifterSwift
// UIBezierPathExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand Down Expand Up @@ -79,7 +79,7 @@ fileprivate extension UIBezierPath {
// Only works for straight lines
var points: [CGPoint] {
var points = [CGPoint]()
if #available(iOS 11.0, *) {
if #available(iOS 11.0, tvOS 11.0, *) {
cgPath.applyWithBlock { pointer in
let element = pointer.pointee
var point = CGPoint.zero
Expand Down
4 changes: 2 additions & 2 deletions Tests/UIKitTests/UICollectionViewExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// UICollectionViewExtensionsTests.swift - Copyright 2020 SwifterSwift
// UICollectionViewExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand All @@ -20,7 +20,7 @@ final class UICollectionViewExtensionsTests: XCTestCase {
let collection = UICollectionView(
frame: CGRect(x: 0, y: 0, width: 10, height: 15),
collectionViewLayout: layout)
if #available(iOS 11, *) {
if #available(iOS 11, tvOS 11, *) {
collection.insetsLayoutMarginsFromSafeArea = false
}
collection.contentInset = .zero
Expand Down
10 changes: 5 additions & 5 deletions Tests/UIKitTests/UIFontExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// UIFontExtensionsTests.swift - Copyright 2020 SwifterSwift
// UIFontExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand All @@ -8,23 +8,23 @@ import UIKit

final class UIFontExtension: XCTestCase {
func testBold() {
let font = UIFont.preferredFont(forTextStyle: .body)
let font = UIFont.systemFont(ofSize: 10)
let boldFont = font.bold
XCTAssert(boldFont.fontDescriptor.symbolicTraits.contains(.traitBold))
}

func testItalic() {
let font = UIFont.preferredFont(forTextStyle: .body)
let font = UIFont.systemFont(ofSize: 10)
let italicFont = font.italic
XCTAssert(italicFont.fontDescriptor.symbolicTraits.contains(.traitItalic))
}

func testMonospacedDigitFont() {
let font = UIFont.preferredFont(forTextStyle: .body)
let font = UIFont.systemFont(ofSize: 10)
let monoFont = font.monospaced

let attributes = monoFont.fontDescriptor.fontAttributes
let fontKey: UIFontDescriptor.AttributeName = UIFontDescriptor.AttributeName.featureSettings
let fontKey = UIFontDescriptor.AttributeName.featureSettings
guard let settings = attributes[fontKey] as? [[UIFontDescriptor.AttributeName: Int]] else {
XCTFail("Unable to get settings from font")
return
Expand Down
7 changes: 5 additions & 2 deletions Tests/UIKitTests/UIImageExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// UIImageExtensionsTests.swift - Copyright 2020 SwifterSwift
// UIImageExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand All @@ -7,6 +7,7 @@ import XCTest
import UIKit

final class UIImageExtensionsTests: XCTestCase {
@available(tvOS 10.0, *)
func testAverageColor() {
let size = CGSize(width: 10, height: 5)

Expand Down Expand Up @@ -246,7 +247,9 @@ final class UIImageExtensionsTests: XCTestCase {
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
func testWithAlwaysOriginalTintColor() {
let image = UIImage(color: .blue, size: CGSize(width: 20, height: 20))
XCTAssertEqual(image.withAlwaysOriginalTintColor(.red), image.withTintColor(.red, renderingMode: .alwaysOriginal))
XCTAssertEqual(
image.withAlwaysOriginalTintColor(.red),
image.withTintColor(.red, renderingMode: .alwaysOriginal))
}
}

Expand Down
3 changes: 1 addition & 2 deletions Tests/UIKitTests/UIViewControllerExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// UIViewControllerExtensionsTests.swift - Copyright 2020 SwifterSwift
// UIViewControllerExtensionsTests.swift - Copyright 2022 SwifterSwift

@testable import SwifterSwift
import XCTest
Expand Down Expand Up @@ -178,7 +178,6 @@ final class UIViewControllerExtensionsTests: XCTestCase {
}

func testPresentPopoverWithDelegate() {
// swiftlint:disable:next nesting
class PopoverDelegate: NSObject, UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for _: UIPresentationController) -> UIModalPresentationStyle {
return .popover
Expand Down

0 comments on commit 98cc80d

Please sign in to comment.