pointfreeco / swift-snapshot-testing

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

Undefined symbols Linker command failed with exit code 1. #816

Closed Nikoloutsos closed 7 months ago

Nikoloutsos commented 7 months ago

Today decided to give InlineSnaphotTesting a shot. Everything was working great until I run into the following error when building my app.

First, I am integrating this library via SPM.

// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "TestingToolkit",
    platforms: [
        .iOS(.v15)
    ],
    products: [
        .library(
            name: "XCTestsUtilities",
            targets: ["XCTestsUtilities"]
        )
    ],
    dependencies: [
        .package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", .upToNextMajor(from: "1.14.0"))
    ],
    targets: [
        .target(
            name: "XCTestsUtilities",
            dependencies: [
                .product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
                .product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing")
            ]
        )
    ]
)

The logs gives me this error

ld: Undefined symbols:
  XCTest.XCTAssertEqual<A where A: Swift.Equatable>(_: @autoclosure () throws -> A, _: @autoclosure () throws -> A, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> (), referenced from:
      XCTestsUtilities.(assertiOSVersionAndPhoneModel in _AF6BB3D00A42C26606B62A9C8B5236F7)() -> () in XCTestsUtilities.o
  XCTest.XCTFail(_: Swift.String, file: Swift.StaticString, line: Swift.UInt) -> (), referenced from:
      (extension in XCTestsUtilities):__C.XCTestCase.assertRawSnapshot<A where A: SwiftUI.View>(view: A, record: Swift.Bool, file: Swift.StaticString, testName: Swift.String, line: Swift.UInt) -> () in XCTestsUtilities.o
      (extension in XCTestsUtilities):__C.XCTestCase.assertNil(_: Swift.AnyObject?, after: () -> (), file: Swift.StaticString, line: Swift.UInt) -> () in XCTestsUtilities.o
      (3) suspend resume partial function for (extension in XCTestsUtilities):__C.XCTest.XCTAssertThrowsError<A where A: Swift.Sendable>(_: @autoclosure () async throws -> A, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt, _: (Swift.Error) -> ()) async -> () in XCTestsUtilities.o
      SnapshotTesting.assertSnapshot<A, B>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, B>, named: Swift.String?, record: Swift.Bool, timeout: Swift.Double, file: Swift.StaticString, testName: Swift.String, line: Swift.UInt) -> () in SnapshotTesting.o
      SnapshotTesting._assertInlineSnapshot<A>(matching: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, Swift.String>, record: Swift.Bool, timeout: Swift.Double, with: Swift.String, file: Swift.StaticString, testName: Swift.String, line: Swift.UInt) -> () in SnapshotTesting.o
      InlineSnapshotTesting.assertInlineSnapshot<A>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, Swift.String>, message: @autoclosure () -> Swift.String, record: Swift.Bool, timeout: Swift.Double, syntaxDescriptor: InlineSnapshotTesting.InlineSnapshotSyntaxDescriptor, matches: (() -> Swift.String)?, file: Swift.StaticString, function: Swift.StaticString, line: Swift.UInt, column: Swift.UInt) -> () in InlineSnapshotTesting.o
      InlineSnapshotTesting.assertInlineSnapshot<A>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, Swift.String>, message: @autoclosure () -> Swift.String, record: Swift.Bool, timeout: Swift.Double, syntaxDescriptor: InlineSnapshotTesting.InlineSnapshotSyntaxDescriptor, matches: (() -> Swift.String)?, file: Swift.StaticString, function: Swift.StaticString, line: Swift.UInt, column: Swift.UInt) -> () in InlineSnapshotTesting.o
      InlineSnapshotTesting.assertInlineSnapshot<A>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, Swift.String>, message: @autoclosure () -> Swift.String, record: Swift.Bool, timeout: Swift.Double, syntaxDescriptor: InlineSnapshotTesting.InlineSnapshotSyntaxDescriptor, matches: (() -> Swift.String)?, file: Swift.StaticString, function: Swift.StaticString, line: Swift.UInt, column: Swift.UInt) -> () in InlineSnapshotTesting.o
      InlineSnapshotTesting.assertInlineSnapshot<A>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, Swift.String>, message: @autoclosure () -> Swift.String, record: Swift.Bool, timeout: Swift.Double, syntaxDescriptor: InlineSnapshotTesting.InlineSnapshotSyntaxDescriptor, matches: (() -> Swift.String)?, file: Swift.StaticString, function: Swift.StaticString, line: Swift.UInt, column: Swift.UInt) -> () in InlineSnapshotTesting.o
      InlineSnapshotTesting.assertInlineSnapshot<A>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, Swift.String>, message: @autoclosure () -> Swift.String, record: Swift.Bool, timeout: Swift.Double, syntaxDescriptor: InlineSnapshotTesting.InlineSnapshotSyntaxDescriptor, matches: (() -> Swift.String)?, file: Swift.StaticString, function: Swift.StaticString, line: Swift.UInt, column: Swift.UInt) -> () in InlineSnapshotTesting.o
      ...
  XCTest.XCTAssert(_: @autoclosure () throws -> Swift.Bool, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> (), referenced from:
      closure #1 () -> () in (extension in XCTestsUtilities):__C.XCTestCase.assertNil(_: Swift.AnyObject?, after: () -> (), file: Swift.StaticString, line: Swift.UInt) -> () in XCTestsUtilities.o
  static (extension in XCTest):__C.XCTContext.runActivity<A>(named: Swift.String, block: (__C.XCTActivity) throws -> A) throws -> A, referenced from:
      SnapshotTesting.verifySnapshot<A, B>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, B>, named: Swift.String?, record: Swift.Bool, snapshotDirectory: Swift.String?, timeout: Swift.Double, file: Swift.StaticString, testName: Swift.String, line: Swift.UInt) -> Swift.String? in SnapshotTesting.o
      SnapshotTesting.verifySnapshot<A, B>(of: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, B>, named: Swift.String?, record: Swift.Bool, snapshotDirectory: Swift.String?, timeout: Swift.Double, file: Swift.StaticString, testName: Swift.String, line: Swift.UInt) -> Swift.String? in SnapshotTesting.o
      SnapshotTesting._verifyInlineSnapshot<A>(matching: @autoclosure () throws -> A, as: SnapshotTesting.Snapshotting<A, Swift.String>, record: Swift.Bool, timeout: Swift.Double, with: Swift.String, file: Swift.StaticString, testName: Swift.String, line: Swift.UInt) -> Swift.String? in SnapshotTesting.o
  _OBJC_CLASS_$_XCTAttachment, referenced from:
       in SnapshotTesting.o
  _OBJC_CLASS_$_XCTContext, referenced from:
       in SnapshotTesting.o
  _OBJC_CLASS_$_XCTWaiter, referenced from:
       in SnapshotTesting.o
  _OBJC_CLASS_$_XCTestExpectation, referenced from:
       in SnapshotTesting.o
  _OBJC_CLASS_$_XCTestObservationCenter, referenced from:
       in SnapshotTesting.o
  __swift_FORCE_LOAD_$_XCTestSwiftSupport, referenced from:
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_XCTestsUtilities in XCTestsUtilities.o
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_SnapshotTesting in SnapshotTesting.o
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_InlineSnapshotTesting in InlineSnapshotTesting.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Has anyone any idea why this error happens? Keep in mind that running tests works as expected and without errors. Also SnapshotTesting product works well and problem showed up when I introduced the InlineSnapshotTesting product. I have tried cleaning derived data, clean project but did not resolve issue. Also when I remove the dependency to InlineSnapshotTesting it build succesfully. Am I missing something?

mbrandonw commented 7 months ago

Hi @Nikoloutsos, I'm not sure why this is happening. We are using the library in a few places with no troubles so far. Can you share a minimal project that reproduces the behavior you are seeing?

Also, I am going to convert this to a discussion because it's most likely not an issue with the library itself.