Unit Testing Frameworks for Fortran

Intel Fortran also has it: ISATTY

You have to watch out, because it’s available both as a non-standard built-in function that returns an integer, or as a function returning a logical value from the ifport module:

use iso_fortran_env, only: output_unit, error_unit, input_unit
use ifport, only: ifport_isatty => isatty

print *, "Is input unit a tty?", isatty(input_unit)  ! integer
print *, "Is output unit a tty?", ifport_isatty(output_unit) ! logical
print *, "Is error unit a tty?", ifport_isatty(error_unit) ! logical
end

I’m glad this question surfaced, as just a few days ago I read the following point in the Command-Line Interface Guidelines, unsure how to do this in Fortran:

If your command is expecting to have something piped to it and stdin is an interactive terminal, display help immediately and quit. This means it doesn’t just hang, like cat . Alternatively, you could print a log message to stderr.

Using the program above shows the difference:

$ ifort -warn all tty.f90      # warnings omitted
$ ./a.out < tty.f90 2>error.txt
 Is input unit a tty?           0
 Is output unit a tty? T
 Is error unit a tty? F
$ ./a.out                      
 Is input unit a tty?           1
 Is output unit a tty? T
 Is error unit a tty? T
2 Likes

I updated my reply :slight_smile:

2 Likes

I’m also looking for a Unit Testing framework. I created a list of 27 frameworks. I ordered them by the date they were updated. And “veggies” came up #1. Seemed pretty good, until I saw that it required fpm. I work in a Government closed network where I can’t run anything that goes out to the internet. In fact many of those 27 frameworks use fpm. I’m currently looking at ObjexxFTK.

It seems to me that there are two misconceptions here, I’ll let @everythingfunctional and @FedericoPerini correct me if I’m wrong:

  1. Veggies, is compatible with fpm for building it and fetching online its dependencies which are
iso_varying_string = { git = "https://gitlab.com/everythingfunctional/iso_varying_string.git", tag = "v3.0.3" }
strff = { git = "https://gitlab.com/everythingfunctional/strff.git", tag = "v3.1.1" }

But nothing is stopping you from downloading them individually and then compiling with another build tool like CMake for instance … or with fpm after changing in the fpm.toml file the location of the dependencies to a local folder instead of a git server online. For instance:

iso_varying_string = { path = "some/local/path/iso_varying_string" }
strff = { path = "some/local/path/strff" }

(The path should point to the folder containing the fpm.toml of the given library)

  1. fpm does not upload anything to the internet unless you want to make your project part of the Fortran registry, which in itself is still a work in progress and by default no project is uploaded to it (AFAIK).
3 Likes