Skip to content

Commit

Permalink
Extend readme with meson related infos
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Feb 24, 2024
1 parent b7fc452 commit 5ae6ca4
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ special pre-processor.

- parallel unit testing for MPI- and coarray-parallel projects, and

- seamless integration with the `fpm <https://fpm.fortran-lang.org/>`_ and
`CMake <https://cmake.org/>`_ build systems.
- integration with the `fpm <https://fpm.fortran-lang.org/>`_, `CMake
<https://cmake.org/>`_ and `Meson <https://mesonbuild.com/>`_ build systems.

Detailed **documentation** is available on the `Fortuno documentation
<https://fortuno.readthedocs.io>`_ page. You can also have a look at the
Expand All @@ -38,6 +38,17 @@ The development can be followed and joined at the `Fortuno project
Quickstart
==========

The following instructions demonstrate how to add unit testing via Fortuno to an
existing project, which uses fpm, CMake or Meson as build system. If you are not
familiar with any of these build systems, visit the `Fortuno documentation
<https://fortuno.readthedocs.io>`_ for a step-by-step guide starting from
scratch.

In the examples below, we will assume that your library has a module ``mylib``,
which provides a function ``factorial()`` for calculating the factorial of
integers. Adapt those names to your actual library and routine names.


Obtaining Fortuno
-----------------

Expand All @@ -61,6 +72,21 @@ project's build process. The actual steps depend on your build system.
)
FetchContent_MakeAvailable(Fortuno)

* **Meson:** Create the file ``fortuno.wrap`` in the ``subprojects/`` folder
of your project (create the folder, if it does not exist yet) with following
content::

[wrap-git]
directory=fortuno
url=https://github.com/fortuno-repos/fortuno
revision=main

Add Fortuno as a subproject by adding the following to your main
``meson.build`` file::

fortuno_subproject = subproject('fortuno')
fortuno_dep = fortuno_subproject.get_variable('fortuno_dep')


Writing unit tests
------------------
Expand All @@ -74,7 +100,7 @@ Given a hypothetical library ``mylib`` providing a function ``factorial()`` for
calculating the factorial of integers, the minimal test program checking the
results for two different input values could look as follows::

! testapp.f90
! file: testapp.f90

!> Test app driving Fortuno unit tests.
program testapp
Expand Down Expand Up @@ -121,11 +147,11 @@ build system:

fpm build

* **CMake:** Register ``testapp.f90`` for compilation and add the
``Fortuno::Fortuno`` target as dependency in the relevant ``CMakeLists.txt``
file. You would, of course, also have to specify your library (e.g. ``mylib``)
as dependency. Additionally, register the executable as a test, so that it can
be executed via ``ctest``::
* **CMake:** Create an executable ``testapp`` with ``testapp.f90`` as source and
add ``Fortuno::Fortuno`` target as dependency in the ``CMakeLists.txt`` file.
Add also the target name of your library (e.g. ``mylib``) as dependency.
Additionally, register the executable as a test, so that it can be executed
via ``ctest``::

add_executable(testapp testapp.f90)
target_link_libraries(testapp PRIVATE mylib Fortuno::Fortuno)
Expand All @@ -140,6 +166,22 @@ build system:
cmake -B _build
cmake --build _build

* **Meson:** Create an executable ``testapp`` with ``testapp.f90`` as source and
``fortuno_dep`` as dependency in the ``meson.build`` file. Add also your
library (e.g. ``mylib_dep``) as dependency::

testapp_exe = executable(
'testapp',
sources: ['testapp.f90'],
dependencies: [mylib_dep, fortuno_dep],
)
test('factorial', testapp_exe)

Build your project as usual::

meson setup _build
ninja -C _build


Running the tests
-----------------
Expand All @@ -158,6 +200,10 @@ You run the units tests by executing the test app:
output of Fortuno. You will only see the final result of the testing procedure
then.

* **Meson:** Run the unit tests with ::

meson test

The result is communicated via the testapp's exit code to the build framework
(zero for success, and non-zero for failure). Additionally, Fortuno logs details
to the console::
Expand Down

0 comments on commit 5ae6ca4

Please sign in to comment.