Hi everyone,
Can a Fortran program return 0 or 1 after end of execution?
I need it for unit testing with cmake/ctest …
In C/C++ we can do
int main()
{
cout << "Hello world!" << endl;
return 0;
}
I saw the different unit testing frameworks recommended by the fortran-wiki, and I think they’re overly complicated, and can be simplified if we’re using cmake/ctest for unit testing our code.
- cmake/ctest deems a test to be successful if the program returns an error code 0,
- and it deems the test as failed, if the program returns an error code 1 (also any other non-zero error code).
So, the simplest unit test framework would be to just return 0 or 1 based on whether the code succeeded or not.
Though I don’t know if that is possible in Fortran.
This old article mentions a way, but it is so convoluted, that I don’t want to use it: Unit testing with Fortran and CTest
A better solution that I came up with, is to …
- Create a function
foo
in Fortran that runs all the unit tests, and returns either 0 or 1 based on whether the tests failed or passed. - Call this
foo
from a C program. - In C,
return
whatever was returned fromfoo
As in …
int main()
{
return foo();
}
This, in theory, should be much more simpler than what’s mentioned in the article, and definitely more simpler than many unit test frameworks recommended by the Fortran wiki.
Is there any other simpler option?
Thanks!