Testing a library that depends on downstream packages

I am writing a library named wumpus (say). wumpus does many amazing things.

There are potentially many ways to interact with wumpus. I have thus decided to put its JSON ability in a separate package, wumpus-json, as not all wumpus users will want the dependencies required for the JSON interface.

I would like to test that wumpus operates correctly. I thus have a testsuite for wumpus. It includes some definitions and some tests over those definitions. I would like to run similar tests for the JSON interface to wumpus.

But now I am stuck. It seems I cannot have the wumpus testsuite depend on wumpus-json, as Cabal thinks that’s a circular dependency. (It’s not: the wumpus testsuite depends on wumpus-json depends on the wumpus library. It’s perhaps U-shaped, but it’s not a closed circle.) And I do not wish to put the tests into wumpus-json's testsuite, because then I have to repeat a bunch of definitions (that I cannot export from wumpus's testsuite). I could move all my tests to wumpus-json, but then poor wumpus is left without a testsuite (and I will also have a problem when I want wumpus-csv). Maybe I make a wumpus-tests that depends on them all? That seems a bit overwrought.

Does the wisdom of the crowd have any insight to offer to get me unstuck? Thanks!

2 Likes

Could those definitions be refactored to the point where they can be relocated to a separate package e.g. wumpus-test-utils which wumpus, wumpus-json, wumpus-csv, etc would then rely on?

Maybe expose the functions if general enough in a Test.Wumpus module in the wumpus package? This way anyone else making wumpus extensions can also use those tests?

And if you want to keep the dependency list as short as possible, then I guess a wumpus-test package might be the way to go? :woman_shrugging:

This could be a good use case for the (still experimental, very undocumented) “public sub-libraries” feature of Cabal.

The idea is to publish a “wumpus-test-support” sublibrary in the “wumpus” package, along with the main library. The tests of “wumpus-json” could depend on “wumpus-test-support”, but the main library would depend only on the main library of “wumpus”.

Here’s a proof-of-concept repository.

But the feature is perhaps still too immature.

Edit: this cabal issue about per-component dependency solving also seems related.

2 Likes

Thanks for the helpful responses. I’ve created a wumpus-test package that is working decently well.

2 Likes