Description
Since @milancurcic brought it up in #177 (comment), it might be worth to have a way to define unit tests within a test target, i.e. “export” tests from our testing framework as test targets to fpm test
. I am also thinking of tests that will require external resources, we cannot really define in a unit test.
An example is the consistency test of the version number specified in the fpm.toml
, meson.build
or CMakeLists.txt
and the internal one in a *_version
module. In this case we would either like to get the correct fpm.toml
as argument and parse it or have the build system pass the version string as command line argument. The unit test without arguments will usually be useless. The alternative would be to generate the *_version
module with configure_file
from a template, but this is nothing we can do with fpm (yet).
Other examples might be test targets requiring correctly set environment variables or test binaries that can run different tests depending on a test input file. The binary might even be an external program that takes an executable as input and provides it with input by some convention (i.e. STDIN) and expects a correct response (i.e. STDOUT or error code).
I am facing four different test scenarios with toml-f
, for which I am relying on the unit test framework of meson and it does a pretty decent job to orchestrate those different scenarios. Only one of them would be supported by fpm right now. Here are the test definitions for reference: https://github.com/toml-f/toml-f/blob/master/test/meson.build.
Activity
certik commentedon Sep 22, 2020
@awvwgk thanks for the idea. Can you give an example how it could look like from a user perspective for
toml-f
usingfpm
?I would prefer if things can somehow work automatically so that users don't have to code a file like https://github.com/toml-f/toml-f/blob/cb04d91e55872f390210a63c3468f168c0da4cbd/test/meson.build, which seems quite long. Is the problem in different dependencies for tests?
awvwgk commentedon Sep 22, 2020
Let's assume fpm would support a
configure_file
like syntax, a hypothetical transcription of my test definitions fortoml-f
with fpm could look like this:Certainly, the test definitions won't get much shorted compared to the declarations in the meson.build of
toml-f
. I actually prefer to be explicit about the declarations.For the sake of the discussion, we can ignore the second half of the tests for now, if they don't fit into fpm's scope of testing (I currently don't support them in CMake as well because they are a bit more involved and so far only meson is able to handle this test scenario gracefully).
But supporting the first two scenarios (
tftest-version
andtftest-fpm
) in some way would be great.ivan-pi commentedon Dec 23, 2020
At least for the first scenario, I believe in Cargo it is done using environment variables. Quoting the relevant sections:
In rust
env!
is a macro which inspects an environment variable at compile time! Then you just need to assert the environment variable version (coming from the manifest file) is equal to the parameter in your Fortran API.For the second version you could use an environment variable
FPM_MANIFEST_DIR
.For the remaining cases I have the feeling it can be done with the environment variables:
awvwgk commentedon Dec 23, 2020
The Rust macro processor is quite powerful, but we would have to emulate something like this with
fypp
orcpp
.Using environment variables at runtime would be the (easier) alternative, which again leads to the problem how we to specify those in the package manifest in case we need non-standard information.