Goddard-Fortran-Ecosystem / pFUnit

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

Feature Request: @assertEquals for string arrays #381

Closed jphill4 closed 1 year ago

jphill4 commented 1 year ago

I would be nice to have an assertEqual overload for arrays of character strings. This did not work for me:

character(3), allocatable :: str1(:), str2(:)
str1 = ['foo', 'bar', 'baz']
str2 = ['bar', 'baz', 'foo']
@assertEqual(str1, str2)

Reproducer attached. test.zip

tclune commented 1 year ago

Yes - this gap in the assert library arises from time to time and should be filled. It should be easy to add, and maybe I'll get to it this evening.

In the mean time, a workaround is to use

@assertTrue(all(str1 == str2))

but, admittedly, the diagnostic for failing cases is less informative that way.

tclune commented 1 year ago

I've done a quick and dirty PR (#385) but it does not give particularly informative failure messages. But at least the new interface are in place.

The AssertEqual package was contributed by someone else, and now that I'm looking at the code, I find it to be overly verbose and cluttered. I did a bit of refactoring now, but more is needed. When done, I can then reuse some of the scalar code to generate proper failure messages for the array case. I've marked the PR as "draft" for now.

jphill4 commented 1 year ago

Thank you for your work on this!