I'm writing a Bluetooth library around CoreBluetooth, to create a solid code coverage I'm using as a Dependency this library.
This library requires that you substitute each import
CoreBluetooth to import
CoreBluetoothMock and since the mock are protocol based I could not use some functionalities. To avoid compiler errors I've created a new Xcode configuration that defines a
TEST flag and I've set up the scheme to use this configuration duration using testing. Thus I have some part of my code wrapped around
#endif including import statements.
Using the SPM and the option
-Xswifc "-DTEST" I'm able to safely run unit tests.
I would like that my library won't come out with this dependency that is used only for CI and I've figured out that setting my SPM file into some like that, I could provide a target user library, a target library with that dependency compiled with that flag defined and test target that depends on this last one.
Unfortunately this configuration led me to the
error: target 'LittleBlueToothForTest' has sources overlapping sources:
I've read that SPM is made that way so my solution it doesn't seem to be applicable. I've read different post on the forum.
Here my Package file:
let package = Package( name: "LittleBlueTooth", platforms: [ // Add support for all platforms starting from a specific version. .macOS(.v10_15), .iOS(.v13), .watchOS(.v6), .tvOS(.v13) ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "LittleBlueTooth", targets: ["LittleBlueTooth"]), .library( name: "LittleBlueToothForTest", targets: ["LittleBlueToothForTest"]) ], dependencies: [ // Dependencies declare other packages that this package depends on. .package(name: "CoreBluetoothMock", url: "https://github.com/enricodk/IOS-CoreBluetooth-Mock.git", .branch("multiplatform")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "LittleBlueTooth", dependencies: ), .target( name: "LittleBlueToothForTest", dependencies: ["CoreBluetoothMock"], path: "./Sources/LittleBlueTooth", swiftSettings: [.define("TEST")] ), .testTarget( name: "LittleBlueToothTests", dependencies: ["LittleBlueToothForTest","CoreBluetoothMock"]) ] )
Has someone any idea/suggestion about how can I solve that issue?