I'm writing a package in which I want to provide my users some testing-setup utility scripts. (https://github.com/PhilippMDoerner/mockingbird/blob/main/src/mockingbird/testSetup.nim)
For that purpose I want to provide a module testSetup.nim (note: ".nim" file, not ".nims" file!) with procs, that users can import into their config.nims and execute there as they desire for their testing setup. As far as my understanding goes, config.nims should be executed just like any normal nimscript would, before any of the test-files are run.
The following test/config.nims file works perfectly fine when executing with nim e test/config.nims:
#config.nims
import mockingbird/testSetup
switch("path", "$projectDir/../src")
testSetup("/home/philipp/dev/tinypool/src", "/home/philipp/dev/tinypool/testos")
This breaks when I run nimble test with the message: Error: cannot open file: mockingbird/testSetup.
I don't quite get what's going on here. Why can I import testSetup.nim with nim e but not the import breaks when executed as part of nimble test?
After a couple hours of experimenting I found something that works as expected. I can't tell you why it works because I don't understand what's supposedly different, but for future readers, there is a solution.
What I did was now I started importing the entire mockingbird module in my config.nims, and I adjusted the mockingbird module file to export testSetup.nim
# mockingbird.nim
import ./mockingbird/[testSetup,pragma]
export pragma
export testSetup
# config.nims of user-package
import mockingbird
switch("path", "$projectDir/../src")
testSetup("/home/philipp/dev/tinypool/src", "/home/philipp/dev/tinypool/testos")
Previously I'd just tried to import testSetup directly. Why this apparently works now? No idea, just one of those gotcha things I assume