Skip to content

Commit

Permalink
Add workaround for gfortran compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Mar 22, 2024
1 parent 296c3f9 commit c6c0381
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/fortuno.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

!> Interface module for the core library of the Fortuno testing framework
module fortuno
use fortuno_basetypes, only : char_repr, test_base, test_case_base, test_item, test_ptr_item,&
use fortuno_basetypes, only : stringable, test_base, test_case_base, test_item, test_ptr_item,&
& test_suite_base
use fortuno_consolelogger, only : console_logger
use fortuno_testcontext, only : context_factory, test_context
Expand Down
41 changes: 19 additions & 22 deletions src/fortuno/basetypes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,16 @@ module fortuno_basetypes
implicit none

private
public :: char_repr
public :: stringable
public :: test_base, test_case_base, test_suite_base
public :: test_item, test_ptr_item


!> Character representable object
type, abstract :: char_repr
type :: stringable
contains
procedure(char_repr_as_char), deferred :: as_char
end type char_repr

abstract interface

!> Returns the character representation of a character representable object.
function char_repr_as_char(this) result(charrepr)
import :: char_repr
implicit none

!> Instance
class(char_repr), intent(in) :: this

!> Character representation of the object.
character(:), allocatable :: charrepr

end function char_repr_as_char

end interface
procedure :: as_char => stringable_as_char
end type stringable


!> Base class for all test objects
Expand All @@ -45,7 +29,7 @@ end function char_repr_as_char
character(:), allocatable :: name

!> Character representable internal state
class(char_repr), allocatable :: state
class(stringable), allocatable :: state

contains

Expand Down Expand Up @@ -99,4 +83,17 @@ subroutine test_base_get_as_char(this, repr)

end subroutine test_base_get_as_char


function stringable_as_char(this) result(repr)

!> Instance
class(stringable), intent(in) :: this

!> Character representation of the object.
character(:), allocatable :: repr

repr = ""

end function stringable_as_char

end module fortuno_basetypes
11 changes: 7 additions & 4 deletions src/fortuno/checkers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

!> Contains some built-in checkers
module fortuno_checkers
use fortuno_namedtypes, only : named_details, named_item, char_repr_int
use fortuno_namedtypes, only : named_details, named_item, stringable_int
use fortuno_testinfo, only : check_result
use fortuno_utils, only : string
implicit none

private
Expand All @@ -32,12 +33,14 @@ function is_equal_i0_i0(obtained, expected) result(checkresult)
!> Result of the check
type(check_result) :: checkresult

type(named_item), allocatable :: items(:)

checkresult%success = (obtained == expected)
if (.not. checkresult%success) then
checkresult%details = named_details([&
& named_item("failure", "mismatching integer values"),&
& named_item("expected", char_repr_int(expected)),&
& named_item("obtained", char_repr_int(obtained))&
& named_item("failure", "Mismatching integer values"),&
& named_item("expected", stringable_int(expected)),&
& named_item("obtained", stringable_int(obtained))&
& ])
end if

Expand Down
50 changes: 39 additions & 11 deletions src/fortuno/namedtypes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

!> Contains a trivial implementation of name value pairs
module fortuno_namedtypes
use fortuno_basetypes, only : char_repr
use fortuno_basetypes, only : stringable
use fortuno_utils, only : as_char, nl, string, to_upper
implicit none

private
public :: named_item, named_details, named_state
public :: char_repr_int
public :: stringable_int


!> Implements a named item of arbitrary type
type :: named_item
Expand All @@ -24,8 +25,15 @@ module fortuno_namedtypes
end type named_item


! Workaround:gfortran:13.2
! Needs defined structure constructor as default constructor does not work with class(*) field
interface named_item
module procedure new_named_item
end interface


!> Represents failure details with an array of named items.
type, extends(char_repr) :: named_details
type, extends(stringable) :: named_details

!> Items containing the information about the failure details
type(named_item), allocatable :: items(:)
Expand All @@ -36,7 +44,7 @@ module fortuno_namedtypes


!> Represents test internal state with an array of named items.
type, extends(char_repr) :: named_state
type, extends(stringable) :: named_state

!> Items containing the information about the failure details
type(named_item), allocatable :: items(:)
Expand All @@ -47,14 +55,14 @@ module fortuno_namedtypes


!> Integer with string representation.
type, extends(char_repr) :: char_repr_int
type, extends(stringable) :: stringable_int

!> Value
integer :: value

contains
procedure :: as_char => char_repr_int_as_char
end type char_repr_int
procedure :: as_char => stringable_int_as_char
end type stringable_int

contains

Expand Down Expand Up @@ -96,17 +104,35 @@ end function named_state_as_char


!> Integer with string representation.
function char_repr_int_as_char(this) result(repr)
function stringable_int_as_char(this) result(repr)

!> Instance
class(char_repr_int), intent(in) :: this
class(stringable_int), intent(in) :: this

!> Character representation
character(:), allocatable :: repr

repr = as_char(this%value)

end function char_repr_int_as_char
end function stringable_int_as_char


!> Explicit constructor for named_item (to avoid gfortran compilation problems)
function new_named_item(name, val) result(this)

!> Name of the item
character(*), intent(in) :: name

!> Value of the item
class(*), intent(in) :: val

!> Initialized instance
type(named_item) :: this

this%name = name
allocate(this%value, source=val)

end function new_named_item


!! Returns the character representation of an array of named items.
Expand All @@ -131,7 +157,9 @@ subroutine get_named_items_as_char_(items, repr, itemsep, namesep, capitalizenam
select type (namedvalue => items(iitem)%value)
type is (character(*))
valuestrings(iitem)%content = namedvalue
class is (char_repr)
class is (string)
valuestrings(iitem)%content = namedvalue%content
class is (stringable)
valuestrings(iitem)%content = namedvalue%as_char()
class default
valuestrings(iitem)%content = "???"
Expand Down
6 changes: 3 additions & 3 deletions src/fortuno/testinfo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

!> Types containing informations about tests and checks
module fortuno_testinfo
use fortuno_basetypes, only : char_repr
use fortuno_basetypes, only : stringable
use fortuno_utils, only : as_char, nl
implicit none

Expand Down Expand Up @@ -45,7 +45,7 @@ module fortuno_testinfo
logical :: success = .false.

!> Further character representable information about the check (reason of failure)
class(char_repr), allocatable :: details
class(stringable), allocatable :: details

end type check_result

Expand Down Expand Up @@ -77,7 +77,7 @@ module fortuno_testinfo
class(failure_location), allocatable :: location

!> Character representable internal details of the check
class(char_repr), allocatable :: details
class(stringable), allocatable :: details

!> Contains previous failure_info (to be able to chain check infos)
type(failure_info), allocatable :: previous
Expand Down
1 change: 1 addition & 0 deletions src/fortuno/utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!> Various helper utilities for the different modules
module fortuno_utils
use iso_fortran_env, only : stderr => error_unit, stdout => output_unit
use fortuno_basetypes, only : stringable
implicit none

private
Expand Down

0 comments on commit c6c0381

Please sign in to comment.