<div dir="ltr">I think this question is better suited for the swift-users mailing list, but I'll answer here since that's where you posted this.<div><br></div><div>The solution I've found is full of caveats, but it does run tests with swift-corelibs-xctest on Darwin.<br><div><br></div><div>The trick is to build your unit tests as an executable target with your main module as a dependency, and to add swift-corelibs-xctest as a dependency:</div><div><br></div><div><div><font face="monospace, monospace">import PackageDescription</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">let package = Package(</font></div><div><font face="monospace, monospace"> name: "MyPackage",</font></div><div><font face="monospace, monospace"> targets: [</font></div><div><font face="monospace, monospace"> Target(name: "MyPackage"),</font></div><div><font face="monospace, monospace"> Target(name: "MyPacakgeTests",</font></div><div><font face="monospace, monospace"> dependencies: [.Target(name: "MyPackage")]),</font></div><div><font face="monospace, monospace"> ],</font></div><div><font face="monospace, monospace"> dependencies: [</font></div><div><font face="monospace, monospace"> .Package(url: "<a href="https://github.com/norio-nomura/swift-corelibs-xctest">https://github.com/norio-nomura/swift-corelibs-xctest</a>", majorVersion: 0),</font></div><div><font face="monospace, monospace"> ]</font></div><div><font face="monospace, monospace">)</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">Note that the XCTest git URL used here isn't the official one, since it doesn't yet have an SPM-compatible version tag. So you can fork it and add a tag like Norio did (0.1.0-test). Then you can run your tests by running </font><font face="monospace, monospace">swift build</font><font face="arial, helvetica, sans-serif"> followed by </font><font face="monospace, monospace">.build/Debug/MyPackageTests</font><font face="arial, helvetica, sans-serif">.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">However, please note that by doing this, you're introducing a target with a local dependency, which means that others won't be able to use your package as a dependency due to <a href="https://bugs.swift.org/browse/SR-688">SR-688</a>.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div>I'm testing my projects on Darwin in both Xcode and SPM, using Darwin XCTest in Xcode, and swift-corelibs-xctest in SPM.<font face="arial, helvetica, sans-serif"><br></font></div><div><br></div><div>You can see the approach we take (including testing on Travis) in <a href="https://github.com/jpsim/SourceKitten">SourceKitten</a> and <a href="https://github.com/realm/SwiftLint">SwiftLint</a>. The relevant files are <font face="monospace, monospace">Package.swift</font>, <font face="monospace, monospace">Makefile</font> and <font face="monospace, monospace">.travis.yml</font>.</div></div><div><br></div><div>I'm hoping that others can share nicer solutions to this as well, but in the meantime, hopefully this gets you unstuck.</div><div>JP</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 8, 2016 at 11:12 AM, Scott Guyer via swift-corelibs-dev <span dir="ltr"><<a href="mailto:swift-corelibs-dev@swift.org" target="_blank">swift-corelibs-dev@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi folks,<div><br></div><div> I've tried to determine the current best practice for managing projects with tests. I figure I would just ask ...</div><div><br></div><div>Scenario: I have a project with a code module and a test module. I need it to run on both macosx (darwin) as well as Linux.</div><div><br></div><div>Using swiftpm on Linux works fine. It fails on macosx (the error is that an underlying dependency for XCTest cannot be loaded). What I read is that corelibs-xctest was not meant to be run on Darwin. I'm coming to the conclusion that I should have a .xcodeproj with a framework target and test target for Darwin testing. Leaving the swiftpm approach for Linux only.</div><div><br></div><div>Does that sound about right?</div><div><br></div><div>Thanks!</div><span class="HOEnZb"><font color="#888888"><div>-Scott</div><div><br></div><div><br></div></font></span></div>
<br>_______________________________________________<br>
swift-corelibs-dev mailing list<br>
<a href="mailto:swift-corelibs-dev@swift.org">swift-corelibs-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a><br>
<br></blockquote></div><br></div>