22.3.8 Testing a script and running programs

MBFL allows a script to execute a “dry run”, that is: do not perform any operation on the system, just print messages describing what will happen if the script is executed with the selected options. This implies, in the MBFL model, that no external program is executed. In many scenarios we have to actively code the logic of testing execution.

We can turn on this feature by using the predefined command line option --test, Predefined options. We can programmatically enable this feature by calling the function mbfl_set_option_test() and disable it by calling the function mbfl_unset_option_test(), Predefined options. We can also save and restore this process state with the functions mbfl_option_test_save() and mbfl_option_test_restore(), Predefined options.

When this feature is turned on: mbfl_program_exec() and the other functions do not execute the program, instead they print the command line on the standard error channel and return successfully.

We can temporarily disable testing mode if we actually need to run a program anyway; we can use a statement like:

if {
     mbfl_location_enter
     {
       mbfl_location_handler_suspend_testing
       mbfl_program_exec /some/program.exe --some-option SOME_ARG
     }
     mbfl_location_leave
}
then handle_the_error
fi

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.