Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Submodule/external/pFUnit"]
path = Submodule/external/pFUnit
url = https://github.com/Goddard-Fortran-Ecosystem/pFUnit.git
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ from the command line.
This demo uses pFUnit's parallel capabilities and includes some
advanced cases with fixtures and parameterized tests.

### Submodule

This demo includes pFUnit as a git submodule and builds the test suite
using `add_subdirectory` instead of `find_package`, such that `pFUnit`,
the demo library and the test suite are built from a single `CMakeLists.txt`


### Parameterized (unimplemented)
Expand Down
2 changes: 2 additions & 0 deletions Submodule/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
test/*.F90
9 changes: 9 additions & 0 deletions Submodule/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.2)
project(playground LANGUAGES Fortran)

# We want to build the library and test suite with these flags, but do not want these flags to be used for pFUnit.
set(mylib_fortran_flags "-cpp -fPIC -fdefault-real-8 -fdefault-double-8 -frecursive -Wno-unused-function -Wno-unused-variable")

add_subdirectory(${CMAKE_SOURCE_DIR}/src stufflib)
add_subdirectory(${CMAKE_SOURCE_DIR}/external/pFUnit)
add_subdirectory(${CMAKE_SOURCE_DIR}/test)
20 changes: 20 additions & 0 deletions Submodule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Example project using `pFUnit` with `add_submodule`

To build and run tests, execute the shell script `build_and_run_tests.sh`.

This is a minimal example of a project where we have some library, built from the files in `src/`, a test suite built from the files in `test/`, and would like to include `pFUnit` in
our project as a git submodule. Note that the `.gitmodules` file is located in the repository root (`..`). We want to build our library and tests with some set of flags/settings that should
not effect the building of `pFUnit`.

Building the project defined in `CMakeLists.txt` will compile the library, `pFUnit`, and the tests, such that this example should work also if you don't have an installed version of `pFUnit`.

Note: If you have installed `pFUnit`, and have defined the environment variable `PFUNIT_DIR`, you should `unset PFUNIT_DIR` before building the example, otherwise `cmake` seems to get confused.

The build system has been tested to work using
* MacOS 12.5.1
* gfortran 13.2.0 (Homebrew)
* gcc 13.2.0 (Homebrew)
* g++ 13.2.0 (Homebrew)
* cmake 3.24.2
* make 3.81
* pFUnit 4.10
9 changes: 9 additions & 0 deletions Submodule/build_and_run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$!/bin/bash
set -e
[ -d build ] && rm -r build

mkdir build
cd build
cmake ..
make mytests
./test/mytests
1 change: 1 addition & 0 deletions Submodule/external/pFUnit
Submodule pFUnit added at 26dadb
4 changes: 4 additions & 0 deletions Submodule/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project(stufflib LANGUAGES Fortran)

set(CMAKE_Fortran_FLAGS ${mylib_fortran_flags})
add_library(stuff ${CMAKE_CURRENT_SOURCE_DIR}/stuff.f90)
15 changes: 15 additions & 0 deletions Submodule/src/stuff.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module stuff
implicit none
public :: add

contains

subroutine add(a, b, res)
real, intent(in) :: a
real, intent(in) :: b
real, intent(out) :: res

res = a + b
end subroutine add

end module stuff
8 changes: 8 additions & 0 deletions Submodule/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_policy(SET CMP0074 NEW)

set(CMAKE_Fortran_FLAGS ${mylib_fortran_flags})

enable_testing()
file(GLOB UNITTEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.pf)
add_pfunit_ctest(mytests TEST_SOURCES ${UNITTEST_SRC} LINK_LIBRARIES stuff)
target_include_directories(mytests PRIVATE ${CMAKE_BINARY_DIR}/stufflib ${CMAKE_CURRENT_BINARY_DIR})
19 changes: 19 additions & 0 deletions Submodule/test/test_stuff.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module test_stuff
use funit
implicit none
real, parameter :: tol = 1e-10
contains

@Test
subroutine test_add()
use stuff, only: add

real :: a = 5.0
real :: b = 6.0
real :: res

call add(a, b, res)
@assertEqual(res, a + b, tol)
end subroutine test_add

end module test_stuff