SwiftGen / SwiftGenPlugin

SwiftGen plugin for SPM
MIT License
95 stars 63 forks source link

Unit test case crashing on accessing generated code #19

Open parvez-keeptruckin opened 1 year ago

parvez-keeptruckin commented 1 year ago

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
            ]
        )
    ]
)
aregler commented 8 months ago

Hey. Did you solve this issue?

fruitcoder commented 8 months ago

I have the same problem