Goddard-Fortran-Ecosystem / pFUnit

Parallel Fortran Unit Testing Framework
Other
172 stars 45 forks source link

Fixtures in separate modules do not link #335

Open hr87 opened 2 years ago

hr87 commented 2 years ago

Using a fixture in a separate module will give a linker error (see below). Using a fixture in a separate module would allow reuse for several tests in different files/modules. If I put the fixture in the same module, the code compiles. I have also seen errors with access to private variable tree when I moved the fixture module to a separate file, but currently cannot reproduce that.

Code:

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! fixtures for adios tests
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module fixture

    ! load unit test
    use funit

    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! fixture to set exception handling
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    @TestCase
    type, extends(TestCase) :: basic_setup
    contains
        ! setup routine
        procedure :: setup
        ! finalize routine
        procedure :: teardown

    end type basic_setup

contains

    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! basic setup routine
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine setUp(this)

        ! variable declaration
        implicit none

        ! object
        class(basic_setup), intent(inout) :: this

    end subroutine setUp

    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! basic finalize routine
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine tearDown(this)

        ! variable declaration
        implicit none

        ! object
        class(basic_setup), intent(inout) :: this

    end subroutine tearDown

end module fixture

module test_fixture

    ! load unit test
    use funit
    use fixture

contains
    @Test
    subroutine test_procedure(self)

        class(basic_setup), intent(inout) :: self

    end subroutine test_procedure

end module test_fixture

CMake (unit_test links in pfunit and the application)

    add_pfunit_ctest(
        test_fixture TEST_SOURCES test_fixture.pf LINK_LIBRARIES unit_test
    )

Error message


[ 94%] Building Fortran object test_fixture.F90.o
test_fixture.F90:119:33:

  119 |    class (Test), allocatable :: t
      |                                 1
Warning: Unused variable ‘t’ declared at (1) [-Wunused-variable]
[ 94%] Building Fortran object test_fixture_driver.F90.o
[ 96%] Linking Fortran executable test_fixture
test_fixture.inc:1: error: undefined reference to 'test_fixture_suite_'
collect2: error: ld returned 1 exit status
make[2]: *** [src/adios/test/test_fixture] Error 1
make[1]: *** [src/adios/test/CMakeFiles/test_fixture.dir/all] Error 2
make: *** [all] Error 2