Swift Package Manager with third party testing frameworks?

I've had a lot of success bringing C++ dependencies under SPM management. It's created a package based import mechanism without storing binaries anywhere, and it's a quick and easy process for smaller dependencies.

But the tests are one thing I haven't been able to bring with me to SPM. GTest is the defecto testing framework for C++, and I haven't seen a way to invoke it from a test target. And until C++ compatibility lands in Swift, there's no way to exercise the C++ (easily) from XCTest.

I also poked around and it looks like there were some stories about third party test framework support many years ago, and these were closed.

Am I correct in thinking there is no clear way to test C++, in a cross platform way, from SPM? And no way to integrate GTest?

This sounds accurate to me, however I think it should be possible to use XCTest by writing the tests in ObjC++ instead of Swift.

Does Obj-C++ function on other platforms like Linux? My impression was that Swift's XCTest didn't support Obj-C/Obj-C++ on other platforms. And that Obj-C required Obj-C Foundation, which is only included on Apple platforms.

Ah true, that is a good point, I think you are correct. Sorry for the confusion.

1 Like

No problem!

One solution might be to write a bridge for GTest to XCTest using C. I know there are Obj-C++ based bridges out there for Xcode. It could be exportable as a Swift Package that also handles the building of GTest.

My recollection of the Obj-C GTest bridge is that it used a lot of dynamism and NSInvocation, but it looks like the Swift.org version of XCTest can do dynamic test case generation, just using different means.

I'll take a look at how feasible that might be.

I am curious to know what your results here were, if you did pursue it? I am in a similar situation at the moment.

I didn't get a chance to look at it. Sorry, I don't have anything else to add right now! :frowning:

1 Like