Skip to content

Commit

Permalink
Fix SPM integration
Browse files Browse the repository at this point in the history
Adjust supported swift versions
Fix FileString conversion
Add missing import
  • Loading branch information
dogo committed Sep 5, 2021
1 parent 1b5447f commit 0f72420
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Nimble_Snapshots/DynamicSize/DynamicSizeSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ func performDynamicSizeSnapshotTest(_ name: String?,

resizer.resize(view: view, for: size)

let filename = "\(actualExpression.location.file)"

return FBSnapshotTest.compareSnapshot(instance, isDeviceAgnostic: isDeviceAgnostic, usesDrawRect: usesDrawRect,
snapshot: finalSnapshotName, record: isRecord,
referenceDirectory: referenceImageDirectory, tolerance: tolerance,
perPixelTolerance: pixelTolerance,
filename: actualExpression.location.file, identifier: nil,
filename: filename, identifier: nil,
shouldIgnoreScale: shouldIgnoreScale)
}

Expand Down
1 change: 1 addition & 0 deletions Nimble_Snapshots/DynamicType/PrettyDynamicTypeSyntax.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Nimble
import UIKit

// MARK: - Nicer syntax using == operator

Expand Down
11 changes: 7 additions & 4 deletions Nimble_Snapshots/HaveValidSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public func recordAllSnapshots() {
switchChecksWithRecords = true
}

func getDefaultReferenceDirectory(_ sourceFileName: String) -> String {
func getDefaultReferenceDirectory(_ sourceFileName: FileString) -> String {
if let globalReference = FBSnapshotTest.sharedInstance.referenceImagesDirectory {
return globalReference
}
Expand All @@ -137,7 +137,8 @@ func getDefaultReferenceDirectory(_ sourceFileName: String) -> String {
// then append "/ReferenceImages" and use that.

// Grab the file's path
let pathComponents = (sourceFileName as NSString).pathComponents as NSArray
let fileName = NSString(string: "\(sourceFileName)")
let pathComponents = fileName.pathComponents as NSArray

// Find the directory in the path that ends with a test suffix.
let testPath = pathComponents.first { component -> Bool in
Expand Down Expand Up @@ -211,12 +212,13 @@ private func performSnapshotTest(_ name: String?,
let snapshotName = sanitizedTestName(name)
let tolerance = tolerance ?? getTolerance()
let pixelTolerance = pixelTolerance ?? getPixelTolerance()
let filename = "\(actualExpression.location.file)"

let result = FBSnapshotTest.compareSnapshot(instance, isDeviceAgnostic: isDeviceAgnostic,
usesDrawRect: usesDrawRect, snapshot: snapshotName, record: false,
referenceDirectory: referenceImageDirectory, tolerance: tolerance,
perPixelTolerance: pixelTolerance,
filename: actualExpression.location.file, identifier: identifier, shouldIgnoreScale: shouldIgnoreScale)
filename: filename, identifier: identifier, shouldIgnoreScale: shouldIgnoreScale)

return PredicateResult(status: PredicateStatus(bool: result),
message: .fail("expected a matching snapshot in \(snapshotName)"))
Expand All @@ -235,6 +237,7 @@ private func recordSnapshot(_ name: String?,
let snapshotName = sanitizedTestName(name)
let tolerance = getTolerance()
let pixelTolerance = getPixelTolerance()
let filename = "\(actualExpression.location.file)"
var message: String = ""

if FBSnapshotTest.compareSnapshot(instance,
Expand All @@ -245,7 +248,7 @@ private func recordSnapshot(_ name: String?,
referenceDirectory: referenceImageDirectory,
tolerance: tolerance,
perPixelTolerance: pixelTolerance,
filename: actualExpression.location.file,
filename: filename,
identifier: identifier,
shouldIgnoreScale: shouldIgnoreScale) {
let name = name ?? snapshotName
Expand Down
2 changes: 2 additions & 0 deletions Nimble_Snapshots/Nimble_Snapshots.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ FOUNDATION_EXPORT const unsigned char Nimble_SnapshotsVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <Nimble_Snapshots/PublicHeader.h>

#if __has_include("NBSMockedApplication.h")
#import "NBSMockedApplication.h"
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#import "XCTestObservationCenter+CurrentTestCaseTracker.h"
#if __has_include("Nimble_Snapshots-Swift.h")
#import "Nimble_Snapshots-Swift.h"
#elif SWIFT_PACKAGE
@import NimbleSnapshotsSwift;
#else
#import <Nimble_Snapshots/Nimble_Snapshots-Swift.h>
#endif
Expand Down
26 changes: 15 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ let package = Package(
products: [
.library(
name: "Nimble-Snapshots",
targets: ["NimbleSnapshotsSwift",
"NimbleSnapshotsObjc"]),
targets: ["NimbleSnapshotsObjc"])
],
dependencies: [
.package(url: "https://github.com/uber/ios-snapshot-test-case.git", .upToNextMajor(from: "7.0.0")),
.package(url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "9.0.0"))
.package(name: "FBSnapshotTestCase",
url: "https://github.com/uber/ios-snapshot-test-case.git",
.upToNextMajor(from: "7.0.0")),
.package(url: "https://github.com/Quick/Nimble.git",
.upToNextMajor(from: "9.0.0"))
],
targets: [
.target(
name: "NimbleSnapshotsSwift",
dependencies: ["NimbleSnapshotsObjc"],
dependencies: ["FBSnapshotTestCase",
"Nimble"],
path: "Nimble_Snapshots",
exclude: ["Nimble_Snapshots.h",
"XCTestObservationCenter+CurrentTestCaseTracker.h",
exclude: ["XCTestObservationCenter+CurrentTestCaseTracker.h",
"XCTestObservationCenter+CurrentTestCaseTracker.m",
"DynamicType/NBSMockedApplication.h",
"DynamicType/NBSMockedApplication.m",
Expand All @@ -37,9 +39,11 @@ let package = Package(
),
.target(
name: "NimbleSnapshotsObjc",
dependencies: [
"NimbleSnapshotsSwift"
],
path: "Nimble_Snapshots",
exclude: ["Nimble_Snapshots.h",
"CurrentTestCaseTracker.swift",
exclude: ["CurrentTestCaseTracker.swift",
"HaveValidSnapshot.swift",
"PrettySyntax.swift",
"DynamicSize/DynamicSizeSnapshot.swift",
Expand All @@ -51,7 +55,7 @@ let package = Package(
"XCTestObservationCenter+CurrentTestCaseTracker.m",
"DynamicType/NBSMockedApplication.h",
"DynamicType/NBSMockedApplication.m"]
),
)
],
swiftLanguageVersions: [.v5]
swiftLanguageVersions: [.v4_2, .v5]
)

0 comments on commit 0f72420

Please sign in to comment.