Running Tests with fpm

I’m trying to run some unittests that I wrote using @everythingfunctional 's vegetables framework, but I keep getting this error:

<ERROR>*cmd_run*:targets error:Unable to find source for module dependency: "my_module" used by "foo/bar/test/my_module_test.f90"
STOP 1

The problem seems to be with my directory structure, since I can’t seem to point the fpm test to the correct directory.

my_repo/
├─ foo/
│  ├─ bar/
│  │  ├─ my_module.f90
│  │  ├─ test/
│  │  │  ├─ main.f90
│  │  │  ├─ my_module_test.f90
├─ fpm.toml

If I move my_module.f90 into the test directory, all the tests run. My fpm.toml file looks like this:

name = "My_Project"
author = "NolantheNerd"

[install]
library = true

[library]
source-dir = "foo/bar"
include-dir = "foo/bar"

[build]
external-modules = "foo/bar"
link = "foo/bar/my_module.f90"

[dev-dependencies]
vegetables = { git = "https://gitlab.com/everythingfunctional/vegetables.git", tag = "v7.2.2" }

[[test]]
name = "TestsForMyModule"
source-dir = "foo/bar/test"
main = "main.f90"
link = "foo/bar/my_module.f90"

How can I run unittests on a module contained in a different directory?

1 Like

Your build section is incorrect, and actually unnecessary in your case. Try removing it and let us know how it goes.

Edit: just noticed as well that the link entry in your test section is incorrect and unnecessary as well.

Thanks for your response @everythingfunctional! Removing both the build section and the link entry under test solved the issue. Cheers!

1 Like