Closed danielhollas closed 2 years ago
This is bizarre. Lot's of tests compare integers.
I just added the following test to my current development project:
@test
subroutine test1()
integer :: int1=1, int2=2
@assertEqual(int1,int2, "test")
end subroutine test1
The output message I get is the expected:
Failure
in:
Test_AddVarSpec_suite.test1
Location:
[Test_AddVarSpec.pf:11]
test
AssertEqual failure:
Expected: <1>
Actual: <2>
Difference: <1>
FAILURES!!!
Tests run: 10, Failures: 1, Errors: 0
, Disabled: 0
STOP: *** Encountered 1 or more failures/errors during testing. ***
Hopefully this is a gcc7-is-too-old problem, as I don't really see what else could be wrong. If a newer GCC (latest of 9 10 or 11) does not work, please post a full test file and I'll try to replicate.
Ah, sorry, in my examples I wanted to have assertNotEqual
. Could you try it? Thanks for quick response! :heart: @assertEqual()
works as expected for me.
@tclune I've just added your simple test case with assertNotEqual
into my test suite and the build fail for all GCC versions that I am testing - 7, 9, 10, on Ubuntu image 18.10.
See for example https://github.com/PHOTOX/ABIN/runs/6096737798?check_suite_focus=true
Ah - yes; I now can reproduce your error:
Failure
in:
Test_AddVarSpec_suite.test1
Location:
[Test_AddVarSpec.pf:11]
test
AssertNotEqual failure:
Same value: <-1734344809>
FAILURES!!!
Tests run: 10, Failures: 1, Errors: 0
, Disabled: 0
And AssertNotEqual is used much more rarely, so this is not terribly surprising. But it has been a long time since anyone spotted a problem in the funit core layers. I'll take a quick look, but I may not be able to fix until the weekend.
A safer "modern" approach (which will not work with older Gfortran) is:
@assert_that(int1, is (not(equal_to(int2)))))
And that does work. The newer approach is more granular and creates better error messages. But it really pushes OO features and breaks older compilers.
Your other option in the mean time is simply to do:
assertTrue(int1 /= int2, message=...)
Failure messages will be less useful though.
@tclune thanks so much for looking into this. My sanity is restored, I was afraid I am doing something silly. :relaxed:
But it has been a long time since anyone spotted a problem in the funit core layers. :blush:
assertTrue(int1 /= int2, message=...)
Thank you for the recommendations, I'll go with this one since I still need to support GCC7 (old clusters die slowly). I have to say, the amount of parenthesis in the "modern" is a bit much for my eyes. I wonder if this is because Fortran doesn't have nice syntax for OO features.
Yeah the numerous parens are distracting. But for meatier assertions they are not quite as dense, even if they are as numerous. And equal_to
is actually a no-op, so it could be removed.
The bug was easier to spot than I feared. (The overloads are done by a python preprocessor, which makes the source code for assertions a bit opaque.)
Hot fix is in with the CI now. If it finishes soon, I'll roll out 4.3.0 before I head home.
It looks like
@assertNotEqual
is not overloaded for integers?Including the message keyword fixes the compilation, but the test does not work as expected
Converting integers to reals works
What am I missing? (tested with GCC-7, will test higher versions if needed)