Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup unit testing with CMake and pFUnit #17

Open
tlestang opened this issue Feb 17, 2022 · 0 comments
Open

Setup unit testing with CMake and pFUnit #17

tlestang opened this issue Feb 17, 2022 · 0 comments

Comments

@tlestang
Copy link

A minimum setup could be

  • Basic CMakeLists.txt for configuration and particularly interfacing with pFUnit.
  • A couple of placeholder unit tests to "test the testing".
  • Build and cache pFUnit in the GH actions workflow, build the test executable and run the tests.

Currently (17.02.2022) some tests are implemented in the hack_doconcurrent branch using CTest and pFUnit, so I'm assuming some of you know about this testing framework. pFUnit looks like a popular option for fortran. It's maybe not as well documented and feature-rich as frameworks in other languages, but seems to be used by many projects out there. Alternatives are Funit, FRUIT and Ftunit but pFUnit is the only one that ibviusly looks actively maintained?

I've played around with it, it's straightforward to install and use. At least following basic examples available at

https://github.com/Goddard-Fortran-Ecosystem/pFUnit_demos

It also had support for MPI. I don't know if this is common among fortran frameworks, but it sounds relevant to me.

Tests are written in free form fortran, e.g.

@test
subroutine test_square()
   use Square_mod
   use funit

   @assertEqual(9., square(3.), 'square(3)')
   
end subroutine test_square

that is meant to be parsed and compiled. But a CMake module is provided that takes care of everything, so that

add_pfunit_ctest (my_tests
  TEST_SOURCES ${test_srcs}
  LINK_LIBRARIES sut # your application library
  )

should be enough to generate test executable my_tests. See Using pFUnit.

@tlestang tlestang self-assigned this Feb 25, 2022
tlestang added a commit that referenced this issue Feb 25, 2022
tlestang added a commit that referenced this issue Feb 25, 2022
A separate list of command line options is defined for both xcompact3d
and the decomp2d library. Because they are currently the same, the
list could technically be defined one for decomp2d with the PUBLIC
attribute. However, it is likely that these 2 lists will diverge in
the future. Or at least it's helpful to allow it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant