pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.74k stars 570 forks source link

Failed to add binary version of framework in Xcode 13 #536

Open ton252 opened 2 years ago

ton252 commented 2 years ago

In our team we have no opportunity to import swift-snapshot-testing using GitHub. And we decided to build a binary version of xcframework and put it inside project. But when we upgraded Xcode to 13 version it stoped working.

We set property Build for distribution = YES in project. Here is a script, that we use to build xcframework:

xcodebuild archive \
 -scheme SnapshotTesting_iOS \
 -archivePath "./build/ios.xcarchive" \
 -sdk iphoneos \
 BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
 SKIP_INSTALL=NO

# iOS simulator

xcodebuild archive \
 -scheme SnapshotTesting_iOS \
 -archivePath "./build/ios_sim.xcarchive" \
 -sdk iphonesimulator \
 BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
 SKIP_INSTALL=NO

 # macOS

xcodebuild archive \
 -scheme SnapshotTesting_macOS \
 -archivePath "./build/macos.xcarchive" \
 BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
 SKIP_INSTALL=NO

 # tvOS

 xcodebuild archive \
 -scheme SnapshotTesting_tvOS \
 -archivePath "./build/tvos.xcarchive" \
 BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
 SKIP_INSTALL=NO

Pack to xcframework

 xcodebuild -create-xcframework \
  -framework "./build/ios.xcarchive/Products/Library/Frameworks/SnapshotTesting.framework" \
  -framework "./build/ios_sim.xcarchive/Products/Library/Frameworks/SnapshotTesting.framework" \
  -framework "./build/macos.xcarchive/Products/Library/Frameworks/SnapshotTesting.framework" \
  -output "./build/SnapshotTesting.xcframework"

and this is an error message:

Failed to build module 'SnapshotTesting'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift 
version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)', while this compiler is 'Apple Swift version 5.5.1 (swiftlang-
1300.0.31.4 clang-1300.0.29.6)'). Please select a toolchain which matches the SDK.
'XCTAttachment' is not a member type of class 'XCTest.XCTest'
'XCTestCase' is not a member type of class 'XCTest.XCTest'
ton252 commented 2 years ago

I don't know why, but the problem is in this lines:

public var diff: (Value, Value) -> (String, [XCTAttachment])?
public typealias SnapshotTestCase = XCTestCase
  init(
    toData: @escaping (_ value: Value) -> Data,
    fromData: @escaping (_ data: Data) -> Value,
    diff: @escaping (_ lhs: Value, _ rhs: Value) -> (String, [XCTAttachment])?
ton252 commented 2 years ago

The same thing is here: https://github.com/Quick/Quick/issues/961

mariusfanu commented 2 years ago

@ton252 did you find any solution to this?

ton252 commented 2 years ago

@mariusfanu The only solution (dirty) that I found is to hide any public declaration of XCTestCase XCTAttachment. For example change XCTAttachment to Any and check type inside function (I know this is a dirty way)

mariusfanu commented 2 years ago

Yes, that's not ideal, thanks for the response

osrufung commented 1 year ago

I solved this by using swift-create-framework tool and this xcodebuild argument (ENABLE_TESTING_SEARCH_PATHS):

swift create-xcframework --package-path . --stack-evolution --configuration debug --output xcframeworks-debug --platform ios --xc-setting ENABLE_TESTING_SEARCH_PATHS=YES

Nikoloutsos commented 6 months ago

@osrufung Using ENABLE_TESTING_SEARCH_PATHS=YES allowed me to generate an xcframework but when added in test target i am getting similar error.

'XCTAttachment' is not a member type of class 'XCTest.XCTest'

Any idea?

CleanShot 2024-03-04 at 00 34 42