Closed szaghi closed 8 years ago
I think it's a great idea!
One suggestion: would it be possible to make the syntax more markdown friendly for FORD, so that if you want to have your unit tests syntax-highlightled in the documentation you could do that? Example:
!FBStest
!!```Fortran
!! type(type_foo) :: my_foo
!! call my_foo%init(b=992)
!! call my_foo%print()
!!```
!!> 992
!FBSendtest
So, it would grab everything in the Fortran block.
@jacobwilliams Yes, I cannot test the idea before the next week, nothing is already done, thus the syntax can be modified as we want. Indeed, when this morning I was writing this idea I was already thinking to adopt directly a markdown code-block :-) your suggestion is welcome :-)
Dear All, I finally finish this feature. Except some limitations (see below) it works incredible well. Monday I will upload a new release (with also some improvements on coarray support). The syntax presently support is the one suggested by jacob (with minor modufication)
!!```Fortran
!! type(type_foo) :: my_foo
!! call my_foo%init(b=992)
!! call my_foo%print()
!!```
!!> 992 <<<
The second limitation does not hurt me very much, wheras the limitation to only public object make me crazy... I would like to test also private objects. Any suggestions are welcome.
See you monday with this feature.
Done in the last release. Documentation coming soon.
AMAZING! Yes, testing private entities would be quite nice... one quick and dirty trick is to have a wrapping module to provide the public API, that controls/limits the scope of entities it imports.... pretty annoying hack but...
As a poor Fortraner I was always fascinated by the introspective-power of Python. One of the amazing Python module that I learned to love is doctest. In a few words
For example, in a code like the following
the comments like
>>> fib(0)
are VALID UNIT TESTS! When you run the above code withdoctest
module all the test-comments are tested and their results compared with the expected results (provided immediately after each test in the above example).During the last night (when Angelica was crying...), I figured out that such a behavior can be mimic by FoBiS.py for Fortran codes (with some limitations).
API desiderata
Let us consider the following Fortran module.
FoBiS.py can:
FBStest
/FBSendtest
;volatile program test skeleton
Fortran is less flexible than Python, than we must use a more verbose syntax for the doctest. In fact, in the above example, the fortran doctest has also the definition of the variable
my_foo
that is not necessary in the Python doctest. From this point of view the definition of the volatile program test corresponding to each doctest is crucial. In general, a possible skeleton could be:The doctests of the above example are
type bound test
non type bound test
Limitations
The approach above described should be very easy to implement into the current FoBiS.py version, but the main limitations are:
Considerations
Your thinking, why? The reasons are:
There many limitations (some above pointed-out), nevertheless such a feature is very useful for my OCD programming approach and I will try to implement it soon.
What do you think about?