Goddard-Fortran-Ecosystem / pFUnit

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

Extending a TestCase to a base class then extended again doesn't work for me #465

Open ekluzek opened 5 months ago

ekluzek commented 5 months ago

I wanted to have a base class that I extend so I can test different types that themselves extends a base class into two specific

So the base class has this structure...

test_DustEmisBase.F90:

  type, extends(TestCase) :: TestDustEmisBase
     integer, allocatable :: filter_nolakep(:)      ! non-lake filter (patches)
     integer :: num_nolakep              ! number of patches in non-lake filter
     type(atm2lnd_type) :: atm2lnd_inst
     type(soilstate_type) :: soilstate_inst
     type(canopystate_type) :: canopystate_inst
     type(temperature_type) :: temperature_inst
     type(unittest_water_type_factory_type) :: water_factory
     type(water_type) :: water_inst
     type(frictionvel_type) :: frictionvel_inst
   contains
     procedure :: setUp_base
     procedure :: setUp_before_subgrid
     procedure :: clean
     procedure :: setupEnvironment
     procedure :: create_atm2lnd
     procedure :: create_fv
     procedure :: print_values
  end type TestDustEmisBase

And the extended class looks like this:

test_DustEmisZender2024.pf

  @TestCase
  type, extends(TestDustEmisBase) :: TestDustEmisZender2003
     type(dust_type) :: dust_emis
   contains
     procedure :: validate_patch
  end type TestDustEmisZender2003

I started this with everything in the extended class and that works fine. It's when I tried to make a base class that it appears that the base class methods don't seem to do anything. So I've got it building, linking and running, but the base methods in the base class don't seem to do anything.

To get it to build I had to have the base class a .F90 file rather than .pf

ekluzek commented 5 months ago

The workaround I'm going to go to is to have the baseclass as a separate object to handle the input for the objects that I want to have different tests for. So this still doesn't require code duplication, it's just not quite as slick as using an OO base class for both.

ekluzek commented 5 months ago

This somewhat relates to #343. But, I did get my case to build and link. Although the base class had to be a .F90 to get CMake to work with it.

tclune commented 4 months ago

I am sorry for the delay in responding. Lots of travel (and then catching up).

I'm not sure that I understand what your particular failure is.

I started this with everything in the extended class and that works fine. It's when I tried to make a base class that it appears that the base class methods don't seem to do anything. So I've got it building, linking and running, but the base methods in the base class don't seem to do anything.

Can you elaborate? How did you invoke the base class methods? Did they return without executing your code?

The CMake issue is presumably separate so let's deal with that once you've got something in true Fortran working.