title: Basic unit testing for Fortran in a locked-down environment
body: <p>What would be a sensible approach to take to try and add some basic unit tests to a large body of existing (Fortran 90) code, that is developee solely on a locked-down system, where there is no opportunity to install any 3rd party framework. I'm pretty much limited to standard Linux tools. At the moment the code base is tested at a full system level using a very limited set of tests, but this is extremely time consuming (multiple days to run), and so is rarely used during development</p>
  
  <p>Ideally looking to be able to incrementally add targetted testing to key systems, rather than completely overhaul the whole code base in a single attempt.</p>
  
  <p>Taking the example module below, and assuming an implementation of assert-type macros as detailed in <a href="https://stackoverflow.com/questions/21724186/assert-in-fortran">Assert in Fortran</a></p>
  
  <pre><code>MODULE foo
      CONTAINS
      FUNCTION bar() RESULT (some_output)
          INTEGER :: some_output
          some_output = 0
      END FUNCTION bar
  END MODULE foo
  </code></pre>
  
  <p>A couple of possible methods spring to mind, but there may be technical or admistrative challenges to implementating these of which I am not aware: </p>
  
  <ol>
  <li><p>Separate test module for each module, as below, and have a single main test runner to call each function within each module</p>
  
  <pre><code>MODULE foo_test
      CONTAINS
      SUBROUTINE bar_test()
       ! ....
      END SUBROUTINE bar_test()
  END MODULE foo_test
  </code></pre></li>
  <li><p>A similar approach as above, but with individual executables for each test. Obvious benefit being that a single failure will not terminate all tests, but may be harder to manage a large set of test executables, and may require large amounts of extra code.</p></li>
  <li><p>Use preprocessor to include main function(s) containing tests within each module, e.g. in gfortran <a href="https://stackoverflow.com/questions/10866075/fortran-90-with-c-c-style-macro-e-g-define-subnamex-s-x">Fortran 90 with C/C++ style macro (e.g. # define SUBNAME(x) s ## x)</a> and use a build-script to automatically test main's stored between preprocessor delimiters in the main code file.</p></li>
  </ol>
  
  <p>I have tried using some of the existing Fortran frameworks (as documented in ><a href="https://stackoverflow.com/questions/5271200/why-the-unit-test-frameworks-in-fortran-rely-on-ruby-instead-of-fortran-itself">Why the unit test frameworks in Fortran rely on Ruby instead of Fortran itself?</a>>) but for this particular project, there is no possibility of being able to install additional tools on the system I am using.</p>