Skip to content

Unit test case crashing on accessing generated code #19

@parvez-keeptruckin

Description

@parvez-keeptruckin

The testTarget is accessing Colour from generated code and thus crashing. The below code results in fatalError

@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
  public private(set) lazy var color: Color = {
    guard let color = Color(asset: self) else {
      fatalError("Unable to load color asset named \(name).")
    }
    return color
  }()

The swiftgen.yml file has bundle as Bundle.module. How to fix this issue ? Below is the Package.swift content:

let package = Package(
    name: "MyLibrary",
    defaultLocalization: "en",
    platforms: [
        .iOS(.v14)
    ],
    products: [
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    dependencies: [
        .package(url: "https://github.com/ReactiveX/RxSwift.git", from: ("6.5.0")),
        .package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.0"),
        .package(url: "https://github.com/realm/SwiftLint.git", from: "0.52.4"),
        .package(url: "https://github.com/DaveWoodCom/XCGLogger.git", from: "7.0.1"),
        .package(url: "https://github.com/Quick/Nimble.git", from: "9.2.1")
    ],
    targets: [
        .target(
            name: "MyLibrary",
            dependencies: [
                "RxSwift",
                "XCGLogger",
                .product(name: "RxCocoa", package: "RxSwift")],
            resources: [
                .copy("Fonts"),
                .copy("GoogleMapTheme"),
                .copy("Assets")
            ],
            plugins: [.plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin")]),
        .testTarget(
            name: "MyLibraryTests",
            dependencies: [
                "MyLibrary",
                "RxSwift",
                .product(name: "RxCocoa", package: "RxSwift"),
                "Nimble"],
            resources: [
                .embedInCode("CoreAssetsCatalog.swift") // <- accessing content of this file in unit test results in fatalError
            ]
        )
    ]
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions