From bb077dfd0dba3557228e5a29b3f6b0c55de83642 Mon Sep 17 00:00:00 2001 From: "Igor S. Gerasimov" Date: Thu, 27 Feb 2025 23:49:47 +0100 Subject: [PATCH 1/2] Automatically deallocate strings in testsuite/unittest structures at the end of lifetimes --- src/testdrive.F90 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/testdrive.F90 b/src/testdrive.F90 index f84bb85..b606436 100644 --- a/src/testdrive.F90 +++ b/src/testdrive.F90 @@ -279,6 +279,11 @@ end subroutine test_interface !> Whether test is supposed to fail logical :: should_fail = .false. + contains + + !> Deallocate unittest's internal data + final :: destroy_unittest + end type unittest_type @@ -303,6 +308,11 @@ end subroutine collect_interface !> Entry point of the test procedure(collect_interface), pointer, nopass :: collect => null() + contains + + !> Deallocate testsuite's internal data + final :: destroy_testsuite + end type testsuite_type @@ -853,6 +863,18 @@ function new_unittest(name, test, should_fail) result(self) end function new_unittest + !> Finalize unit test + subroutine destroy_unittest(self) + + !> unittest to destroy + type(unittest_type), intent(inout) :: self + + if (allocated(self%name)) deallocate(self%name) + self%test => null() + + end subroutine destroy_unittest + + !> Register a new testsuite function new_testsuite(name, collect) result(self) @@ -871,6 +893,18 @@ function new_testsuite(name, collect) result(self) end function new_testsuite + !> Finalize testsuite + subroutine destroy_testsuite(self) + + !> testsuite to destroy + type(testsuite_type), intent(inout) :: self + + if (allocated(self%name)) deallocate(self%name) + self%collect => null() + + end subroutine destroy_testsuite + + subroutine check_stat(error, stat, message, more) !> Error handling From 7ab35240a0c965b28f22c08ad73c16da9e78ce4b Mon Sep 17 00:00:00 2001 From: "Igor S. Gerasimov" Date: Thu, 27 Feb 2025 23:57:19 +0100 Subject: [PATCH 2/2] Automatically deallocate strings in junit_output structure at the end of lifetimes --- src/testdrive.F90 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/testdrive.F90 b/src/testdrive.F90 index b606436..97d8ac7 100644 --- a/src/testdrive.F90 +++ b/src/testdrive.F90 @@ -344,6 +344,8 @@ end subroutine collect_interface integer :: skipped = 0 !> Running time real(sp) :: time = 0.0_sp + contains + final :: destroy_junit_output end type junit_output @@ -774,6 +776,22 @@ subroutine junit_write(junit) end subroutine junit_write + !> deallocate internal data of junit_output + subroutine destroy_junit_output(self) + + !> JUnit output + type(junit_output), intent(inout) :: self + + if (allocated(self%xml_start)) deallocate(self%xml_start) + if (allocated(self%xml_block)) deallocate(self%xml_block) + if (allocated(self%xml_final)) deallocate(self%xml_final) + if (allocated(self%hostname)) deallocate(self%hostname) + if (allocated(self%package)) deallocate(self%package) + if (allocated(self%testsuite)) deallocate(self%testsuite) + + end subroutine destroy_junit_output + + !> Create ISO 8601 formatted timestamp function get_timestamp() result(timestamp)