Skip to content
Merged
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
30 changes: 27 additions & 3 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,39 @@ alias build := library
alias clr := clear
alias d := doxygen
alias l := library
alias v := valgrind
alias ver := bump
alias version := bump



# Compiler flags.
exe := '-fPIE'
f18 := '-std=f2018'
flags := '-Wall -Werror -Wextra -Wpedantic'
lib := '-c -fPIC'

# Targets.
library := 'libcndmem.a'
# Linker flags.
lflags := '-L. -lf18cndmem'

# Settings for the supported language modes.
f18-exe := f18 + ' ' + exe + ' ' + flags
f18-lib := f18 + ' ' + lib + ' ' + flags
lnk-f18 := '-I. ' + lflags

# Targets.
library := 'libf18cndmem.a'

# Valgrind settings.
vflags := '--leak-check=full --redzone-size=512 --show-leak-kinds=all'



# The default recipe to execute.
@default: all

# Execute all configured recipes.
@all: clear doxygen library
@all: clear doxygen valgrind

# Increment the version numbers.
@bump part:
Expand All @@ -80,6 +90,10 @@ f18-lib := f18 + ' ' + lib + ' ' + flags
ar rsv {{library}} *.o
rm -rf *.o

# Create the required directories.
@directories:
mkdir -p target/

# Create the Doxygen documentation for this project.
@doxygen:
doxygen doxygen.cfg
Expand All @@ -93,4 +107,14 @@ f18-lib := f18 + ' ' + lib + ' ' + flags
# Compile the target library.
@library: character

# Compile and run a single unit test.
@test name: directories library
gfortran {{f18-exe}} tests/test_{{name}}.f08 -o \
target/test_{{name}} {{lnk-f18}}
valgrind {{vflags}} target/test_{{name}}

# Analyse the memory management of the unit tests.
@valgrind:
just test character

################################################################################
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ version is as follows:
| Latexmk | application | LaTeX compilation of Doxygen manual |
| Scriv | Python CLI | changelog management |
| TeX Live (full) | package | LaTeX environment for Doxygen manual |
| Valgrind | application | memory leak detection |

This library is written in Fortran 2018 such that its build requires a compiler
supporting this standard. This project relies on **GFortran** therefore.
Expand All @@ -94,6 +95,10 @@ In order to finalise the LaTeX documentation, an appropriate LaTeX distribution
is required. A *full* installation of **TeX Live** is recommended. This
project employs **Latexmk** as LaTeX build manager for the manual finalisation.

There are unit tests for the library logic written in plain Fortran 2018 without
requiring any further libraries. When running the tests, **Valgrind** will
analyse their memory management.

In order to simplify the maintenance, **bump2version** as well as **Scriv** are
used to automate the release generation. Scriv will compile the changelog on
release after all version numbers were incremented by bump2version.
Expand Down Expand Up @@ -155,8 +160,18 @@ just d
just doxygen
```

The correctness of this library is ensured by a set of unit tests. They are
furthermore analysed for their memory management by Valgrind. By calling for
the Valgrind analysis, the unit tests are executed implicitly. This can be
done with one of the following commands.

```bash
just v
just valgrind
```

If the compilation of both the library and its documentation is wished, the
following instructions can be executed.
following instructions can be executed. This will also run all unit tests.

```bash
just
Expand Down
6 changes: 6 additions & 0 deletions changelog.d/feature:unit-test-character.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Added
.....

- unit test: conditional allocation (type ``character``, default)

- unit test: conditional deallocation (type ``character``, default)
3 changes: 2 additions & 1 deletion doxygen.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,8 @@ WARN_LOGFILE =
# Note: If this tag is empty the current directory is searched.

INPUT = src/ \
src/type_character/
src/type_character/ \
tests/

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
4 changes: 2 additions & 2 deletions src/lib.f08
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

module libcndmem
module libf18cndmem
implicit none
private
!> This library's version.
Expand All @@ -66,6 +66,6 @@ pure module subroutine cnddel_character (tgt)
character (:), allocatable, intent (inout) :: tgt
end subroutine cnddel_character
end interface cnddel
end module libcndmem
end module libf18cndmem

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 changes: 1 addition & 1 deletion src/type_character.f08
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

submodule (libcndmem) type_character
submodule (libf18cndmem) type_character
implicit none
contains
include 'type_character/cndall_character.f08'
Expand Down
105 changes: 105 additions & 0 deletions tests/test_character.f08
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
!!!!!!!!!!!!!!!!!!!!!!!! GNU General Public License 2.0 !!!!!!!!!!!!!!!!!!!!!!!!
!! !!
!! Copyright (C) 2022 Kevin Matthes !!
!! !!
!! This program is free software; you can redistribute it and/or modify !!
!! it under the terms of the GNU General Public License as published by !!
!! the Free Software Foundation; either version 2 of the License, or !!
!! (at your option) any later version. !!
!! !!
!! This program is distributed in the hope that it will be useful, !!
!! but WITHOUT ANY WARRANTY; without even the implied warranty of !!
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !!
!! GNU General Public License for more details. !!
!! !!
!! You should have received a copy of the GNU General Public License along !!
!! with this program; if not, write to the Free Software Foundation, Inc., !!
!! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. !!
!! !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!> \file test_character.f08
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!> \author Kevin Matthes
!> \copyright GPL-2.0
!> \date 2022
!> \note See `LICENSE' for full license.
!> See `README.md' for project details.
!>
!> \brief A set of simple tests for the `character` type (default).
!> \return Whether this test succeeds.
!>
!> This unit test will check whether
!>
!> * an unallocated allocatable object can be deallocated.
!> * an unallocated allocatable object can be allocated and receive a constant.
!> * an allocated allocatable object can receive another constant by conditional
!> reallocation.
!> * an allocated allocatable object can be deallocated.
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

program test_character
use, non_intrinsic :: libf18cndmem, only: cndall
use, non_intrinsic :: libf18cndmem, only: cnddel
implicit none
character (:), allocatable :: object
character (*), parameter :: constant &
= 'constant'
character (*), parameter :: error_allocated &
= 'Allocatable object should not be allocated!'
character (*), parameter :: error_not_allocated &
= 'Allocatable object should be allocated!'
character (*), parameter :: error_wrong_value &
= 'Allocatable object does not have the expect&
&ed value!'
character (*), parameter :: hello &
= 'Hello'
character (*), parameter :: world &
= ', World!'
intrinsic :: allocated

if (allocated (object)) then
error stop error_allocated
else
call cnddel (object)
end if

if (allocated (object)) then
error stop error_allocated
else
call cndall (object, constant)
end if

if (.not. allocated (object)) then
error stop error_not_allocated
else if (object /= constant) then
error stop error_wrong_value
end if

call cndall (object, hello)

if (.not. allocated (object)) then
error stop error_not_allocated
else if (object // world /= hello // world) then
error stop error_wrong_value
end if

if (.not. allocated (object)) then
error stop error_not_allocated
else
call cnddel (object)
end if

if (allocated (object)) then
error stop error_allocated
end if
end program test_character

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!