Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixtures in separate modules do not link #335

Open
hr87 opened this issue Dec 7, 2021 · 0 comments
Open

Fixtures in separate modules do not link #335

hr87 opened this issue Dec 7, 2021 · 0 comments

Comments

@hr87
Copy link

hr87 commented Dec 7, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant