(AggregatorX/test) pkg> status
Status `C:\Users\magnusl\local-work\AggregatorX\test\Project.toml`
[a3088200] AggregatorX v0.1.0 `.`
[87dc4568] HiGHS v1.21.1
⌅ [682c06a0] JSON v0.21.4
[4076af6c] JuMP v1.29.4
[8dfed614] Test v1.11.0
But when I run pkg>test (after activating main project environment) I get
ERROR: LoadError: ArgumentError: Package InteractiveUtils not found in current path.
- Run `import Pkg; Pkg.add("InteractiveUtils")` to install the InteractiveUtils package.
So it seems like the packages that only are explicitly added in the main project (like InteractiveUtils) can’t be seen from the test (i though that was the idea of the workspace, that this should be possible)? Any ideas why?
I think I found the error (shared here in case someone should end up here due to a similarly stupid mistake). I had made a package that was not registered in the general registry so I had initally added it like this to runtests.jl:
include("../src/AggregatorX.jl")
using .AggregatorX
as a locally defined module. Later I learned about add and dev for local git repos and directories, respectively. So when I added the main package (AggregatorX) to Project.tomlof /test I guess the dot syntax of using messed up something so the deps in the main project weren’t included in the namespace or something (if anyone understands the exact details, please share…). When I removed the include statement and simply wrote using AggregatorX it worked as expected!
That is not the right way to do it. You’re not loading the right package, you’re including a file, sidestepping the package manager. Testing non-registered packages is fully supported, otherwise you wouldn’t even be able to test non-registered revision at all.
The thing you need to do when using a workspace is to inform the package manager where to find the desired package, using the [sources] section of the Project.toml file. Concretely, in your test/Project.toml file add AggregatorX as an explicit dependency and then add
And I have using AggregatorX in test/runtests.jl
This seems to work. As far as I could tell from the most recent (dev) version of the Pkg.jl documentation (Pkg docs), this was the current recommended way and that a seperate [sources] block in test/Project.toml was not needed. Is this correct?
If you don’t use the workspace, then the source isn’t necessary but still ok to have it, if you do use the workspace then the source becomes necessary. Workspace is a new feature, but I’d say going forward it’ll probably become more and more useful. The source can be used regardless of whether you have a workspace or not, and it’d actually make activating the test environment easier in all cases (the alternative is to use TestEnv.jl), provided that you use at least Julia v1.11.