Matlab exit return code for CI

CI systems including CMake CTest generally rely on integer return code to detect success (== 0) or failure (!= 0).

Writing to stderr from Matlab / GNU Octave on any operating system is done by

fprintf(2, 'test message')

The error() function of Matlab / GNU Octave returns non-zero status that works well with CI systems.

GNU Octave

octave-cli --eval test_myscript

Matlab

Matlab R2019a added -batch, which makes error() return code 1.

matlab -batch test_myscript

Check last error code

From Terminal / Command Prompt, the return code from the last command is printed by:

  • Mac / Linux: echo $?
  • Windows: echo %errorlevel%